diff --git a/ControlsPreference.xib b/ControlsPreference.xib new file mode 100644 index 0000000..b6547c6 --- /dev/null +++ b/ControlsPreference.xib @@ -0,0 +1,647 @@ + + + + 1060 + 11C74 + 1938 + 1138.23 + 567.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 1938 + + + NSTextField + NSCustomObject + NSMatrix + NSStepper + NSNumberFormatter + NSCustomView + NSButtonCell + NSStepperCell + NSTextFieldCell + + + com.apple.InterfaceBuilder.CocoaPlugin + + + PluginDependencyRecalculationVersion + + + + + GBAControlsPreference + + + FirstResponder + + + NSApplication + + + + 268 + + + + 268 + {{168, 260}, {101, 17}} + + + + YES + + 68288064 + 272630784 + Show bindings: + + LucidaGrande + 13 + 1044 + + + + 6 + System + controlColor + + 3 + MC42NjY2NjY2NjY3AA + + + + 6 + System + controlTextColor + + 3 + MAA + + + + + + + 268 + {{274, 259}, {168, 18}} + + + + YES + 1 + 2 + + + -2080244224 + 0 + Keyboard + + + 1211912703 + 0 + + NSRadioButton + + + + 200 + 25 + + + 67239424 + 0 + Gamepad + + + 1 + 1211912703 + 0 + + 549453824 + {18, 18} + + + + + + TU0AKgAABRgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAMAAAADAAAAAwAAAAAAAAAA +AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAADwRERGLJycnySsrK/A1NTXw +IyMjyRwcHIsJCQk8AAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFFRUVdVBQUOCoqKj/ +29vb//n5+f/6+vr/2tra/6qqqv9UVFTgHx8fdQAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUZGRl5 +dXV198PDw//8/Pz////////////////////////////U1NT/fHx89yUlJXkAAAAFAAAAAAAAAAAAAAAA +AAAAAxEREUZqamrmtbW1/+3t7f/+/v7//v7+//7+/v/9/f3//f39//39/f/39/f/xMTE/3d3d+YZGRlG +AAAAAwAAAAAAAAAAAAAACkJCQqGtra3/xsbG/+vr6//y8vL/9fX1//X19f/z8/P/9fX1//Ly8v/u7u7/ +0tLS/6+vr/9KSkqhAAAACgAAAAAAAAAAAAAAF3h4eN2/v7//z8/P/93d3f/q6ur/7+/v/+/v7//w8PD/ +7e3t/+3t7f/i4uL/zs7O/8XFxf98fHzdAAAAFwAAAAAAAAADAAAAJKSkpPjOzs7/2dnZ/+Dg4P/i4uL/ +5eXl/+bm5v/n5+f/5eXl/+Li4v/e3t7/2tra/9DQ0P+srKz4AAAAJAAAAAMAAAADAAAALrCwsPrW1tb/ +3t7e/+Tk5P/p6en/6+vr/+zs7P/p6en/6+vr/+fn5//k5OT/4ODg/9nZ2f+zs7P6AAAALgAAAAMAAAAD +AAAALp2dnezg4OD/5eXl/+rq6v/u7u7/8PDw//Dw8P/x8fH/8PDw/+7u7v/q6ur/5ubm/+Hh4f+ZmZns +AAAALgAAAAMAAAADAAAAJG5ubs/l5eX/6enp/+/v7//y8vL/9vb2//r6+v/5+fn/9/f3//b29v/x8fH/ +6+vr/+Tk5P9ra2vPAAAAJAAAAAMAAAAAAAAAFy4uLpPCwsL67Ozs//Pz8//5+fn//v7+//7+/v/+/v7/ +/v7+//v7+//19fX/8PDw/8LCwvosLCyTAAAAFwAAAAAAAAAAAAAACgAAAENfX1/S5OTk/vn5+f/+/v7/ +///////////////////////////8/Pz/5ubm/l9fX9IAAABDAAAACgAAAAAAAAAAAAAAAwAAABcAAABl +YmJi3NLS0v3////////////////////////////////V1dX9ZGRk3AAAAGUAAAAXAAAAAwAAAAAAAAAA +AAAAAAAAAAUAAAAfAAAAZTMzM8KAgIDwv7+//O3t7f/t7e3/v7+//ICAgPAzMzPCAAAAZQAAAB8AAAAF +AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAFwAAAEMAAAB3AAAAnwAAALMAAACzAAAAnwAAAHcAAABD +AAAAFwAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAoAAAAXAAAAJAAAAC4AAAAu +AAAAJAAAABcAAAAKAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +AAAAAwAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgEAAAMAAAABABIAAAEB +AAMAAAABABIAAAECAAMAAAAEAAAFxgEDAAMAAAABAAEAAAEGAAMAAAABAAIAAAERAAQAAAABAAAACAES +AAMAAAABAAEAAAEVAAMAAAABAAQAAAEWAAMAAAABABIAAAEXAAQAAAABAAAFEAEcAAMAAAABAAEAAAFS +AAMAAAABAAEAAAFTAAMAAAAEAAAFzodzAAcAABEgAAAF1gAAAAAACAAIAAgACAABAAEAAQABAAARIGFw +cGwCAAAAbW50clJHQiBYWVogB9kABQANAAAAOwAMYWNzcEFQUEwAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +AAAAAPbWAAEAAAAA0y1hcHBsvQkfoRizoa3hZ+SMa9pbkwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +AAAAAAAOclhZWgAAASwAAAAUZ1hZWgAAAUAAAAAUYlhZWgAAAVQAAAAUd3RwdAAAAWgAAAAUY2hhZAAA +AXwAAAAsclRSQwAAAagAAAAOZ1RSQwAAAbgAAAAOYlRSQwAAAcgAAAAOdmNndAAAAdgAAAYSbmRpbgAA +B+wAAAY+ZGVzYwAADiwAAABkZHNjbQAADpAAAAJCbW1vZAAAENQAAAAoY3BydAAAEPwAAAAkWFlaIAAA +AAAAAGVxAAA6MQAACZZYWVogAAAAAAAAaloAAK9yAAAa+VhZWiAAAAAAAAAnCwAAFncAAK6WWFlaIAAA +AAAAAPNSAAEAAAABFs9zZjMyAAAAAAABDEIAAAXe///zJgAAB5IAAP2R///7ov///aMAAAPcAADAbGN1 +cnYAAAAAAAAAAQHNAABjdXJ2AAAAAAAAAAEBzQAAY3VydgAAAAAAAAABAc0AAHZjZ3QAAAAAAAAAAAAD +AQAAAgAAACEAcgDsAYICNQMBA/0FJAZqB84JXwsFDNYOxBDCEtwU8hczGWQbpx3qICsiciSnJuEpDys6 +LUcvNjEdMwc07jbSOLI6jDxZPiE/5kGeQ1JE/UadSDdJyktZTNROVU/CUTJSmVP7VVlWulgOWV9asFv0 +XTRecl+mYN5iEWNGZHNlnWbCZ+ZpCmopa0ZsXm12bo1voHCvcb9y0HPhdPF2AHcOeB55MHo2exl77nzC +fZZ+cX9IgCKA/YHagruDnoSAhWmGU4c/iC+JIYoWiw2MBYz/jf2O/o//kQGSA5MGlAaU+5XilsaXq5iS +mXeaYptRnD6dLZ4enxCgBKD4oeyi4KPVpMeluqawp52ojal8qmyrV6xArSiuD67+sACxB7ILsw60DbUM +tgu3B7f/uPS56breu9C8wb2wvp+/isB3wWbCVcNExDXFJcYYxw3IAsj4yenKwMuIzEzNDs3PzpDPT9AO +0MnRhNI/0vnTr9Rm1R3V09aL10LX+Nit2WLaGNrP24bcPdz03bDeZd8M35ngJOCt4TnhxuJU4uPjdeQH +5JjlLOXA5lPm5ud56Azon+ky6cTqU+rj63TsBeyT7SHtr+477sXvUu/g8Grw8/F68gLyjPMW86D0KPSu +9TL1tfYv9qL3Dfdm9774C/hF+H74uPjx+WT53vrU/H3+i///AAAAJAB8AQIBkAJAAxQD/gUjBlwHuQk7 +CtIMiw5jEEoSOhRCFloYfRqhHMce7iEeI0slZCeEKZQrcy0kLsgwcTIaM8I1aTcOOKo6QjvaPW0+/ECI +Qg1Di0UFRnxH50lWSrVMFE1uTsNQFlFqUrJT91U9VnZXr1jjWhNbRFxtXZtew1/mYQZiJGNDZF9leGaO +Z6VovGnPauFr820Ibh5vMnBKcVxydnOQdKF1iHZldzx4F3j1edN6sXuRfHB9Vn46fx6ABIDsgdaCwIOr +hJaFgoZuh1qISIk3iiWLEov/jOuN1Y6/j6OQh5FsklKTN5QflQqV85bel8qYtpmkmpGbf5xsnVmeRZ8y +oB+hCqH0ouCjzaS0pZumhKdoqFqpZqp7q4ismq2krq2vvbDFscyyzrPRtNa12LbZt9m427nYutm73rzh +vea+77/1wQDCDcMbxCrFL8YdxvnHz8ikyXrKUcspzADM1s2szoPPWtAv0QPR19Kr03/UU9Ul1fTWv9eN +2FrZJtnw2rjbgtxI3Qfdtt5k3xHfwOBv4R/hzeJ64ynj1+SD5S7l1uZ95yTnyehu6RHpsOpR6vHrjuwq +7MbtYe377pHvKO/C8Fjw7PF/8hLyqPM+89L0YvTx9YH2EPae9yT3nPgY+KD5MfnU+pH7Z/xj/YT+m/8g +/1j/j//H//8AAAAVAEoAmQEBAXEB9QKOAzwEAATbBdMG2wgACSwKdwvHDSUOig/6EXES5RRZFcsXOBik +GgobZxy+HgsfUCCYId8jJyRqJakm4ygbKU8qfiurLNIt9i8WMDIxSzJWM2c0cDV3Nnw3fDh6OXk6cjto +PGU9ZD5mP2ZAX0FaQlJDTERBRTNGIUcQSABI7knZSsNLrkyYTYBOZk9PUDhRJFIOUvlT5FTQVb5WpFd6 +WEpZFVniWrFbgFxPXRxd6l66X4lgVmElYfRiwmORZGBlLGX5ZsZnkWhfaSxp+GrDa41sVm0bbdVuhm8w +b9lwgnEmcc1ydXMac790ZXUJda92VXb6d6F4SXjyeZt6SHr1e6N8U30Gfbp+bX8kf9uAlYFTgg+CzIOK +hESFAIW+hnuHN4fziK+JbYoqiueLpIxijR6N246bj1qQG5DbkZuSXpMhk+SUqJVrljSXApfRmJ+Zb5pA +mxOb5Zy3nYueYp85oBGg6qHFoqGjgqRkpUWmJ6cJp+2o06m6qqGriKx0rV6uSa83sCOxD7IAsvKz47TZ +tc22w7e3uLS5q7qlu6C8m72Yvpe/k8CNwYrCh8OGxIDFecZ1x3DIZslmynrLk8ynzbbOus/B0MHRwNLJ +09XU3dXz1xrYStmD2sjcM92u30rhBeLm5PrnYuoP7S/w5/WS+6X//wAAbmRpbgAAAAAAAAY2AACVRgAA +Vs8AAFKpAACRTgAAKBAAABVgAABQDQAAVDkAAtwoAAKo9QABczMAAwEAAAIAAAAYADIATQBmAH4AlgCu +AMYA3QD0AQwBIgE6AVABaAF/AZcBrgHGAd8B+AIQAigCQgJcAnYCkAKrAsYC4gL/AxsDOANVA3QDkwOz +A9MD8wQVBDcEWgR9BKMEyQTyBRwFRwVzBZ8FzAX5BigGVwaHBrgG6QccB1AHhge9B/QILAhmCKII3gkc +CVsJnAnfCiMKaQqwCvkLQwuSC+EMMAyFDNoNMA2JDeQOQQ6gDv4PYA/GEC0QlBEAEXAR4RJUEs0TRBO/ +FDwUuRU7Fb8WRxbSF10X6xh9GREZqRpDGt4bfRwhHMUdbB4SHrwfZyAVIMUhdCIlIuIjxiSyJaEmiid5 +KGcpVypEKzAsIC0LLfYu4S/KMLMxnDKDM200VTU7NiI3Cjf0ON45yzq+O8c82z3uPwFAGUEpQjlDTURf +RXJGhUeYSK5JxUrdS/tNGU41T15QhVGwUtpUEVVIVoVXxFjmWf9bIFxBXWhelV/AYPBiJmNkZKRl5Wcr +aHZpxWsWbG9txW8acHRxy3MmdIB113cweIl543tyfSN+4oClgm6EO4YVh/WJ1YvGjbiPr5Gmk6GVp5et +mbGbuJ3Dn8Oh36SSp1uqGKzTr4CyNLTft5m6VL0Uv9/CvMWQyH7LcM570XXUkde72t3eA+FJ5Kfohu2W +9XX5NPrX++382f2m/qH//wAAABYAMQBLAGYAfgCXALAAyADgAPgBEQEpAUEBWQFxAYoBowG9AdYB8AIK +AiQCPgJZAnQCkAKsAskC5gMEAyIDQANfA38DngPAA+IEBAQnBEoEbwSWBMAE7wUfBVEFhAW3BesGIAZW +BowGxAb8BzYHcQeuB+wIKghqCKsI7gkxCXYJvQoFCk8KmwroCzYLiAvbDC4MhgzfDTkNlg31DlUOuA8a +D4EP6xBWEMIRNBGnEhwSlRMQE4sUDBSLFQ4VlRYeFqsXORfIGFsY8BmJGiMavhtcG/4coR1FHekejh83 +H94giyE0Id8iiyNeJD8lKCYOJvQn3ijHKbQqnCuILHYtYy5RL0AwLzEiMhQzCTQBNPc17zbqN+g46Tnu +OvQ8BT0YPis/QEBYQWtCgUOaRLFFzEblSAFJH0o/S2FMiE2sTtZQBFEzUmBTl1TSVgtXTVh4WYRak1ur +XL5d3F78YBZhOmJgY45kvWXqZxxoUmmKasJsAW0+bndvs3DwcihzZ3Shddl3EnhLeYV633xiffd/j4En +gr+EWIX5h5uJO4rhjI6OPI/tkaCTV5UZluWYrpp+nFWeMqAOof6kKKZfqJKqxa0Br0Kxg7PQti+4krsC +vXnAB8KUxTbH3sqSzV/QHtL81ebYxNut3rnhxuTf6I/r2e6c8Ofy1PRz9fj3tP//AAAAJQBPAHgAoADH +AOwBEgE2AVwBgAGlAcsB8QIYAj8CZwKPArkC5AMQAz4DbAOdA84EAgQ3BG4EqATjBSIFYwWlBegGLQZz +BrsHBQdSB6EH8ghFCJsI8wlNCasKCwpuCtQLPAusDBsMjw0GDYAN/g6ADwIPihAXEKIRLRG5EkcS3BNx +FAsUpRVFFegWkRc7F+YYlxlLGgEauht2HDcc+B27Hn0fRCALINYhnyJrI04kPSU0JionIigdKRwqHSse +LCctLi46L0kwWTFwMogzpjTDNeQ3Cjg0OWM6mzv3PWk+4EBkQeVDckUBRpZILEnGS19M+k6PUChRvFNL +VOBWb1f+WYVbElygXjhfy2FjYv9koWZAZ+NpimszbOJui3A5ceVzmHVFdvV4qHpdfAR9pH9KgO6CkoQ0 +hdyHg4kkisaMa44Nj62RSJLhlH6WHpe7mVWa8ZyOniufwqFhovuklaY2p9KpZ6sFrJmuM6/LsWmy+LSV +tiy3xLlduvS8i74ov8nBZ8MHxKTGT8f5yZ7LTM0Czp3QG9Ge0yrUv9Zn2AjZudtr3Q7eruBX4ezjbeTk +5lPnuekU6lDrg+yt7cbu0e/U8MbxtfKQ82z0LPTr9Z72SPby94j4HPiv+S/5qvok+p77Avtm+8r8LvyH +/NH9G/1l/a/9+v5N/rn/Jv+S//8AAGRlc2MAAAAAAAAACkNvbG9yIExDRAAAAAAAAAAAAAAAAAAAAAAA +AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +AABtbHVjAAAAAAAAABIAAAAMbmJOTwAAABIAAADocHRQVAAAABYAAAD6c3ZTRQAAABAAAAEQZmlGSQAA +ABAAAAEgZGFESwAAABwAAAEwemhDTgAAAAwAAAFMZnJGUgAAABYAAAFYamFKUAAAAA4AAAFuZW5VUwAA +ABIAAAF8cGxQTAAAABIAAAGOcHRCUgAAABgAAAGgZXNFUwAAABIAAAG4emhUVwAAAA4AAAHKcnVSVQAA +ACQAAAHYa29LUgAAAAwAAAH8ZGVERQAAABAAAAIIbmxOTAAAABYAAAIYaXRJVAAAABQAAAIuAEYAYQBy +AGcAZQAtAEwAQwBEAEwAQwBEACAAYQAgAEMAbwByAGUAcwBGAOQAcgBnAC0ATABDAEQAVgDkAHIAaQAt +AEwAQwBEAEwAQwBEAC0AZgBhAHIAdgBlAHMAawDmAHIAbV9pgnIAIABMAEMARABMAEMARAAgAGMAbwB1 +AGwAZQB1AHIwqzDpMPwAIABMAEMARABDAG8AbABvAHIAIABMAEMARABLAG8AbABvAHIAIABMAEMARABM +AEMARAAgAEMAbwBsAG8AcgBpAGQAbwBMAEMARAAgAGMAbwBsAG8Acl9pgnJtsmZ2mG95OlZoBCYEMgQ1 +BEIEPQQ+BDkAIAQWBBoALQQ0BDgEQQQ/BDsENQQ5zuy37AAgAEwAQwBEAEYAYQByAGIALQBMAEMARABL +AGwAZQB1AHIAZQBuAC0ATABDAEQATABDAEQAIABjAG8AbABvAHIAaQAAbW1vZAAAAAAAAAYQAACchAAA +AADDleyhAAAAAAAAAAAAAAAAAAAAAHRleHQAAAAAQ29weXJpZ2h0IEFwcGxlLCBJbmMuLCAyMDA5AA + + + + + + 3 + MCAwAA + + + + 400 + 75 + + + {82, 18} + {4, 2} + 1151868928 + NSActionCell + + 67239424 + 0 + Radio + + 1211912703 + 0 + + 549453824 + {18, 18} + + + + + + TU0AKgAABRgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAMAAAADAAAAAwAAAAAAAAAA +AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAADwRERGLJycnySsrK/A1NTXw +IyMjyRwcHIsJCQk8AAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFFRUVdVBQUOCoqKj/ +29vb//n5+f/6+vr/2tra/6qqqv9UVFTgHx8fdQAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUZGRl5 +dXV198PDw//8/Pz////////////////////////////U1NT/fHx89yUlJXkAAAAFAAAAAAAAAAAAAAAA +AAAAAxEREUZqamrmtbW1/+3t7f/+/v7//v7+//7+/v/9/f3//f39//39/f/39/f/xMTE/3d3d+YZGRlG +AAAAAwAAAAAAAAAAAAAACkJCQqGtra3/xsbG/+vr6//y8vL/9fX1//X19f/z8/P/9fX1//Ly8v/u7u7/ +0tLS/6+vr/9KSkqhAAAACgAAAAAAAAAAAAAAF3h4eN2/v7//z8/P/93d3f/q6ur/7+/v/+/v7//w8PD/ +7e3t/+3t7f/i4uL/zs7O/8XFxf98fHzdAAAAFwAAAAAAAAADAAAAJKSkpPjOzs7/2dnZ/+Dg4P/i4uL/ +5eXl/+bm5v/n5+f/5eXl/+Li4v/e3t7/2tra/9DQ0P+srKz4AAAAJAAAAAMAAAADAAAALrCwsPrW1tb/ +3t7e/+Tk5P/p6en/6+vr/+zs7P/p6en/6+vr/+fn5//k5OT/4ODg/9nZ2f+zs7P6AAAALgAAAAMAAAAD +AAAALp2dnezg4OD/5eXl/+rq6v/u7u7/8PDw//Dw8P/x8fH/8PDw/+7u7v/q6ur/5ubm/+Hh4f+ZmZns +AAAALgAAAAMAAAADAAAAJG5ubs/l5eX/6enp/+/v7//y8vL/9vb2//r6+v/5+fn/9/f3//b29v/x8fH/ +6+vr/+Tk5P9ra2vPAAAAJAAAAAMAAAAAAAAAFy4uLpPCwsL67Ozs//Pz8//5+fn//v7+//7+/v/+/v7/ +/v7+//v7+//19fX/8PDw/8LCwvosLCyTAAAAFwAAAAAAAAAAAAAACgAAAENfX1/S5OTk/vn5+f/+/v7/ +///////////////////////////8/Pz/5ubm/l9fX9IAAABDAAAACgAAAAAAAAAAAAAAAwAAABcAAABl +YmJi3NLS0v3////////////////////////////////V1dX9ZGRk3AAAAGUAAAAXAAAAAwAAAAAAAAAA +AAAAAAAAAAUAAAAfAAAAZTMzM8KAgIDwv7+//O3t7f/t7e3/v7+//ICAgPAzMzPCAAAAZQAAAB8AAAAF +AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAFwAAAEMAAAB3AAAAnwAAALMAAACzAAAAnwAAAHcAAABD +AAAAFwAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAoAAAAXAAAAJAAAAC4AAAAu +AAAAJAAAABcAAAAKAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +AAAAAwAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADQEAAAMAAAABABIAAAEB +AAMAAAABABIAAAECAAMAAAAEAAAFugEDAAMAAAABAAEAAAEGAAMAAAABAAIAAAERAAQAAAABAAAACAES +AAMAAAABAAEAAAEVAAMAAAABAAQAAAEWAAMAAAABABIAAAEXAAQAAAABAAAFEAEcAAMAAAABAAEAAAFS +AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA + + + + + + + + 400 + 75 + + + + + 3 + MQA + + + + + + 268 + {{17, 260}, {84, 17}} + + + + YES + + 68288064 + 272630784 + Show player: + + + + + + + + + 268 + {{106, 258}, {36, 22}} + + + + YES + + -1804468671 + -1874852864 + + + + + + + + + + + + + + + + #1 + #1 + + + + + + NaN + + + + + + 3 + YES + YES + YES + + . + , + NO + NO + NO + + + YES + + 6 + System + textBackgroundColor + + + + 6 + System + textColor + + + + + + + 268 + {{147, 255}, {19, 27}} + + + + YES + + 654848 + 0 + + 1 + 1 + 4 + 1 + YES + + + + {600, 300} + + + + OEGameControllerView + + + + + + + view + + + + 2 + + + + showedBindingsChanged: + + + + 9 + + + + bindingType + + + + 10 + + + + playerField + + + + 24 + + + + playerStepper + + + + 25 + + + + showedBindingsChanged: + + + + 26 + + + + showedBindingsChanged: + + + + 27 + + + + + + 0 + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 1 + + + + + + + + + + + + 3 + + + + + + + + 4 + + + + + + + + + + 5 + + + + + 6 + + + + + 7 + + + + + 8 + + + + + 15 + + + + + + + + 16 + + + + + + + + 17 + + + + + + + + 18 + + + + + 19 + + + + + + + + 20 + + + + + 21 + + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + + + 27 + + + + + OEGameControllerView + NSView + + IBProjectSource + ./Classes/OEGameControllerView.h + + + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.macosx + + + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES + 3 + + diff --git a/English.lproj/InfoPlist.strings b/English.lproj/InfoPlist.strings new file mode 100644 index 0000000..5e45963 Binary files /dev/null and b/English.lproj/InfoPlist.strings differ diff --git a/FCEU.pch b/FCEU.pch new file mode 100644 index 0000000..7a3c792 --- /dev/null +++ b/FCEU.pch @@ -0,0 +1,42 @@ +/* + Copyright (c) 2009, OpenEmu Team + + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the OpenEmu Team nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// +// Prefix header for all source files of the 'VisualBoyAdvance' target in the 'VisualBoyAdvance' project. +// + +#ifdef __OBJC__ + #import +#else + #define __GNUC__ 4 +#endif + +#ifdef __cplusplus +#define OE_EXTERN extern "C" +#else +#define OE_EXTERN extern +#endif diff --git a/FCEU.xcodeproj/TemplateIcon.icns b/FCEU.xcodeproj/TemplateIcon.icns new file mode 100644 index 0000000..62cb701 Binary files /dev/null and b/FCEU.xcodeproj/TemplateIcon.icns differ diff --git a/FCEU.xcodeproj/project.pbxproj b/FCEU.xcodeproj/project.pbxproj new file mode 100644 index 0000000..a11f734 --- /dev/null +++ b/FCEU.xcodeproj/project.pbxproj @@ -0,0 +1,1895 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXAggregateTarget section */ + 82CAFD070FEDD57400CCDC7E /* Distribution */ = { + isa = PBXAggregateTarget; + buildConfigurationList = 82CAFD170FEDD58500CCDC7E /* Build configuration list for PBXAggregateTarget "Distribution" */; + buildPhases = ( + 82CAFD250FEDD5CD00CCDC7E /* CopyFiles */, + 82CAFD060FEDD57400CCDC7E /* ShellScript */, + ); + dependencies = ( + 82CAFD0B0FEDD57B00CCDC7E /* PBXTargetDependency */, + ); + name = Distribution; + productName = Distribution; + }; + 82D815AB0F1D882B00EF8CF5 /* Build & Install FCEU */ = { + isa = PBXAggregateTarget; + buildConfigurationList = 82D815B90F1D883D00EF8CF5 /* Build configuration list for PBXAggregateTarget "Build & Install FCEU" */; + buildPhases = ( + 82D815AA0F1D882B00EF8CF5 /* ShellScript */, + ); + dependencies = ( + 82D815AF0F1D883500EF8CF5 /* PBXTargetDependency */, + ); + name = "Build & Install FCEU"; + productName = "Build & Install"; + }; +/* End PBXAggregateTarget section */ + +/* Begin PBXBuildFile section */ + 82CAFD020FEDD54000CCDC7E /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = 82CAFD010FEDD54000CCDC7E /* dsa_pub.pem */; }; + 82CAFD1E0FEDD5B300CCDC7E /* config.yaml in CopyFiles */ = {isa = PBXBuildFile; fileRef = 82CAFD030FEDD54800CCDC7E /* config.yaml */; }; + 82EA60570F514D8C008E18C5 /* OpenEmuBase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 82EA60550F514D80008E18C5 /* OpenEmuBase.framework */; settings = {ATTRIBUTES = (Required, ); }; }; + 82EC409F0FD9EC420017FC19 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 82EC409E0FD9EC420017FC19 /* libz.dylib */; }; + 82EC40A30FD9EC5A0017FC19 /* FCEUGameEmu.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5008DAE0E8BFB3E005AECAF /* FCEUGameEmu.mm */; }; + 82EC40A40FD9EC5D0017FC19 /* FCEUGameController.m in Sources */ = {isa = PBXBuildFile; fileRef = C63E6C7A0FCDA5D6009C8555 /* FCEUGameController.m */; }; + 8D5B49B0048680CD000E48DA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C167DFE841241C02AAC07 /* InfoPlist.strings */; }; + 8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */; }; + 942D9B4414E8AFDF00772772 /* libsnes.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A0B14E8AFDE00772772 /* libsnes.c */; }; + 942D9B4514E8AFDF00772772 /* memstream.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A0D14E8AFDE00772772 /* memstream.c */; }; + 942D9B4614E8AFDF00772772 /* 01-222.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A1114E8AFDF00772772 /* 01-222.c */; }; + 942D9B4714E8AFDF00772772 /* 103.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A1214E8AFDF00772772 /* 103.c */; }; + 942D9B4814E8AFDF00772772 /* 106.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A1314E8AFDF00772772 /* 106.c */; }; + 942D9B4914E8AFDF00772772 /* 108.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A1414E8AFDF00772772 /* 108.c */; }; + 942D9B4A14E8AFDF00772772 /* 112.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A1514E8AFDF00772772 /* 112.c */; }; + 942D9B4B14E8AFDF00772772 /* 116.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A1614E8AFDF00772772 /* 116.c */; }; + 942D9B4C14E8AFDF00772772 /* 117.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A1714E8AFDF00772772 /* 117.c */; }; + 942D9B4D14E8AFDF00772772 /* 120.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A1814E8AFDF00772772 /* 120.c */; }; + 942D9B4E14E8AFDF00772772 /* 121.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A1914E8AFDF00772772 /* 121.c */; }; + 942D9B4F14E8AFDF00772772 /* 12in1.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A1A14E8AFDF00772772 /* 12in1.c */; }; + 942D9B5014E8AFDF00772772 /* 15.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A1B14E8AFDF00772772 /* 15.c */; }; + 942D9B5114E8AFDF00772772 /* 156.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A1C14E8AFDF00772772 /* 156.c */; }; + 942D9B5214E8AFDF00772772 /* 164.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A1D14E8AFDF00772772 /* 164.c */; }; + 942D9B5314E8AFDF00772772 /* 168.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A1E14E8AFDF00772772 /* 168.c */; }; + 942D9B5414E8AFDF00772772 /* 170.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A1F14E8AFDF00772772 /* 170.c */; }; + 942D9B5514E8AFDF00772772 /* 175.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A2014E8AFDF00772772 /* 175.c */; }; + 942D9B5614E8AFDF00772772 /* 176.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A2114E8AFDF00772772 /* 176.c */; }; + 942D9B5714E8AFDF00772772 /* 177.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A2214E8AFDF00772772 /* 177.c */; }; + 942D9B5814E8AFDF00772772 /* 178.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A2314E8AFDF00772772 /* 178.c */; }; + 942D9B5914E8AFDF00772772 /* 183.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A2414E8AFDF00772772 /* 183.c */; }; + 942D9B5A14E8AFDF00772772 /* 185.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A2514E8AFDF00772772 /* 185.c */; }; + 942D9B5B14E8AFDF00772772 /* 186.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A2614E8AFDF00772772 /* 186.c */; }; + 942D9B5C14E8AFDF00772772 /* 187.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A2714E8AFDF00772772 /* 187.c */; }; + 942D9B5D14E8AFDF00772772 /* 189.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A2814E8AFDF00772772 /* 189.c */; }; + 942D9B5E14E8AFDF00772772 /* 193.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A2914E8AFDF00772772 /* 193.c */; }; + 942D9B5F14E8AFDF00772772 /* 199.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A2A14E8AFDF00772772 /* 199.c */; }; + 942D9B6014E8AFDF00772772 /* 208.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A2B14E8AFDF00772772 /* 208.c */; }; + 942D9B6114E8AFDF00772772 /* 222.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A2C14E8AFDF00772772 /* 222.c */; }; + 942D9B6214E8AFDF00772772 /* 225.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A2D14E8AFDF00772772 /* 225.c */; }; + 942D9B6314E8AFDF00772772 /* 23.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A2E14E8AFDF00772772 /* 23.c */; }; + 942D9B6414E8AFDF00772772 /* 235.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A2F14E8AFDF00772772 /* 235.c */; }; + 942D9B6514E8AFDF00772772 /* 253.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A3014E8AFDF00772772 /* 253.c */; }; + 942D9B6614E8AFDF00772772 /* 3d-block.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A3114E8AFDF00772772 /* 3d-block.c */; }; + 942D9B6714E8AFDF00772772 /* 411120-c.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A3214E8AFDF00772772 /* 411120-c.c */; }; + 942D9B6814E8AFDF00772772 /* 43.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A3314E8AFDF00772772 /* 43.c */; }; + 942D9B6914E8AFDF00772772 /* 57.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A3414E8AFDF00772772 /* 57.c */; }; + 942D9B6A14E8AFDF00772772 /* 603-5052.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A3514E8AFDF00772772 /* 603-5052.c */; }; + 942D9B6B14E8AFDF00772772 /* 68.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A3614E8AFDF00772772 /* 68.c */; }; + 942D9B6C14E8AFDF00772772 /* 8157.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A3714E8AFDF00772772 /* 8157.c */; }; + 942D9B6D14E8AFDF00772772 /* 8237.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A3814E8AFDF00772772 /* 8237.c */; }; + 942D9B6E14E8AFDF00772772 /* 830118C.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A3914E8AFDF00772772 /* 830118C.c */; }; + 942D9B6F14E8AFDF00772772 /* 88.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A3A14E8AFDF00772772 /* 88.c */; }; + 942D9B7014E8AFDF00772772 /* 90.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A3B14E8AFDF00772772 /* 90.c */; }; + 942D9B7114E8AFDF00772772 /* 95.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A3C14E8AFDF00772772 /* 95.c */; }; + 942D9B7414E8AFDF00772772 /* a9746.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A3F14E8AFDF00772772 /* a9746.c */; }; + 942D9B7514E8AFDF00772772 /* ac-08.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A4014E8AFDF00772772 /* ac-08.c */; }; + 942D9B7614E8AFDF00772772 /* addrlatch.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A4114E8AFDF00772772 /* addrlatch.c */; }; + 942D9B7714E8AFDF00772772 /* ax5705.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A4214E8AFDF00772772 /* ax5705.c */; }; + 942D9B7814E8AFDF00772772 /* bandai.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A4314E8AFDF00772772 /* bandai.c */; }; + 942D9B7914E8AFDF00772772 /* bmc13in1jy110.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A4414E8AFDF00772772 /* bmc13in1jy110.c */; }; + 942D9B7A14E8AFDF00772772 /* bmc42in1r.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A4514E8AFDF00772772 /* bmc42in1r.c */; }; + 942D9B7B14E8AFDF00772772 /* bmc64in1nr.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A4614E8AFDF00772772 /* bmc64in1nr.c */; }; + 942D9B7C14E8AFDF00772772 /* bmc70in1.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A4714E8AFDF00772772 /* bmc70in1.c */; }; + 942D9B7D14E8AFDF00772772 /* bonza.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A4814E8AFDF00772772 /* bonza.c */; }; + 942D9B7E14E8AFDF00772772 /* bs-5.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A4914E8AFDF00772772 /* bs-5.c */; }; + 942D9B7F14E8AFDF00772772 /* copyfami_emu.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A4A14E8AFDF00772772 /* copyfami_emu.c */; }; + 942D9B8014E8AFDF00772772 /* copyfami_hwi.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A4B14E8AFDF00772772 /* copyfami_hwi.c */; }; + 942D9B8114E8AFDF00772772 /* dance2000.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A4C14E8AFDF00772772 /* dance2000.c */; }; + 942D9B8214E8AFDF00772772 /* datalatch.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A4D14E8AFDF00772772 /* datalatch.c */; }; + 942D9B8314E8AFDF00772772 /* deirom.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A4E14E8AFDF00772772 /* deirom.c */; }; + 942D9B8414E8AFDF00772772 /* dream.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A4F14E8AFDF00772772 /* dream.c */; }; + 942D9B8514E8AFDF00772772 /* dummy_mapper.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A5014E8AFDF00772772 /* dummy_mapper.c */; }; + 942D9B8614E8AFDF00772772 /* edu2000.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A5114E8AFDF00772772 /* edu2000.c */; }; + 942D9B8714E8AFDF00772772 /* fk23c.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A5214E8AFDF00772772 /* fk23c.c */; }; + 942D9B8814E8AFDF00772772 /* ghostbusters63in1.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A5314E8AFDF00772772 /* ghostbusters63in1.c */; }; + 942D9B8914E8AFDF00772772 /* gs-2004.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A5414E8AFDF00772772 /* gs-2004.c */; }; + 942D9B8A14E8AFDF00772772 /* gs-2013.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A5514E8AFDF00772772 /* gs-2013.c */; }; + 942D9B8B14E8AFDF00772772 /* h2288.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A5614E8AFDF00772772 /* h2288.c */; }; + 942D9B8C14E8AFDF00772772 /* karaoke.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A5714E8AFDF00772772 /* karaoke.c */; }; + 942D9B8D14E8AFDF00772772 /* kof97.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A5814E8AFDF00772772 /* kof97.c */; }; + 942D9B8E14E8AFDF00772772 /* konami-qtai.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A5914E8AFDF00772772 /* konami-qtai.c */; }; + 942D9B8F14E8AFDF00772772 /* KS7012.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A5A14E8AFDF00772772 /* KS7012.c */; }; + 942D9B9014E8AFDF00772772 /* KS7013.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A5B14E8AFDF00772772 /* KS7013.c */; }; + 942D9B9114E8AFDF00772772 /* KS7017.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A5C14E8AFDF00772772 /* KS7017.c */; }; + 942D9B9214E8AFDF00772772 /* KS7032.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A5D14E8AFDF00772772 /* KS7032.c */; }; + 942D9B9314E8AFDF00772772 /* KS7037.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A5E14E8AFDF00772772 /* KS7037.c */; }; + 942D9B9414E8AFDF00772772 /* KS7057.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A5F14E8AFDF00772772 /* KS7057.c */; }; + 942D9B9514E8AFDF00772772 /* le05.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A6014E8AFDF00772772 /* le05.c */; }; + 942D9B9614E8AFDF00772772 /* malee.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A6114E8AFDF00772772 /* malee.c */; }; + 942D9B9714E8AFDF00772772 /* mmc1.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A6314E8AFDF00772772 /* mmc1.c */; }; + 942D9B9814E8AFDF00772772 /* mmc3.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A6414E8AFDF00772772 /* mmc3.c */; }; + 942D9B9914E8AFDF00772772 /* mmc5.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A6614E8AFDF00772772 /* mmc5.c */; }; + 942D9B9A14E8AFDF00772772 /* n106.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A6714E8AFDF00772772 /* n106.c */; }; + 942D9B9B14E8AFDF00772772 /* n625092.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A6814E8AFDF00772772 /* n625092.c */; }; + 942D9B9C14E8AFDF00772772 /* novel.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A6914E8AFDF00772772 /* novel.c */; }; + 942D9B9D14E8AFDF00772772 /* onebus.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A6A14E8AFDF00772772 /* onebus.c */; }; + 942D9B9E14E8AFDF00772772 /* pec-586.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A6B14E8AFDF00772772 /* pec-586.c */; }; + 942D9B9F14E8AFDF00772772 /* sachen.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A6C14E8AFDF00772772 /* sachen.c */; }; + 942D9BA014E8AFDF00772772 /* sc-127.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A6D14E8AFDF00772772 /* sc-127.c */; }; + 942D9BA114E8AFDF00772772 /* sheroes.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A6E14E8AFDF00772772 /* sheroes.c */; }; + 942D9BA214E8AFDF00772772 /* sl1632.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A6F14E8AFDF00772772 /* sl1632.c */; }; + 942D9BA314E8AFDF00772772 /* smb2j.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A7014E8AFDF00772772 /* smb2j.c */; }; + 942D9BA414E8AFDF00772772 /* subor.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A7114E8AFDF00772772 /* subor.c */; }; + 942D9BA514E8AFDF00772772 /* super24.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A7214E8AFDF00772772 /* super24.c */; }; + 942D9BA614E8AFDF00772772 /* supervision.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A7314E8AFDF00772772 /* supervision.c */; }; + 942D9BA714E8AFDF00772772 /* t-227-1.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A7414E8AFDF00772772 /* t-227-1.c */; }; + 942D9BA814E8AFDF00772772 /* t-262.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A7514E8AFDF00772772 /* t-262.c */; }; + 942D9BA914E8AFDF00772772 /* tengen.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A7614E8AFDF00772772 /* tengen.c */; }; + 942D9BAA14E8AFDF00772772 /* tf-1201.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A7714E8AFDF00772772 /* tf-1201.c */; }; + 942D9BAB14E8AFDF00772772 /* transformer.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A7814E8AFDF00772772 /* transformer.c */; }; + 942D9BAC14E8AFDF00772772 /* vrc7.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A7914E8AFDF00772772 /* vrc7.c */; }; + 942D9BAD14E8AFDF00772772 /* yoko.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A7A14E8AFDF00772772 /* yoko.c */; }; + 942D9BAE14E8AFDF00772772 /* cart.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A7B14E8AFDF00772772 /* cart.c */; }; + 942D9BAF14E8AFDF00772772 /* cheat.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A7D14E8AFDF00772772 /* cheat.c */; }; + 942D9BB014E8AFDF00772772 /* fceu.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A8114E8AFDF00772772 /* fceu.c */; }; + 942D9BB114E8AFDF00772772 /* fds.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A8414E8AFDF00772772 /* fds.c */; }; + 942D9BB214E8AFDF00772772 /* file.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A8614E8AFDF00772772 /* file.c */; }; + 942D9BC114E8AFDF00772772 /* general.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9A9D14E8AFDF00772772 /* general.c */; }; + 942D9BC214E8AFDF00772772 /* ines.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AA214E8AFDF00772772 /* ines.c */; }; + 942D9BC314E8AFDF00772772 /* arkanoid.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AA514E8AFDF00772772 /* arkanoid.c */; }; + 942D9BC414E8AFDF00772772 /* bbox.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AA614E8AFDF00772772 /* bbox.c */; }; + 942D9BC514E8AFDF00772772 /* bworld.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AA714E8AFDF00772772 /* bworld.c */; }; + 942D9BC614E8AFDF00772772 /* cursor.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AA814E8AFDF00772772 /* cursor.c */; }; + 942D9BC714E8AFDF00772772 /* fkb.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AA914E8AFDF00772772 /* fkb.c */; }; + 942D9BC814E8AFDF00772772 /* ftrainer.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AAB14E8AFDF00772772 /* ftrainer.c */; }; + 942D9BC914E8AFDF00772772 /* hypershot.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AAC14E8AFDF00772772 /* hypershot.c */; }; + 942D9BCA14E8AFDF00772772 /* mahjong.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AAD14E8AFDF00772772 /* mahjong.c */; }; + 942D9BCB14E8AFDF00772772 /* mouse.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AAE14E8AFDF00772772 /* mouse.c */; }; + 942D9BCC14E8AFDF00772772 /* oekakids.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AAF14E8AFDF00772772 /* oekakids.c */; }; + 942D9BCD14E8AFDF00772772 /* pads.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AB014E8AFDF00772772 /* pads.c */; }; + 942D9BCE14E8AFE000772772 /* pec586kb.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AB114E8AFDF00772772 /* pec586kb.c */; }; + 942D9BCF14E8AFE000772772 /* powerpad.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AB214E8AFDF00772772 /* powerpad.c */; }; + 942D9BD014E8AFE000772772 /* quiz.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AB314E8AFDF00772772 /* quiz.c */; }; + 942D9BD114E8AFE000772772 /* shadow.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AB414E8AFDF00772772 /* shadow.c */; }; + 942D9BD214E8AFE000772772 /* suborkb.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AB614E8AFDF00772772 /* suborkb.c */; }; + 942D9BD314E8AFE000772772 /* toprider.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AB814E8AFDF00772772 /* toprider.c */; }; + 942D9BD414E8AFE000772772 /* zapper.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AB914E8AFDF00772772 /* zapper.c */; }; + 942D9BD514E8AFE000772772 /* input.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9ABA14E8AFDF00772772 /* input.c */; }; + 942D9BD614E8AFE000772772 /* 151.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9ABD14E8AFDF00772772 /* 151.c */; }; + 942D9BD714E8AFE000772772 /* 157.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9ABE14E8AFDF00772772 /* 157.c */; }; + 942D9BD814E8AFE000772772 /* 17.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9ABF14E8AFDF00772772 /* 17.c */; }; + 942D9BD914E8AFE000772772 /* 18.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AC014E8AFDF00772772 /* 18.c */; }; + 942D9BDA14E8AFE000772772 /* 201.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AC114E8AFDF00772772 /* 201.c */; }; + 942D9BDB14E8AFE000772772 /* 202.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AC214E8AFDF00772772 /* 202.c */; }; + 942D9BDC14E8AFE000772772 /* 203.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AC314E8AFDF00772772 /* 203.c */; }; + 942D9BDD14E8AFE000772772 /* 204.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AC414E8AFDF00772772 /* 204.c */; }; + 942D9BDE14E8AFE000772772 /* 21.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AC514E8AFDF00772772 /* 21.c */; }; + 942D9BDF14E8AFE000772772 /* 212.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AC614E8AFDF00772772 /* 212.c */; }; + 942D9BE014E8AFE000772772 /* 213.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AC714E8AFDF00772772 /* 213.c */; }; + 942D9BE114E8AFE000772772 /* 214.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AC814E8AFDF00772772 /* 214.c */; }; + 942D9BE214E8AFE000772772 /* 215.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AC914E8AFDF00772772 /* 215.c */; }; + 942D9BE314E8AFE000772772 /* 217.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9ACA14E8AFDF00772772 /* 217.c */; }; + 942D9BE414E8AFE000772772 /* 22.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9ACB14E8AFDF00772772 /* 22.c */; }; + 942D9BE514E8AFE000772772 /* 227.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9ACC14E8AFDF00772772 /* 227.c */; }; + 942D9BE614E8AFE000772772 /* 228.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9ACD14E8AFDF00772772 /* 228.c */; }; + 942D9BE714E8AFE000772772 /* 229.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9ACE14E8AFDF00772772 /* 229.c */; }; + 942D9BE814E8AFE000772772 /* 230.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9ACF14E8AFDF00772772 /* 230.c */; }; + 942D9BE914E8AFE000772772 /* 231.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AD014E8AFDF00772772 /* 231.c */; }; + 942D9BEA14E8AFE000772772 /* 232.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AD114E8AFDF00772772 /* 232.c */; }; + 942D9BEB14E8AFE000772772 /* 234.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AD214E8AFDF00772772 /* 234.c */; }; + 942D9BEC14E8AFE000772772 /* 241.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AD314E8AFDF00772772 /* 241.c */; }; + 942D9BED14E8AFE000772772 /* 242.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AD414E8AFDF00772772 /* 242.c */; }; + 942D9BEE14E8AFE000772772 /* 244.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AD514E8AFDF00772772 /* 244.c */; }; + 942D9BEF14E8AFE000772772 /* 246.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AD614E8AFDF00772772 /* 246.c */; }; + 942D9BF014E8AFE000772772 /* 24and26.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AD714E8AFDF00772772 /* 24and26.c */; }; + 942D9BF114E8AFE000772772 /* 25.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AD814E8AFDF00772772 /* 25.c */; }; + 942D9BF214E8AFE000772772 /* 255.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AD914E8AFDF00772772 /* 255.c */; }; + 942D9BF314E8AFE000772772 /* 27.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9ADA14E8AFDF00772772 /* 27.c */; }; + 942D9BF414E8AFE000772772 /* 32.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9ADB14E8AFDF00772772 /* 32.c */; }; + 942D9BF514E8AFE000772772 /* 33.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9ADC14E8AFDF00772772 /* 33.c */; }; + 942D9BF614E8AFE000772772 /* 40.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9ADD14E8AFDF00772772 /* 40.c */; }; + 942D9BF714E8AFE000772772 /* 41.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9ADE14E8AFDF00772772 /* 41.c */; }; + 942D9BF814E8AFE000772772 /* 42.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9ADF14E8AFDF00772772 /* 42.c */; }; + 942D9BF914E8AFE000772772 /* 46.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AE014E8AFDF00772772 /* 46.c */; }; + 942D9BFA14E8AFE000772772 /* 50.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AE114E8AFDF00772772 /* 50.c */; }; + 942D9BFB14E8AFE000772772 /* 51.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AE214E8AFDF00772772 /* 51.c */; }; + 942D9BFC14E8AFE000772772 /* 59.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AE314E8AFDF00772772 /* 59.c */; }; + 942D9BFD14E8AFE000772772 /* 6.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AE414E8AFDF00772772 /* 6.c */; }; + 942D9BFE14E8AFE000772772 /* 61.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AE514E8AFDF00772772 /* 61.c */; }; + 942D9BFF14E8AFE000772772 /* 62.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AE614E8AFDF00772772 /* 62.c */; }; + 942D9C0014E8AFE000772772 /* 65.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AE714E8AFDF00772772 /* 65.c */; }; + 942D9C0114E8AFE000772772 /* 67.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AE814E8AFDF00772772 /* 67.c */; }; + 942D9C0214E8AFE000772772 /* 69.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AE914E8AFDF00772772 /* 69.c */; }; + 942D9C0314E8AFE000772772 /* 71.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AEA14E8AFDF00772772 /* 71.c */; }; + 942D9C0414E8AFE000772772 /* 72.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AEB14E8AFDF00772772 /* 72.c */; }; + 942D9C0514E8AFE000772772 /* 73.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AEC14E8AFDF00772772 /* 73.c */; }; + 942D9C0614E8AFE000772772 /* 75.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AED14E8AFDF00772772 /* 75.c */; }; + 942D9C0714E8AFE000772772 /* 76.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AEE14E8AFDF00772772 /* 76.c */; }; + 942D9C0814E8AFE000772772 /* 77.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AEF14E8AFDF00772772 /* 77.c */; }; + 942D9C0914E8AFE000772772 /* 79.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AF014E8AFDF00772772 /* 79.c */; }; + 942D9C0A14E8AFE000772772 /* 8.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AF114E8AFDF00772772 /* 8.c */; }; + 942D9C0B14E8AFE000772772 /* 80.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AF214E8AFDF00772772 /* 80.c */; }; + 942D9C0C14E8AFE000772772 /* 82.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AF314E8AFDF00772772 /* 82.c */; }; + 942D9C0D14E8AFE000772772 /* 83.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AF414E8AFDF00772772 /* 83.c */; }; + 942D9C0E14E8AFE000772772 /* 85.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AF514E8AFDF00772772 /* 85.c */; }; + 942D9C0F14E8AFE000772772 /* 86.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AF614E8AFDF00772772 /* 86.c */; }; + 942D9C1014E8AFE000772772 /* 89.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AF714E8AFDF00772772 /* 89.c */; }; + 942D9C1114E8AFE000772772 /* 91.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AF814E8AFDF00772772 /* 91.c */; }; + 942D9C1214E8AFE000772772 /* 92.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AF914E8AFDF00772772 /* 92.c */; }; + 942D9C1314E8AFE000772772 /* 97.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AFA14E8AFDF00772772 /* 97.c */; }; + 942D9C1414E8AFE000772772 /* 99.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AFB14E8AFDF00772772 /* 99.c */; }; + 942D9C1514E8AFE000772772 /* emu2413.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9AFC14E8AFDF00772772 /* emu2413.c */; }; + 942D9C1614E8AFE000772772 /* mmc2and4.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B0014E8AFDF00772772 /* mmc2and4.c */; }; + 942D9C1714E8AFE000772772 /* simple.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B0114E8AFDF00772772 /* simple.c */; }; + 942D9C1814E8AFE000772772 /* md5.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B0314E8AFDF00772772 /* md5.c */; }; + 942D9C1914E8AFE000772772 /* memory.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B0514E8AFDF00772772 /* memory.c */; }; + 942D9C1A14E8AFE000772772 /* mycrc32.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B0714E8AFDF00772772 /* mycrc32.c */; }; + 942D9C1B14E8AFE000772772 /* myendian.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B0814E8AFDF00772772 /* myendian.c */; }; + 942D9C1C14E8AFE000772772 /* palette.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B0B14E8AFDF00772772 /* palette.c */; }; + 942D9C1E14E8AFE000772772 /* ppu.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B1414E8AFDF00772772 /* ppu.c */; }; + 942D9C1F14E8AFE000772772 /* sound.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B1814E8AFDF00772772 /* sound.c */; }; + 942D9C2014E8AFE000772772 /* state.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B1C14E8AFDF00772772 /* state.c */; }; + 942D9C2114E8AFE000772772 /* unif.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B1F14E8AFDF00772772 /* unif.c */; }; + 942D9C2214E8AFE000772772 /* unzip.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B2114E8AFDF00772772 /* unzip.c */; }; + 942D9C2314E8AFE000772772 /* vsuni.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B2314E8AFDF00772772 /* vsuni.c */; }; + 942D9C2414E8AFE000772772 /* x6502.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B2514E8AFDF00772772 /* x6502.c */; }; + 942D9C2514E8AFE000772772 /* adler32.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B2914E8AFDF00772772 /* adler32.c */; }; + 942D9C2614E8AFE000772772 /* compress.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B2A14E8AFDF00772772 /* compress.c */; }; + 942D9C2714E8AFE000772772 /* crc32.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B2B14E8AFDF00772772 /* crc32.c */; }; + 942D9C2814E8AFE000772772 /* deflate.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B2C14E8AFDF00772772 /* deflate.c */; }; + 942D9C2914E8AFE000772772 /* gzio.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B2E14E8AFDF00772772 /* gzio.c */; }; + 942D9C2A14E8AFE000772772 /* infblock.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B2F14E8AFDF00772772 /* infblock.c */; }; + 942D9C2B14E8AFE000772772 /* infcodes.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B3114E8AFDF00772772 /* infcodes.c */; }; + 942D9C2C14E8AFE000772772 /* inffast.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B3314E8AFDF00772772 /* inffast.c */; }; + 942D9C2D14E8AFE000772772 /* inflate.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B3614E8AFDF00772772 /* inflate.c */; }; + 942D9C2E14E8AFE000772772 /* inftrees.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B3714E8AFDF00772772 /* inftrees.c */; }; + 942D9C2F14E8AFE000772772 /* infutil.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B3914E8AFDF00772772 /* infutil.c */; }; + 942D9C3014E8AFE000772772 /* trees.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B3B14E8AFDF00772772 /* trees.c */; }; + 942D9C3114E8AFE000772772 /* uncompr.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B3D14E8AFDF00772772 /* uncompr.c */; }; + 942D9C3314E8AFE000772772 /* zutil.c in Sources */ = {isa = PBXBuildFile; fileRef = 942D9B4214E8AFDF00772772 /* zutil.c */; }; + 945942D014E4F2DC0015D2AA /* FCEUX.icns in Resources */ = {isa = PBXBuildFile; fileRef = 945942CF14E4F2DC0015D2AA /* FCEUX.icns */; }; + C6C71E4A0FCDE25F002FAC4D /* ControlsPreference.xib in Resources */ = {isa = PBXBuildFile; fileRef = C63E6C640FCDA565009C8555 /* ControlsPreference.xib */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 1B32153014DDDB4000C5B50A /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 8227754F148946DF00B19E27; + remoteInfo = GameGear; + }; + 378394E41029257000168304 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 3887A7F61024D1F9000FC4CF; + remoteInfo = OESaveStateQLPlugin; + }; + 82CAFD0A0FEDD57B00CCDC7E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 089C1669FE841209C02AAC07 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 8D5B49AC048680CD000E48DA; + remoteInfo = VisualBoyAdvance; + }; + 82D815AE0F1D883500EF8CF5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 089C1669FE841209C02AAC07 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 8D5B49AC048680CD000E48DA; + remoteInfo = VisualBoyAdvance; + }; + 82EA60500F514D80008E18C5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 8D15AC370486D014006FF6A4; + remoteInfo = OpenEmu; + }; + 82EA60540F514D80008E18C5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 82444BA10F51256C007C171B; + remoteInfo = OpenEmuBase; + }; + 8390474B14597FE200335E4F /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 1415540F1442B3B300A01683; + remoteInfo = N64; + }; + C62A2649116F094C0003DEE4 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 1BEF2A9411682A530090F72B; + remoteInfo = OpenEmuHelperApp; + }; + C646575813771F4F002A4F70 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C646574813771F12002A4F70; + remoteInfo = "GameBoy Advance"; + }; + C6B948FF13651ACD00A425F0 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C6711807136367240034379A; + remoteInfo = OpenEmuSystem; + }; + C6B9490113651ACD00A425F0 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C671180F136368330034379A; + remoteInfo = SegaMasterSystem; + }; + C6B9490313651ACD00A425F0 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C64BB08D136478E600C1AB23; + remoteInfo = NES; + }; + C6B9490513651ACD00A425F0 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C6480FC113648F670094FA33; + remoteInfo = SuperNES; + }; + C6B9490713651ACD00A425F0 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C6B947AF1364ECA600A425F0; + remoteInfo = GameBoy; + }; + C6B9490913651ACD00A425F0 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C6B947E61365080B00A425F0; + remoteInfo = Genesis; + }; + C6B9E3FC14841AC400836111 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 820EB74A1483F9A2008EC398; + remoteInfo = NeoGeoPocket; + }; + C6E916860FD34D5800AC2CCC /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = 82444BA00F51256C007C171B; + remoteInfo = OpenEmuBase; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 82CAFD250FEDD5CD00CCDC7E /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 16; + files = ( + 82CAFD1E0FEDD5B300CCDC7E /* config.yaml in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 089C1672FE841209C02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; + 089C167EFE841241C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; }; + 089C167FFE841241C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; }; + 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; + 32DBCF630370AF2F00C91783 /* FCEU.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FCEU.pch; sourceTree = ""; }; + 82CAFD010FEDD54000CCDC7E /* dsa_pub.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = dsa_pub.pem; sourceTree = ""; }; + 82CAFD030FEDD54800CCDC7E /* config.yaml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = config.yaml; sourceTree = ""; }; + 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = OpenEmu.xcodeproj; path = ../OpenEmu/OpenEmu.xcodeproj; sourceTree = SOURCE_ROOT; }; + 82EC409E0FD9EC420017FC19 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; }; + 8D5B49B6048680CD000E48DA /* FCEU.oecoreplugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FCEU.oecoreplugin; sourceTree = BUILT_PRODUCTS_DIR; }; + 8D5B49B7048680CD000E48DA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 942D9A0B14E8AFDE00772772 /* libsnes.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = libsnes.c; sourceTree = ""; }; + 942D9A0C14E8AFDE00772772 /* libsnes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = libsnes.h; sourceTree = ""; }; + 942D9A0D14E8AFDE00772772 /* memstream.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = memstream.c; sourceTree = ""; }; + 942D9A0E14E8AFDE00772772 /* memstream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = memstream.h; sourceTree = ""; }; + 942D9A1114E8AFDF00772772 /* 01-222.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "01-222.c"; sourceTree = ""; }; + 942D9A1214E8AFDF00772772 /* 103.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 103.c; sourceTree = ""; }; + 942D9A1314E8AFDF00772772 /* 106.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 106.c; sourceTree = ""; }; + 942D9A1414E8AFDF00772772 /* 108.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 108.c; sourceTree = ""; }; + 942D9A1514E8AFDF00772772 /* 112.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 112.c; sourceTree = ""; }; + 942D9A1614E8AFDF00772772 /* 116.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 116.c; sourceTree = ""; }; + 942D9A1714E8AFDF00772772 /* 117.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 117.c; sourceTree = ""; }; + 942D9A1814E8AFDF00772772 /* 120.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 120.c; sourceTree = ""; }; + 942D9A1914E8AFDF00772772 /* 121.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 121.c; sourceTree = ""; }; + 942D9A1A14E8AFDF00772772 /* 12in1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 12in1.c; sourceTree = ""; }; + 942D9A1B14E8AFDF00772772 /* 15.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 15.c; sourceTree = ""; }; + 942D9A1C14E8AFDF00772772 /* 156.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 156.c; sourceTree = ""; }; + 942D9A1D14E8AFDF00772772 /* 164.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 164.c; sourceTree = ""; }; + 942D9A1E14E8AFDF00772772 /* 168.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 168.c; sourceTree = ""; }; + 942D9A1F14E8AFDF00772772 /* 170.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 170.c; sourceTree = ""; }; + 942D9A2014E8AFDF00772772 /* 175.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 175.c; sourceTree = ""; }; + 942D9A2114E8AFDF00772772 /* 176.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 176.c; sourceTree = ""; }; + 942D9A2214E8AFDF00772772 /* 177.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 177.c; sourceTree = ""; }; + 942D9A2314E8AFDF00772772 /* 178.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 178.c; sourceTree = ""; }; + 942D9A2414E8AFDF00772772 /* 183.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 183.c; sourceTree = ""; }; + 942D9A2514E8AFDF00772772 /* 185.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 185.c; sourceTree = ""; }; + 942D9A2614E8AFDF00772772 /* 186.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 186.c; sourceTree = ""; }; + 942D9A2714E8AFDF00772772 /* 187.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 187.c; sourceTree = ""; }; + 942D9A2814E8AFDF00772772 /* 189.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 189.c; sourceTree = ""; }; + 942D9A2914E8AFDF00772772 /* 193.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 193.c; sourceTree = ""; }; + 942D9A2A14E8AFDF00772772 /* 199.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 199.c; sourceTree = ""; }; + 942D9A2B14E8AFDF00772772 /* 208.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 208.c; sourceTree = ""; }; + 942D9A2C14E8AFDF00772772 /* 222.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 222.c; sourceTree = ""; }; + 942D9A2D14E8AFDF00772772 /* 225.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 225.c; sourceTree = ""; }; + 942D9A2E14E8AFDF00772772 /* 23.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 23.c; sourceTree = ""; }; + 942D9A2F14E8AFDF00772772 /* 235.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 235.c; sourceTree = ""; }; + 942D9A3014E8AFDF00772772 /* 253.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 253.c; sourceTree = ""; }; + 942D9A3114E8AFDF00772772 /* 3d-block.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "3d-block.c"; sourceTree = ""; }; + 942D9A3214E8AFDF00772772 /* 411120-c.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "411120-c.c"; sourceTree = ""; }; + 942D9A3314E8AFDF00772772 /* 43.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 43.c; sourceTree = ""; }; + 942D9A3414E8AFDF00772772 /* 57.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 57.c; sourceTree = ""; }; + 942D9A3514E8AFDF00772772 /* 603-5052.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "603-5052.c"; sourceTree = ""; }; + 942D9A3614E8AFDF00772772 /* 68.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 68.c; sourceTree = ""; }; + 942D9A3714E8AFDF00772772 /* 8157.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 8157.c; sourceTree = ""; }; + 942D9A3814E8AFDF00772772 /* 8237.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 8237.c; sourceTree = ""; }; + 942D9A3914E8AFDF00772772 /* 830118C.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 830118C.c; sourceTree = ""; }; + 942D9A3A14E8AFDF00772772 /* 88.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 88.c; sourceTree = ""; }; + 942D9A3B14E8AFDF00772772 /* 90.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 90.c; sourceTree = ""; }; + 942D9A3C14E8AFDF00772772 /* 95.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 95.c; sourceTree = ""; }; + 942D9A3D14E8AFDF00772772 /* __serial.c.win32 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = __serial.c.win32; sourceTree = ""; }; + 942D9A3E14E8AFDF00772772 /* __serial.h.win32 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = __serial.h.win32; sourceTree = ""; }; + 942D9A3F14E8AFDF00772772 /* a9746.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = a9746.c; sourceTree = ""; }; + 942D9A4014E8AFDF00772772 /* ac-08.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "ac-08.c"; sourceTree = ""; }; + 942D9A4114E8AFDF00772772 /* addrlatch.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = addrlatch.c; sourceTree = ""; }; + 942D9A4214E8AFDF00772772 /* ax5705.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ax5705.c; sourceTree = ""; }; + 942D9A4314E8AFDF00772772 /* bandai.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bandai.c; sourceTree = ""; }; + 942D9A4414E8AFDF00772772 /* bmc13in1jy110.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bmc13in1jy110.c; sourceTree = ""; }; + 942D9A4514E8AFDF00772772 /* bmc42in1r.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bmc42in1r.c; sourceTree = ""; }; + 942D9A4614E8AFDF00772772 /* bmc64in1nr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bmc64in1nr.c; sourceTree = ""; }; + 942D9A4714E8AFDF00772772 /* bmc70in1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bmc70in1.c; sourceTree = ""; }; + 942D9A4814E8AFDF00772772 /* bonza.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bonza.c; sourceTree = ""; }; + 942D9A4914E8AFDF00772772 /* bs-5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "bs-5.c"; sourceTree = ""; }; + 942D9A4A14E8AFDF00772772 /* copyfami_emu.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = copyfami_emu.c; sourceTree = ""; }; + 942D9A4B14E8AFDF00772772 /* copyfami_hwi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = copyfami_hwi.c; sourceTree = ""; }; + 942D9A4C14E8AFDF00772772 /* dance2000.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dance2000.c; sourceTree = ""; }; + 942D9A4D14E8AFDF00772772 /* datalatch.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = datalatch.c; sourceTree = ""; }; + 942D9A4E14E8AFDF00772772 /* deirom.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = deirom.c; sourceTree = ""; }; + 942D9A4F14E8AFDF00772772 /* dream.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dream.c; sourceTree = ""; }; + 942D9A5014E8AFDF00772772 /* dummy_mapper.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dummy_mapper.c; sourceTree = ""; }; + 942D9A5114E8AFDF00772772 /* edu2000.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = edu2000.c; sourceTree = ""; }; + 942D9A5214E8AFDF00772772 /* fk23c.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = fk23c.c; sourceTree = ""; }; + 942D9A5314E8AFDF00772772 /* ghostbusters63in1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ghostbusters63in1.c; sourceTree = ""; }; + 942D9A5414E8AFDF00772772 /* gs-2004.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "gs-2004.c"; sourceTree = ""; }; + 942D9A5514E8AFDF00772772 /* gs-2013.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "gs-2013.c"; sourceTree = ""; }; + 942D9A5614E8AFDF00772772 /* h2288.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = h2288.c; sourceTree = ""; }; + 942D9A5714E8AFDF00772772 /* karaoke.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = karaoke.c; sourceTree = ""; }; + 942D9A5814E8AFDF00772772 /* kof97.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = kof97.c; sourceTree = ""; }; + 942D9A5914E8AFDF00772772 /* konami-qtai.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "konami-qtai.c"; sourceTree = ""; }; + 942D9A5A14E8AFDF00772772 /* KS7012.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = KS7012.c; sourceTree = ""; }; + 942D9A5B14E8AFDF00772772 /* KS7013.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = KS7013.c; sourceTree = ""; }; + 942D9A5C14E8AFDF00772772 /* KS7017.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = KS7017.c; sourceTree = ""; }; + 942D9A5D14E8AFDF00772772 /* KS7032.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = KS7032.c; sourceTree = ""; }; + 942D9A5E14E8AFDF00772772 /* KS7037.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = KS7037.c; sourceTree = ""; }; + 942D9A5F14E8AFDF00772772 /* KS7057.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = KS7057.c; sourceTree = ""; }; + 942D9A6014E8AFDF00772772 /* le05.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = le05.c; sourceTree = ""; }; + 942D9A6114E8AFDF00772772 /* malee.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = malee.c; sourceTree = ""; }; + 942D9A6214E8AFDF00772772 /* mapinc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mapinc.h; sourceTree = ""; }; + 942D9A6314E8AFDF00772772 /* mmc1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mmc1.c; sourceTree = ""; }; + 942D9A6414E8AFDF00772772 /* mmc3.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mmc3.c; sourceTree = ""; }; + 942D9A6514E8AFDF00772772 /* mmc3.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mmc3.h; sourceTree = ""; }; + 942D9A6614E8AFDF00772772 /* mmc5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mmc5.c; sourceTree = ""; }; + 942D9A6714E8AFDF00772772 /* n106.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = n106.c; sourceTree = ""; }; + 942D9A6814E8AFDF00772772 /* n625092.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = n625092.c; sourceTree = ""; }; + 942D9A6914E8AFDF00772772 /* novel.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = novel.c; sourceTree = ""; }; + 942D9A6A14E8AFDF00772772 /* onebus.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = onebus.c; sourceTree = ""; }; + 942D9A6B14E8AFDF00772772 /* pec-586.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "pec-586.c"; sourceTree = ""; }; + 942D9A6C14E8AFDF00772772 /* sachen.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sachen.c; sourceTree = ""; }; + 942D9A6D14E8AFDF00772772 /* sc-127.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "sc-127.c"; sourceTree = ""; }; + 942D9A6E14E8AFDF00772772 /* sheroes.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sheroes.c; sourceTree = ""; }; + 942D9A6F14E8AFDF00772772 /* sl1632.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sl1632.c; sourceTree = ""; }; + 942D9A7014E8AFDF00772772 /* smb2j.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smb2j.c; sourceTree = ""; }; + 942D9A7114E8AFDF00772772 /* subor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = subor.c; sourceTree = ""; }; + 942D9A7214E8AFDF00772772 /* super24.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = super24.c; sourceTree = ""; }; + 942D9A7314E8AFDF00772772 /* supervision.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = supervision.c; sourceTree = ""; }; + 942D9A7414E8AFDF00772772 /* t-227-1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "t-227-1.c"; sourceTree = ""; }; + 942D9A7514E8AFDF00772772 /* t-262.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "t-262.c"; sourceTree = ""; }; + 942D9A7614E8AFDF00772772 /* tengen.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tengen.c; sourceTree = ""; }; + 942D9A7714E8AFDF00772772 /* tf-1201.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "tf-1201.c"; sourceTree = ""; }; + 942D9A7814E8AFDF00772772 /* transformer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = transformer.c; sourceTree = ""; }; + 942D9A7914E8AFDF00772772 /* vrc7.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = vrc7.c; sourceTree = ""; }; + 942D9A7A14E8AFDF00772772 /* yoko.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = yoko.c; sourceTree = ""; }; + 942D9A7B14E8AFDF00772772 /* cart.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cart.c; sourceTree = ""; }; + 942D9A7C14E8AFDF00772772 /* cart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cart.h; sourceTree = ""; }; + 942D9A7D14E8AFDF00772772 /* cheat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cheat.c; sourceTree = ""; }; + 942D9A7E14E8AFDF00772772 /* cheat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cheat.h; sourceTree = ""; }; + 942D9A7F14E8AFDF00772772 /* crc32.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = crc32.h; sourceTree = ""; }; + 942D9A8014E8AFDF00772772 /* driver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = driver.h; sourceTree = ""; }; + 942D9A8114E8AFDF00772772 /* fceu.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = fceu.c; sourceTree = ""; }; + 942D9A8214E8AFDF00772772 /* fceu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fceu.h; sourceTree = ""; }; + 942D9A8314E8AFDF00772772 /* fcoeffs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fcoeffs.h; sourceTree = ""; }; + 942D9A8414E8AFDF00772772 /* fds.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = fds.c; sourceTree = ""; }; + 942D9A8514E8AFDF00772772 /* fds.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fds.h; sourceTree = ""; }; + 942D9A8614E8AFDF00772772 /* file.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = file.c; sourceTree = ""; }; + 942D9A8714E8AFDF00772772 /* file.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = file.h; sourceTree = ""; }; + 942D9A8914E8AFDF00772772 /* c44100ntsc.coef */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = c44100ntsc.coef; sourceTree = ""; }; + 942D9A8A14E8AFDF00772772 /* c44100ntsc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = c44100ntsc.h; sourceTree = ""; }; + 942D9A8B14E8AFDF00772772 /* c44100ntsc.scm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = c44100ntsc.scm; sourceTree = ""; }; + 942D9A8C14E8AFDF00772772 /* c44100pal.coef */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = c44100pal.coef; sourceTree = ""; }; + 942D9A8D14E8AFDF00772772 /* c44100pal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = c44100pal.h; sourceTree = ""; }; + 942D9A8E14E8AFDF00772772 /* c44100pal.scm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = c44100pal.scm; sourceTree = ""; }; + 942D9A8F14E8AFDF00772772 /* c48000ntsc.coef */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = c48000ntsc.coef; sourceTree = ""; }; + 942D9A9014E8AFDF00772772 /* c48000ntsc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = c48000ntsc.h; sourceTree = ""; }; + 942D9A9114E8AFDF00772772 /* c48000ntsc.scm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = c48000ntsc.scm; sourceTree = ""; }; + 942D9A9214E8AFDF00772772 /* c48000pal.coef */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = c48000pal.coef; sourceTree = ""; }; + 942D9A9314E8AFDF00772772 /* c48000pal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = c48000pal.h; sourceTree = ""; }; + 942D9A9414E8AFDF00772772 /* c48000pal.scm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = c48000pal.scm; sourceTree = ""; }; + 942D9A9514E8AFDF00772772 /* c96000ntsc.coef */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = c96000ntsc.coef; sourceTree = ""; }; + 942D9A9614E8AFDF00772772 /* c96000ntsc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = c96000ntsc.h; sourceTree = ""; }; + 942D9A9714E8AFDF00772772 /* c96000ntsc.scm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = c96000ntsc.scm; sourceTree = ""; }; + 942D9A9814E8AFDF00772772 /* c96000pal.coef */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = c96000pal.coef; sourceTree = ""; }; + 942D9A9914E8AFDF00772772 /* c96000pal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = c96000pal.h; sourceTree = ""; }; + 942D9A9A14E8AFDF00772772 /* c96000pal.scm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = c96000pal.scm; sourceTree = ""; }; + 942D9A9B14E8AFDF00772772 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = ""; }; + 942D9A9C14E8AFDF00772772 /* toh.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = toh.c; sourceTree = ""; }; + 942D9A9D14E8AFDF00772772 /* general.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = general.c; sourceTree = ""; }; + 942D9A9E14E8AFDF00772772 /* general.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = general.h; sourceTree = ""; }; + 942D9A9F14E8AFDF00772772 /* git.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = git.h; sourceTree = ""; }; + 942D9AA014E8AFDF00772772 /* ines-bad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ines-bad.h"; sourceTree = ""; }; + 942D9AA114E8AFDF00772772 /* ines-correct.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ines-correct.h"; sourceTree = ""; }; + 942D9AA214E8AFDF00772772 /* ines.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ines.c; sourceTree = ""; }; + 942D9AA314E8AFDF00772772 /* ines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ines.h; sourceTree = ""; }; + 942D9AA514E8AFDF00772772 /* arkanoid.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = arkanoid.c; sourceTree = ""; }; + 942D9AA614E8AFDF00772772 /* bbox.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bbox.c; sourceTree = ""; }; + 942D9AA714E8AFDF00772772 /* bworld.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bworld.c; sourceTree = ""; }; + 942D9AA814E8AFDF00772772 /* cursor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cursor.c; sourceTree = ""; }; + 942D9AA914E8AFDF00772772 /* fkb.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = fkb.c; sourceTree = ""; }; + 942D9AAA14E8AFDF00772772 /* fkb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fkb.h; sourceTree = ""; }; + 942D9AAB14E8AFDF00772772 /* ftrainer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ftrainer.c; sourceTree = ""; }; + 942D9AAC14E8AFDF00772772 /* hypershot.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = hypershot.c; sourceTree = ""; }; + 942D9AAD14E8AFDF00772772 /* mahjong.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mahjong.c; sourceTree = ""; }; + 942D9AAE14E8AFDF00772772 /* mouse.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mouse.c; sourceTree = ""; }; + 942D9AAF14E8AFDF00772772 /* oekakids.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = oekakids.c; sourceTree = ""; }; + 942D9AB014E8AFDF00772772 /* pads.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pads.c; sourceTree = ""; }; + 942D9AB114E8AFDF00772772 /* pec586kb.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pec586kb.c; sourceTree = ""; }; + 942D9AB214E8AFDF00772772 /* powerpad.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = powerpad.c; sourceTree = ""; }; + 942D9AB314E8AFDF00772772 /* quiz.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = quiz.c; sourceTree = ""; }; + 942D9AB414E8AFDF00772772 /* shadow.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = shadow.c; sourceTree = ""; }; + 942D9AB514E8AFDF00772772 /* share.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = share.h; sourceTree = ""; }; + 942D9AB614E8AFDF00772772 /* suborkb.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = suborkb.c; sourceTree = ""; }; + 942D9AB714E8AFDF00772772 /* suborkb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = suborkb.h; sourceTree = ""; }; + 942D9AB814E8AFDF00772772 /* toprider.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = toprider.c; sourceTree = ""; }; + 942D9AB914E8AFDF00772772 /* zapper.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zapper.c; sourceTree = ""; }; + 942D9ABA14E8AFDF00772772 /* input.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = input.c; sourceTree = ""; }; + 942D9ABB14E8AFDF00772772 /* input.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = input.h; sourceTree = ""; }; + 942D9ABD14E8AFDF00772772 /* 151.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 151.c; sourceTree = ""; }; + 942D9ABE14E8AFDF00772772 /* 157.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 157.c; sourceTree = ""; }; + 942D9ABF14E8AFDF00772772 /* 17.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 17.c; sourceTree = ""; }; + 942D9AC014E8AFDF00772772 /* 18.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 18.c; sourceTree = ""; }; + 942D9AC114E8AFDF00772772 /* 201.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 201.c; sourceTree = ""; }; + 942D9AC214E8AFDF00772772 /* 202.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 202.c; sourceTree = ""; }; + 942D9AC314E8AFDF00772772 /* 203.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 203.c; sourceTree = ""; }; + 942D9AC414E8AFDF00772772 /* 204.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 204.c; sourceTree = ""; }; + 942D9AC514E8AFDF00772772 /* 21.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 21.c; sourceTree = ""; }; + 942D9AC614E8AFDF00772772 /* 212.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 212.c; sourceTree = ""; }; + 942D9AC714E8AFDF00772772 /* 213.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 213.c; sourceTree = ""; }; + 942D9AC814E8AFDF00772772 /* 214.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 214.c; sourceTree = ""; }; + 942D9AC914E8AFDF00772772 /* 215.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 215.c; sourceTree = ""; }; + 942D9ACA14E8AFDF00772772 /* 217.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 217.c; sourceTree = ""; }; + 942D9ACB14E8AFDF00772772 /* 22.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 22.c; sourceTree = ""; }; + 942D9ACC14E8AFDF00772772 /* 227.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 227.c; sourceTree = ""; }; + 942D9ACD14E8AFDF00772772 /* 228.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 228.c; sourceTree = ""; }; + 942D9ACE14E8AFDF00772772 /* 229.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 229.c; sourceTree = ""; }; + 942D9ACF14E8AFDF00772772 /* 230.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 230.c; sourceTree = ""; }; + 942D9AD014E8AFDF00772772 /* 231.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 231.c; sourceTree = ""; }; + 942D9AD114E8AFDF00772772 /* 232.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 232.c; sourceTree = ""; }; + 942D9AD214E8AFDF00772772 /* 234.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 234.c; sourceTree = ""; }; + 942D9AD314E8AFDF00772772 /* 241.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 241.c; sourceTree = ""; }; + 942D9AD414E8AFDF00772772 /* 242.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 242.c; sourceTree = ""; }; + 942D9AD514E8AFDF00772772 /* 244.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 244.c; sourceTree = ""; }; + 942D9AD614E8AFDF00772772 /* 246.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 246.c; sourceTree = ""; }; + 942D9AD714E8AFDF00772772 /* 24and26.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 24and26.c; sourceTree = ""; }; + 942D9AD814E8AFDF00772772 /* 25.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 25.c; sourceTree = ""; }; + 942D9AD914E8AFDF00772772 /* 255.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 255.c; sourceTree = ""; }; + 942D9ADA14E8AFDF00772772 /* 27.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 27.c; sourceTree = ""; }; + 942D9ADB14E8AFDF00772772 /* 32.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 32.c; sourceTree = ""; }; + 942D9ADC14E8AFDF00772772 /* 33.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 33.c; sourceTree = ""; }; + 942D9ADD14E8AFDF00772772 /* 40.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 40.c; sourceTree = ""; }; + 942D9ADE14E8AFDF00772772 /* 41.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 41.c; sourceTree = ""; }; + 942D9ADF14E8AFDF00772772 /* 42.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 42.c; sourceTree = ""; }; + 942D9AE014E8AFDF00772772 /* 46.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 46.c; sourceTree = ""; }; + 942D9AE114E8AFDF00772772 /* 50.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 50.c; sourceTree = ""; }; + 942D9AE214E8AFDF00772772 /* 51.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 51.c; sourceTree = ""; }; + 942D9AE314E8AFDF00772772 /* 59.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 59.c; sourceTree = ""; }; + 942D9AE414E8AFDF00772772 /* 6.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 6.c; sourceTree = ""; }; + 942D9AE514E8AFDF00772772 /* 61.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 61.c; sourceTree = ""; }; + 942D9AE614E8AFDF00772772 /* 62.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 62.c; sourceTree = ""; }; + 942D9AE714E8AFDF00772772 /* 65.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 65.c; sourceTree = ""; }; + 942D9AE814E8AFDF00772772 /* 67.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 67.c; sourceTree = ""; }; + 942D9AE914E8AFDF00772772 /* 69.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 69.c; sourceTree = ""; }; + 942D9AEA14E8AFDF00772772 /* 71.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 71.c; sourceTree = ""; }; + 942D9AEB14E8AFDF00772772 /* 72.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 72.c; sourceTree = ""; }; + 942D9AEC14E8AFDF00772772 /* 73.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 73.c; sourceTree = ""; }; + 942D9AED14E8AFDF00772772 /* 75.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 75.c; sourceTree = ""; }; + 942D9AEE14E8AFDF00772772 /* 76.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 76.c; sourceTree = ""; }; + 942D9AEF14E8AFDF00772772 /* 77.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 77.c; sourceTree = ""; }; + 942D9AF014E8AFDF00772772 /* 79.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 79.c; sourceTree = ""; }; + 942D9AF114E8AFDF00772772 /* 8.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 8.c; sourceTree = ""; }; + 942D9AF214E8AFDF00772772 /* 80.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 80.c; sourceTree = ""; }; + 942D9AF314E8AFDF00772772 /* 82.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 82.c; sourceTree = ""; }; + 942D9AF414E8AFDF00772772 /* 83.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 83.c; sourceTree = ""; }; + 942D9AF514E8AFDF00772772 /* 85.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 85.c; sourceTree = ""; }; + 942D9AF614E8AFDF00772772 /* 86.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 86.c; sourceTree = ""; }; + 942D9AF714E8AFDF00772772 /* 89.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 89.c; sourceTree = ""; }; + 942D9AF814E8AFDF00772772 /* 91.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 91.c; sourceTree = ""; }; + 942D9AF914E8AFDF00772772 /* 92.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 92.c; sourceTree = ""; }; + 942D9AFA14E8AFDF00772772 /* 97.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 97.c; sourceTree = ""; }; + 942D9AFB14E8AFDF00772772 /* 99.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 99.c; sourceTree = ""; }; + 942D9AFC14E8AFDF00772772 /* emu2413.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = emu2413.c; sourceTree = ""; }; + 942D9AFD14E8AFDF00772772 /* emu2413.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = emu2413.h; sourceTree = ""; }; + 942D9AFE14E8AFDF00772772 /* emutypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = emutypes.h; sourceTree = ""; }; + 942D9AFF14E8AFDF00772772 /* mapinc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mapinc.h; sourceTree = ""; }; + 942D9B0014E8AFDF00772772 /* mmc2and4.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mmc2and4.c; sourceTree = ""; }; + 942D9B0114E8AFDF00772772 /* simple.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = simple.c; sourceTree = ""; }; + 942D9B0214E8AFDF00772772 /* vrc7tone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = vrc7tone.h; sourceTree = ""; }; + 942D9B0314E8AFDF00772772 /* md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md5.c; sourceTree = ""; }; + 942D9B0414E8AFDF00772772 /* md5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md5.h; sourceTree = ""; }; + 942D9B0514E8AFDF00772772 /* memory.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = memory.c; sourceTree = ""; }; + 942D9B0614E8AFDF00772772 /* memory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = memory.h; sourceTree = ""; }; + 942D9B0714E8AFDF00772772 /* mycrc32.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mycrc32.c; sourceTree = ""; }; + 942D9B0814E8AFDF00772772 /* myendian.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = myendian.c; sourceTree = ""; }; + 942D9B0914E8AFDF00772772 /* myendian.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = myendian.h; sourceTree = ""; }; + 942D9B0A14E8AFDF00772772 /* ops.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ops.h; sourceTree = ""; }; + 942D9B0B14E8AFDF00772772 /* palette.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = palette.c; sourceTree = ""; }; + 942D9B0C14E8AFDF00772772 /* palette.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = palette.h; sourceTree = ""; }; + 942D9B0E14E8AFDF00772772 /* conv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = conv.c; sourceTree = ""; }; + 942D9B0F14E8AFDF00772772 /* palettes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = palettes.h; sourceTree = ""; }; + 942D9B1014E8AFDF00772772 /* rp2c04001.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rp2c04001.h; sourceTree = ""; }; + 942D9B1114E8AFDF00772772 /* rp2c04002.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rp2c04002.h; sourceTree = ""; }; + 942D9B1214E8AFDF00772772 /* rp2c04003.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rp2c04003.h; sourceTree = ""; }; + 942D9B1314E8AFDF00772772 /* rp2c05004.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rp2c05004.h; sourceTree = ""; }; + 942D9B1414E8AFDF00772772 /* ppu.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ppu.c; sourceTree = ""; }; + 942D9B1514E8AFDF00772772 /* ppu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ppu.h; sourceTree = ""; }; + 942D9B1614E8AFDF00772772 /* pputile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pputile.h; sourceTree = ""; }; + 942D9B1714E8AFDF00772772 /* ppuview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ppuview.h; sourceTree = ""; }; + 942D9B1814E8AFDF00772772 /* sound.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sound.c; sourceTree = ""; }; + 942D9B1914E8AFDF00772772 /* sound.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sound.h; sourceTree = ""; }; + 942D9B1A14E8AFDF00772772 /* sound_hq_.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sound_hq_.h; sourceTree = ""; }; + 942D9B1B14E8AFDF00772772 /* sound_lq_.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sound_lq_.h; sourceTree = ""; }; + 942D9B1C14E8AFDF00772772 /* state.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = state.c; sourceTree = ""; }; + 942D9B1D14E8AFDF00772772 /* state.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = state.h; sourceTree = ""; }; + 942D9B1E14E8AFDF00772772 /* types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = types.h; sourceTree = ""; }; + 942D9B1F14E8AFDF00772772 /* unif.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = unif.c; sourceTree = ""; }; + 942D9B2014E8AFDF00772772 /* unif.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unif.h; sourceTree = ""; }; + 942D9B2114E8AFDF00772772 /* unzip.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = unzip.c; sourceTree = ""; }; + 942D9B2214E8AFDF00772772 /* unzip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unzip.h; sourceTree = ""; }; + 942D9B2314E8AFDF00772772 /* vsuni.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = vsuni.c; sourceTree = ""; }; + 942D9B2414E8AFDF00772772 /* vsuni.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = vsuni.h; sourceTree = ""; }; + 942D9B2514E8AFDF00772772 /* x6502.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = x6502.c; sourceTree = ""; }; + 942D9B2614E8AFDF00772772 /* x6502.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = x6502.h; sourceTree = ""; }; + 942D9B2714E8AFDF00772772 /* x6502struct.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = x6502struct.h; sourceTree = ""; }; + 942D9B2914E8AFDF00772772 /* adler32.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = adler32.c; sourceTree = ""; }; + 942D9B2A14E8AFDF00772772 /* compress.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compress.c; sourceTree = ""; }; + 942D9B2B14E8AFDF00772772 /* crc32.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = crc32.c; sourceTree = ""; }; + 942D9B2C14E8AFDF00772772 /* deflate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = deflate.c; sourceTree = ""; }; + 942D9B2D14E8AFDF00772772 /* deflate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = deflate.h; sourceTree = ""; }; + 942D9B2E14E8AFDF00772772 /* gzio.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = gzio.c; sourceTree = ""; }; + 942D9B2F14E8AFDF00772772 /* infblock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = infblock.c; sourceTree = ""; }; + 942D9B3014E8AFDF00772772 /* infblock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = infblock.h; sourceTree = ""; }; + 942D9B3114E8AFDF00772772 /* infcodes.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = infcodes.c; sourceTree = ""; }; + 942D9B3214E8AFDF00772772 /* infcodes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = infcodes.h; sourceTree = ""; }; + 942D9B3314E8AFDF00772772 /* inffast.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = inffast.c; sourceTree = ""; }; + 942D9B3414E8AFDF00772772 /* inffast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = inffast.h; sourceTree = ""; }; + 942D9B3514E8AFDF00772772 /* inffixed.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = inffixed.h; sourceTree = ""; }; + 942D9B3614E8AFDF00772772 /* inflate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = inflate.c; sourceTree = ""; }; + 942D9B3714E8AFDF00772772 /* inftrees.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = inftrees.c; sourceTree = ""; }; + 942D9B3814E8AFDF00772772 /* inftrees.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = inftrees.h; sourceTree = ""; }; + 942D9B3914E8AFDF00772772 /* infutil.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = infutil.c; sourceTree = ""; }; + 942D9B3A14E8AFDF00772772 /* infutil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = infutil.h; sourceTree = ""; }; + 942D9B3B14E8AFDF00772772 /* trees.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = trees.c; sourceTree = ""; }; + 942D9B3C14E8AFDF00772772 /* trees.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = trees.h; sourceTree = ""; }; + 942D9B3D14E8AFDF00772772 /* uncompr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = uncompr.c; sourceTree = ""; }; + 942D9B3E14E8AFDF00772772 /* unzip.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = unzip.c; sourceTree = ""; }; + 942D9B3F14E8AFDF00772772 /* unzip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unzip.h; sourceTree = ""; }; + 942D9B4014E8AFDF00772772 /* zconf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = zconf.h; sourceTree = ""; }; + 942D9B4114E8AFDF00772772 /* zlib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = zlib.h; sourceTree = ""; }; + 942D9B4214E8AFDF00772772 /* zutil.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zutil.c; sourceTree = ""; }; + 942D9B4314E8AFDF00772772 /* zutil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = zutil.h; sourceTree = ""; }; + 945942CE14E4EF180015D2AA /* OENESSystemResponderClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OENESSystemResponderClient.h; path = ../OpenEmu/NES/OENESSystemResponderClient.h; sourceTree = ""; }; + 945942CF14E4F2DC0015D2AA /* FCEUX.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = FCEUX.icns; sourceTree = ""; }; + B5008DAD0E8BFB3E005AECAF /* FCEUGameEmu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FCEUGameEmu.h; sourceTree = ""; }; + B5008DAE0E8BFB3E005AECAF /* FCEUGameEmu.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FCEUGameEmu.mm; sourceTree = ""; }; + C63E6C640FCDA565009C8555 /* ControlsPreference.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ControlsPreference.xib; sourceTree = ""; }; + C63E6C790FCDA5D6009C8555 /* FCEUGameController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FCEUGameController.h; sourceTree = ""; }; + C63E6C7A0FCDA5D6009C8555 /* FCEUGameController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FCEUGameController.m; sourceTree = ""; }; + D2F7E65807B2D6F200F64583 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 8D5B49B3048680CD000E48DA /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 82EA60570F514D8C008E18C5 /* OpenEmuBase.framework in Frameworks */, + 8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */, + 82EC409F0FD9EC420017FC19 /* libz.dylib in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 089C166AFE841209C02AAC07 /* VisualBoyAdvance */ = { + isa = PBXGroup; + children = ( + 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */, + 08FB77AFFE84173DC02AAC07 /* Classes */, + 32C88E010371C26100C91783 /* Other Sources */, + 089C167CFE841241C02AAC07 /* Resources */, + 089C1671FE841209C02AAC07 /* Frameworks and Libraries */, + 19C28FB8FE9D52D311CA2CBB /* Products */, + ); + name = VisualBoyAdvance; + sourceTree = ""; + }; + 089C1671FE841209C02AAC07 /* Frameworks and Libraries */ = { + isa = PBXGroup; + children = ( + 82EC409E0FD9EC420017FC19 /* libz.dylib */, + 1058C7ACFEA557BF11CA2CBB /* Linked Frameworks */, + 1058C7AEFEA557BF11CA2CBB /* Other Frameworks */, + ); + name = "Frameworks and Libraries"; + sourceTree = ""; + }; + 089C167CFE841241C02AAC07 /* Resources */ = { + isa = PBXGroup; + children = ( + 82CAFD010FEDD54000CCDC7E /* dsa_pub.pem */, + 8D5B49B7048680CD000E48DA /* Info.plist */, + 089C167DFE841241C02AAC07 /* InfoPlist.strings */, + 945942CF14E4F2DC0015D2AA /* FCEUX.icns */, + C63E6C640FCDA565009C8555 /* ControlsPreference.xib */, + ); + name = Resources; + sourceTree = ""; + }; + 08FB77AFFE84173DC02AAC07 /* Classes */ = { + isa = PBXGroup; + children = ( + 82EC3FED0FD9EAE90017FC19 /* Core */, + 945942CE14E4EF180015D2AA /* OENESSystemResponderClient.h */, + B5008DAD0E8BFB3E005AECAF /* FCEUGameEmu.h */, + B5008DAE0E8BFB3E005AECAF /* FCEUGameEmu.mm */, + C63E6C790FCDA5D6009C8555 /* FCEUGameController.h */, + C63E6C7A0FCDA5D6009C8555 /* FCEUGameController.m */, + ); + name = Classes; + sourceTree = ""; + }; + 1058C7ACFEA557BF11CA2CBB /* Linked Frameworks */ = { + isa = PBXGroup; + children = ( + 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */, + ); + name = "Linked Frameworks"; + sourceTree = ""; + }; + 1058C7AEFEA557BF11CA2CBB /* Other Frameworks */ = { + isa = PBXGroup; + children = ( + 089C167FFE841241C02AAC07 /* AppKit.framework */, + D2F7E65807B2D6F200F64583 /* CoreData.framework */, + 089C1672FE841209C02AAC07 /* Foundation.framework */, + ); + name = "Other Frameworks"; + sourceTree = ""; + }; + 19C28FB8FE9D52D311CA2CBB /* Products */ = { + isa = PBXGroup; + children = ( + 8D5B49B6048680CD000E48DA /* FCEU.oecoreplugin */, + ); + name = Products; + sourceTree = ""; + }; + 32C88E010371C26100C91783 /* Other Sources */ = { + isa = PBXGroup; + children = ( + 82CAFD030FEDD54800CCDC7E /* config.yaml */, + 32DBCF630370AF2F00C91783 /* FCEU.pch */, + ); + name = "Other Sources"; + sourceTree = ""; + }; + 82EA60490F514D80008E18C5 /* Products */ = { + isa = PBXGroup; + children = ( + 82EA60510F514D80008E18C5 /* OpenEmu.app */, + C62A264A116F094C0003DEE4 /* OpenEmuHelperApp */, + 82EA60550F514D80008E18C5 /* OpenEmuBase.framework */, + C6B9490013651ACD00A425F0 /* OpenEmuSystem.framework */, + 378394E51029257000168304 /* OESaveStateQLPlugin.qlgenerator */, + C6B9490213651ACD00A425F0 /* SegaMasterSystem.oesystemplugin */, + C6B9490413651ACD00A425F0 /* NES.oesystemplugin */, + C6B9490613651ACD00A425F0 /* SuperNES.oesystemplugin */, + C6B9490813651ACD00A425F0 /* GameBoy.oesystemplugin */, + C6B9490A13651ACD00A425F0 /* Genesis.oesystemplugin */, + C646575913771F4F002A4F70 /* GameBoy Advance.oesystemplugin */, + 8390474C14597FE200335E4F /* N64.oesystemplugin */, + C6B9E3FD14841AC400836111 /* NeoGeo Pocket.oesystemplugin */, + 1B32153114DDDB4000C5B50A /* GameGear.oesystemplugin */, + ); + name = Products; + sourceTree = ""; + }; + 82EC3FED0FD9EAE90017FC19 /* Core */ = { + isa = PBXGroup; + children = ( + 942D9A0A14E8AFDE00772772 /* libsnes-fceumm */, + 942D9A0F14E8AFDE00772772 /* src-fceumm */, + ); + path = Core; + sourceTree = ""; + }; + 942D9A0A14E8AFDE00772772 /* libsnes-fceumm */ = { + isa = PBXGroup; + children = ( + 942D9A0B14E8AFDE00772772 /* libsnes.c */, + 942D9A0C14E8AFDE00772772 /* libsnes.h */, + 942D9A0D14E8AFDE00772772 /* memstream.c */, + 942D9A0E14E8AFDE00772772 /* memstream.h */, + ); + name = "libsnes-fceumm"; + path = "fceumm/libsnes-fceumm"; + sourceTree = SOURCE_ROOT; + }; + 942D9A0F14E8AFDE00772772 /* src-fceumm */ = { + isa = PBXGroup; + children = ( + 942D9A1014E8AFDF00772772 /* boards */, + 942D9A7B14E8AFDF00772772 /* cart.c */, + 942D9A7C14E8AFDF00772772 /* cart.h */, + 942D9A7D14E8AFDF00772772 /* cheat.c */, + 942D9A7E14E8AFDF00772772 /* cheat.h */, + 942D9A7F14E8AFDF00772772 /* crc32.h */, + 942D9A8014E8AFDF00772772 /* driver.h */, + 942D9A8114E8AFDF00772772 /* fceu.c */, + 942D9A8214E8AFDF00772772 /* fceu.h */, + 942D9A8314E8AFDF00772772 /* fcoeffs.h */, + 942D9A8414E8AFDF00772772 /* fds.c */, + 942D9A8514E8AFDF00772772 /* fds.h */, + 942D9A8614E8AFDF00772772 /* file.c */, + 942D9A8714E8AFDF00772772 /* file.h */, + 942D9A8814E8AFDF00772772 /* fir */, + 942D9A9D14E8AFDF00772772 /* general.c */, + 942D9A9E14E8AFDF00772772 /* general.h */, + 942D9A9F14E8AFDF00772772 /* git.h */, + 942D9AA014E8AFDF00772772 /* ines-bad.h */, + 942D9AA114E8AFDF00772772 /* ines-correct.h */, + 942D9AA214E8AFDF00772772 /* ines.c */, + 942D9AA314E8AFDF00772772 /* ines.h */, + 942D9AA414E8AFDF00772772 /* input */, + 942D9ABA14E8AFDF00772772 /* input.c */, + 942D9ABB14E8AFDF00772772 /* input.h */, + 942D9ABC14E8AFDF00772772 /* mappers */, + 942D9B0314E8AFDF00772772 /* md5.c */, + 942D9B0414E8AFDF00772772 /* md5.h */, + 942D9B0514E8AFDF00772772 /* memory.c */, + 942D9B0614E8AFDF00772772 /* memory.h */, + 942D9B0714E8AFDF00772772 /* mycrc32.c */, + 942D9B0814E8AFDF00772772 /* myendian.c */, + 942D9B0914E8AFDF00772772 /* myendian.h */, + 942D9B0A14E8AFDF00772772 /* ops.h */, + 942D9B0B14E8AFDF00772772 /* palette.c */, + 942D9B0C14E8AFDF00772772 /* palette.h */, + 942D9B0D14E8AFDF00772772 /* palettes */, + 942D9B1414E8AFDF00772772 /* ppu.c */, + 942D9B1514E8AFDF00772772 /* ppu.h */, + 942D9B1614E8AFDF00772772 /* pputile.h */, + 942D9B1714E8AFDF00772772 /* ppuview.h */, + 942D9B1814E8AFDF00772772 /* sound.c */, + 942D9B1914E8AFDF00772772 /* sound.h */, + 942D9B1A14E8AFDF00772772 /* sound_hq_.h */, + 942D9B1B14E8AFDF00772772 /* sound_lq_.h */, + 942D9B1C14E8AFDF00772772 /* state.c */, + 942D9B1D14E8AFDF00772772 /* state.h */, + 942D9B1E14E8AFDF00772772 /* types.h */, + 942D9B1F14E8AFDF00772772 /* unif.c */, + 942D9B2014E8AFDF00772772 /* unif.h */, + 942D9B2114E8AFDF00772772 /* unzip.c */, + 942D9B2214E8AFDF00772772 /* unzip.h */, + 942D9B2314E8AFDF00772772 /* vsuni.c */, + 942D9B2414E8AFDF00772772 /* vsuni.h */, + 942D9B2514E8AFDF00772772 /* x6502.c */, + 942D9B2614E8AFDF00772772 /* x6502.h */, + 942D9B2714E8AFDF00772772 /* x6502struct.h */, + 942D9B2814E8AFDF00772772 /* zlib */, + ); + name = "src-fceumm"; + path = "fceumm/src-fceumm"; + sourceTree = SOURCE_ROOT; + }; + 942D9A1014E8AFDF00772772 /* boards */ = { + isa = PBXGroup; + children = ( + 942D9A1114E8AFDF00772772 /* 01-222.c */, + 942D9A1214E8AFDF00772772 /* 103.c */, + 942D9A1314E8AFDF00772772 /* 106.c */, + 942D9A1414E8AFDF00772772 /* 108.c */, + 942D9A1514E8AFDF00772772 /* 112.c */, + 942D9A1614E8AFDF00772772 /* 116.c */, + 942D9A1714E8AFDF00772772 /* 117.c */, + 942D9A1814E8AFDF00772772 /* 120.c */, + 942D9A1914E8AFDF00772772 /* 121.c */, + 942D9A1A14E8AFDF00772772 /* 12in1.c */, + 942D9A1B14E8AFDF00772772 /* 15.c */, + 942D9A1C14E8AFDF00772772 /* 156.c */, + 942D9A1D14E8AFDF00772772 /* 164.c */, + 942D9A1E14E8AFDF00772772 /* 168.c */, + 942D9A1F14E8AFDF00772772 /* 170.c */, + 942D9A2014E8AFDF00772772 /* 175.c */, + 942D9A2114E8AFDF00772772 /* 176.c */, + 942D9A2214E8AFDF00772772 /* 177.c */, + 942D9A2314E8AFDF00772772 /* 178.c */, + 942D9A2414E8AFDF00772772 /* 183.c */, + 942D9A2514E8AFDF00772772 /* 185.c */, + 942D9A2614E8AFDF00772772 /* 186.c */, + 942D9A2714E8AFDF00772772 /* 187.c */, + 942D9A2814E8AFDF00772772 /* 189.c */, + 942D9A2914E8AFDF00772772 /* 193.c */, + 942D9A2A14E8AFDF00772772 /* 199.c */, + 942D9A2B14E8AFDF00772772 /* 208.c */, + 942D9A2C14E8AFDF00772772 /* 222.c */, + 942D9A2D14E8AFDF00772772 /* 225.c */, + 942D9A2E14E8AFDF00772772 /* 23.c */, + 942D9A2F14E8AFDF00772772 /* 235.c */, + 942D9A3014E8AFDF00772772 /* 253.c */, + 942D9A3114E8AFDF00772772 /* 3d-block.c */, + 942D9A3214E8AFDF00772772 /* 411120-c.c */, + 942D9A3314E8AFDF00772772 /* 43.c */, + 942D9A3414E8AFDF00772772 /* 57.c */, + 942D9A3514E8AFDF00772772 /* 603-5052.c */, + 942D9A3614E8AFDF00772772 /* 68.c */, + 942D9A3714E8AFDF00772772 /* 8157.c */, + 942D9A3814E8AFDF00772772 /* 8237.c */, + 942D9A3914E8AFDF00772772 /* 830118C.c */, + 942D9A3A14E8AFDF00772772 /* 88.c */, + 942D9A3B14E8AFDF00772772 /* 90.c */, + 942D9A3C14E8AFDF00772772 /* 95.c */, + 942D9A3D14E8AFDF00772772 /* __serial.c.win32 */, + 942D9A3E14E8AFDF00772772 /* __serial.h.win32 */, + 942D9A3F14E8AFDF00772772 /* a9746.c */, + 942D9A4014E8AFDF00772772 /* ac-08.c */, + 942D9A4114E8AFDF00772772 /* addrlatch.c */, + 942D9A4214E8AFDF00772772 /* ax5705.c */, + 942D9A4314E8AFDF00772772 /* bandai.c */, + 942D9A4414E8AFDF00772772 /* bmc13in1jy110.c */, + 942D9A4514E8AFDF00772772 /* bmc42in1r.c */, + 942D9A4614E8AFDF00772772 /* bmc64in1nr.c */, + 942D9A4714E8AFDF00772772 /* bmc70in1.c */, + 942D9A4814E8AFDF00772772 /* bonza.c */, + 942D9A4914E8AFDF00772772 /* bs-5.c */, + 942D9A4A14E8AFDF00772772 /* copyfami_emu.c */, + 942D9A4B14E8AFDF00772772 /* copyfami_hwi.c */, + 942D9A4C14E8AFDF00772772 /* dance2000.c */, + 942D9A4D14E8AFDF00772772 /* datalatch.c */, + 942D9A4E14E8AFDF00772772 /* deirom.c */, + 942D9A4F14E8AFDF00772772 /* dream.c */, + 942D9A5014E8AFDF00772772 /* dummy_mapper.c */, + 942D9A5114E8AFDF00772772 /* edu2000.c */, + 942D9A5214E8AFDF00772772 /* fk23c.c */, + 942D9A5314E8AFDF00772772 /* ghostbusters63in1.c */, + 942D9A5414E8AFDF00772772 /* gs-2004.c */, + 942D9A5514E8AFDF00772772 /* gs-2013.c */, + 942D9A5614E8AFDF00772772 /* h2288.c */, + 942D9A5714E8AFDF00772772 /* karaoke.c */, + 942D9A5814E8AFDF00772772 /* kof97.c */, + 942D9A5914E8AFDF00772772 /* konami-qtai.c */, + 942D9A5A14E8AFDF00772772 /* KS7012.c */, + 942D9A5B14E8AFDF00772772 /* KS7013.c */, + 942D9A5C14E8AFDF00772772 /* KS7017.c */, + 942D9A5D14E8AFDF00772772 /* KS7032.c */, + 942D9A5E14E8AFDF00772772 /* KS7037.c */, + 942D9A5F14E8AFDF00772772 /* KS7057.c */, + 942D9A6014E8AFDF00772772 /* le05.c */, + 942D9A6114E8AFDF00772772 /* malee.c */, + 942D9A6214E8AFDF00772772 /* mapinc.h */, + 942D9A6314E8AFDF00772772 /* mmc1.c */, + 942D9A6414E8AFDF00772772 /* mmc3.c */, + 942D9A6514E8AFDF00772772 /* mmc3.h */, + 942D9A6614E8AFDF00772772 /* mmc5.c */, + 942D9A6714E8AFDF00772772 /* n106.c */, + 942D9A6814E8AFDF00772772 /* n625092.c */, + 942D9A6914E8AFDF00772772 /* novel.c */, + 942D9A6A14E8AFDF00772772 /* onebus.c */, + 942D9A6B14E8AFDF00772772 /* pec-586.c */, + 942D9A6C14E8AFDF00772772 /* sachen.c */, + 942D9A6D14E8AFDF00772772 /* sc-127.c */, + 942D9A6E14E8AFDF00772772 /* sheroes.c */, + 942D9A6F14E8AFDF00772772 /* sl1632.c */, + 942D9A7014E8AFDF00772772 /* smb2j.c */, + 942D9A7114E8AFDF00772772 /* subor.c */, + 942D9A7214E8AFDF00772772 /* super24.c */, + 942D9A7314E8AFDF00772772 /* supervision.c */, + 942D9A7414E8AFDF00772772 /* t-227-1.c */, + 942D9A7514E8AFDF00772772 /* t-262.c */, + 942D9A7614E8AFDF00772772 /* tengen.c */, + 942D9A7714E8AFDF00772772 /* tf-1201.c */, + 942D9A7814E8AFDF00772772 /* transformer.c */, + 942D9A7914E8AFDF00772772 /* vrc7.c */, + 942D9A7A14E8AFDF00772772 /* yoko.c */, + ); + path = boards; + sourceTree = ""; + }; + 942D9A8814E8AFDF00772772 /* fir */ = { + isa = PBXGroup; + children = ( + 942D9A8914E8AFDF00772772 /* c44100ntsc.coef */, + 942D9A8A14E8AFDF00772772 /* c44100ntsc.h */, + 942D9A8B14E8AFDF00772772 /* c44100ntsc.scm */, + 942D9A8C14E8AFDF00772772 /* c44100pal.coef */, + 942D9A8D14E8AFDF00772772 /* c44100pal.h */, + 942D9A8E14E8AFDF00772772 /* c44100pal.scm */, + 942D9A8F14E8AFDF00772772 /* c48000ntsc.coef */, + 942D9A9014E8AFDF00772772 /* c48000ntsc.h */, + 942D9A9114E8AFDF00772772 /* c48000ntsc.scm */, + 942D9A9214E8AFDF00772772 /* c48000pal.coef */, + 942D9A9314E8AFDF00772772 /* c48000pal.h */, + 942D9A9414E8AFDF00772772 /* c48000pal.scm */, + 942D9A9514E8AFDF00772772 /* c96000ntsc.coef */, + 942D9A9614E8AFDF00772772 /* c96000ntsc.h */, + 942D9A9714E8AFDF00772772 /* c96000ntsc.scm */, + 942D9A9814E8AFDF00772772 /* c96000pal.coef */, + 942D9A9914E8AFDF00772772 /* c96000pal.h */, + 942D9A9A14E8AFDF00772772 /* c96000pal.scm */, + 942D9A9B14E8AFDF00772772 /* Makefile */, + 942D9A9C14E8AFDF00772772 /* toh.c */, + ); + path = fir; + sourceTree = ""; + }; + 942D9AA414E8AFDF00772772 /* input */ = { + isa = PBXGroup; + children = ( + 942D9AA514E8AFDF00772772 /* arkanoid.c */, + 942D9AA614E8AFDF00772772 /* bbox.c */, + 942D9AA714E8AFDF00772772 /* bworld.c */, + 942D9AA814E8AFDF00772772 /* cursor.c */, + 942D9AA914E8AFDF00772772 /* fkb.c */, + 942D9AAA14E8AFDF00772772 /* fkb.h */, + 942D9AAB14E8AFDF00772772 /* ftrainer.c */, + 942D9AAC14E8AFDF00772772 /* hypershot.c */, + 942D9AAD14E8AFDF00772772 /* mahjong.c */, + 942D9AAE14E8AFDF00772772 /* mouse.c */, + 942D9AAF14E8AFDF00772772 /* oekakids.c */, + 942D9AB014E8AFDF00772772 /* pads.c */, + 942D9AB114E8AFDF00772772 /* pec586kb.c */, + 942D9AB214E8AFDF00772772 /* powerpad.c */, + 942D9AB314E8AFDF00772772 /* quiz.c */, + 942D9AB414E8AFDF00772772 /* shadow.c */, + 942D9AB514E8AFDF00772772 /* share.h */, + 942D9AB614E8AFDF00772772 /* suborkb.c */, + 942D9AB714E8AFDF00772772 /* suborkb.h */, + 942D9AB814E8AFDF00772772 /* toprider.c */, + 942D9AB914E8AFDF00772772 /* zapper.c */, + ); + path = input; + sourceTree = ""; + }; + 942D9ABC14E8AFDF00772772 /* mappers */ = { + isa = PBXGroup; + children = ( + 942D9ABD14E8AFDF00772772 /* 151.c */, + 942D9ABE14E8AFDF00772772 /* 157.c */, + 942D9ABF14E8AFDF00772772 /* 17.c */, + 942D9AC014E8AFDF00772772 /* 18.c */, + 942D9AC114E8AFDF00772772 /* 201.c */, + 942D9AC214E8AFDF00772772 /* 202.c */, + 942D9AC314E8AFDF00772772 /* 203.c */, + 942D9AC414E8AFDF00772772 /* 204.c */, + 942D9AC514E8AFDF00772772 /* 21.c */, + 942D9AC614E8AFDF00772772 /* 212.c */, + 942D9AC714E8AFDF00772772 /* 213.c */, + 942D9AC814E8AFDF00772772 /* 214.c */, + 942D9AC914E8AFDF00772772 /* 215.c */, + 942D9ACA14E8AFDF00772772 /* 217.c */, + 942D9ACB14E8AFDF00772772 /* 22.c */, + 942D9ACC14E8AFDF00772772 /* 227.c */, + 942D9ACD14E8AFDF00772772 /* 228.c */, + 942D9ACE14E8AFDF00772772 /* 229.c */, + 942D9ACF14E8AFDF00772772 /* 230.c */, + 942D9AD014E8AFDF00772772 /* 231.c */, + 942D9AD114E8AFDF00772772 /* 232.c */, + 942D9AD214E8AFDF00772772 /* 234.c */, + 942D9AD314E8AFDF00772772 /* 241.c */, + 942D9AD414E8AFDF00772772 /* 242.c */, + 942D9AD514E8AFDF00772772 /* 244.c */, + 942D9AD614E8AFDF00772772 /* 246.c */, + 942D9AD714E8AFDF00772772 /* 24and26.c */, + 942D9AD814E8AFDF00772772 /* 25.c */, + 942D9AD914E8AFDF00772772 /* 255.c */, + 942D9ADA14E8AFDF00772772 /* 27.c */, + 942D9ADB14E8AFDF00772772 /* 32.c */, + 942D9ADC14E8AFDF00772772 /* 33.c */, + 942D9ADD14E8AFDF00772772 /* 40.c */, + 942D9ADE14E8AFDF00772772 /* 41.c */, + 942D9ADF14E8AFDF00772772 /* 42.c */, + 942D9AE014E8AFDF00772772 /* 46.c */, + 942D9AE114E8AFDF00772772 /* 50.c */, + 942D9AE214E8AFDF00772772 /* 51.c */, + 942D9AE314E8AFDF00772772 /* 59.c */, + 942D9AE414E8AFDF00772772 /* 6.c */, + 942D9AE514E8AFDF00772772 /* 61.c */, + 942D9AE614E8AFDF00772772 /* 62.c */, + 942D9AE714E8AFDF00772772 /* 65.c */, + 942D9AE814E8AFDF00772772 /* 67.c */, + 942D9AE914E8AFDF00772772 /* 69.c */, + 942D9AEA14E8AFDF00772772 /* 71.c */, + 942D9AEB14E8AFDF00772772 /* 72.c */, + 942D9AEC14E8AFDF00772772 /* 73.c */, + 942D9AED14E8AFDF00772772 /* 75.c */, + 942D9AEE14E8AFDF00772772 /* 76.c */, + 942D9AEF14E8AFDF00772772 /* 77.c */, + 942D9AF014E8AFDF00772772 /* 79.c */, + 942D9AF114E8AFDF00772772 /* 8.c */, + 942D9AF214E8AFDF00772772 /* 80.c */, + 942D9AF314E8AFDF00772772 /* 82.c */, + 942D9AF414E8AFDF00772772 /* 83.c */, + 942D9AF514E8AFDF00772772 /* 85.c */, + 942D9AF614E8AFDF00772772 /* 86.c */, + 942D9AF714E8AFDF00772772 /* 89.c */, + 942D9AF814E8AFDF00772772 /* 91.c */, + 942D9AF914E8AFDF00772772 /* 92.c */, + 942D9AFA14E8AFDF00772772 /* 97.c */, + 942D9AFB14E8AFDF00772772 /* 99.c */, + 942D9AFC14E8AFDF00772772 /* emu2413.c */, + 942D9AFD14E8AFDF00772772 /* emu2413.h */, + 942D9AFE14E8AFDF00772772 /* emutypes.h */, + 942D9AFF14E8AFDF00772772 /* mapinc.h */, + 942D9B0014E8AFDF00772772 /* mmc2and4.c */, + 942D9B0114E8AFDF00772772 /* simple.c */, + 942D9B0214E8AFDF00772772 /* vrc7tone.h */, + ); + path = mappers; + sourceTree = ""; + }; + 942D9B0D14E8AFDF00772772 /* palettes */ = { + isa = PBXGroup; + children = ( + 942D9B0E14E8AFDF00772772 /* conv.c */, + 942D9B0F14E8AFDF00772772 /* palettes.h */, + 942D9B1014E8AFDF00772772 /* rp2c04001.h */, + 942D9B1114E8AFDF00772772 /* rp2c04002.h */, + 942D9B1214E8AFDF00772772 /* rp2c04003.h */, + 942D9B1314E8AFDF00772772 /* rp2c05004.h */, + ); + path = palettes; + sourceTree = ""; + }; + 942D9B2814E8AFDF00772772 /* zlib */ = { + isa = PBXGroup; + children = ( + 942D9B2914E8AFDF00772772 /* adler32.c */, + 942D9B2A14E8AFDF00772772 /* compress.c */, + 942D9B2B14E8AFDF00772772 /* crc32.c */, + 942D9B2C14E8AFDF00772772 /* deflate.c */, + 942D9B2D14E8AFDF00772772 /* deflate.h */, + 942D9B2E14E8AFDF00772772 /* gzio.c */, + 942D9B2F14E8AFDF00772772 /* infblock.c */, + 942D9B3014E8AFDF00772772 /* infblock.h */, + 942D9B3114E8AFDF00772772 /* infcodes.c */, + 942D9B3214E8AFDF00772772 /* infcodes.h */, + 942D9B3314E8AFDF00772772 /* inffast.c */, + 942D9B3414E8AFDF00772772 /* inffast.h */, + 942D9B3514E8AFDF00772772 /* inffixed.h */, + 942D9B3614E8AFDF00772772 /* inflate.c */, + 942D9B3714E8AFDF00772772 /* inftrees.c */, + 942D9B3814E8AFDF00772772 /* inftrees.h */, + 942D9B3914E8AFDF00772772 /* infutil.c */, + 942D9B3A14E8AFDF00772772 /* infutil.h */, + 942D9B3B14E8AFDF00772772 /* trees.c */, + 942D9B3C14E8AFDF00772772 /* trees.h */, + 942D9B3D14E8AFDF00772772 /* uncompr.c */, + 942D9B3E14E8AFDF00772772 /* unzip.c */, + 942D9B3F14E8AFDF00772772 /* unzip.h */, + 942D9B4014E8AFDF00772772 /* zconf.h */, + 942D9B4114E8AFDF00772772 /* zlib.h */, + 942D9B4214E8AFDF00772772 /* zutil.c */, + 942D9B4314E8AFDF00772772 /* zutil.h */, + ); + path = zlib; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 8D5B49AC048680CD000E48DA /* FCEU */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1DEB913A08733D840010E9CD /* Build configuration list for PBXNativeTarget "FCEU" */; + buildPhases = ( + 8D5B49AF048680CD000E48DA /* Resources */, + 8D5B49B1048680CD000E48DA /* Sources */, + 8D5B49B3048680CD000E48DA /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + C6E916870FD34D5800AC2CCC /* PBXTargetDependency */, + ); + name = FCEU; + productInstallPath = "$(HOME)/Library/Bundles"; + productName = VisualBoyAdvance; + productReference = 8D5B49B6048680CD000E48DA /* FCEU.oecoreplugin */; + productType = "com.apple.product-type.bundle"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 089C1669FE841209C02AAC07 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = YES; + LastUpgradeCheck = 0420; + }; + buildConfigurationList = 1DEB913E08733D840010E9CD /* Build configuration list for PBXProject "FCEU" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 1; + knownRegions = ( + en, + ); + mainGroup = 089C166AFE841209C02AAC07 /* VisualBoyAdvance */; + projectDirPath = ""; + projectReferences = ( + { + ProductGroup = 82EA60490F514D80008E18C5 /* Products */; + ProjectRef = 82EA60480F514D80008E18C5 /* OpenEmu.xcodeproj */; + }, + ); + projectRoot = ""; + targets = ( + 8D5B49AC048680CD000E48DA /* FCEU */, + 82D815AB0F1D882B00EF8CF5 /* Build & Install FCEU */, + 82CAFD070FEDD57400CCDC7E /* Distribution */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXReferenceProxy section */ + 1B32153114DDDB4000C5B50A /* GameGear.oesystemplugin */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = GameGear.oesystemplugin; + remoteRef = 1B32153014DDDB4000C5B50A /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 378394E51029257000168304 /* OESaveStateQLPlugin.qlgenerator */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = OESaveStateQLPlugin.qlgenerator; + remoteRef = 378394E41029257000168304 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 82EA60510F514D80008E18C5 /* OpenEmu.app */ = { + isa = PBXReferenceProxy; + fileType = wrapper.application; + path = OpenEmu.app; + remoteRef = 82EA60500F514D80008E18C5 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 82EA60550F514D80008E18C5 /* OpenEmuBase.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = OpenEmuBase.framework; + remoteRef = 82EA60540F514D80008E18C5 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 8390474C14597FE200335E4F /* N64.oesystemplugin */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = N64.oesystemplugin; + remoteRef = 8390474B14597FE200335E4F /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + C62A264A116F094C0003DEE4 /* OpenEmuHelperApp */ = { + isa = PBXReferenceProxy; + fileType = "compiled.mach-o.executable"; + path = OpenEmuHelperApp; + remoteRef = C62A2649116F094C0003DEE4 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + C646575913771F4F002A4F70 /* GameBoy Advance.oesystemplugin */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = "GameBoy Advance.oesystemplugin"; + remoteRef = C646575813771F4F002A4F70 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + C6B9490013651ACD00A425F0 /* OpenEmuSystem.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = OpenEmuSystem.framework; + remoteRef = C6B948FF13651ACD00A425F0 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + C6B9490213651ACD00A425F0 /* SegaMasterSystem.oesystemplugin */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = SegaMasterSystem.oesystemplugin; + remoteRef = C6B9490113651ACD00A425F0 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + C6B9490413651ACD00A425F0 /* NES.oesystemplugin */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = NES.oesystemplugin; + remoteRef = C6B9490313651ACD00A425F0 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + C6B9490613651ACD00A425F0 /* SuperNES.oesystemplugin */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = SuperNES.oesystemplugin; + remoteRef = C6B9490513651ACD00A425F0 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + C6B9490813651ACD00A425F0 /* GameBoy.oesystemplugin */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = GameBoy.oesystemplugin; + remoteRef = C6B9490713651ACD00A425F0 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + C6B9490A13651ACD00A425F0 /* Genesis.oesystemplugin */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = Genesis.oesystemplugin; + remoteRef = C6B9490913651ACD00A425F0 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + C6B9E3FD14841AC400836111 /* NeoGeo Pocket.oesystemplugin */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = "NeoGeo Pocket.oesystemplugin"; + remoteRef = C6B9E3FC14841AC400836111 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; +/* End PBXReferenceProxy section */ + +/* Begin PBXResourcesBuildPhase section */ + 8D5B49AF048680CD000E48DA /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 8D5B49B0048680CD000E48DA /* InfoPlist.strings in Resources */, + C6C71E4A0FCDE25F002FAC4D /* ControlsPreference.xib in Resources */, + 82CAFD020FEDD54000CCDC7E /* dsa_pub.pem in Resources */, + 945942D014E4F2DC0015D2AA /* FCEUX.icns in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 82CAFD060FEDD57400CCDC7E /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = /usr/bin/openemu_rb_automation.rb; + }; + 82D815AA0F1D882B00EF8CF5 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "mkdir -p \"$USER_LIBRARY_DIR/Application Support/OpenEmu/Cores\"\nrm -rf \"$USER_LIBRARY_DIR/Application Support/OpenEmu/Cores/$PROJECT_NAME.oecoreplugin\"{,.dSYM}\ncp -rf \"$BUILT_PRODUCTS_DIR/$PROJECT_NAME.oecoreplugin\"{,.dSYM} \"$USER_LIBRARY_DIR/Application Support/OpenEmu/Cores/\"\n"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 8D5B49B1048680CD000E48DA /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 82EC40A30FD9EC5A0017FC19 /* FCEUGameEmu.mm in Sources */, + 82EC40A40FD9EC5D0017FC19 /* FCEUGameController.m in Sources */, + 942D9B4414E8AFDF00772772 /* libsnes.c in Sources */, + 942D9B4514E8AFDF00772772 /* memstream.c in Sources */, + 942D9B4614E8AFDF00772772 /* 01-222.c in Sources */, + 942D9B4714E8AFDF00772772 /* 103.c in Sources */, + 942D9B4814E8AFDF00772772 /* 106.c in Sources */, + 942D9B4914E8AFDF00772772 /* 108.c in Sources */, + 942D9B4A14E8AFDF00772772 /* 112.c in Sources */, + 942D9B4B14E8AFDF00772772 /* 116.c in Sources */, + 942D9B4C14E8AFDF00772772 /* 117.c in Sources */, + 942D9B4D14E8AFDF00772772 /* 120.c in Sources */, + 942D9B4E14E8AFDF00772772 /* 121.c in Sources */, + 942D9B4F14E8AFDF00772772 /* 12in1.c in Sources */, + 942D9B5014E8AFDF00772772 /* 15.c in Sources */, + 942D9B5114E8AFDF00772772 /* 156.c in Sources */, + 942D9B5214E8AFDF00772772 /* 164.c in Sources */, + 942D9B5314E8AFDF00772772 /* 168.c in Sources */, + 942D9B5414E8AFDF00772772 /* 170.c in Sources */, + 942D9B5514E8AFDF00772772 /* 175.c in Sources */, + 942D9B5614E8AFDF00772772 /* 176.c in Sources */, + 942D9B5714E8AFDF00772772 /* 177.c in Sources */, + 942D9B5814E8AFDF00772772 /* 178.c in Sources */, + 942D9B5914E8AFDF00772772 /* 183.c in Sources */, + 942D9B5A14E8AFDF00772772 /* 185.c in Sources */, + 942D9B5B14E8AFDF00772772 /* 186.c in Sources */, + 942D9B5C14E8AFDF00772772 /* 187.c in Sources */, + 942D9B5D14E8AFDF00772772 /* 189.c in Sources */, + 942D9B5E14E8AFDF00772772 /* 193.c in Sources */, + 942D9B5F14E8AFDF00772772 /* 199.c in Sources */, + 942D9B6014E8AFDF00772772 /* 208.c in Sources */, + 942D9B6114E8AFDF00772772 /* 222.c in Sources */, + 942D9B6214E8AFDF00772772 /* 225.c in Sources */, + 942D9B6314E8AFDF00772772 /* 23.c in Sources */, + 942D9B6414E8AFDF00772772 /* 235.c in Sources */, + 942D9B6514E8AFDF00772772 /* 253.c in Sources */, + 942D9B6614E8AFDF00772772 /* 3d-block.c in Sources */, + 942D9B6714E8AFDF00772772 /* 411120-c.c in Sources */, + 942D9B6814E8AFDF00772772 /* 43.c in Sources */, + 942D9B6914E8AFDF00772772 /* 57.c in Sources */, + 942D9B6A14E8AFDF00772772 /* 603-5052.c in Sources */, + 942D9B6B14E8AFDF00772772 /* 68.c in Sources */, + 942D9B6C14E8AFDF00772772 /* 8157.c in Sources */, + 942D9B6D14E8AFDF00772772 /* 8237.c in Sources */, + 942D9B6E14E8AFDF00772772 /* 830118C.c in Sources */, + 942D9B6F14E8AFDF00772772 /* 88.c in Sources */, + 942D9B7014E8AFDF00772772 /* 90.c in Sources */, + 942D9B7114E8AFDF00772772 /* 95.c in Sources */, + 942D9B7414E8AFDF00772772 /* a9746.c in Sources */, + 942D9B7514E8AFDF00772772 /* ac-08.c in Sources */, + 942D9B7614E8AFDF00772772 /* addrlatch.c in Sources */, + 942D9B7714E8AFDF00772772 /* ax5705.c in Sources */, + 942D9B7814E8AFDF00772772 /* bandai.c in Sources */, + 942D9B7914E8AFDF00772772 /* bmc13in1jy110.c in Sources */, + 942D9B7A14E8AFDF00772772 /* bmc42in1r.c in Sources */, + 942D9B7B14E8AFDF00772772 /* bmc64in1nr.c in Sources */, + 942D9B7C14E8AFDF00772772 /* bmc70in1.c in Sources */, + 942D9B7D14E8AFDF00772772 /* bonza.c in Sources */, + 942D9B7E14E8AFDF00772772 /* bs-5.c in Sources */, + 942D9B7F14E8AFDF00772772 /* copyfami_emu.c in Sources */, + 942D9B8014E8AFDF00772772 /* copyfami_hwi.c in Sources */, + 942D9B8114E8AFDF00772772 /* dance2000.c in Sources */, + 942D9B8214E8AFDF00772772 /* datalatch.c in Sources */, + 942D9B8314E8AFDF00772772 /* deirom.c in Sources */, + 942D9B8414E8AFDF00772772 /* dream.c in Sources */, + 942D9B8514E8AFDF00772772 /* dummy_mapper.c in Sources */, + 942D9B8614E8AFDF00772772 /* edu2000.c in Sources */, + 942D9B8714E8AFDF00772772 /* fk23c.c in Sources */, + 942D9B8814E8AFDF00772772 /* ghostbusters63in1.c in Sources */, + 942D9B8914E8AFDF00772772 /* gs-2004.c in Sources */, + 942D9B8A14E8AFDF00772772 /* gs-2013.c in Sources */, + 942D9B8B14E8AFDF00772772 /* h2288.c in Sources */, + 942D9B8C14E8AFDF00772772 /* karaoke.c in Sources */, + 942D9B8D14E8AFDF00772772 /* kof97.c in Sources */, + 942D9B8E14E8AFDF00772772 /* konami-qtai.c in Sources */, + 942D9B8F14E8AFDF00772772 /* KS7012.c in Sources */, + 942D9B9014E8AFDF00772772 /* KS7013.c in Sources */, + 942D9B9114E8AFDF00772772 /* KS7017.c in Sources */, + 942D9B9214E8AFDF00772772 /* KS7032.c in Sources */, + 942D9B9314E8AFDF00772772 /* KS7037.c in Sources */, + 942D9B9414E8AFDF00772772 /* KS7057.c in Sources */, + 942D9B9514E8AFDF00772772 /* le05.c in Sources */, + 942D9B9614E8AFDF00772772 /* malee.c in Sources */, + 942D9B9714E8AFDF00772772 /* mmc1.c in Sources */, + 942D9B9814E8AFDF00772772 /* mmc3.c in Sources */, + 942D9B9914E8AFDF00772772 /* mmc5.c in Sources */, + 942D9B9A14E8AFDF00772772 /* n106.c in Sources */, + 942D9B9B14E8AFDF00772772 /* n625092.c in Sources */, + 942D9B9C14E8AFDF00772772 /* novel.c in Sources */, + 942D9B9D14E8AFDF00772772 /* onebus.c in Sources */, + 942D9B9E14E8AFDF00772772 /* pec-586.c in Sources */, + 942D9B9F14E8AFDF00772772 /* sachen.c in Sources */, + 942D9BA014E8AFDF00772772 /* sc-127.c in Sources */, + 942D9BA114E8AFDF00772772 /* sheroes.c in Sources */, + 942D9BA214E8AFDF00772772 /* sl1632.c in Sources */, + 942D9BA314E8AFDF00772772 /* smb2j.c in Sources */, + 942D9BA414E8AFDF00772772 /* subor.c in Sources */, + 942D9BA514E8AFDF00772772 /* super24.c in Sources */, + 942D9BA614E8AFDF00772772 /* supervision.c in Sources */, + 942D9BA714E8AFDF00772772 /* t-227-1.c in Sources */, + 942D9BA814E8AFDF00772772 /* t-262.c in Sources */, + 942D9BA914E8AFDF00772772 /* tengen.c in Sources */, + 942D9BAA14E8AFDF00772772 /* tf-1201.c in Sources */, + 942D9BAB14E8AFDF00772772 /* transformer.c in Sources */, + 942D9BAC14E8AFDF00772772 /* vrc7.c in Sources */, + 942D9BAD14E8AFDF00772772 /* yoko.c in Sources */, + 942D9BAE14E8AFDF00772772 /* cart.c in Sources */, + 942D9BAF14E8AFDF00772772 /* cheat.c in Sources */, + 942D9BB014E8AFDF00772772 /* fceu.c in Sources */, + 942D9BB114E8AFDF00772772 /* fds.c in Sources */, + 942D9BB214E8AFDF00772772 /* file.c in Sources */, + 942D9BC114E8AFDF00772772 /* general.c in Sources */, + 942D9BC214E8AFDF00772772 /* ines.c in Sources */, + 942D9BC314E8AFDF00772772 /* arkanoid.c in Sources */, + 942D9BC414E8AFDF00772772 /* bbox.c in Sources */, + 942D9BC514E8AFDF00772772 /* bworld.c in Sources */, + 942D9BC614E8AFDF00772772 /* cursor.c in Sources */, + 942D9BC714E8AFDF00772772 /* fkb.c in Sources */, + 942D9BC814E8AFDF00772772 /* ftrainer.c in Sources */, + 942D9BC914E8AFDF00772772 /* hypershot.c in Sources */, + 942D9BCA14E8AFDF00772772 /* mahjong.c in Sources */, + 942D9BCB14E8AFDF00772772 /* mouse.c in Sources */, + 942D9BCC14E8AFDF00772772 /* oekakids.c in Sources */, + 942D9BCD14E8AFDF00772772 /* pads.c in Sources */, + 942D9BCE14E8AFE000772772 /* pec586kb.c in Sources */, + 942D9BCF14E8AFE000772772 /* powerpad.c in Sources */, + 942D9BD014E8AFE000772772 /* quiz.c in Sources */, + 942D9BD114E8AFE000772772 /* shadow.c in Sources */, + 942D9BD214E8AFE000772772 /* suborkb.c in Sources */, + 942D9BD314E8AFE000772772 /* toprider.c in Sources */, + 942D9BD414E8AFE000772772 /* zapper.c in Sources */, + 942D9BD514E8AFE000772772 /* input.c in Sources */, + 942D9BD614E8AFE000772772 /* 151.c in Sources */, + 942D9BD714E8AFE000772772 /* 157.c in Sources */, + 942D9BD814E8AFE000772772 /* 17.c in Sources */, + 942D9BD914E8AFE000772772 /* 18.c in Sources */, + 942D9BDA14E8AFE000772772 /* 201.c in Sources */, + 942D9BDB14E8AFE000772772 /* 202.c in Sources */, + 942D9BDC14E8AFE000772772 /* 203.c in Sources */, + 942D9BDD14E8AFE000772772 /* 204.c in Sources */, + 942D9BDE14E8AFE000772772 /* 21.c in Sources */, + 942D9BDF14E8AFE000772772 /* 212.c in Sources */, + 942D9BE014E8AFE000772772 /* 213.c in Sources */, + 942D9BE114E8AFE000772772 /* 214.c in Sources */, + 942D9BE214E8AFE000772772 /* 215.c in Sources */, + 942D9BE314E8AFE000772772 /* 217.c in Sources */, + 942D9BE414E8AFE000772772 /* 22.c in Sources */, + 942D9BE514E8AFE000772772 /* 227.c in Sources */, + 942D9BE614E8AFE000772772 /* 228.c in Sources */, + 942D9BE714E8AFE000772772 /* 229.c in Sources */, + 942D9BE814E8AFE000772772 /* 230.c in Sources */, + 942D9BE914E8AFE000772772 /* 231.c in Sources */, + 942D9BEA14E8AFE000772772 /* 232.c in Sources */, + 942D9BEB14E8AFE000772772 /* 234.c in Sources */, + 942D9BEC14E8AFE000772772 /* 241.c in Sources */, + 942D9BED14E8AFE000772772 /* 242.c in Sources */, + 942D9BEE14E8AFE000772772 /* 244.c in Sources */, + 942D9BEF14E8AFE000772772 /* 246.c in Sources */, + 942D9BF014E8AFE000772772 /* 24and26.c in Sources */, + 942D9BF114E8AFE000772772 /* 25.c in Sources */, + 942D9BF214E8AFE000772772 /* 255.c in Sources */, + 942D9BF314E8AFE000772772 /* 27.c in Sources */, + 942D9BF414E8AFE000772772 /* 32.c in Sources */, + 942D9BF514E8AFE000772772 /* 33.c in Sources */, + 942D9BF614E8AFE000772772 /* 40.c in Sources */, + 942D9BF714E8AFE000772772 /* 41.c in Sources */, + 942D9BF814E8AFE000772772 /* 42.c in Sources */, + 942D9BF914E8AFE000772772 /* 46.c in Sources */, + 942D9BFA14E8AFE000772772 /* 50.c in Sources */, + 942D9BFB14E8AFE000772772 /* 51.c in Sources */, + 942D9BFC14E8AFE000772772 /* 59.c in Sources */, + 942D9BFD14E8AFE000772772 /* 6.c in Sources */, + 942D9BFE14E8AFE000772772 /* 61.c in Sources */, + 942D9BFF14E8AFE000772772 /* 62.c in Sources */, + 942D9C0014E8AFE000772772 /* 65.c in Sources */, + 942D9C0114E8AFE000772772 /* 67.c in Sources */, + 942D9C0214E8AFE000772772 /* 69.c in Sources */, + 942D9C0314E8AFE000772772 /* 71.c in Sources */, + 942D9C0414E8AFE000772772 /* 72.c in Sources */, + 942D9C0514E8AFE000772772 /* 73.c in Sources */, + 942D9C0614E8AFE000772772 /* 75.c in Sources */, + 942D9C0714E8AFE000772772 /* 76.c in Sources */, + 942D9C0814E8AFE000772772 /* 77.c in Sources */, + 942D9C0914E8AFE000772772 /* 79.c in Sources */, + 942D9C0A14E8AFE000772772 /* 8.c in Sources */, + 942D9C0B14E8AFE000772772 /* 80.c in Sources */, + 942D9C0C14E8AFE000772772 /* 82.c in Sources */, + 942D9C0D14E8AFE000772772 /* 83.c in Sources */, + 942D9C0E14E8AFE000772772 /* 85.c in Sources */, + 942D9C0F14E8AFE000772772 /* 86.c in Sources */, + 942D9C1014E8AFE000772772 /* 89.c in Sources */, + 942D9C1114E8AFE000772772 /* 91.c in Sources */, + 942D9C1214E8AFE000772772 /* 92.c in Sources */, + 942D9C1314E8AFE000772772 /* 97.c in Sources */, + 942D9C1414E8AFE000772772 /* 99.c in Sources */, + 942D9C1514E8AFE000772772 /* emu2413.c in Sources */, + 942D9C1614E8AFE000772772 /* mmc2and4.c in Sources */, + 942D9C1714E8AFE000772772 /* simple.c in Sources */, + 942D9C1814E8AFE000772772 /* md5.c in Sources */, + 942D9C1914E8AFE000772772 /* memory.c in Sources */, + 942D9C1A14E8AFE000772772 /* mycrc32.c in Sources */, + 942D9C1B14E8AFE000772772 /* myendian.c in Sources */, + 942D9C1C14E8AFE000772772 /* palette.c in Sources */, + 942D9C1E14E8AFE000772772 /* ppu.c in Sources */, + 942D9C1F14E8AFE000772772 /* sound.c in Sources */, + 942D9C2014E8AFE000772772 /* state.c in Sources */, + 942D9C2114E8AFE000772772 /* unif.c in Sources */, + 942D9C2214E8AFE000772772 /* unzip.c in Sources */, + 942D9C2314E8AFE000772772 /* vsuni.c in Sources */, + 942D9C2414E8AFE000772772 /* x6502.c in Sources */, + 942D9C2514E8AFE000772772 /* adler32.c in Sources */, + 942D9C2614E8AFE000772772 /* compress.c in Sources */, + 942D9C2714E8AFE000772772 /* crc32.c in Sources */, + 942D9C2814E8AFE000772772 /* deflate.c in Sources */, + 942D9C2914E8AFE000772772 /* gzio.c in Sources */, + 942D9C2A14E8AFE000772772 /* infblock.c in Sources */, + 942D9C2B14E8AFE000772772 /* infcodes.c in Sources */, + 942D9C2C14E8AFE000772772 /* inffast.c in Sources */, + 942D9C2D14E8AFE000772772 /* inflate.c in Sources */, + 942D9C2E14E8AFE000772772 /* inftrees.c in Sources */, + 942D9C2F14E8AFE000772772 /* infutil.c in Sources */, + 942D9C3014E8AFE000772772 /* trees.c in Sources */, + 942D9C3114E8AFE000772772 /* uncompr.c in Sources */, + 942D9C3314E8AFE000772772 /* zutil.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 82CAFD0B0FEDD57B00CCDC7E /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 8D5B49AC048680CD000E48DA /* FCEU */; + targetProxy = 82CAFD0A0FEDD57B00CCDC7E /* PBXContainerItemProxy */; + }; + 82D815AF0F1D883500EF8CF5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 8D5B49AC048680CD000E48DA /* FCEU */; + targetProxy = 82D815AE0F1D883500EF8CF5 /* PBXContainerItemProxy */; + }; + C6E916870FD34D5800AC2CCC /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = OpenEmuBase; + targetProxy = C6E916860FD34D5800AC2CCC /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 089C167DFE841241C02AAC07 /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + 089C167EFE841241C02AAC07 /* English */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 1DEB913B08733D840010E9CD /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = YES; + CLANG_ENABLE_OBJC_ARC = YES; + EXPORTED_SYMBOLS_FILE = ""; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = FCEU.pch; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)/../OpenEmu\"/**", + "\"$(PROJECT_DIR)/core/src-fceumm\"", + "\"$(PROJECT_DIR)/core/utils/zlib\"", + "\"$(PROJECT_DIR)/core/utils/unzip\"", + core, + ); + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = "$(HOME)/Library/Bundles"; + LD_RUNPATH_SEARCH_PATHS = "\"/Library/Graphics/Quartz Composer Plug-Ins/OpenEmuQC.plugin/Contents/Frameworks/\" \"~/Library/Graphics/Quartz Composer Plug-Ins/OpenEmuQC.plugin/Contents/Frameworks/\" ~/Library/Frameworks /Library/Frameworks @loader_path/../Frameworks"; + LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/fceumm\""; + OTHER_CFLAGS = ( + "-fPIC", + "-DHAVE_ASPRINTF", + "-DNDEBUG", + "-D__LIBSNES__", + "-DSOUND_QUALITY=0", + "-DPATH_MAX=1024", + "-DINLINE=inline", + "-DPSS_STYLE=1", + "-DLSB_FIRST", + "-DLOCAL_LE=1", + "-I./libsnes-fceumm", + "-I./src-fceumm", + "-I./src-fceumm/input", + "-I./src-fceumm/boards", + "-I./src-fceumm/mappers", + "-I./utils/zlib", + ); + PRODUCT_NAME = FCEU; + USER_HEADER_SEARCH_PATHS = "\"$(PROJECT_DIR)/core/\""; + VALID_ARCHS = x86_64; + WARNING_CFLAGS = "-Wno-write-strings"; + WRAPPER_EXTENSION = oecoreplugin; + }; + name = Debug; + }; + 1DEB913C08733D840010E9CD /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = YES; + CLANG_ENABLE_OBJC_ARC = YES; + EXPORTED_SYMBOLS_FILE = ""; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = FCEU.pch; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)/../OpenEmu\"/**", + "\"$(PROJECT_DIR)/core/src-fceumm\"", + "\"$(PROJECT_DIR)/core/utils/zlib\"", + "\"$(PROJECT_DIR)/core/utils/unzip\"", + core, + ); + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = "$(HOME)/Library/Bundles"; + LD_RUNPATH_SEARCH_PATHS = "\"/Library/Graphics/Quartz Composer Plug-Ins/OpenEmuQC.plugin/Contents/Frameworks/\" \"~/Library/Graphics/Quartz Composer Plug-Ins/OpenEmuQC.plugin/Contents/Frameworks/\" ~/Library/Frameworks /Library/Frameworks @loader_path/../Frameworks"; + LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/fceumm\""; + OTHER_CFLAGS = ( + "-fPIC", + "-DHAVE_ASPRINTF", + "-DNDEBUG", + "-D__LIBSNES__", + "-DSOUND_QUALITY=0", + "-DPATH_MAX=1024", + "-DINLINE=inline", + "-DPSS_STYLE=1", + "-DLSB_FIRST", + "-DLOCAL_LE=1", + "-I./libsnes-fceumm", + "-I./src-fceumm", + "-I./src-fceumm/input", + "-I./src-fceumm/boards", + "-I./src-fceumm/mappers", + "-I./utils/zlib", + ); + PRODUCT_NAME = FCEU; + USER_HEADER_SEARCH_PATHS = "\"$(PROJECT_DIR)/core/\""; + VALID_ARCHS = x86_64; + WARNING_CFLAGS = "-Wno-write-strings"; + WRAPPER_EXTENSION = oecoreplugin; + }; + name = Release; + }; + 1DEB913F08733D840010E9CD /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_ENABLE_OBJC_EXPERIMENTAL = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_C_LANGUAGE_STANDARD = c99; + GCC_INCREASE_PRECOMPILED_HEADER_SHARING = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = "$(SRCROOT)/../OpenEmu"; + MACOSX_DEPLOYMENT_TARGET = 10.7; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + VALID_ARCHS = x86_64; + }; + name = Debug; + }; + 1DEB914008733D840010E9CD /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_ENABLE_OBJC_EXPERIMENTAL = YES; + DEAD_CODE_STRIPPING = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_C_LANGUAGE_STANDARD = c99; + GCC_INCREASE_PRECOMPILED_HEADER_SHARING = YES; + GCC_OPTIMIZATION_LEVEL = 3; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = "$(SRCROOT)/../OpenEmu"; + MACOSX_DEPLOYMENT_TARGET = 10.7; + SDKROOT = macosx; + VALID_ARCHS = x86_64; + }; + name = Release; + }; + 82CAFD080FEDD57400CCDC7E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = Distribution; + }; + name = Debug; + }; + 82CAFD090FEDD57400CCDC7E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = Distribution; + }; + name = Release; + }; + 82D815AC0F1D882C00EF8CF5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "Build & Install"; + }; + name = Debug; + }; + 82D815AD0F1D882C00EF8CF5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "Build & Install"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 1DEB913A08733D840010E9CD /* Build configuration list for PBXNativeTarget "FCEU" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1DEB913B08733D840010E9CD /* Debug */, + 1DEB913C08733D840010E9CD /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 1DEB913E08733D840010E9CD /* Build configuration list for PBXProject "FCEU" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1DEB913F08733D840010E9CD /* Debug */, + 1DEB914008733D840010E9CD /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 82CAFD170FEDD58500CCDC7E /* Build configuration list for PBXAggregateTarget "Distribution" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 82CAFD080FEDD57400CCDC7E /* Debug */, + 82CAFD090FEDD57400CCDC7E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 82D815B90F1D883D00EF8CF5 /* Build configuration list for PBXAggregateTarget "Build & Install FCEU" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 82D815AC0F1D882C00EF8CF5 /* Debug */, + 82D815AD0F1D882C00EF8CF5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 089C1669FE841209C02AAC07 /* Project object */; +} diff --git a/FCEUGameController.h b/FCEUGameController.h new file mode 100644 index 0000000..b38d20c --- /dev/null +++ b/FCEUGameController.h @@ -0,0 +1,32 @@ +/* + Copyright (c) 2009, OpenEmu Team + + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the OpenEmu Team nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import +#import + +@interface FCEUGameController : OEGameCoreController +@end diff --git a/FCEUGameController.m b/FCEUGameController.m new file mode 100644 index 0000000..1017bc5 --- /dev/null +++ b/FCEUGameController.m @@ -0,0 +1,55 @@ +/* + Copyright (c) 2009, OpenEmu Team + + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the OpenEmu Team nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import "FCEUGameController.h" +#import "FCEUGameEmu.h" + +@implementation FCEUGameController + ++ (void)initialize +{ + if(self == [FCEUGameController class]) + { + } +} + +- (NSArray *)genericControlNames +{ + return nil; +} + +- (NSUInteger)playerCount +{ + return MAC_MAX_PLAYERS; +} + +- (Class)gameCoreClass +{ + return [FCEUGameEmu class]; +} + +@end diff --git a/FCEUGameEmu.h b/FCEUGameEmu.h new file mode 100644 index 0000000..7fc53d4 --- /dev/null +++ b/FCEUGameEmu.h @@ -0,0 +1,49 @@ +/* + Copyright (c) 2009, OpenEmu Team + + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the OpenEmu Team nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import +#import + +#define MAC_MAX_PLAYERS 2 +#define SNES_CONTROL_COUNT 8 + +extern NSString *FCEUEmulatorNames[]; + +@class OERingBuffer; + +@interface FCEUGameEmu : OEGameCore +{ + @public + uint32 controlPad[MAC_MAX_PLAYERS]; + uint16_t *soundBuffer; + uint16_t *videoBuffer; + int videoWidth, videoHeight; + int16_t pad[2][8]; + NSString *romName; +} + +@end diff --git a/FCEUGameEmu.mm b/FCEUGameEmu.mm new file mode 100644 index 0000000..c8f4021 --- /dev/null +++ b/FCEUGameEmu.mm @@ -0,0 +1,434 @@ +/* + Copyright (c) 2009, OpenEmu Team + + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the OpenEmu Team nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import "FCEUGameEmu.h" +#import +#import "OENESSystemResponderClient.h" +#import + +#include "libsnes.h" +//#include "../src-fceumm/sound.h" + +//#define SAMPLERATE 32040 +#define SAMPLERATE 48000 +#define SAMPLEFRAME 800 +#define SIZESOUNDBUFFER SAMPLEFRAME*4 + +@interface FCEUGameEmu () +@end + +NSUInteger FCEUEmulatorValues[] = { SNES_DEVICE_ID_JOYPAD_A, SNES_DEVICE_ID_JOYPAD_B, SNES_DEVICE_ID_JOYPAD_UP, SNES_DEVICE_ID_JOYPAD_DOWN, SNES_DEVICE_ID_JOYPAD_LEFT, SNES_DEVICE_ID_JOYPAD_RIGHT, SNES_DEVICE_ID_JOYPAD_START, SNES_DEVICE_ID_JOYPAD_SELECT }; +NSString *FCEUEmulatorKeys[] = { @"Joypad@ A", @"Joypad@ B", @"Joypad@ Up", @"Joypad@ Down", @"Joypad@ Left", @"Joypad@ Right", @"Joypad@ Start", @"Joypad@ Select"}; + +FCEUGameEmu *current; +@implementation FCEUGameEmu + +static uint16_t conv555Rto565(uint16_t p) +{ + unsigned r, g, b; + + b = (p >> 10); + g = (p >> 5) & 0x1f; + r = p & 0x1f; + + // 5 to 6 bit + g = (g << 1) + (g >> 4); + + return r | (g << 5) | (b << 11); +} + +static void audio_callback(uint16_t left, uint16_t right) +{ + [[current ringBufferAtIndex:0] write:&left maxLength:2]; + [[current ringBufferAtIndex:0] write:&right maxLength:2]; +} + +static void video_callback(const uint16_t *data, unsigned width, unsigned height) +{ + // Normally our pitch is 2048 bytes. + int stride = 1024; + // If we have an interlaced mode, pitch is 1024 bytes. + if ( height == 256 || height == 478 ) + stride = 256; + + current->videoWidth = width; + current->videoHeight = height; + + dispatch_queue_t the_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); + + // TODO opencl CPU device? + dispatch_apply(height, the_queue, ^(size_t y){ + const uint16_t *src = data + y * stride; + uint16_t *dst = current->videoBuffer + y * 256; + + for (int x = 0; x < width; x++) { + dst[x] = conv555Rto565(src[x]); + } + }); +} + +static void input_poll_callback(void) +{ + //NSLog(@"poll callback"); +} + +static int16_t input_state_callback(bool port, unsigned device, unsigned index, unsigned devid) +{ + //NSLog(@"polled input: port: %d device: %d id: %d", port, device, devid); + + if (port == SNES_PORT_1 & device == SNES_DEVICE_JOYPAD) { + return current->pad[0][devid]; + } + else if(port == SNES_PORT_2 & device == SNES_DEVICE_JOYPAD) { + return current->pad[1][devid]; + } + + return 0; +} + +static bool environment_callback(unsigned cmd, void *data) +{ + switch (cmd) + { + case SNES_ENVIRONMENT_GET_FULLPATH: + *(const char**)data = [current->romName cStringUsingEncoding:NSUTF8StringEncoding]; + NSLog(@"Environ FULLPATH: \"%@\"\n", current->romName); + break; + + case SNES_ENVIRONMENT_SET_TIMING: + + break; + + default: + NSLog(@"Environ UNSUPPORTED (#%u)!\n", cmd); + return false; + } + + return true; +} + +static void loadSaveFile(const char* path, int type) +{ + FILE *file; + + file = fopen(path, "rb"); + if ( !file ) + { + return; + } + + size_t size = snes_get_memory_size(type); + uint8_t *data = snes_get_memory_data(type); + + if (size == 0 || !data) + { + fclose(file); + return; + } + + int rc = fread(data, sizeof(uint8_t), size, file); + if ( rc != size ) + { + NSLog(@"Couldn't load save file."); + } + + NSLog(@"Loaded save file: %s", path); + + fclose(file); +} + +static void writeSaveFile(const char* path, int type) +{ + size_t size = snes_get_memory_size(type); + uint8_t *data = snes_get_memory_data(type); + + if ( data && size > 0 ) + { + FILE *file = fopen(path, "wb"); + if ( file != NULL ) + { + NSLog(@"Saving state %s. Size: %d bytes.", path, (int)size); + if ( fwrite(data, sizeof(uint8_t), size, file) != size ) + NSLog(@"Did not save state properly."); + fclose(file); + } + } +} + +- (void)didPushNESButton:(OENESButton)button forPlayer:(NSUInteger)player; +{ + pad[player-1][FCEUEmulatorValues[button]] = 0xFFFF; + //pad[player-1][FCEUEmulatorValues[button]] = 1; +} + +- (void)didReleaseNESButton:(OENESButton)button forPlayer:(NSUInteger)player; +{ + pad[player-1][FCEUEmulatorValues[button]] = 0; +} + +- (void)didPushFDSChangeSideButton; +{ + +} +- (void)didReleaseFDSChangeSideButton; +{ + +} + +- (id)init +{ + self = [super init]; + if(self != nil) + { + if(videoBuffer) + free(videoBuffer); + videoBuffer = (uint16_t*)malloc(256 * 240 * 2); + } + + current = self; + + return self; +} + +#pragma mark Exectuion + +- (void)executeFrame +{ + [self executeFrameSkippingFrame:NO]; +} + +- (void)executeFrameSkippingFrame: (BOOL) skip +{ + snes_run(); +} + +- (BOOL)loadFileAtPath: (NSString*) path +{ + memset(pad, 0, sizeof(int16_t) * 16); + + uint8_t *data; + unsigned size; + romName = [path copy]; + + //load cart, read bytes, get length + NSData* dataObj = [NSData dataWithContentsOfFile:[romName stringByStandardizingPath]]; + if(dataObj == nil) return false; + size = [dataObj length]; + data = (uint8_t*)[dataObj bytes]; + + //remove copier header, if it exists + //ssif((size & 0x7fff) == 512) memmove(data, data + 512, size -= 512); + + //memory.copy(data, size); + snes_set_environment(environment_callback); + snes_init(); + + snes_set_audio_sample(audio_callback); + snes_set_video_refresh(video_callback); + snes_set_input_poll(input_poll_callback); + snes_set_input_state(input_state_callback); + + if(snes_load_cartridge_normal(NULL, data, size)) + { + NSString *path = romName; + NSString *extensionlessFilename = [[path lastPathComponent] stringByDeletingPathExtension]; + + NSString *batterySavesDirectory = [self batterySavesDirectoryPath]; + + // if((batterySavesDirectory != nil) && ![batterySavesDirectory isEqualToString:@""]) + if([batterySavesDirectory length] != 0) + { + [[NSFileManager defaultManager] createDirectoryAtPath:batterySavesDirectory withIntermediateDirectories:YES attributes:nil error:NULL]; + + NSString *filePath = [batterySavesDirectory stringByAppendingPathComponent:[extensionlessFilename stringByAppendingPathExtension:@"sav"]]; + + loadSaveFile([filePath UTF8String], SNES_MEMORY_CARTRIDGE_RAM); + } + + snes_set_controller_port_device(SNES_PORT_1, SNES_DEVICE_JOYPAD); + snes_set_controller_port_device(SNES_PORT_2, SNES_DEVICE_JOYPAD); + + snes_get_region(); + + snes_run(); + } + + return YES; +} + +#pragma mark Video +- (const void *)videoBuffer +{ + return videoBuffer; +} + +- (OEIntRect)screenRect +{ + return OERectMake(0, 0, videoWidth, videoHeight); +} + +- (OEIntSize)bufferSize +{ + return OESizeMake(256, 240); +} + +- (void)setupEmulation +{ + if(soundBuffer) + free(soundBuffer); + soundBuffer = (UInt16*)malloc(SIZESOUNDBUFFER* sizeof(UInt16)); + memset(soundBuffer, 0, SIZESOUNDBUFFER*sizeof(UInt16)); +} + +- (void)resetEmulation +{ + snes_reset(); +} + +- (void)stopEmulation +{ + NSString *path = romName; + NSString *extensionlessFilename = [[path lastPathComponent] stringByDeletingPathExtension]; + + NSString *batterySavesDirectory = [self batterySavesDirectoryPath]; + + if([batterySavesDirectory length] != 0) + { + + [[NSFileManager defaultManager] createDirectoryAtPath:batterySavesDirectory withIntermediateDirectories:YES attributes:nil error:NULL]; + + NSLog(@"Trying to save SRAM"); + + NSString *filePath = [batterySavesDirectory stringByAppendingPathComponent:[extensionlessFilename stringByAppendingPathExtension:@"sav"]]; + + writeSaveFile([filePath UTF8String], SNES_MEMORY_CARTRIDGE_RAM); + } + + NSLog(@"snes term"); + snes_unload_cartridge(); + snes_term(); + [super stopEmulation]; +} + +- (void)dealloc +{ + free(videoBuffer); + free(soundBuffer); +} + +- (GLenum)pixelFormat +{ + return GL_RGB; +} + +- (GLenum)pixelType +{ + return GL_UNSIGNED_SHORT_5_6_5; +} + +- (GLenum)internalPixelFormat +{ + return GL_RGB5; +} + +- (NSUInteger)soundBufferSize +{ + return SIZESOUNDBUFFER; +} + +- (NSUInteger)frameSampleCount +{ + return SAMPLEFRAME; +} + +- (NSUInteger)frameSampleRate +{ + return SAMPLERATE; +} + +- (NSTimeInterval)frameInterval +{ + return (snes_get_region() == SNES_REGION_NTSC) ? 60 : 50; +} + +- (NSUInteger)channelCount +{ + return 2; +} + +- (BOOL)saveStateToFileAtPath:(NSString *)fileName +{ + int serial_size = snes_serialize_size(); + uint8_t *serial_data = (uint8_t *) malloc(serial_size); + + snes_serialize(serial_data, serial_size); + + FILE *state_file = fopen([fileName UTF8String], "wb"); + long bytes_written = fwrite(serial_data, sizeof(uint8_t), serial_size, state_file); + + free(serial_data); + + if( bytes_written != serial_size ) + { + NSLog(@"Couldn't write state"); + return NO; + } + fclose( state_file ); + return YES; +} + +- (BOOL)loadStateFromFileAtPath:(NSString *)fileName +{ + FILE *state_file = fopen([fileName UTF8String], "rb"); + if( !state_file ) + { + NSLog(@"Could not open state file"); + return NO; + } + + int serial_size = snes_serialize_size(); + uint8_t *serial_data = (uint8_t *) malloc(serial_size); + + if(!fread(serial_data, sizeof(uint8_t), serial_size, state_file)) + { + NSLog(@"Couldn't read file"); + return NO; + } + fclose(state_file); + + if(!snes_unserialize(serial_data, serial_size)) + { + NSLog(@"Couldn't unpack state"); + return NO; + } + + free(serial_data); + + return YES; +} + +@end diff --git a/FCEUX.icns b/FCEUX.icns new file mode 100644 index 0000000..cc62722 Binary files /dev/null and b/FCEUX.icns differ diff --git a/Info.plist b/Info.plist new file mode 100644 index 0000000..6179dd1 --- /dev/null +++ b/Info.plist @@ -0,0 +1,36 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFile + FCEUX + CFBundleIdentifier + com.openemu.${PRODUCT_NAME:identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleSignature + ???? + CFBundleVersion + 1.0-fceummnext + NSPrincipalClass + FCEUGameController + OEProjectURL + http://sourceforge.net/projects/fceumm/ + OESystemIdentifiers + + openemu.system.nes + + SUEnableAutomaticChecks + 1 + SUFeedURL + http://openemu.org/update/fceu_appcast.xml + SUPublicDSAKeyFile + dsa_pub.pem + + diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..a8b3975 --- /dev/null +++ b/config.yaml @@ -0,0 +1,9 @@ +build_now: 'YES' +create_core_path: 'YES' +download_base_url: http://github.com/downloads/openemu/openemu +release_notes_base_url: http://openemu.org/category/releasenotes/fceux/ +appcast_basefolder: '/Users/jweinberg/Desktop/Appcast' +appcast_xml_name: 'fceux_appcast.xml' +keychain_privkey_name: 'Sparkle Private Key' +css_file_name: 'rnotes.css' +bundle_extension: 'oecoreplugin' \ No newline at end of file diff --git a/dsa_pub.pem b/dsa_pub.pem new file mode 100644 index 0000000..372bdff --- /dev/null +++ b/dsa_pub.pem @@ -0,0 +1,20 @@ +-----BEGIN PUBLIC KEY----- +MIIDOjCCAi0GByqGSM44BAEwggIgAoIBAQD/nSuLzikeU6MrymSPr34AiU2RDJz6 +0pm/3PPs27f6QTtbUAvGC13q6XWrE3HJU8Gz7RM0EJZGpiwb86LgqOJhjfQ7WKse +uaGdbHnvJEFsGqpKX7rnUWaWO3HAsKzDx4HzJqKupFEbTbzXl/GT3JMm+a3PXA3S +kyATydRPrX583Ih8iHO1zQs1pwp2AnUvaQXvp4QOLFWheH5napkDZBjc9B7H38dg +f4c0QqEXJw0lJbG26FxhpOWMiXwpWpOHSfb+XtmzpeTDIHxKPLMEdf2wc+xNC/M9 +GdVBfM7+hCEhl1JGqNWPpT7ZzciX8Cxg+5/MIfx+BQ7xQ4wo1SN7y1bZAhUAuBcT ++ZsHbLXlR3uGHLIMg8boUKcCggEAGKgD56/tB6siFr5zEY+RTozPLmbBEcvhz5/p +hAQo7z7ODimZAA1MN1J7Hv7o1S5D9dpZuOnGhiXaN3Z50WdePb9LVH7twrB8v3Xn +ZOEHpumYNcYhvXrIx8LbhnMZmU27xSnrOQF9UfokRxGnXkNmlIwjT0NWqZCqQZwM +wVj1Bgld3YV7CpGTF3aGM6a0pk9LBB71PoczXAx0Cum87ouXXy3c8F/82RF9tgXE +ZBQ+7K2QXYPv9smbYDB+ZlsQ4VTOi3AReG5AeHTVWha3uaSFxY5vKpfau31iMRuT +b1VQ2HVynBpemwhAw4FFvj5dm94aN0Rrvq9BKM09DL4zoOlLogOCAQUAAoIBAE8B +I8z38GdbtswSoSV5JZ9z9cBMj/7x/sHi5ED9v1M8MD6AcxJSbo2cbK98xA3A9U22 +6XFHthGReVLa0dyN3Ov+GhBdf8b4CBuebAAS4z8du2EvUFtwDUHorLIo2Qtq2SYR +wpznpB9+3g+z+8GZbzZkdm2mFBKa6GItj82qfEHwxB40aEBx7uQXzM3TH0rV8sMq +u91aAVUQuoiG2/IYWc5O34kKMlHUTt6+uuJiSG0ax8ysWE5XltCfSh/VJcGrzKU6 +ZjGBzh8j5+KSXgoe9TuKlsnN5HDCZKaFTCvrxq889HJj0/ks4UrIF+meEyJvDt4P +O4HHoKRtUdLEBMcY0JA= +-----END PUBLIC KEY----- diff --git a/fceumm/Makefile.libsnes-fceumm b/fceumm/Makefile.libsnes-fceumm new file mode 100644 index 0000000..2102dc1 --- /dev/null +++ b/fceumm/Makefile.libsnes-fceumm @@ -0,0 +1,109 @@ +DEBUG = 0 + +ifeq ($(platform),) +platform = unix +ifeq ($(shell uname -a),) + platform = win +else ifneq ($(findstring MINGW,$(shell uname -a)),) + platform = win +else ifneq ($(findstring Darwin,$(shell uname -a)),) + platform = osx +else ifneq ($(findstring win,$(shell uname -a)),) + platform = win +endif +endif + +ifeq ($(platform), unix) + TARGET := libsnes.so + fpic := -fPIC + SHARED := -shared -Wl,--version-script=libsnes-fceumm/link.T + ENDIANNESS_DEFINES = -DLSB_FIRST -DLOCAL_LE=1 +else ifeq ($(platform), osx) + TARGET := libsnes.dylib + fpic := -fPIC + SHARED := -dynamiclib + ENDIANNESS_DEFINES = -DLSB_FIRST -DLOCAL_LE=1 + CFLAGS += -DHAVE_ASPRINTF +else ifeq ($(platform), ps3) + TARGET := libsnes.a + CC = ppu-lv2-gcc + AR = ppu-lv2-ar + PLATFORM_DEFINES := -D__CELLOS_LV2 +else ifeq ($(platform), snc-ps3) + TARGET := libsnes.a + CC = ps3ppusnc + AR = ps3snarl + PLATFORM_DEFINES := -D__CELLOS_LV2 +else ifeq ($(platform), xenon) + TARGET := libsnes.a + CC = xenon-gcc + AR = xenon-ar + PLATFORM_DEFINES := -D__LIBXENON__ + CFLAGS += -DHAVE_ASPRINTF +else ifeq ($(platform), wii) + TARGET := libsnes.a + CC = powerpc-eabi-gcc + AR = powerpc-eabi-ar + PLATFORM_DEFINES := -DGEKKO -mrvl -mcpu=750 -meabi -mhard-float + CFLAGS += -DHAVE_ASPRINTF +else + TARGET := snes.dll + CC = gcc + SHARED := -shared -static-libgcc -static-libstdc++ -s -Wl,--version-script=libsnes-fceumm/link.T + ENDIANNESS_DEFINES = -DLSB_FIRST -DLOCAL_LE=1 +endif + +ifeq ($(DEBUG), 1) + CFLAGS += -O0 -g +else + CFLAGS += -O3 -DNDEBUG +endif + +LIBSNES_DIR := ./libsnes-fceumm +FCEU_DIR := ./src-fceumm +UTILS_DIR := ./utils + +FCEU_SRC_DIRS := $(LIBSNES_DIR) $(FCEU_DIR) $(FCEU_DIR)/boards $(FCEU_DIR)/input $(FCEU_DIR)/mappers $(FCEU_DIR)/utils $(UTILS_DIR)/zlib + +FCEU_CSRCS := $(foreach dir,$(FCEU_SRC_DIRS),$(wildcard $(dir)/*.c)) +FCEU_COBJ := $(FCEU_CSRCS:.c=.o) + +OBJS := $(FCEU_COBJ) + +FCEU_DEFINES := -D__LIBSNES__ -DSOUND_QUALITY=0 -DPATH_MAX=1024 -DINLINE=inline -DPSS_STYLE=1 $(PLATFORM_DEFINES) + +ifeq ($(platform), snc-ps3) +CODE_DEFINES = +WARNING_DEFINES = +else +CODE_DEFINES = -std=gnu99 +WARNING_DEFINES = -Wno-write-strings +endif + +CFLAGS += $(CODE_DEFINES) $(fpic) $(WARNING_DEFINES) $(FCEU_DEFINES) $(ENDIANNESS_DEFINES) +LDFLAGS += -lm + +INCDIRS := -I$(LIBSNES_DIR) -I$(FCEU_DIR) -I$(FCEU_DIR)/input -I$(FCEU_DIR)/boards -I$(FCEU_DIR)/mappers -I$(UTILS_DIR)/zlib +LIBS := + +$(TARGET): $(OBJS) +ifeq ($(platform), ps3) + $(AR) rcs $@ $(OBJS) +else ifeq ($(platform), snc-ps3) + $(AR) rcs $@ $(OBJS) +else ifeq ($(platform), xenon) + $(AR) rcs $@ $(OBJS) +else ifeq ($(platform), wii) + $(AR) rcs $@ $(OBJS) +else + $(CC) -o $@ $(SHARED) $(OBJS) $(LDFLAGS) $(LIBS) +endif + +%.o: %.c + $(CC) -c -o $@ $< $(CFLAGS) $(INCDIRS) + +clean: + rm -f $(OBJS) + rm -f $(TARGET) + +.PHONY: clean diff --git a/fceumm/compile_libsnes.sh b/fceumm/compile_libsnes.sh new file mode 100755 index 0000000..34f98c1 --- /dev/null +++ b/fceumm/compile_libsnes.sh @@ -0,0 +1,160 @@ +#!/bin/sh +FORMAT=libsnes +START_DIR=`pwd` + +#****************** +# PROGRAM FUNCTIONS +#****************** + +function clean_fceux() +{ + make -f Makefile.libsnes-fceux clean +} + +function clean_fceumm() +{ + make -f Makefile.libsnes-fceumm clean +} + +function make_libsnes_fceumm() +{ + make -f Makefile.libsnes-fceumm +} + +function make_libsnes_fceumm_debug() +{ + make -f Makefile.libsnes-fceumm DEBUG=1 +} + +function make_libsnes_fceux() +{ + make -f Makefile.libsnes-fceux +} + +function make_libsnes_fceux_debug() +{ + make -f Makefile.libsnes-fceux DEBUG=1 +} + +#****************** +# DISPLAY FUNCTIONS +#****************** + +function title() +{ + echo "" + echo "***********************" + echo "COMPILER SCRIPT FOR $FORMAT" + echo "***********************" +} + +function display_clean_fceumm() +{ + echo "clean_fceumm Clean the object files" +} + +function display_clean_fceux() +{ + echo "clean_fceux Clean the object files" +} + +function display_make_fceux() +{ + echo "make_fceux Compile libsnes library for FCEUx" +} + +function display_make_fceux_debug() +{ + echo "make_fceux_debug Compile DEBUG libsnes library for FCEUx" +} + +function display_make_fceumm() +{ + echo "make_fceumm Compile libsnes library for FCEUmm" +} + +function display_make_fceumm_debug() +{ + echo "make_fceumm_debug Compile DEBUG libsnes library for FCEUmm" +} + +function display_all_options() +{ + display_clean_fceux + display_clean_fceumm + display_make_fceux + display_make_fceux_debug + display_make_fceumm + display_make_fceumm_debug +} + +function display_usage() +{ + echo "Usage: compile_libsnes.sh [options]" + echo "Options:" + display_all_options +} + +#*********************** +# MAIN CONTROL FLOW LOOP +#*********************** + +title +if [ ! -n "$1" ]; then + display_usage +else + for i in "$@" + do + if [ "$i" = "help" ]; then + display_usage + fi + if [ "$i" = "clean_fceux" ]; then + echo "" + echo "*************************************" + echo "DOING:" + display_clean_fceux + echo "*************************************" + clean_fceux + fi + if [ "$i" = "clean_fceumm" ]; then + echo "" + echo "*************************************" + echo "DOING:" + display_clean_fceumm + echo "*************************************" + clean_fceumm + fi + if [ "$i" = "make_fceux" ]; then + echo "" + echo "*************************************" + echo "DOING:" + display_make_fceux + echo "*************************************" + make_libsnes_fceux + fi + if [ "$i" = "make_fceux_debug" ]; then + echo "" + echo "*************************************" + echo "DOING:" + display_make_fceux_debug + echo "*************************************" + make_libsnes_fceux_debug + fi + if [ "$i" = "make_fceumm" ]; then + echo "" + echo "*************************************" + echo "DOING:" + display_make_fceumm + echo "*************************************" + make_libsnes_fceumm + fi + if [ "$i" = "make_fceumm_debug" ]; then + echo "" + echo "*************************************" + echo "DOING:" + display_make_fceumm_debug + echo "*************************************" + make_libsnes_fceumm_debug + fi + done +fi diff --git a/fceumm/libsnes-fceumm/libsnes.c b/fceumm/libsnes-fceumm/libsnes.c new file mode 100644 index 0000000..342351b --- /dev/null +++ b/fceumm/libsnes-fceumm/libsnes.c @@ -0,0 +1,658 @@ +#include +#include +#ifndef _MSC_VER +#include +#else +#define TRUE 1 +#define FALSE 0 +typedef unsigned char bool; +#endif +#include +#include + +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + +#define LIBSNES_CORE 1 + +#if defined(_MSC_VER) && defined(LIBSNES_CORE) +#define EXPORT __declspec(dllexport) +#else +#define EXPORT +#endif + +#include "libsnes.h" + +/* emulator-specific includes */ + +#include "../src-fceumm/fceu.h" +#include "../src-fceumm/myendian.h" +#include "../src-fceumm/input.h" +#include "../src-fceumm/state.h" +#include "../src-fceumm/ppu.h" +#include "../src-fceumm/cart.h" +#include "../src-fceumm/x6502.h" +#include "../src-fceumm/git.h" +#include "../src-fceumm/palette.h" +#include "../src-fceumm/sound.h" +#include "../src-fceumm/file.h" +#include "../src-fceumm/cheat.h" +#include "../src-fceumm/ines.h" +#include "../src-fceumm/unif.h" +#include "../src-fceumm/fds.h" + +#include +#include "memstream.h" + +static snes_video_refresh_t video_cb = NULL; +static snes_audio_sample_t audio_cb = NULL; +static snes_input_poll_t poll_cb = NULL; +static snes_input_state_t input_cb = NULL; + +/* emulator-specific variables */ + +static uint16_t palette[256]; + +static int32 *sound = 0; +static int32 ssize = 0; +static uint8 *gfx = 0; +static uint32 JSReturn[2]; +static uint32 current_palette = 0; + +/* extern forward decls.*/ +extern FCEUGI *FCEUGameInfo; +extern uint8 *XBuf; +extern CartInfo iNESCart; +extern CartInfo UNIFCart; + +/* emulator-specific callback functions */ + +const char * GetKeyboard(void) { return ""; } +void FCEUD_SetPalette(unsigned char index, unsigned char r, unsigned char g, unsigned char b) +{ + r >>= 3; + g >>= 3; + b >>= 3; + palette[index] = (r << 10) | (g << 5) | (b << 0); +} + +bool FCEUD_ShouldDrawInputAids() { return 1; } +void FCEUD_PrintError(const char *c) { } +void FCEUD_Message(const char *text) { } +void FCEUD_SoundToggle() { FCEUI_SetSoundVolume(256); } +void FCEUD_VideoChanged() {} + +#define MAX_PAH 1024 + +/*palette for FCEU*/ +#define MAXPAL 13 + +struct st_palettes { + char name[32]; + char desc[32]; + unsigned int data[64]; +}; + +struct st_palettes palettes[] = { + { "asqrealc", "AspiringSquire's Real palette", + { 0x6c6c6c, 0x00268e, 0x0000a8, 0x400094, + 0x700070, 0x780040, 0x700000, 0x621600, + 0x442400, 0x343400, 0x005000, 0x004444, + 0x004060, 0x000000, 0x101010, 0x101010, + 0xbababa, 0x205cdc, 0x3838ff, 0x8020f0, + 0xc000c0, 0xd01474, 0xd02020, 0xac4014, + 0x7c5400, 0x586400, 0x008800, 0x007468, + 0x00749c, 0x202020, 0x101010, 0x101010, + 0xffffff, 0x4ca0ff, 0x8888ff, 0xc06cff, + 0xff50ff, 0xff64b8, 0xff7878, 0xff9638, + 0xdbab00, 0xa2ca20, 0x4adc4a, 0x2ccca4, + 0x1cc2ea, 0x585858, 0x101010, 0x101010, + 0xffffff, 0xb0d4ff, 0xc4c4ff, 0xe8b8ff, + 0xffb0ff, 0xffb8e8, 0xffc4c4, 0xffd4a8, + 0xffe890, 0xf0f4a4, 0xc0ffc0, 0xacf4f0, + 0xa0e8ff, 0xc2c2c2, 0x202020, 0x101010 } + }, + { "loopy", "Loopy's palette", + { 0x757575, 0x271b8f, 0x0000ab, 0x47009f, + 0x8f0077, 0xab0013, 0xa70000, 0x7f0b00, + 0x432f00, 0x004700, 0x005100, 0x003f17, + 0x1b3f5f, 0x000000, 0x000000, 0x000000, + 0xbcbcbc, 0x0073ef, 0x233bef, 0x8300f3, + 0xbf00bf, 0xe7005b, 0xdb2b00, 0xcb4f0f, + 0x8b7300, 0x009700, 0x00ab00, 0x00933b, + 0x00838b, 0x000000, 0x000000, 0x000000, + 0xffffff, 0x3fbfff, 0x5f97ff, 0xa78bfd, + 0xf77bff, 0xff77b7, 0xff7763, 0xff9b3b, + 0xf3bf3f, 0x83d313, 0x4fdf4b, 0x58f898, + 0x00ebdb, 0x000000, 0x000000, 0x000000, + 0xffffff, 0xabe7ff, 0xc7d7ff, 0xd7cbff, + 0xffc7ff, 0xffc7db, 0xffbfb3, 0xffdbab, + 0xffe7a3, 0xe3ffa3, 0xabf3bf, 0xb3ffcf, + 0x9ffff3, 0x000000, 0x000000, 0x000000 } + }, + { "quor", "Quor's palette", + { 0x3f3f3f, 0x001f3f, 0x00003f, 0x1f003f, + 0x3f003f, 0x3f0020, 0x3f0000, 0x3f2000, + 0x3f3f00, 0x203f00, 0x003f00, 0x003f20, + 0x003f3f, 0x000000, 0x000000, 0x000000, + 0x7f7f7f, 0x405f7f, 0x40407f, 0x5f407f, + 0x7f407f, 0x7f4060, 0x7f4040, 0x7f6040, + 0x7f7f40, 0x607f40, 0x407f40, 0x407f60, + 0x407f7f, 0x000000, 0x000000, 0x000000, + 0xbfbfbf, 0x809fbf, 0x8080bf, 0x9f80bf, + 0xbf80bf, 0xbf80a0, 0xbf8080, 0xbfa080, + 0xbfbf80, 0xa0bf80, 0x80bf80, 0x80bfa0, + 0x80bfbf, 0x000000, 0x000000, 0x000000, + 0xffffff, 0xc0dfff, 0xc0c0ff, 0xdfc0ff, + 0xffc0ff, 0xffc0e0, 0xffc0c0, 0xffe0c0, + 0xffffc0, 0xe0ffc0, 0xc0ffc0, 0xc0ffe0, + 0xc0ffff, 0x000000, 0x000000, 0x000000 } + }, + { "chris", "Chris Covell's palette", + { 0x808080, 0x003DA6, 0x0012B0, 0x440096, + 0xA1005E, 0xC70028, 0xBA0600, 0x8C1700, + 0x5C2F00, 0x104500, 0x054A00, 0x00472E, + 0x004166, 0x000000, 0x050505, 0x050505, + 0xC7C7C7, 0x0077FF, 0x2155FF, 0x8237FA, + 0xEB2FB5, 0xFF2950, 0xFF2200, 0xD63200, + 0xC46200, 0x358000, 0x058F00, 0x008A55, + 0x0099CC, 0x212121, 0x090909, 0x090909, + 0xFFFFFF, 0x0FD7FF, 0x69A2FF, 0xD480FF, + 0xFF45F3, 0xFF618B, 0xFF8833, 0xFF9C12, + 0xFABC20, 0x9FE30E, 0x2BF035, 0x0CF0A4, + 0x05FBFF, 0x5E5E5E, 0x0D0D0D, 0x0D0D0D, + 0xFFFFFF, 0xA6FCFF, 0xB3ECFF, 0xDAABEB, + 0xFFA8F9, 0xFFABB3, 0xFFD2B0, 0xFFEFA6, + 0xFFF79C, 0xD7E895, 0xA6EDAF, 0xA2F2DA, + 0x99FFFC, 0xDDDDDD, 0x111111, 0x111111 } + }, + { "matt", "Matthew Conte's palette", + { 0x808080, 0x0000bb, 0x3700bf, 0x8400a6, + 0xbb006a, 0xb7001e, 0xb30000, 0x912600, + 0x7b2b00, 0x003e00, 0x00480d, 0x003c22, + 0x002f66, 0x000000, 0x050505, 0x050505, + 0xc8c8c8, 0x0059ff, 0x443cff, 0xb733cc, + 0xff33aa, 0xff375e, 0xff371a, 0xd54b00, + 0xc46200, 0x3c7b00, 0x1e8415, 0x009566, + 0x0084c4, 0x111111, 0x090909, 0x090909, + 0xffffff, 0x0095ff, 0x6f84ff, 0xd56fff, + 0xff77cc, 0xff6f99, 0xff7b59, 0xff915f, + 0xffa233, 0xa6bf00, 0x51d96a, 0x4dd5ae, + 0x00d9ff, 0x666666, 0x0d0d0d, 0x0d0d0d, + 0xffffff, 0x84bfff, 0xbbbbff, 0xd0bbff, + 0xffbfea, 0xffbfcc, 0xffc4b7, 0xffccae, + 0xffd9a2, 0xcce199, 0xaeeeb7, 0xaaf7ee, + 0xb3eeff, 0xdddddd, 0x111111, 0x111111 } + }, + { "pasofami", "PasoFami/99 palette", + { 0x7f7f7f, 0x0000ff, 0x0000bf, 0x472bbf, + 0x970087, 0xab0023, 0xab1300, 0x8b1700, + 0x533000, 0x007800, 0x006b00, 0x005b00, + 0x004358, 0x000000, 0x000000, 0x000000, + 0xbfbfbf, 0x0078f8, 0x0058f8, 0x6b47ff, + 0xdb00cd, 0xe7005b, 0xf83800, 0xe75f13, + 0xaf7f00, 0x00b800, 0x00ab00, 0x00ab47, + 0x008b8b, 0x000000, 0x000000, 0x000000, + 0xf8f8f8, 0x3fbfff, 0x6b88ff, 0x9878f8, + 0xf878f8, 0xf85898, 0xf87858, 0xffa347, + 0xf8b800, 0xb8f818, 0x5bdb57, 0x58f898, + 0x00ebdb, 0x787878, 0x000000, 0x000000, + 0xffffff, 0xa7e7ff, 0xb8b8f8, 0xd8b8f8, + 0xf8b8f8, 0xfba7c3, 0xf0d0b0, 0xffe3ab, + 0xfbdb7b, 0xd8f878, 0xb8f8b8, 0xb8f8d8, + 0x00ffff, 0xf8d8f8, 0x000000, 0x000000 } + }, + { "crashman", "CrashMan's palette", + { 0x585858, 0x001173, 0x000062, 0x472bbf, + 0x970087, 0x910009, 0x6f1100, 0x4c1008, + 0x371e00, 0x002f00, 0x005500, 0x004d15, + 0x002840, 0x000000, 0x000000, 0x000000, + 0xa0a0a0, 0x004499, 0x2c2cc8, 0x590daa, + 0xae006a, 0xb00040, 0xb83418, 0x983010, + 0x704000, 0x308000, 0x207808, 0x007b33, + 0x1c6888, 0x000000, 0x000000, 0x000000, + 0xf8f8f8, 0x267be1, 0x5870f0, 0x9878f8, + 0xff73c8, 0xf060a8, 0xd07b37, 0xe09040, + 0xf8b300, 0x8cbc00, 0x40a858, 0x58f898, + 0x00b7bf, 0x787878, 0x000000, 0x000000, + 0xffffff, 0xa7e7ff, 0xb8b8f8, 0xd8b8f8, + 0xe6a6ff, 0xf29dc4, 0xf0c0b0, 0xfce4b0, + 0xe0e01e, 0xd8f878, 0xc0e890, 0x95f7c8, + 0x98e0e8, 0xf8d8f8, 0x000000, 0x000000 } + }, + { "mess", "MESS palette", + { 0x747474, 0x24188c, 0x0000a8, 0x44009c, + 0x8c0074, 0xa80010, 0xa40000, 0x7c0800, + 0x402c00, 0x004400, 0x005000, 0x003c14, + 0x183c5c, 0x000000, 0x000000, 0x000000, + 0xbcbcbc, 0x0070ec, 0x2038ec, 0x8000f0, + 0xbc00bc, 0xe40058, 0xd82800, 0xc84c0c, + 0x887000, 0x009400, 0x00a800, 0x009038, + 0x008088, 0x000000, 0x000000, 0x000000, + 0xfcfcfc, 0x3cbcfc, 0x5c94fc, 0x4088fc, + 0xf478fc, 0xfc74b4, 0xfc7460, 0xfc9838, + 0xf0bc3c, 0x80d010, 0x4cdc48, 0x58f898, + 0x00e8d8, 0x000000, 0x000000, 0x000000, + 0xfcfcfc, 0xa8e4fc, 0xc4d4fc, 0xd4c8fc, + 0xfcc4fc, 0xfcc4d8, 0xfcbcb0, 0xfcd8a8, + 0xfce4a0, 0xe0fca0, 0xa8f0bc, 0xb0fccc, + 0x9cfcf0, 0x000000, 0x000000, 0x000000 } + }, + { "zaphod-cv", "Zaphod's VS Castlevania palette", + { 0x7f7f7f, 0xffa347, 0x0000bf, 0x472bbf, + 0x970087, 0xf85898, 0xab1300, 0xf8b8f8, + 0xbf0000, 0x007800, 0x006b00, 0x005b00, + 0xffffff, 0x9878f8, 0x000000, 0x000000, + 0xbfbfbf, 0x0078f8, 0xab1300, 0x6b47ff, + 0x00ae00, 0xe7005b, 0xf83800, 0x7777ff, + 0xaf7f00, 0x00b800, 0x00ab00, 0x00ab47, + 0x008b8b, 0x000000, 0x000000, 0x472bbf, + 0xf8f8f8, 0xffe3ab, 0xf87858, 0x9878f8, + 0x0078f8, 0xf85898, 0xbfbfbf, 0xffa347, + 0xc800c8, 0xb8f818, 0x7f7f7f, 0x007800, + 0x00ebdb, 0x000000, 0x000000, 0xffffff, + 0xffffff, 0xa7e7ff, 0x5bdb57, 0xe75f13, + 0x004358, 0x0000ff, 0xe7005b, 0x00b800, + 0xfbdb7b, 0xd8f878, 0x8b1700, 0xffe3ab, + 0x00ffff, 0xab0023, 0x000000, 0x000000 } + }, + { "zaphod-smb", "Zaphod's VS SMB palette", + { 0x626a00, 0x0000ff, 0x006a77, 0x472bbf, + 0x970087, 0xab0023, 0xab1300, 0xb74800, + 0xa2a2a2, 0x007800, 0x006b00, 0x005b00, + 0xffd599, 0xffff00, 0x009900, 0x000000, + 0xff66ff, 0x0078f8, 0x0058f8, 0x6b47ff, + 0x000000, 0xe7005b, 0xf83800, 0xe75f13, + 0xaf7f00, 0x00b800, 0x5173ff, 0x00ab47, + 0x008b8b, 0x000000, 0x91ff88, 0x000088, + 0xf8f8f8, 0x3fbfff, 0x6b0000, 0x4855f8, + 0xf878f8, 0xf85898, 0x595958, 0xff009d, + 0x002f2f, 0xb8f818, 0x5bdb57, 0x58f898, + 0x00ebdb, 0x787878, 0x000000, 0x000000, + 0xffffff, 0xa7e7ff, 0x590400, 0xbb0000, + 0xf8b8f8, 0xfba7c3, 0xffffff, 0x00e3e1, + 0xfbdb7b, 0xffae00, 0xb8f8b8, 0xb8f8d8, + 0x00ff00, 0xf8d8f8, 0xffaaaa, 0x004000 } + }, + { "vs-drmar", "VS Dr. Mario palette", + { 0x5f97ff, 0x000000, 0x000000, 0x47009f, + 0x00ab00, 0xffffff, 0xabe7ff, 0x000000, + 0x000000, 0x000000, 0x000000, 0x000000, + 0xe7005b, 0x000000, 0x000000, 0x000000, + 0x5f97ff, 0x000000, 0x000000, 0x000000, + 0x000000, 0x8b7300, 0xcb4f0f, 0x000000, + 0xbcbcbc, 0x000000, 0x000000, 0x000000, + 0x000000, 0x000000, 0x000000, 0x000000, + 0x00ebdb, 0x000000, 0x000000, 0x000000, + 0x000000, 0xff9b3b, 0x000000, 0x000000, + 0x83d313, 0x000000, 0x3fbfff, 0x000000, + 0x0073ef, 0x000000, 0x000000, 0x000000, + 0x00ebdb, 0x000000, 0x000000, 0x000000, + 0x000000, 0x000000, 0xf3bf3f, 0x000000, + 0x005100, 0x000000, 0xc7d7ff, 0xffdbab, + 0x000000, 0x000000, 0x000000, 0x000000 } + }, + { "vs-cv", "VS Castlevania palette", + { 0xaf7f00, 0xffa347, 0x008b8b, 0x472bbf, + 0x970087, 0xf85898, 0xab1300, 0xf8b8f8, + 0xf83800, 0x007800, 0x006b00, 0x005b00, + 0xffffff, 0x9878f8, 0x00ab00, 0x000000, + 0xbfbfbf, 0x0078f8, 0xab1300, 0x6b47ff, + 0x000000, 0xe7005b, 0xf83800, 0x6b88ff, + 0xaf7f00, 0x00b800, 0x6b88ff, 0x00ab47, + 0x008b8b, 0x000000, 0x000000, 0x472bbf, + 0xf8f8f8, 0xffe3ab, 0xf87858, 0x9878f8, + 0x0078f8, 0xf85898, 0xbfbfbf, 0xffa347, + 0x004358, 0xb8f818, 0x7f7f7f, 0x007800, + 0x00ebdb, 0x000000, 0x000000, 0xffffff, + 0xffffff, 0xa7e7ff, 0x5bdb57, 0x6b88ff, + 0x004358, 0x0000ff, 0xe7005b, 0x00b800, + 0xfbdb7b, 0xffa347, 0x8b1700, 0xffe3ab, + 0xb8f818, 0xab0023, 0x000000, 0x007800 } + }, + { "vs-smb", "VS SMB/VS Ice Climber palette", + { 0xaf7f00, 0x0000ff, 0x008b8b, 0x472bbf, + 0x970087, 0xab0023, 0x0000ff, 0xe75f13, + 0xbfbfbf, 0x007800, 0x5bdb57, 0x005b00, + 0xf0d0b0, 0xffe3ab, 0x00ab00, 0x000000, + 0xbfbfbf, 0x0078f8, 0x0058f8, 0x6b47ff, + 0x000000, 0xe7005b, 0xf83800, 0xf87858, + 0xaf7f00, 0x00b800, 0x6b88ff, 0x00ab47, + 0x008b8b, 0x000000, 0x000000, 0x3fbfff, + 0xf8f8f8, 0x006b00, 0x8b1700, 0x9878f8, + 0x6b47ff, 0xf85898, 0x7f7f7f, 0xe7005b, + 0x004358, 0xb8f818, 0x0078f8, 0x58f898, + 0x00ebdb, 0xfbdb7b, 0x000000, 0x000000, + 0xffffff, 0xa7e7ff, 0xb8b8f8, 0xf83800, + 0xf8b8f8, 0xfba7c3, 0xffffff, 0x00ffff, + 0xfbdb7b, 0xffa347, 0xb8f8b8, 0xb8f8d8, + 0xb8f818, 0xf8d8f8, 0x000000, 0x007800 } + } +}; + +unsigned snes_library_revision_major(void) +{ + return 1; +} + +unsigned snes_library_revision_minor(void) +{ + return 3; +} + +const char *snes_library_id(void) +{ + return "FCEUNext"; +} + +void snes_set_video_refresh(snes_video_refresh_t cb) +{ + video_cb = cb; +} + +void snes_set_audio_sample(snes_audio_sample_t cb) +{ + audio_cb = cb; +} + +void snes_set_input_poll(snes_input_poll_t cb) +{ + poll_cb = cb; +} + +void snes_set_input_state(snes_input_state_t cb) +{ + input_cb = cb; +} + +void snes_set_controller_port_device(bool a, unsigned b) +{} + +static char g_basename[1024]; + +void snes_set_cartridge_basename(const char * path_) +{ + char path[1024], *split; + strncpy(path, path_, sizeof(path)); + + split = strrchr(path_, '/'); + if (!split) split = strrchr(path_, '\\'); + if (split) + { + int len_filename, len_split; + + strncpy(g_basename, split + 1, sizeof(g_basename)); + len_filename = strlen(path_); + len_split = strlen(split); + } + else + { + strncpy(g_basename, path_, sizeof(path_)); + } + + fprintf(stderr, "BASENAME: %s\n", g_basename); +} + +/* SSNES extension.*/ +static snes_environment_t environ_cb; +void snes_set_environment(snes_environment_t cb) { environ_cb = cb; } + +void snes_init(void) +{ + if (environ_cb) + { + struct snes_geometry geom = { 256, 240, 256, 240 }; + environ_cb(SNES_ENVIRONMENT_SET_GEOMETRY, &geom); + } +} + +static void emulator_set_input(void) +{ + FCEUI_SetInput(0, SI_GAMEPAD, &JSReturn[0], 0); + FCEUI_SetInput(1, SI_GAMEPAD, &JSReturn[1], 0); +} + +static void emulator_set_custom_palette (void) +{ + if (current_palette == 0 ) + { + FCEU_ResetPalette(); /* Do palette reset*/ + } + else + { + /* Now setup this palette*/ + uint8 i,r,g,b; + + for ( i = 0; i < 64; i++ ) + { + r = palettes[current_palette-1].data[i] >> 16; + g = ( palettes[current_palette-1].data[i] & 0xff00 ) >> 8; + b = ( palettes[current_palette-1].data[i] & 0xff ); + FCEUD_SetPalette( i, r, g, b); + FCEUD_SetPalette( i+64, r, g, b); + FCEUD_SetPalette( i+128, r, g, b); + FCEUD_SetPalette( i+192, r, g, b); + } + } +} + +static void fceu_init(void) +{ + emulator_set_input(); + emulator_set_custom_palette(); + + FCEUD_SoundToggle(); +} + +void snes_term(void) {} + +void snes_power(void) +{ + PowerNES(); +} + +void snes_reset(void) +{ + ResetNES(); +} + + +typedef struct +{ + unsigned snes; + unsigned nes; +} keymap; + +static const keymap bindmap[] = { + { SNES_DEVICE_ID_JOYPAD_A, JOY_A }, + { SNES_DEVICE_ID_JOYPAD_B, JOY_B }, + { SNES_DEVICE_ID_JOYPAD_SELECT, JOY_SELECT }, + { SNES_DEVICE_ID_JOYPAD_START, JOY_START }, + { SNES_DEVICE_ID_JOYPAD_UP, JOY_UP }, + { SNES_DEVICE_ID_JOYPAD_DOWN, JOY_DOWN }, + { SNES_DEVICE_ID_JOYPAD_LEFT, JOY_LEFT }, + { SNES_DEVICE_ID_JOYPAD_RIGHT, JOY_RIGHT }, +}; + +static void update_input(void) +{ + unsigned i; + unsigned char pad[2]; + + pad[0] = 0; + pad[1] = 0; + + poll_cb(); + + for ( i = 0; i < 8; i++) + pad[0] |= input_cb(SNES_PORT_1, SNES_DEVICE_JOYPAD, 0, bindmap[i].snes) ? bindmap[i].nes : 0; + for ( i = 0; i < 8; i++) + pad[1] |= input_cb(SNES_PORT_2, SNES_DEVICE_JOYPAD, 0, bindmap[i].snes) ? bindmap[i].nes : 0; + JSReturn[0] = pad[0]; + JSReturn[1] = pad[1]; +} + +EXPORT void snes_run(void) +{ + unsigned i, y, x, ssize; + uint8_t *gfx; + static uint16_t video_out[1024 * 240]; + + ssize = 0; + FCEUI_Emulate(&gfx, &sound, &ssize); + + gfx = XBuf; + for ( y = 0; y < 240; y++) + for ( x = 0; x < 256; x++, gfx++) + video_out[y * 1024 + x] = palette[*gfx]; + + video_cb(video_out, 256, 240); + update_input(); + + for ( i = 0; i < ssize; i++) + audio_cb(sound[i] & 0xffff, sound[i] & 0xffff); +} + + +static unsigned serialize_size = 0; + +unsigned snes_serialize_size(void) +{ + if (serialize_size == 0) + { + /* Something arbitrarily big.*/ + uint8_t *buffer = (uint8_t*)malloc(1000000); + memstream_set_buffer(buffer, 1000000); + + FCEUSS_Save(); + serialize_size = memstream_get_last_size(); + free(buffer); + } + + return serialize_size; +} + +bool snes_serialize(uint8_t *data, unsigned size) +{ + if (size != snes_serialize_size()) + return FALSE; + + memstream_set_buffer(data, size); + FCEUSS_Save(); + return TRUE; +} + +bool snes_unserialize(const uint8_t *data, unsigned size) +{ + if (size != snes_serialize_size()) + return FALSE; + + memstream_set_buffer((uint8_t*)data, size); + FCEUSS_Load(); + return TRUE; +} + +void snes_cheat_reset(void) {} + +void snes_cheat_set(unsigned a, bool b, const char* c) { } + +bool snes_load_cartridge_normal(const char* a, const uint8_t *rom_data, unsigned rom_size) +{ + const char *full_path; + struct snes_system_timing timing; + + if (!environ_cb) + { + fprintf(stderr, "Environment callback not set. Cannot continue ...\n"); + return FALSE; + } + + if (!environ_cb(SNES_ENVIRONMENT_GET_FULLPATH, &full_path) || !full_path) + { + fprintf(stderr, "GET_FULLPATH extension not supported. Cannot continue ...\n"); + return FALSE; + } + + FCEUI_Initialize(); + + FCEUI_SetSoundVolume(256); + //FCEUI_Sound(32050); + FCEUI_Sound(48000); + + FCEUGameInfo = FCEUI_LoadGame(full_path); + + fceu_init(); + + //timing.sample_rate = 32050.0; + timing.sample_rate = 48000; + if (FSettings.PAL) + timing.fps = 838977920.0/16777215.0; + else + timing.fps = 1008307711.0/16777215.0; + + environ_cb(SNES_ENVIRONMENT_SET_TIMING, &timing); + + return TRUE; +} + +bool snes_load_cartridge_bsx_slotted( + const char* a, const uint8_t* b, unsigned c, + const char* d, const uint8_t* e, unsigned f +) +{ return FALSE; } + +bool snes_load_cartridge_bsx( + const char* a, const uint8_t * b, unsigned c, + const char* d, const uint8_t * e, unsigned f +) +{ return FALSE; } + +bool snes_load_cartridge_sufami_turbo( + const char* a, const uint8_t* b, unsigned c, + const char* d, const uint8_t* e, unsigned f, + const char* g, const uint8_t* h, unsigned i +) +{ return FALSE; } + +bool snes_load_cartridge_super_game_boy( + const char* a, const uint8_t* b, unsigned c, + const char* d, const uint8_t* e, unsigned f +) +{ return FALSE; } + +void snes_unload_cartridge(void) +{ + FCEUI_CloseGame(); +} + +bool snes_get_region(void) +{ + return FSettings.PAL ? SNES_REGION_PAL : SNES_REGION_NTSC; +} + +uint8_t *snes_get_memory_data(unsigned id) +{ + if (id != SNES_MEMORY_CARTRIDGE_RAM) + return NULL; + + if (iNESCart.battery) + return iNESCart.SaveGame[0]; + if (UNIFCart.battery) + return UNIFCart.SaveGame[0]; + + return 0; +} + +unsigned snes_get_memory_size(unsigned id) +{ + if (id != SNES_MEMORY_CARTRIDGE_RAM) + return 0; + + if (iNESCart.battery) + return iNESCart.SaveGameLen[0]; + if (UNIFCart.battery) + return UNIFCart.SaveGameLen[0]; + + return 0; +} diff --git a/fceumm/libsnes-fceumm/libsnes.h b/fceumm/libsnes-fceumm/libsnes.h new file mode 100755 index 0000000..cf22562 --- /dev/null +++ b/fceumm/libsnes-fceumm/libsnes.h @@ -0,0 +1,162 @@ +#ifndef LIBSNES_HPP +#define LIBSNES_HPP + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define SNES_PORT_1 0 +#define SNES_PORT_2 1 + +#define SNES_DEVICE_NONE 0 +#define SNES_DEVICE_JOYPAD 1 +#define SNES_DEVICE_MULTITAP 2 +#define SNES_DEVICE_MOUSE 3 +#define SNES_DEVICE_SUPER_SCOPE 4 +#define SNES_DEVICE_JUSTIFIER 5 +#define SNES_DEVICE_JUSTIFIERS 6 + +#define SNES_DEVICE_ID_JOYPAD_B 0 +#define SNES_DEVICE_ID_JOYPAD_Y 1 +#define SNES_DEVICE_ID_JOYPAD_SELECT 2 +#define SNES_DEVICE_ID_JOYPAD_START 3 +#define SNES_DEVICE_ID_JOYPAD_UP 4 +#define SNES_DEVICE_ID_JOYPAD_DOWN 5 +#define SNES_DEVICE_ID_JOYPAD_LEFT 6 +#define SNES_DEVICE_ID_JOYPAD_RIGHT 7 +#define SNES_DEVICE_ID_JOYPAD_A 8 +#define SNES_DEVICE_ID_JOYPAD_X 9 +#define SNES_DEVICE_ID_JOYPAD_L 10 +#define SNES_DEVICE_ID_JOYPAD_R 11 + +#define SNES_DEVICE_ID_MOUSE_X 0 +#define SNES_DEVICE_ID_MOUSE_Y 1 +#define SNES_DEVICE_ID_MOUSE_LEFT 2 +#define SNES_DEVICE_ID_MOUSE_RIGHT 3 + +#define SNES_DEVICE_ID_SUPER_SCOPE_X 0 +#define SNES_DEVICE_ID_SUPER_SCOPE_Y 1 +#define SNES_DEVICE_ID_SUPER_SCOPE_TRIGGER 2 +#define SNES_DEVICE_ID_SUPER_SCOPE_CURSOR 3 +#define SNES_DEVICE_ID_SUPER_SCOPE_TURBO 4 +#define SNES_DEVICE_ID_SUPER_SCOPE_PAUSE 5 + +#define SNES_DEVICE_ID_JUSTIFIER_X 0 +#define SNES_DEVICE_ID_JUSTIFIER_Y 1 +#define SNES_DEVICE_ID_JUSTIFIER_TRIGGER 2 +#define SNES_DEVICE_ID_JUSTIFIER_START 3 + +#define SNES_REGION_NTSC 0 +#define SNES_REGION_PAL 1 + +#define SNES_MEMORY_CARTRIDGE_RAM 0 +#define SNES_MEMORY_CARTRIDGE_RTC 1 +#define SNES_MEMORY_BSX_RAM 2 +#define SNES_MEMORY_BSX_PRAM 3 +#define SNES_MEMORY_SUFAMI_TURBO_A_RAM 4 +#define SNES_MEMORY_SUFAMI_TURBO_B_RAM 5 +#define SNES_MEMORY_GAME_BOY_RAM 6 +#define SNES_MEMORY_GAME_BOY_RTC 7 + +#define SNES_MEMORY_WRAM 100 +#define SNES_MEMORY_APURAM 101 +#define SNES_MEMORY_VRAM 102 +#define SNES_MEMORY_OAM 103 +#define SNES_MEMORY_CGRAM 104 + +/* SSNES extension. Not required to be implemented for a working implementation.*/ +#define SNES_ENVIRONMENT_GET_FULLPATH 0 /* const char ***/ +#define SNES_ENVIRONMENT_SET_GEOMETRY 1 /* const struct snes_geometry **/ +#define SNES_ENVIRONMENT_SET_PITCH 2 /* const unsigned **/ +#define SNES_ENVIRONMENT_GET_OVERSCAN 3 /* bool * -- Boolean value whether or not the implementation should use overscan.*/ +#define SNES_ENVIRONMENT_SET_TIMING 4 /* const struct snes_system_timing * -- Set exact timings of the system.*/ + /* Used primarily for video recording*/ + +struct snes_geometry +{ + unsigned base_width; /* Nominal video width of system.*/ + unsigned base_height; /* Nominal video height of system.*/ + unsigned max_width; /* Maximum possible width of system.*/ + unsigned max_height; /* Maximum possible height of system.*/ +}; + +struct snes_system_timing +{ + double fps; + double sample_rate; +}; + +typedef bool (*snes_environment_t)(unsigned cmd, void *data); + +/* Must be called before calling snes_init().*/ +void snes_set_environment(snes_environment_t); + +typedef void (*snes_video_refresh_t)(const uint16_t *data, unsigned width, unsigned height); +typedef void (*snes_audio_sample_t)(uint16_t left, uint16_t right); +typedef void (*snes_input_poll_t)(void); +typedef int16_t (*snes_input_state_t)(bool port, unsigned device, unsigned index, unsigned id); + +unsigned snes_library_revision_major(void); +unsigned snes_library_revision_minor(void); +const char *snes_library_id(void); + +void snes_set_video_refresh(snes_video_refresh_t); +void snes_set_audio_sample(snes_audio_sample_t); +void snes_set_input_poll(snes_input_poll_t); +void snes_set_input_state(snes_input_state_t); + +void snes_set_controller_port_device(bool port, unsigned device); +void snes_set_cartridge_basename(const char *basename); + +void snes_init(void); +void snes_term(void); +void snes_power(void); +void snes_reset(void); +void snes_run(void); + +unsigned snes_serialize_size(void); +bool snes_serialize(uint8_t *data, unsigned size); +bool snes_unserialize(const uint8_t *data, unsigned size); + +void snes_cheat_reset(void); +void snes_cheat_set(unsigned index, bool enabled, const char *code); + +bool snes_load_cartridge_normal( + const char *rom_xml, const uint8_t *rom_data, unsigned rom_size +); + +bool snes_load_cartridge_bsx_slotted( + const char *rom_xml, const uint8_t *rom_data, unsigned rom_size, + const char *bsx_xml, const uint8_t *bsx_data, unsigned bsx_size +); + +bool snes_load_cartridge_bsx( + const char *rom_xml, const uint8_t *rom_data, unsigned rom_size, + const char *bsx_xml, const uint8_t *bsx_data, unsigned bsx_size +); + +bool snes_load_cartridge_sufami_turbo( + const char *rom_xml, const uint8_t *rom_data, unsigned rom_size, + const char *sta_xml, const uint8_t *sta_data, unsigned sta_size, + const char *stb_xml, const uint8_t *stb_data, unsigned stb_size +); + +bool snes_load_cartridge_super_game_boy( + const char *rom_xml, const uint8_t *rom_data, unsigned rom_size, + const char *dmg_xml, const uint8_t *dmg_data, unsigned dmg_size +); + +void snes_unload_cartridge(void); + +bool snes_get_region(void); +uint8_t* snes_get_memory_data(unsigned id); +unsigned snes_get_memory_size(unsigned id); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/fceumm/libsnes-fceumm/memstream.c b/fceumm/libsnes-fceumm/memstream.c new file mode 100644 index 0000000..92331f1 --- /dev/null +++ b/fceumm/libsnes-fceumm/memstream.c @@ -0,0 +1,133 @@ +#include +#include +#include +#include +#include +#include "memstream.h" + +static uint8_t *g_buffer = NULL; +static size_t g_size = 0; +static size_t g_last_file_size = 0; + +struct memstream +{ + uint8_t *m_buf; + size_t m_size; + size_t m_ptr; + size_t m_max_ptr; + bool writing; +}; + +static void memstream_update_ptr(memstream_t *stream) +{ + if (stream->m_ptr > stream->m_max_ptr) + stream->m_max_ptr = stream->m_ptr; +} + +static void memstream_init(memstream_t *stream, uint8_t *buffer, size_t max_size, bool writing) +{ + stream->m_buf = buffer; + stream->m_size = max_size; + stream->m_ptr = 0; + stream->m_max_ptr = 0; + stream->writing = writing; +} + +void memstream_set_buffer(uint8_t *buffer, size_t size) +{ + g_buffer = buffer; + g_size = size; +} + +size_t memstream_get_last_size(void) +{ + return g_last_file_size; +} + +memstream_t *memstream_open(bool writing) +{ + memstream_t *stream; + if (!g_buffer || !g_size) + return NULL; + + stream = (memstream_t*)calloc(1, sizeof(*stream)); + memstream_init(stream, g_buffer, g_size, writing); + g_buffer = NULL; + g_size = 0; + return stream; +} + +void memstream_close(memstream_t *stream) +{ + g_last_file_size = stream->writing ? stream->m_max_ptr : stream->m_size; + free(stream); +} + +size_t memstream_read(memstream_t *stream, void *data, size_t bytes) +{ + size_t avail = stream->m_size - stream->m_ptr; + if (bytes > avail) + bytes = avail; + + memcpy(data, stream->m_buf + stream->m_ptr, bytes); + stream->m_ptr += bytes; + memstream_update_ptr(stream); + return bytes; +} + +size_t memstream_write(memstream_t *stream, const void *data, size_t bytes) +{ + size_t avail = stream->m_size - stream->m_ptr; + if (bytes > avail) + bytes = avail; + + memcpy(stream->m_buf + stream->m_ptr, data, bytes); + stream->m_ptr += bytes; + memstream_update_ptr(stream); + return bytes; +} + +int memstream_seek(memstream_t *stream, int offset, int whence) +{ + size_t ptr; + if (whence == SEEK_SET) + ptr = offset; + else if (whence == SEEK_CUR) + ptr = stream->m_ptr + offset; + else if (whence == SEEK_END) + ptr = (stream->writing ? stream->m_max_ptr : stream->m_size) + offset; + else + return -1; + + if (ptr <= stream->m_size) + { + stream->m_ptr = ptr; + return 0; + } + else + return -1; +} + +size_t memstream_pos(memstream_t *stream) +{ + return stream->m_ptr; +} + +int memstream_getc(memstream_t *stream) +{ + if (stream->m_ptr >= stream->m_size) + return EOF; + else + return stream->m_buf[stream->m_ptr++]; + + memstream_update_ptr(stream); +} + +void memstream_putc(memstream_t *stream, int c) +{ + if (stream->m_ptr < stream->m_size) + stream->m_buf[stream->m_ptr++] = c; + + memstream_update_ptr(stream); +} + diff --git a/fceumm/libsnes-fceumm/memstream.h b/fceumm/libsnes-fceumm/memstream.h new file mode 100644 index 0000000..de5424d --- /dev/null +++ b/fceumm/libsnes-fceumm/memstream.h @@ -0,0 +1,30 @@ +#ifndef __MEMSTREAM_H +#define __MEMSTREAM_H + +#include +#include +#ifndef _MSC_VER +#include +#else +#define TRUE 1 +#define FALSE 0 +typedef unsigned char bool; +#endif + +typedef struct memstream memstream_t; + +memstream_t *memstream_open(bool writing); +void memstream_close(memstream_t *stream); + +size_t memstream_read(memstream_t *stream, void *data, size_t bytes); +size_t memstream_write(memstream_t *stream, const void *data, size_t bytes); +int memstream_getc(memstream_t *stream); +void memstream_putc(memstream_t *stream, int c); +char *memstream_gets(memstream_t *stream, char *buffer, size_t len); +size_t memstream_pos(memstream_t *stream); +int memstream_seek(memstream_t *stream, int offset, int whence); + +void memstream_set_buffer(uint8_t *buffer, size_t size); +size_t memstream_get_last_size(void); + +#endif diff --git a/fceumm/src-fceumm/boards/01-222.c b/fceumm/src-fceumm/boards/01-222.c new file mode 100644 index 0000000..f91080c --- /dev/null +++ b/fceumm/src-fceumm/boards/01-222.c @@ -0,0 +1,103 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * TXC mappers, originally much complex banksitching + */ + +#include "mapinc.h" + +static uint8 reg[4], cmd, is172, is173; +static SFORMAT StateRegs[]= +{ + {reg, 4, "REGS"}, + {&cmd, 1, "CMD"}, + {0} +}; + +static void Sync(void) +{ + setprg32(0x8000,(reg[2]>>2)&1); + if(is172) + setchr8((((cmd^reg[2])>>3)&2)|(((cmd^reg[2])>>5)&1)); /* 1991 DU MA Racing probably CHR bank sequence is WRONG, so it is possible to*/ + /* rearrange CHR banks for normal UNIF board and mapper 172 is unneccessary*/ + else + setchr8(reg[2]&3); +} + +static DECLFW(UNL22211WriteLo) +{ +/* FCEU_printf("bs %04x %02x\n",A,V);*/ + reg[A&3]=V; +} + +static DECLFW(UNL22211WriteHi) +{ +/* FCEU_printf("bs %04x %02x\n",A,V);*/ + cmd=V; + Sync(); +} + +static DECLFR(UNL22211ReadLo) +{ + return (reg[1]^reg[2])|(is173?0x01:0x40); +/* if(reg[3])*/ +/* return reg[2];*/ +/* else*/ +/* return X.DB;*/ +} + +static void UNL22211Power(void) +{ + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetReadHandler(0x4100,0x4100,UNL22211ReadLo); + SetWriteHandler(0x4100,0x4103,UNL22211WriteLo); + SetWriteHandler(0x8000,0xFFFF,UNL22211WriteHi); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNL22211_Init(CartInfo *info) +{ + is172=0; + is173=0; + info->Power=UNL22211Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper172_Init(CartInfo *info) +{ + is172=1; + is173=0; + info->Power=UNL22211Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper173_Init(CartInfo *info) +{ + is172=0; + is173=1; + info->Power=UNL22211Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/103.c b/fceumm/src-fceumm/boards/103.c new file mode 100644 index 0000000..06dff2d --- /dev/null +++ b/fceumm/src-fceumm/boards/103.c @@ -0,0 +1,128 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg0, reg1, reg2; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {®0, 1, "REG0"}, + {®1, 1, "REG1"}, + {®2, 1, "REG2"}, + {0} +}; + +static void Sync(void) +{ + setchr8(0); + setprg8(0x8000,0xc); + setprg8(0xe000,0xf); + if(reg2&0x10) + { + setprg8(0x6000,reg0); + setprg8(0xa000,0xd); + setprg8(0xc000,0xe); + } + else + { + setprg8r(0x10,0x6000,0); + setprg4(0xa000,(0xd<<1)); + setprg2(0xb000,(0xd<<2)+2); + setprg2r(0x10,0xb800,4); + setprg2r(0x10,0xc000,5); + setprg2r(0x10,0xc800,6); + setprg2r(0x10,0xd000,7); + setprg2(0xd800,(0xe<<2)+3); + } + setmirror(reg1^1); +} + +static DECLFW(M103RamWrite0) +{ + WRAM[A&0x1FFF]=V; +} + +static DECLFW(M103RamWrite1) +{ + WRAM[0x2000+((A-0xB800)&0x1FFF)]=V; +} + +static DECLFW(M103Write0) +{ + reg0=V&0xf; + Sync(); +} + +static DECLFW(M103Write1) +{ + reg1=(V>>3)&1; + Sync(); +} + +static DECLFW(M103Write2) +{ + reg2=V; + Sync(); +} + +static void M103Power(void) +{ + reg0=reg1=0; reg2=0; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,M103RamWrite0); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0xB800,0xD7FF,M103RamWrite1); + SetWriteHandler(0x8000,0x8FFF,M103Write0); + SetWriteHandler(0xE000,0xEFFF,M103Write1); + SetWriteHandler(0xF000,0xFFFF,M103Write2); +} + +static void M103Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper103_Init(CartInfo *info) +{ + info->Power=M103Power; + info->Close=M103Close; + GameStateRestore=StateRestore; + + WRAMSIZE=16384; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/106.c b/fceumm/src-fceumm/boards/106.c new file mode 100644 index 0000000..794ddff --- /dev/null +++ b/fceumm/src-fceumm/boards/106.c @@ -0,0 +1,119 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg[16], IRQa; +static uint32 IRQCount; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {&IRQa, 1, "IRQA"}, + {&IRQCount, 4, "IRQCOUNT"}, + {reg, 16, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setchr1(0x0000,reg[0]&0xfe); + setchr1(0x0400,reg[1]|1); + setchr1(0x0800,reg[2]&0xfe); + setchr1(0x0c00,reg[3]|1); + setchr1(0x1000,reg[4]); + setchr1(0x1400,reg[5]); + setchr1(0x1800,reg[6]); + setchr1(0x1c00,reg[7]); + setprg8r(0x10,0x6000,0); + setprg8(0x8000,(reg[0x8]&0xf)|0x10); + setprg8(0xA000,(reg[0x9]&0x1f)); + setprg8(0xC000,(reg[0xa]&0x1f)); + setprg8(0xE000,(reg[0xb]&0xf)|0x10); + setmirror((reg[0xc]&1)^1); +} + +static DECLFW(M106Write) +{ + A&=0xF; + switch(A) + { + case 0xD: IRQa=0; IRQCount=0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xE: IRQCount=(IRQCount&0xFF00)|V; break; + case 0xF: IRQCount=(IRQCount&0x00FF)|(V<<8); IRQa=1; break; + default: reg[A]=V; Sync(); break; + } +} + +static void M106Power(void) +{ + reg[8]=reg[9]=reg[0xa]=reg[0xb]=-1; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetWriteHandler(0x8000,0xFFFF,M106Write); +} + +static void M106Reset(void) +{ +} + +static void M106Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +void M106CpuHook(int a) +{ + if(IRQa) + { + IRQCount+=a; + if(IRQCount>0x10000) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper106_Init(CartInfo *info) +{ + info->Reset=M106Reset; + info->Power=M106Power; + info->Close=M106Close; + MapIRQHook=M106CpuHook; + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/108.c b/fceumm/src-fceumm/boards/108.c new file mode 100644 index 0000000..4e4df2b --- /dev/null +++ b/fceumm/src-fceumm/boards/108.c @@ -0,0 +1,65 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REG"}, + {0} +}; + +static void Sync(void) +{ + setprg8(0x6000,reg); + setprg32(0x8000,~0); + setchr8(0); +} + +static DECLFW(M108Write) +{ + reg=V; + Sync(); +} + +static void M108Power(void) +{ + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8FFF,0x8FFF,M108Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper108_Init(CartInfo *info) +{ + info->Power=M108Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/112.c b/fceumm/src-fceumm/boards/112.c new file mode 100644 index 0000000..07abf68 --- /dev/null +++ b/fceumm/src-fceumm/boards/112.c @@ -0,0 +1,94 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * NTDEC, ASDER games + */ + +#include "mapinc.h" + +static uint8 reg[8]; +static uint8 mirror, cmd, bank; +static uint8 *WRAM=NULL; + +static SFORMAT StateRegs[]= +{ + {&cmd, 1, "CMD"}, + {&mirror, 1, "MIRR"}, + {&bank, 1, "BANK"}, + {reg, 8, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setmirror(mirror^1); + setprg8(0x8000,reg[0]); + setprg8(0xA000,reg[1]); + setchr2(0x0000,(reg[2]>>1)); + setchr2(0x0800,(reg[3]>>1)); + setchr1(0x1000,((bank&0x10)<<4)|reg[4]); + setchr1(0x1400,((bank&0x20)<<3)|reg[5]); + setchr1(0x1800,((bank&0x40)<<2)|reg[6]); + setchr1(0x1C00,((bank&0x80)<<1)|reg[7]); +} + +static DECLFW(M112Write) +{ + switch(A) + { + case 0xe000: mirror=V&1; Sync(); ;break; + case 0x8000: cmd=V&7; break; + case 0xa000: reg[cmd]=V; Sync(); break; + case 0xc000: bank=V; Sync(); break; + } +} + +static void M112Close(void) +{ + if(WRAM) + free(WRAM); + WRAM = NULL; +} + +static void M112Power(void) +{ + bank=0; + setprg16(0xC000,~0); + setprg8r(0x10,0x6000,0); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M112Write); + SetWriteHandler(0x4020,0x5FFF,M112Write); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper112_Init(CartInfo *info) +{ + info->Power=M112Power; + info->Close=M112Close; + GameStateRestore=StateRestore; + WRAM=(uint8*)FCEU_gmalloc(8192); + SetupCartPRGMapping(0x10,WRAM,8192,1); + AddExState(WRAM, 8192, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/116.c b/fceumm/src-fceumm/boards/116.c new file mode 100644 index 0000000..9af0eb5 --- /dev/null +++ b/fceumm/src-fceumm/boards/116.c @@ -0,0 +1,349 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * SL12 Protected 3-in-1 mapper hardware (VRC2, MMC3, MMC1) + * the same as 603-5052 board (TODO: add reading registers, merge) + * SL1632 2-in-1 protected board, similar to SL12 (TODO: find difference) + * + * Known PCB: + * + * Garou Densetsu Special (G0904.PCB, Huang-1, GAL dip: W conf.) + * Kart Fighter (008, Huang-1, GAL dip: W conf.) + * Somari (008, C5052-13, GAL dip: P conf., GK2-P/GK2-V maskroms) + * Somari (008, Huang-1, GAL dip: W conf., GK1-P/GK1-V maskroms) + * AV Mei Shao Nv Zhan Shi () + * Samurai Spirits (Full version) (Huang-1, GAL dip: unk conf. GS-2A/GS-4A maskroms) + * Contra Fighter (603-5052 board, C5052-3, GAL dip: unk conf. SC603-A/SCB603-B maskroms) + * + */ + +#include "mapinc.h" + +static uint8 mode; +static uint8 vrc2_chr[8], vrc2_prg[2], vrc2_mirr; +static uint8 mmc3_regs[10], mmc3_ctrl, mmc3_mirr; +static uint8 IRQCount,IRQLatch,IRQa; +static uint8 IRQReload; +static uint8 mmc1_regs[4], mmc1_buffer, mmc1_shift; + +static SFORMAT StateRegs[]= +{ + {&mode, 1, "MODE"}, + {vrc2_chr, 8, "VRC2CHR"}, + {vrc2_prg, 2, "VRC2PRG"}, + {&vrc2_mirr, 1, "VRC2MIR"}, + {mmc3_regs, 10, "MMC3REGS"}, + {&mmc3_ctrl, 1, "MMC3CTRL"}, + {&mmc3_mirr, 1, "MMC3MIR"}, + {&IRQReload, 1, "IRQR"}, + {&IRQCount, 1, "IRQC"}, + {&IRQLatch, 1, "IRQL"}, + {&IRQa, 1, "IRQA"}, + {mmc1_regs, 4, "MMC1REGS"}, + {&mmc1_buffer, 1, "MMC1BUF"}, + {&mmc1_shift, 1, "MMC1MIR"}, + {0} +}; + +static void SyncPRG(void) +{ + switch(mode & 3) { + case 0: + setprg8(0x8000, vrc2_prg[0]); + setprg8(0xA000, vrc2_prg[1]); + setprg8(0xC000, ~1); + setprg8(0xE000, ~0); + break; + case 1: { + uint32 swap = (mmc3_ctrl >> 5) & 2; + setprg8(0x8000, mmc3_regs[6 + swap]); + setprg8(0xA000, mmc3_regs[7]); + setprg8(0xC000, mmc3_regs[6 + (swap ^ 2)]); + setprg8(0xE000, mmc3_regs[9]); + break; + } + case 2: + case 3: { + uint8 bank = mmc1_regs[3] & 0xF; + if(mmc1_regs[0] & 8) + { + if(mmc1_regs[0] & 4) + { + setprg16(0x8000, bank); + setprg16(0xC000, 0x0F); + } + else + { + setprg16(0x8000, 0); + setprg16(0xC000, bank); + } + } + else + setprg32(0x8000, bank >> 1); + break; + } + } +} + +static void SyncCHR(void) +{ + uint32 base = (mode & 4) << 6; + switch(mode & 3) { + case 0: + setchr1(0x0000, base|vrc2_chr[0]); + setchr1(0x0400, base|vrc2_chr[1]); + setchr1(0x0800, base|vrc2_chr[2]); + setchr1(0x0c00, base|vrc2_chr[3]); + setchr1(0x1000, base|vrc2_chr[4]); + setchr1(0x1400, base|vrc2_chr[5]); + setchr1(0x1800, base|vrc2_chr[6]); + setchr1(0x1c00, base|vrc2_chr[7]); + break; + case 1: { + uint32 swap = (mmc3_ctrl & 0x80) << 5; + setchr1(0x0000 ^ swap, base|((mmc3_regs[0])&0xFE)); + setchr1(0x0400 ^ swap, base|(mmc3_regs[0]|1)); + setchr1(0x0800 ^ swap, base|((mmc3_regs[1])&0xFE)); + setchr1(0x0c00 ^ swap, base|(mmc3_regs[1]|1)); + setchr1(0x1000 ^ swap, base|mmc3_regs[2]); + setchr1(0x1400 ^ swap, base|mmc3_regs[3]); + setchr1(0x1800 ^ swap, base|mmc3_regs[4]); + setchr1(0x1c00 ^ swap, base|mmc3_regs[5]); + break; + } + case 2: + case 3: + if(mmc1_regs[0]&0x10) + { + setchr4(0x0000, mmc1_regs[1]); + setchr4(0x1000, mmc1_regs[2]); + } + else + setchr8(mmc1_regs[1] >> 1); + break; + } +} + +static void SyncMIR(void) +{ + switch(mode & 3) { + case 0: { + setmirror((vrc2_mirr&1)^1); + break; + } + case 1: { + setmirror((mmc3_mirr&1)^1); + break; + } + case 2: + case 3: { + switch(mmc1_regs[0]&3) { + case 0: setmirror(MI_0); break; + case 1: setmirror(MI_1); break; + case 2: setmirror(MI_V); break; + case 3: setmirror(MI_H); break; + } + break; + } + } +} + +static void Sync(void) +{ + SyncPRG(); + SyncCHR(); + SyncMIR(); +} + +static DECLFW(UNLSL12ModeWrite) +{ +/* FCEU_printf("%04X:%02X\n",A,V);*/ + if((A & 0x4100) == 0x4100) { + mode = V; + if(A&1) { /* hacky hacky, there are two configuration modes on SOMARI HUANG-1 PCBs*/ + /* Solder pads with P1/P2 shorted called SOMARI P,*/ + /* Solder pads with W1/W2 shorted called SOMARI W*/ + /* Both identical 3-in-1 but W wanted MMC1 registers*/ + /* to be reset when switch to MMC1 mode P one - doesn't*/ + /* There is issue with W version of Somari at starting copyrights*/ + mmc1_regs[0] = 0xc; + mmc1_regs[3] = 0; + mmc1_buffer = 0; + mmc1_shift = 0; + } + Sync(); + } +} + +static DECLFW(UNLSL12Write) +{ +/* FCEU_printf("%04X:%02X\n",A,V);*/ + switch(mode & 3) { + case 0: { + if((A>=0xB000)&&(A<=0xE003)) + { + int32 ind=((((A&2)|(A>>10))>>1)+2)&7; + int32 sar=((A&1)<<2); + vrc2_chr[ind]=(vrc2_chr[ind]&(0xF0>>sar))|((V&0x0F)<> 13) - 4; + mmc1_buffer |= (V & 1) << (mmc1_shift++); + if(mmc1_shift == 5) + { + mmc1_regs[n] = mmc1_buffer; + mmc1_buffer = mmc1_shift = 0; + switch(n) { + case 0: SyncMIR(); + case 2: SyncCHR(); + case 3: + case 1: SyncPRG(); + } + } + } + break; + } + } +} + +static void UNLSL12HBIRQ(void) +{ + if((mode & 3) == 1) + { + int32 count = IRQCount; + if(!count || IRQReload) + { + IRQCount = IRQLatch; + IRQReload = 0; + } + else + IRQCount--; + if(!IRQCount) + { + if(IRQa) + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +static void UNLSL12Power(void) +{ + mode = 0; + vrc2_chr[0] = ~0; + vrc2_chr[1] = ~0; + vrc2_chr[2] = ~0; + vrc2_chr[3] = ~0; /* W conf. of Somari wanted CHR3 has to be set to BB bank (or similar), but doesn't do that directly*/ + vrc2_chr[4] = 4; + vrc2_chr[5] = 5; + vrc2_chr[6] = 6; + vrc2_chr[7] = 7; + vrc2_prg[0] = 0; + vrc2_prg[1] = 1; + vrc2_mirr = 0; + mmc3_regs[0] = 0; + mmc3_regs[1] = 2; + mmc3_regs[2] = 4; + mmc3_regs[3] = 5; + mmc3_regs[4] = 6; + mmc3_regs[5] = 7; + mmc3_regs[6] = ~3; + mmc3_regs[7] = ~2; + mmc3_regs[8] = ~1; + mmc3_regs[9] = ~0; + mmc3_ctrl = mmc3_mirr = IRQCount = IRQLatch = IRQa = 0; + mmc1_regs[0] = 0xc; + mmc1_regs[1] = 0; + mmc1_regs[2] = 0; + mmc1_regs[3] = 0; + mmc1_buffer = 0; + mmc1_shift = 0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4100,0x7FFF,UNLSL12ModeWrite); + SetWriteHandler(0x8000,0xFFFF,UNLSL12Write); +} + +void UNLSL12_Init(CartInfo *info) +{ + info->Power = UNLSL12Power; + GameHBIRQHook = UNLSL12HBIRQ; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/117.c b/fceumm/src-fceumm/boards/117.c new file mode 100644 index 0000000..ab283ab --- /dev/null +++ b/fceumm/src-fceumm/boards/117.c @@ -0,0 +1,104 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 prgreg[4], chrreg[8], mirror; +static uint8 IRQa, IRQCount, IRQLatch; + +static SFORMAT StateRegs[]= +{ + {&IRQa, 1, "IRQA"}, + {&IRQCount, 1, "IRQC"}, + {&IRQLatch, 1, "IRQL"}, + {prgreg, 4, "PREGS"}, + {chrreg, 8, "CREGS"}, + {&mirror, 1, "MREG"}, + {0} +}; + +static void Sync(void) +{ + int i; + setprg8(0x8000,prgreg[0]); + setprg8(0xa000,prgreg[1]); + setprg8(0xc000,prgreg[2]); + setprg8(0xe000,prgreg[3]); + for(i=0; i<8; i++) + setchr1(i<<10,chrreg[i]); + setmirror(mirror^1); +} + +static DECLFW(M117Write) +{ + if(A<0x8004) + { + prgreg[A&3]=V; + Sync(); + } + else if((A>=0xA000)&&(A<=0xA007)) + { + chrreg[A&7]=V; + Sync(); + } + else switch(A) + { + case 0xc001: IRQLatch=V; break; + case 0xc003: IRQCount=IRQLatch; IRQa|=2; break; + case 0xe000: IRQa&=~1; IRQa|=V&1; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xc002: X6502_IRQEnd(FCEU_IQEXT); break; + case 0xd000: mirror=V&1; + } +} + +static void M117Power(void) +{ + prgreg[0]=~3; prgreg[1]=~2; prgreg[2]=~1; prgreg[3]=~0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M117Write); +} + +static void M117IRQHook(void) +{ + if(IRQa==3&&IRQCount) + { + IRQCount--; + if(!IRQCount) + { + IRQa&=1; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper117_Init(CartInfo *info) +{ + info->Power=M117Power; + GameHBIRQHook=M117IRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/fceumm/src-fceumm/boards/120.c b/fceumm/src-fceumm/boards/120.c new file mode 100644 index 0000000..cacd122 --- /dev/null +++ b/fceumm/src-fceumm/boards/120.c @@ -0,0 +1,68 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REG"}, + {0} +}; + +static void Sync(void) +{ + setprg8(0x6000,reg); + setprg32(0x8000,2); + setchr8(0); +} + +static DECLFW(M120Write) +{ + if(A==0x41FF) + { + reg=V&7; + Sync(); + } +} + +static void M120Power(void) +{ + reg=0; + Sync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x4100,0x5FFF,M120Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper120_Init(CartInfo *info) +{ + info->Power=M120Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/121.c b/fceumm/src-fceumm/boards/121.c new file mode 100644 index 0000000..40dca66 --- /dev/null +++ b/fceumm/src-fceumm/boards/121.c @@ -0,0 +1,126 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007-2008 Mad Dumper, CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Panda prince pirate. + * MK4, MK6, A9711 board + * 6035052 seems to be the same too, but with prot array in reverse + * A9746 seems to be the same too, check + * 187 seems to be the same too, check (A98402 board) + */ + +#include "mapinc.h" +#include "mmc3.h" + +static void Sync() +{ + switch(EXPREGS[5]&0x3F) + { + case 0x20: EXPREGS[7] = 1; EXPREGS[0]=EXPREGS[6]; break; + case 0x29: EXPREGS[7] = 1; EXPREGS[0]=EXPREGS[6]; break; + case 0x26: EXPREGS[7] = 0; EXPREGS[0]=EXPREGS[6]; break; + case 0x2B: EXPREGS[7] = 1; EXPREGS[0]=EXPREGS[6]; break; + case 0x2C: EXPREGS[7] = 1; if(EXPREGS[6]) EXPREGS[0]=EXPREGS[6]; break; + case 0x3F: EXPREGS[7] = 1; EXPREGS[0]=EXPREGS[6]; break; + case 0x28: EXPREGS[7] = 0; EXPREGS[1]=EXPREGS[6]; break; + case 0x2A: EXPREGS[7] = 0; EXPREGS[2]=EXPREGS[6]; break; + case 0x2F: break; + default: EXPREGS[5] = 0; break; + } +} + +static void M121CW(uint32 A, uint8 V) +{ + if((A&0x1000)==((MMC3_cmd&0x80)<<5)) + setchr1(A,V|0x100); + else + setchr1(A,V); +} + +static void M121PW(uint32 A, uint8 V) +{ + if(EXPREGS[5]&0x3F) + { +/* FCEU_printf("prot banks: %02x %02x %02x %02x\n",V,EXPREGS[2],EXPREGS[1],EXPREGS[0]);*/ + setprg8(A,V&0x3F); + setprg8(0xE000,EXPREGS[0]); + setprg8(0xC000,EXPREGS[1]); + setprg8(0xA000,EXPREGS[2]); + } + else + { +/* FCEU_printf("gen banks: %04x %02x\n",A,V);*/ + setprg8(A,V&0x3F); + } +} + +static DECLFW(M121Write) +{ +/* FCEU_printf("write: %04x:%04x\n",A&0xE003,V);*/ + switch(A&0xE003) + { + case 0x8000: /*EXPREGS[5] = 0;*/ +/* FCEU_printf("gen: %02x\n",V);*/ + MMC3_CMDWrite(A,V); + FixMMC3PRG(MMC3_cmd); + break; + case 0x8001: EXPREGS[6] = ((V&1)<<5)|((V&2)<<3)|((V&4)<<1)|((V&8)>>1)|((V&0x10)>>3)|((V&0x20)>>5); +/* FCEU_printf("bank: %02x (%02x)\n",V,EXPREGS[6]);*/ + if(!EXPREGS[7]) Sync(); + MMC3_CMDWrite(A,V); + FixMMC3PRG(MMC3_cmd); + break; + case 0x8003: EXPREGS[5] = V; +/* EXPREGS[7] = 0;*/ +/* FCEU_printf("prot: %02x\n",EXPREGS[5]);*/ + Sync(); + MMC3_CMDWrite(0x8000,V); + FixMMC3PRG(MMC3_cmd); + break; + } +} + +static uint8 prot_array[16] = { 0x83, 0x83, 0x42, 0x00 }; +static DECLFW(M121LoWrite) +{ + EXPREGS[4] = prot_array[V&3]; /* 0x100 bit in address seems to be switch arrays 0, 2, 2, 3 (Contra Fighter)*/ +/* FCEU_printf("write: %04x:%04x\n",A,V);*/ +} + +static DECLFR(M121Read) +{ +/* FCEU_printf("read: %04x->\n",A,EXPREGS[0]);*/ + return EXPREGS[4]; +} + +static void M121Power(void) +{ + EXPREGS[5] = 0; + GenMMC3Power(); + SetReadHandler(0x5000,0x5FFF,M121Read); + SetWriteHandler(0x5000,0x5FFF,M121LoWrite); + SetWriteHandler(0x8000,0x9FFF,M121Write); +} + +void Mapper121_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 256, 8, 0); + pwrap=M121PW; + cwrap=M121CW; + info->Power=M121Power; + AddExState(EXPREGS, 8, 0, "EXPR"); +} diff --git a/fceumm/src-fceumm/boards/12in1.c b/fceumm/src-fceumm/boards/12in1.c new file mode 100644 index 0000000..4a10a42 --- /dev/null +++ b/fceumm/src-fceumm/boards/12in1.c @@ -0,0 +1,79 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * 7-in-1 Darkwing Duck, Snake, MagicBlock (PCB marked as "12 in 1") + */ + +#include "mapinc.h" + +static uint8 reg[4]; +static SFORMAT StateRegs[]= +{ + {reg, 4, "REGS"}, + {0} +}; + +static void Sync(void) +{ + uint8 bank = (reg[3]&3)<<3; + setchr4(0x0000, (reg[1]>>3)|(bank<<2)); + setchr4(0x1000, (reg[2]>>3)|(bank<<2)); + if(reg[3]&8) + { + setprg32(0x8000,((reg[2]&7)>>1)|bank); + } + else + { + setprg16(0x8000, (reg[1]&7)|bank); + setprg16(0xc000, 7|bank); + } + setmirror(((reg[3]&4)>>2)^1); +} + +static DECLFW(BMC12IN1Write) +{ + switch(A) + { + case 0xafff: reg[0] = V; break; + case 0xbfff: reg[1] = V; break; + case 0xdfff: reg[2] = V; break; + case 0xefff: reg[3] = V; break; + } + Sync(); +} + +static void BMC12IN1Power(void) +{ + reg[0]=reg[1]=reg[2]=reg[3]=0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,BMC12IN1Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void BMC12IN1_Init(CartInfo *info) +{ + info->Power=BMC12IN1Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/15.c b/fceumm/src-fceumm/boards/15.c new file mode 100644 index 0000000..6dc7e3d --- /dev/null +++ b/fceumm/src-fceumm/boards/15.c @@ -0,0 +1,119 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "mapinc.h" + +static uint16 latchea; +static uint8 latched; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; +static SFORMAT StateRegs[]= +{ + {&latchea, 2, "LATCHEA"}, + {&latched, 1, "LATCHED"}, + {0} +}; + +static void Sync(void) +{ + int i; + setmirror(((latched>>6)&1)^1); + switch(latchea) + { + case 0x8000: + for(i=0;i<4;i++) + setprg8(0x8000+(i<<13),(((latched&0x7F)<<1)+i)^(latched>>7)); + break; + case 0x8002: + for(i=0;i<4;i++) + setprg8(0x8000+(i<<13),((latched&0x7F)<<1)+(latched>>7)); + break; + case 0x8001: + case 0x8003: + for(i=0;i<4;i++) + { + unsigned int b; + b=latched&0x7F; + if(i>=2 && !(latchea&0x2)) + i=0x7F; + setprg8(0x8000+(i<<13),(i&1)+((b<<1)^(latched>>7))); + } + break; + } +} + +static DECLFW(M15Write) +{ + latchea=A; + latched=V; + Sync(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +static void M15Power(void) +{ + latchea=0x8000; + latched=0; + setchr8(0); + setprg8r(0x10,0x6000,0); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetWriteHandler(0x8000,0xFFFF,M15Write); + SetReadHandler(0x8000,0xFFFF,CartBR); + Sync(); +} + +static void M15Reset(void) +{ + latchea=0x8000; + latched=0; + Sync(); +} + +static void M15Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +void Mapper15_Init(CartInfo *info) +{ + info->Power=M15Power; + info->Reset=M15Reset; + info->Close=M15Close; + GameStateRestore=StateRestore; + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/fceumm/src-fceumm/boards/156.c b/fceumm/src-fceumm/boards/156.c new file mode 100644 index 0000000..cc9d866 --- /dev/null +++ b/fceumm/src-fceumm/boards/156.c @@ -0,0 +1,112 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * DIS23C01 DAOU ROM CONTROLLER, Korea + * Metal Force (K) + * Buzz and Waldog (K) + * General's Son (K) + * + */ + +#include "mapinc.h" + +static uint8 chrlo[8], chrhi[8], prg, mirr, mirrisused = 0; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {&prg, 1, "PREG"}, + {chrlo, 8, "CREGSLO"}, + {chrhi, 8, "CREGSHI"}, + {&mirr, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + uint32 i; + for(i=0; i<8; i++) + setchr1(i<<10, chrlo[i]|(chrhi[i] << 8)); + setprg8r(0x10,0x6000,0); + setprg16(0x8000,prg); + setprg16(0xC000,~0); + if(mirrisused) + setmirror(mirr ^ 1); + else + setmirror(MI_0); +} + +static DECLFW(M156Write) +{ + switch(A) { + case 0xC000: + case 0xC001: + case 0xC002: + case 0xC003: chrlo[A&3] = V; Sync(); break; + case 0xC004: + case 0xC005: + case 0xC006: + case 0xC007: chrhi[A&3] = V; Sync(); break; + case 0xC008: + case 0xC009: + case 0xC00A: + case 0xC00B: chrlo[4+(A&3)] = V; Sync(); break; + case 0xC00C: + case 0xC00D: + case 0xC00E: + case 0xC00F: chrhi[4+(A&3)] = V; Sync(); break; + case 0xC010: prg = V; Sync(); break; + case 0xC014: mirr = V; mirrisused = 1; Sync(); break; + } +} + +static void M156Power(void) +{ + Sync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetWriteHandler(0xC000,0xCFFF,M156Write); +} + +static void M156Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper156_Init(CartInfo *info) +{ + info->Power=M156Power; + info->Close=M156Close; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/164.c b/fceumm/src-fceumm/boards/164.c new file mode 100644 index 0000000..b06f852 --- /dev/null +++ b/fceumm/src-fceumm/boards/164.c @@ -0,0 +1,238 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel 2006 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 laststrobe, trigger; +static uint8 reg[8]; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static void(*WSync)(void); + +static SFORMAT StateRegs[]= +{ + {&laststrobe, 1, "STB"}, + {&trigger, 1, "TRG"}, + {reg, 8, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setprg8r(0x10,0x6000,0); + setprg32(0x8000,(reg[0]<<4)|(reg[1]&0xF)); + setchr8(0); +} + +static void StateRestore(int version) +{ + WSync(); +} + +static DECLFR(ReadLow) +{ + switch (A&0x7700) + { + case 0x5100: return reg[2]|reg[0]|reg[1]|reg[3]^0xff; break; + case 0x5500: if(trigger) + return reg[2]|reg[1]; /* Lei Dian Huang Bi Ka Qiu Chuan Shuo (NJ046) may broke other games*/ + else + return 0; + } + return 4; +} + +static void M163HB(void) +{ + if(reg[1]&0x80) + { + if(scanline==239) + { + setchr4(0x0000,0); + setchr4(0x1000,0); + } + else if(scanline==127) + { + setchr4(0x0000,1); + setchr4(0x1000,1); + } + /* Hu Lu Jin Gang (NJ039) (Ch) [!] don't like it */ + + /* + if(scanline>=127) + { + setchr4(0x0000,1); + setchr4(0x1000,1); + } + else + { + setchr4(0x0000,0); + setchr4(0x1000,0); + } + */ + } +} + +static DECLFW(Write) +{ + switch (A&0x7300) + { + case 0x5100: reg[0]=V; WSync(); break; + case 0x5000: reg[1]=V; WSync(); break; + case 0x5200: reg[3]=V; WSync(); break; + case 0x5300: reg[2]=V; break; + } +} + +static void Power(void) +{ + memset(reg,0,8); + reg[1]=0xFF; + SetWriteHandler(0x5000,0x5FFF,Write); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + WSync(); +} + +static void Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +void Mapper164_Init(CartInfo *info) +{ + info->Power=Power; + info->Close=Close; + WSync = Sync; + + WRAMSIZE = 8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +static DECLFW(Write2) +{ + if(A==0x5101) + { + if(laststrobe&&!V) + { + trigger^=1; + } + laststrobe=V; + }else if(A==0x5100&&V==6) /*damn thoose protected games*/ + setprg32(0x8000,3); + else + switch (A&0x7300) + { + case 0x5200: reg[0]=V; WSync(); break; + case 0x5100: reg[3]=V; WSync(); break; + case 0x5000: reg[1]=V; WSync(); if(!(reg[1]&0x80)&&(scanline<128)) setchr8(0); /* setchr8(0); */ break; + case 0x5300: reg[2]=V; break; + } +} + +static void Power2(void) +{ + memset(reg,0,8); + laststrobe=1; + SetReadHandler(0x5000,0x5FFF,ReadLow); + SetWriteHandler(0x5000,0x5FFF,Write2); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + WSync(); +} + +void Mapper163_Init(CartInfo *info) +{ + info->Power=Power2; + info->Close=Close; + WSync = Sync; + GameHBIRQHook=M163HB; + + WRAMSIZE = 8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +static void Sync3(void) +{ + setchr8(0); + setprg8r(0x10,0x6000,0); + setprg32(0x8000,(reg[0]&0xe)|((reg[1]>>1)&1)|((reg[2]&15)<<4)); +} + +static DECLFW(Write3) +{ +/* FCEU_printf("bs %04x %02x\n",A,V);*/ + reg[(A>>8)&3]=V; + WSync(); +} + +static void Power3(void) +{ + memset(reg,0,8); + SetWriteHandler(0x5000,0x5FFF,Write3); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + WSync(); +} + +void UNLFS304_Init(CartInfo *info) +{ + info->Power=Power3; + info->Close=Close; + WSync = Sync3; + + WRAMSIZE = 8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/168.c b/fceumm/src-fceumm/boards/168.c new file mode 100644 index 0000000..a2daa34 --- /dev/null +++ b/fceumm/src-fceumm/boards/168.c @@ -0,0 +1,89 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * RacerMate Chalenge II + * + */ + +#include "mapinc.h" + +static uint8 reg; +static uint8 *CHRRAM=NULL; +static uint32 CHRRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setchr4r(0x10,0x0000,0); + setchr4r(0x10,0x1000,reg&0x0f); + setprg16(0x8000,reg>>6); + setprg16(0xc000,~0); +} + +static DECLFW(M168Write) +{ + reg=V; + Sync(); +} + +static DECLFW(M168Dummy) +{ +} + +static void M168Power(void) +{ + reg=0; + Sync(); + SetWriteHandler(0x4020,0x7fff,M168Dummy); + SetWriteHandler(0xB000,0xB000,M168Write); + SetWriteHandler(0xF000,0xF000,M168Dummy); + SetWriteHandler(0xF080,0xF080,M168Dummy); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void MNNNClose(void) +{ + if(CHRRAM) + free(CHRRAM); + CHRRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper168_Init(CartInfo *info) +{ + info->Power=M168Power; + info->Close=MNNNClose; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); + + CHRRAMSIZE=8192*8; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10,CHRRAM,CHRRAMSIZE,1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); + +} diff --git a/fceumm/src-fceumm/boards/170.c b/fceumm/src-fceumm/boards/170.c new file mode 100644 index 0000000..7237634 --- /dev/null +++ b/fceumm/src-fceumm/boards/170.c @@ -0,0 +1,69 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setprg16(0x8000, 0); + setprg16(0xc000,~0); + setchr8(0); +} + +static DECLFW(M170ProtW) +{ + reg = V << 1 & 0x80; +} + +static DECLFR(M170ProtR) +{ + return reg | (X.DB & 0x7F); +} + +static void M170Power(void) +{ + Sync(); + SetWriteHandler(0x6502,0x6502,M170ProtW); + SetWriteHandler(0x7000,0x7000,M170ProtW); + SetReadHandler(0x7001,0x7001,M170ProtR); + SetReadHandler(0x7777,0x7777,M170ProtR); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper170_Init(CartInfo *info) +{ + info->Power=M170Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/fceumm/src-fceumm/boards/175.c b/fceumm/src-fceumm/boards/175.c new file mode 100644 index 0000000..13bbddd --- /dev/null +++ b/fceumm/src-fceumm/boards/175.c @@ -0,0 +1,88 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg, delay, mirr; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REG"}, + {&mirr, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + setchr8(reg); + if(!delay) + { + setprg16(0x8000,reg); + setprg8(0xC000,reg << 1); + } + setprg8(0xE000,(reg << 1) + 1); + setmirror(((mirr&4)>>2)^1); +} + +static DECLFW(M175Write1) +{ + mirr = V; + delay = 1; + Sync(); +} + +static DECLFW(M175Write2) +{ + reg = V & 0x0F; + delay = 1; + Sync(); +} + +static DECLFR(M175Read) +{ + if(A==0xFFFC) + { + delay = 0; + Sync(); + } + return CartBR(A); +} + +static void M175Power(void) +{ + reg = mirr = delay = 0; + SetReadHandler(0x8000,0xFFFF,M175Read); + SetWriteHandler(0x8000,0x8000,M175Write1); + SetWriteHandler(0xA000,0xA000,M175Write2); + Sync(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper175_Init(CartInfo *info) +{ + info->Power=M175Power; + GameStateRestore=StateRestore; + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/176.c b/fceumm/src-fceumm/boards/176.c new file mode 100644 index 0000000..25246af --- /dev/null +++ b/fceumm/src-fceumm/boards/176.c @@ -0,0 +1,89 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 prg, chr; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {&prg, 1, "PRG"}, + {&chr, 1, "CHR"}, + {0} +}; + +static void Sync(void) +{ + setprg8r(0x10,0x6000,0); + setprg32(0x8000,prg>>1); + setchr8(chr); +} + +static DECLFW(M176Write1) +{ + prg = V; + Sync(); +} + +static DECLFW(M176Write2) +{ + chr = V; + Sync(); +} + +static void M176Power(void) +{ + prg = ~0; + SetReadHandler(0x6000,0x7fff,CartBR); + SetWriteHandler(0x6000,0x7fff,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x5ff1,0x5ff1,M176Write1); + SetWriteHandler(0x5ff2,0x5ff2,M176Write2); + Sync(); +} + + +static void M176Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper176_Init(CartInfo *info) +{ + info->Power=M176Power; + info->Close=M176Close; + + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/177.c b/fceumm/src-fceumm/boards/177.c new file mode 100644 index 0000000..5331e36 --- /dev/null +++ b/fceumm/src-fceumm/boards/177.c @@ -0,0 +1,87 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg; + +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REG"}, + {0} +}; + +static void Sync(void) +{ + setchr8(0); + setprg8r(0x10,0x6000,0); + setprg32(0x8000,reg&0x1f); + setmirror(((reg&0x20)>>5)^1); +} + +static DECLFW(M177Write) +{ + reg=V; + Sync(); +} + +static void M177Power(void) +{ + reg=0; + Sync(); + SetReadHandler(0x6000,0x7fff,CartBR); + SetWriteHandler(0x6000,0x7fff,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M177Write); +} + +static void M177Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper177_Init(CartInfo *info) +{ + info->Power=M177Power; + info->Close=M177Close; + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/178.c b/fceumm/src-fceumm/boards/178.c new file mode 100644 index 0000000..77968cb --- /dev/null +++ b/fceumm/src-fceumm/boards/178.c @@ -0,0 +1,104 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * San Guo Zhong Lie Zhuan (Ch) + * win200, etc + * + */ + +#include "mapinc.h" + +static uint8 reg[4]; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {reg, 4, "REGS"}, + {0} +}; + +static void Sync(void) +{ + uint8 bank = (reg[2]&3)<<3; + setmirror((reg[0]&1)^1); + setprg8r(0x10,0x6000,0); + setchr8(0); + if(reg[0]&2) + { + setprg16(0x8000,(reg[1]&7)|bank); + setprg16(0xC000,((~0)&7)|bank); + } + else + { + setprg16(0x8000,(reg[1]&6)|bank); + setprg16(0xC000,(reg[1]&6)|bank|1); + } +} + +static DECLFW(M178Write) +{ + reg[A&3]=V; + Sync(); +} + +static void M178Power(void) +{ + reg[0]=1; + reg[1]=0; + reg[2]=0; + reg[3]=0; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4800,0x4803,M178Write); +} + +static void M178Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper178_Init(CartInfo *info) +{ + info->Power=M178Power; + info->Close=M178Close; + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/183.c b/fceumm/src-fceumm/boards/183.c new file mode 100644 index 0000000..b394b32 --- /dev/null +++ b/fceumm/src-fceumm/boards/183.c @@ -0,0 +1,117 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Gimmick Bootleg (VRC4 mapper) + */ + +#include "mapinc.h" + +static uint8 prg[4]; +static uint8 chr[8]; +static uint8 IRQCount; +static uint8 IRQPre; +static uint8 IRQa; + +static SFORMAT StateRegs[]= +{ + {prg, 4, "PRG"}, + {chr, 8, "CHR"}, + {&IRQCount, 1, "IRQCOUNT"}, + {&IRQPre, 1, "IRQPRE"}, + {&IRQa, 1, "IRQA"}, + {0} +}; + +static void SyncPrg(void) +{ + setprg8(0x6000,0); + setprg8(0x8000,prg[0]); + setprg8(0xA000,prg[1]); + setprg8(0xC000,prg[2]); + setprg8(0xE000,~0); +} + +static void SyncChr(void) +{ + int i; + for(i=0; i<8; i++) + setchr1(i<<10,chr[i]); +} + +static void StateRestore(int version) +{ + SyncPrg(); + SyncChr(); +} + +static DECLFW(M183Write) +{ + if(((A&0xF80C)>=0xB000)&&((A&0xF80C)<=0xE00C)) + { + int index=(((A>>11)-6)|(A>>3))&7; + chr[index]=(chr[index]&(0xF0>>(A&4)))|((V&0x0F)<<(A&4)); + SyncChr(); + } + else switch (A&0xF80C) + { + case 0x8800: prg[0]=V; SyncPrg(); break; + case 0xA800: prg[1]=V; SyncPrg(); break; + case 0xA000: prg[2]=V; SyncPrg(); break; + case 0x9800: switch (V&3) + { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } + break; + case 0xF000: IRQCount=((IRQCount&0xF0)|(V&0xF)); break; + case 0xF004: IRQCount=((IRQCount&0x0F)|((V&0xF)<<4)); break; + case 0xF008: IRQa=V; if(!V)IRQPre=0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xF00C: IRQPre=16; break; + } +} + +static void M183IRQCounter(void) +{ + if(IRQa) + { + IRQCount++; + if((IRQCount-IRQPre)==238) + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static void M183Power(void) +{ + IRQPre=IRQCount=IRQa=0; + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M183Write); + SetReadHandler(0x6000,0x7FFF,CartBR); + SyncPrg(); + SyncChr(); +} + +void Mapper183_Init(CartInfo *info) +{ + info->Power=M183Power; + GameHBIRQHook=M183IRQCounter; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/185.c b/fceumm/src-fceumm/boards/185.c new file mode 100644 index 0000000..08cd530 --- /dev/null +++ b/fceumm/src-fceumm/boards/185.c @@ -0,0 +1,115 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "mapinc.h" + +static uint8 *DummyCHR=NULL; +static uint8 datareg; +static void(*Sync)(void); + + +static SFORMAT StateRegs[]= +{ + {&datareg, 1, "DREG"}, + {0} +}; + +/* on off*/ +/*1 0x0F, 0xF0 - Bird Week*/ +/*2 0x33, 0x00 - B-Wings*/ +/*3 0x11, 0x00 - Mighty Bomb Jack*/ +/*4 0x22, 0x20 - Sansuu 1 Nen, Sansuu 2 Nen*/ +/*5 0xFF, 0x00 - Sansuu 3 Nen*/ +/*6 0x21, 0x13 - Spy vs Spy*/ +/*7 0x20, 0x21 - Seicross*/ + +static void Sync185(void) +{ + /* little dirty eh? ;_)*/ + if((datareg&3)&&(datareg!=0x13)) /* 1, 2, 3, 4, 5, 6*/ + setchr8(0); + else + setchr8r(0x10,0); +} + +static void Sync181(void) +{ + if(!(datareg&1)) /* 7*/ + setchr8(0); + else + setchr8r(0x10,0); +} + +static DECLFW(MWrite) +{ + datareg=V; + Sync(); +} + +static void MPower(void) +{ + datareg=0; + Sync(); + setprg16(0x8000,0); + setprg16(0xC000,~0); + SetWriteHandler(0x8000,0xFFFF,MWrite); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void MClose(void) +{ + if(DummyCHR) + free(DummyCHR); + DummyCHR=NULL; +} + +static void MRestore(int version) +{ + Sync(); +} + +void Mapper185_Init(CartInfo *info) +{ + int x; + Sync=Sync185; + info->Power=MPower; + info->Close=MClose; + GameStateRestore=MRestore; + DummyCHR=(uint8*)FCEU_gmalloc(8192); + for(x=0;x<8192;x++) + DummyCHR[x]=0xff; + SetupCartCHRMapping(0x10,DummyCHR,8192,0); + AddExState(StateRegs, ~0, 0, 0); +} + +void Mapper181_Init(CartInfo *info) +{ + int x; + Sync=Sync181; + info->Power=MPower; + info->Close=MClose; + GameStateRestore=MRestore; + DummyCHR=(uint8*)FCEU_gmalloc(8192); + for(x=0;x<8192;x++) + DummyCHR[x]=0xff; + SetupCartCHRMapping(0x10,DummyCHR,8192,0); + AddExState(StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/186.c b/fceumm/src-fceumm/boards/186.c new file mode 100644 index 0000000..3f878b3 --- /dev/null +++ b/fceumm/src-fceumm/boards/186.c @@ -0,0 +1,104 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Family Study Box by Fukutake Shoten + */ + +#include "mapinc.h" + +static uint8 SWRAM[2816]; +static uint8 *WRAM=NULL; +static uint8 regs[4]; + +static SFORMAT StateRegs[]= +{ + {regs, 4, "DREG"}, + {SWRAM, 2816, "SWRAM"}, + {0} +}; + +static void Sync(void) +{ + setprg8r(0x10,0x6000,regs[0]>>6); + setprg16(0x8000,regs[1]); + setprg16(0xc000,0); +} + +static DECLFW(M186Write) +{ + if(A&0x4203) regs[A&3]=V; + Sync(); +} + +static DECLFR(M186Read) +{ + switch(A) + { + case 0x4200: return 0x00; break; + case 0x4201: return 0x00; break; + case 0x4202: return 0x40; break; + case 0x4203: return 0x00; break; + } + return 0xFF; +} + +static DECLFR(ASWRAM) +{ + return(SWRAM[A-0x4400]); +} +static DECLFW(BSWRAM) +{ + SWRAM[A-0x4400]=V; +} + +static void M186Power(void) +{ + setchr8(0); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0xFFFF,CartBW); + SetReadHandler(0x4200,0x43FF,M186Read); + SetWriteHandler(0x4200,0x43FF,M186Write); + SetReadHandler(0x4400,0x4EFF,ASWRAM); + SetWriteHandler(0x4400,0x4EFF,BSWRAM); + regs[0]=regs[1]=regs[2]=regs[3]; + Sync(); +} + +static void M186Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +static void M186Restore(int version) +{ + Sync(); +} + +void Mapper186_Init(CartInfo *info) +{ + info->Power=M186Power; + info->Close=M186Close; + GameStateRestore=M186Restore; + WRAM=(uint8*)FCEU_gmalloc(32768); + SetupCartPRGMapping(0x10,WRAM,32768,1); + AddExState(WRAM, 32768, 0, "WRAM"); + AddExState(StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/187.c b/fceumm/src-fceumm/boards/187.c new file mode 100644 index 0000000..4d83acc --- /dev/null +++ b/fceumm/src-fceumm/boards/187.c @@ -0,0 +1,102 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * A98402 board, A9711, A9746 similar + * King of Fighters 96, The (Unl), Street Fighter Zero 2 (Unl) + * + */ + +#include "mapinc.h" +#include "mmc3.h" + +static void M187CW(uint32 A, uint8 V) +{ + if((A&0x1000)==((MMC3_cmd&0x80)<<5)) + setchr1(A,V|0x100); + else + setchr1(A,V); +} + +static void M187PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x80) + { + uint8 bank=EXPREGS[0]&0x1F; + if(EXPREGS[0]&0x20) + { + if(EXPREGS[0]&0x40) + setprg32(0x8000,bank>>2); + else + setprg32(0x8000,bank>>1); /* hacky hacky! two mappers in one! need real hw carts to test*/ + } + else + { + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else + setprg8(A,V&0x3F); +} + +static DECLFW(M187Write8000) +{ + EXPREGS[1]=1; + MMC3_CMDWrite(A,V); +} + +static DECLFW(M187Write8001) +{ + if(EXPREGS[1]) + MMC3_CMDWrite(A,V); +} + +static DECLFW(M187WriteLo) +{ + if((A==0x5000)||(A==0x6000)) + { + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + } +} + +static uint8 prot_data[4] = { 0x83, 0x83, 0x42, 0x00 }; +static DECLFR(M187Read) +{ + return prot_data[EXPREGS[1]&3]; +} + +static void M187Power(void) +{ + EXPREGS[0]=EXPREGS[1]=0; + GenMMC3Power(); + SetReadHandler(0x5000,0x5FFF,M187Read); + SetWriteHandler(0x5000,0x6FFF,M187WriteLo); + SetWriteHandler(0x8000,0x8000,M187Write8000); + SetWriteHandler(0x8001,0x8001,M187Write8001); +} + +void Mapper187_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap=M187PW; + cwrap=M187CW; + info->Power=M187Power; + AddExState(EXPREGS, 3, 0, "EXPR"); +} diff --git a/fceumm/src-fceumm/boards/189.c b/fceumm/src-fceumm/boards/189.c new file mode 100644 index 0000000..c9dcf59 --- /dev/null +++ b/fceumm/src-fceumm/boards/189.c @@ -0,0 +1,48 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" +#include "mmc3.h" + +static void M189PW(uint32 A, uint8 V) +{ + setprg32(0x8000,EXPREGS[0]&7); +} + +static DECLFW(M189Write) +{ + EXPREGS[0]=V|(V>>4); /*actually, there is a two versions of 189 mapper with hi or lo bits bankswitching.*/ + FixMMC3PRG(MMC3_cmd); +} + +static void M189Power(void) +{ + EXPREGS[0]=EXPREGS[1]=0; + GenMMC3Power(); + SetWriteHandler(0x4120,0x7FFF,M189Write); +} + +void Mapper189_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap=M189PW; + info->Power=M189Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} diff --git a/fceumm/src-fceumm/boards/193.c b/fceumm/src-fceumm/boards/193.c new file mode 100644 index 0000000..89b9f86 --- /dev/null +++ b/fceumm/src-fceumm/boards/193.c @@ -0,0 +1,78 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * MEGA-SOFT WAR IN THE GULF + */ + +#include "mapinc.h" + +static uint8 reg[8]; +static uint8 mirror, cmd, bank; + +static SFORMAT StateRegs[]= +{ + {&cmd, 1, "CMD"}, + {&mirror, 1, "MIRR"}, + {&bank, 1, "BANK"}, + {reg, 8, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setmirror(mirror^1); + setprg8(0x8000,reg[3]); + setprg8(0xA000,0xD); + setprg8(0xC000,0xE); + setprg8(0xE000,0xF); + setchr4(0x0000,reg[0]>>2); + setchr2(0x1000,reg[1]>>1); + setchr2(0x1800,reg[2]>>1); +} + +static DECLFW(M193Write) +{ + reg[A&3]=V; + Sync(); +} + +static void M193Power(void) +{ + bank=0; + Sync(); + SetWriteHandler(0x6000,0x6003,M193Write); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,CartBW); +} + +static void M193Reset(void) +{ +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper193_Init(CartInfo *info) +{ + info->Reset=M193Reset; + info->Power=M193Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/199.c b/fceumm/src-fceumm/boards/199.c new file mode 100644 index 0000000..9f446e0 --- /dev/null +++ b/fceumm/src-fceumm/boards/199.c @@ -0,0 +1,107 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Dragon Ball Z 2 - Gekishin Freeza! (C) + * Dragon Ball Z Gaiden - Saiya Jin Zetsumetsu Keikaku (C) + * San Guo Zhi 2 (C) + * + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 *CHRRAM=NULL; +static uint32 CHRRAMSIZE; + +static void M199PW(uint32 A, uint8 V) +{ + setprg8(A,V); + setprg8(0xC000,EXPREGS[0]); + setprg8(0xE000,EXPREGS[1]); +} + +static void M199CW(uint32 A, uint8 V) +{ + setchr1r((V<8)?0x10:0x00,A,V); + setchr1r((DRegBuf[0]<8)?0x10:0x00,0x0000,DRegBuf[0]); + setchr1r((EXPREGS[2]<8)?0x10:0x00,0x0400,EXPREGS[2]); + setchr1r((DRegBuf[1]<8)?0x10:0x00,0x0800,DRegBuf[1]); + setchr1r((EXPREGS[3]<8)?0x10:0x00,0x0c00,EXPREGS[3]); +} + +static void M199MW(uint8 V) +{ +/* FCEU_printf("%02x\n",V);*/ + switch(V&3) + { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(M199Write) +{ + if((A==0x8001)&&(MMC3_cmd&8)) + { + EXPREGS[MMC3_cmd&3]=V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } + else + if(A<0xC000) + MMC3_CMDWrite(A,V); + else + MMC3_IRQWrite(A,V); +} + +static void M199Power(void) +{ + EXPREGS[0]=~1; + EXPREGS[1]=~0; + EXPREGS[2]=1; + EXPREGS[3]=3; + GenMMC3Power(); + SetWriteHandler(0x8000,0xFFFF,M199Write); +} + +static void M199Close(void) +{ + if(CHRRAM) + free(CHRRAM); + CHRRAM=NULL; +} + +void Mapper199_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M199CW; + pwrap=M199PW; + mwrap=M199MW; + info->Power=M199Power; + info->Close=M199Close; + + CHRRAMSIZE=8192; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CHRR"); + + AddExState(EXPREGS, 4, 0, "EXPR"); +} diff --git a/fceumm/src-fceumm/boards/208.c b/fceumm/src-fceumm/boards/208.c new file mode 100644 index 0000000..14156a6 --- /dev/null +++ b/fceumm/src-fceumm/boards/208.c @@ -0,0 +1,83 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 lut[256]={ + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01, + 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00, + 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static void M208PW(uint32 A, uint8 V) +{ + setprg32(0x8000,EXPREGS[5]); +} + +static DECLFW(M208Write) +{ + EXPREGS[5]=(V&0x1)|((V>>3)&0x2); + FixMMC3PRG(MMC3_cmd); +} + +static DECLFW(M208ProtWrite) +{ + if(A<=0x57FF) + EXPREGS[4]=V; + else + EXPREGS[(A&0x03)]=V^lut[EXPREGS[4]]; +} + +static DECLFR(M208ProtRead) +{ + return(EXPREGS[(A&0x3)]); +} + +static void M208Power(void) +{ + EXPREGS[5]=3; + GenMMC3Power(); + SetWriteHandler(0x4800,0x4FFF,M208Write); + SetWriteHandler(0x5000,0x5fff,M208ProtWrite); + SetReadHandler(0x5800,0x5FFF,M208ProtRead); + SetReadHandler(0x8000,0xffff,CartBR); +} + +void Mapper208_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 256, 0, 0); + pwrap=M208PW; + info->Power=M208Power; + AddExState(EXPREGS, 6, 0, "EXPR"); +} diff --git a/fceumm/src-fceumm/boards/222.c b/fceumm/src-fceumm/boards/222.c new file mode 100644 index 0000000..08d8fb6 --- /dev/null +++ b/fceumm/src-fceumm/boards/222.c @@ -0,0 +1,106 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * (VRC4 mapper) + */ + +#include "mapinc.h" + +static uint8 IRQCount;/*, IRQPre;*/ +static uint8 IRQa; +static uint8 prg_reg[2]; +static uint8 chr_reg[8]; +static uint8 mirr; + +static SFORMAT StateRegs[]= +{ + {&IRQCount, 1, "IRQC"}, + {&IRQa, 1, "IRQA"}, + {prg_reg, 2, "PRG"}, + {chr_reg, 8, "CHR"}, + {&mirr, 1, "MIRR"}, + {0} +}; + +static void M222IRQ(void) +{ + if(IRQa) + { + IRQCount++; + if(IRQCount>=238) + { + X6502_IRQBegin(FCEU_IQEXT); +/* IRQa=0;*/ + } + } +} + +static void Sync(void) +{ + int i; + setprg8(0x8000,prg_reg[0]); + setprg8(0xA000,prg_reg[1]); + for(i=0; i<8; i++) + setchr1(i<<10,chr_reg[i]); + setmirror(mirr^1); +} + +static DECLFW(M222Write) +{ + switch(A&0xF003) + { + case 0x8000: prg_reg[0]=V; break; + case 0x9000: mirr=V&1; break; + case 0xA000: prg_reg[1]=V; break; + case 0xB000: chr_reg[0]=V; break; + case 0xB002: chr_reg[1]=V; break; + case 0xC000: chr_reg[2]=V; break; + case 0xC002: chr_reg[3]=V; break; + case 0xD000: chr_reg[4]=V; break; + case 0xD002: chr_reg[5]=V; break; + case 0xE000: chr_reg[6]=V; break; + case 0xE002: chr_reg[7]=V; break; +/* case 0xF000: FCEU_printf("%04x:%02x %d\n",A,V,scanline); IRQa=V; if(!V)IRQPre=0; X6502_IRQEnd(FCEU_IQEXT); break;*/ +/* / case 0xF001: FCEU_printf("%04x:%02x %d\n",A,V,scanline); IRQCount=V; break;*/ +/* case 0xF002: FCEU_printf("%04x:%02x %d\n",A,V,scanline); break;*/ +/* case 0xD001: IRQa=V; X6502_IRQEnd(FCEU_IQEXT); FCEU_printf("%04x:%02x %d\n",A,V,scanline); break;*/ +/* case 0xC001: IRQPre=16; FCEU_printf("%04x:%02x %d\n",A,V,scanline); break;*/ + case 0xF000: IRQa=IRQCount=V; if(scanline<240) IRQCount-=8; else IRQCount+=4; X6502_IRQEnd(FCEU_IQEXT); break; + } + Sync(); +} + +static void M222Power(void) +{ + setprg16(0xC000,~0); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M222Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper222_Init(CartInfo *info) +{ + info->Power=M222Power; + GameHBIRQHook=M222IRQ; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/225.c b/fceumm/src-fceumm/boards/225.c new file mode 100644 index 0000000..552b418 --- /dev/null +++ b/fceumm/src-fceumm/boards/225.c @@ -0,0 +1,98 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * PCB-018 board, discrete multigame cart 110-in-1 + * + */ + +#include "mapinc.h" + +static uint8 prot[4], prg, mode, chr, mirr; + +static SFORMAT StateRegs[]= +{ + {prot, 4, "PROT"}, + {&prg, 1, "PRG"}, + {&chr, 1, "CHR"}, + {&mode, 1, "MODE"}, + {&mirr, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + if(mode) + { + setprg16(0x8000,prg); + setprg16(0xC000,prg); + } + else + setprg32(0x8000,prg>>1); + setchr8(chr); + setmirror(mirr); +} + +static DECLFW(M225Write) +{ + uint32 bank = (A >> 14) & 1; + mirr = (A >> 13) & 1; + mode = (A >> 12) & 1; + chr = (A & 0x3f) | (bank << 6); + prg = ((A >> 6) & 0x3f) | (bank << 6); + Sync(); +} + +static DECLFW(M225LoWrite) +{ +} + +static DECLFR(M225LoRead) +{ +} + +static void M225Power(void) +{ + prg = 0; + mode = 0; + Sync(); + SetReadHandler(0x5000,0x5fff,M225LoRead); + SetWriteHandler(0x5000,0x5fff,M225LoWrite); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M225Write); +} + +static void M225Reset(void) +{ + prg = 0; + mode = 0; + Sync(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper225_Init(CartInfo *info) +{ + info->Reset=M225Reset; + info->Power=M225Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/23.c b/fceumm/src-fceumm/boards/23.c new file mode 100644 index 0000000..23294f0 --- /dev/null +++ b/fceumm/src-fceumm/boards/23.c @@ -0,0 +1,204 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 is23; +static uint16 IRQCount; +static uint8 IRQLatch,IRQa; +static uint8 prgreg[2]; +static uint8 chrreg[8]; +static uint8 regcmd, irqcmd, mirr, big_bank; +static uint16 acount=0; + +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {prgreg, 2, "PRGREGS"}, + {chrreg, 8, "CHRREGS"}, + {®cmd, 1, "REGCMD"}, + {&irqcmd, 1, "IRQCMD"}, + {&mirr, 1, "MIRR"}, + {&big_bank, 1, "MIRR"}, + {&IRQCount, 2, "IRQC"}, + {&IRQLatch, 1, "IRQL"}, + {&IRQa, 1, "IRQA"}, + {0} +}; + +static void Sync(void) +{ + if(regcmd&2) + { + setprg8(0xC000,prgreg[0]|big_bank); + setprg8(0x8000,((~1)&0x1F)|big_bank); + } + else + { + setprg8(0x8000,prgreg[0]|big_bank); + setprg8(0xC000,((~1)&0x1F)|big_bank); + } + setprg8(0xA000,prgreg[1]|big_bank); + setprg8(0xE000,((~0)&0x1F)|big_bank); + if(UNIFchrrama) + setchr8(0); + else + { + uint8 i; + for(i=0; i<8; i++) + setchr1(i<<10, chrreg[i]); + } + switch(mirr&0x3) + { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(M23Write) +{ +/* FCEU_printf("%04x:%04x\n",A,V);*/ + A|=((A>>2)&0x3)|((A>>4)&0x3)|((A>>6)&0x3); /* actually there is many-in-one mapper source, some pirate or*/ + /* licensed games use various address bits for registers*/ + A&=0xF003; + if((A>=0xB000)&&(A<=0xE003)) + { + if(UNIFchrrama) + big_bank=(V&8)<<2; /* my personally many-in-one feature ;) just for support pirate cart 2-in-1*/ + else + { + uint16 i=((A>>1)&1)|((A-0xB000)>>11); + chrreg[i]&=(0xF0)>>((A&1)<<2); + chrreg[i]|=(V&0xF)<<((A&1)<<2); + } + Sync(); + } + else + switch(A&0xF003) + { + case 0x8000: + case 0x8001: + case 0x8002: + case 0x8003: if(is23) + prgreg[0]=V&0x1F; + Sync(); + break; + case 0xA000: + case 0xA001: + case 0xA002: + case 0xA003: if(is23) + prgreg[1]=V&0x1F; + else + { + prgreg[0]=(V<<1)&0x1F; + prgreg[1]=((V<<1)&0x1F)|1; + } + Sync(); + break; + case 0x9000: + case 0x9001: if(V!=0xFF) mirr=V; Sync(); break; + case 0x9002: + case 0x9003: regcmd=V; Sync(); break; + case 0xF000: X6502_IRQEnd(FCEU_IQEXT); IRQLatch&=0xF0; IRQLatch|=V&0xF; break; + case 0xF001: X6502_IRQEnd(FCEU_IQEXT); IRQLatch&=0x0F; IRQLatch|=V<<4; break; + case 0xF002: X6502_IRQEnd(FCEU_IQEXT); acount=0; IRQCount=IRQLatch; IRQa=V&2; irqcmd=V&1; break; + case 0xF003: X6502_IRQEnd(FCEU_IQEXT); IRQa=irqcmd; break; + } +} + +static void M23Power(void) +{ + big_bank=0x20; + Sync(); + setprg8r(0x10,0x6000,0); /* another many-in-one code, WRAM actually contain only WaiWaiWorld game*/ + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M23Write); +} + +void M23IRQHook(int a) +{ + #define LCYCS 341 + if(IRQa) + { + acount+=a*3; + if(acount>=LCYCS) + { + while(acount>=LCYCS) + { + acount-=LCYCS; + IRQCount++; + if(IRQCount&0x100) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount=IRQLatch; + } + } + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +static void M23Close(void) +{ + if(WRAM) + free(WRAM); +} + +void Mapper23_Init(CartInfo *info) +{ + is23=1; + info->Power=M23Power; + info->Close=M23Close; + MapIRQHook=M23IRQHook; + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} + +void UNLT230_Init(CartInfo *info) +{ + is23=0; + info->Power=M23Power; + info->Close=M23Close; + MapIRQHook=M23IRQHook; + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/235.c b/fceumm/src-fceumm/boards/235.c new file mode 100644 index 0000000..e866e39 --- /dev/null +++ b/fceumm/src-fceumm/boards/235.c @@ -0,0 +1,70 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint16 cmdreg; +static SFORMAT StateRegs[]= +{ + {&cmdreg, 2, "CMDREG"}, + {0} +}; + +static void Sync(void) +{ + if(cmdreg&0x400) + setmirror(MI_0); + else + setmirror(((cmdreg>>13)&1)^1); + if(cmdreg&0x800) + { + setprg16(0x8000,((cmdreg&0x300)>>3)|((cmdreg&0x1F)<<1)|((cmdreg>>12)&1)); + setprg16(0xC000,((cmdreg&0x300)>>3)|((cmdreg&0x1F)<<1)|((cmdreg>>12)&1)); + } + else + setprg32(0x8000,((cmdreg&0x300)>>4)|(cmdreg&0x1F)); +} + +static DECLFW(M235Write) +{ + cmdreg=A; + Sync(); +} + +static void M235Power(void) +{ + setchr8(0); + SetWriteHandler(0x8000,0xFFFF,M235Write); + SetReadHandler(0x8000,0xFFFF,CartBR); + cmdreg=0; + Sync(); +} + +static void M235Restore(int version) +{ + Sync(); +} + +void Mapper235_Init(CartInfo *info) +{ + info->Power=M235Power; + GameStateRestore=M235Restore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/253.c b/fceumm/src-fceumm/boards/253.c new file mode 100644 index 0000000..a02707f --- /dev/null +++ b/fceumm/src-fceumm/boards/253.c @@ -0,0 +1,166 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * TODO: cram disable cases! (Shen Hua Jian Yun III cannot boot with CRAM enabled) + */ + +#include "mapinc.h" + +static uint8 chrlo[8], chrhi[8], prg[2], mirr; +static int32 IRQa, IRQCount, IRQLatch, IRQClock; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; +static uint8 *CHRRAM=NULL; +static uint32 CHRRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {chrlo, 8, "CHRLO"}, + {chrhi, 8, "CHRHI"}, + {prg, 2, "PRGR"}, + {&mirr, 1, "MIRR"}, + {&IRQa, 4, "IRQA"}, + {&IRQCount, 4, "IRQC"}, + {&IRQLatch, 4, "IRQL"}, + {&IRQClock, 4, "IRQCL"}, + {0} +}; + +static void Sync(void) +{ + uint8 i; + setprg8r(0x10,0x6000,0); + setprg8(0x8000,prg[0]); + setprg8(0xa000,prg[1]); + setprg8(0xc000,~1); + setprg8(0xe000,~0); + for(i=0; i<8; i++) + { + uint32 chr = chrlo[i]|(chrhi[i]<<8); + if((chr==4)||(chr==5)) + setchr1r(0x10,i<<10,chr&1); + else + setchr1(i<<10,chr); + } + switch(mirr) + { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(M253Write) +{ + if((A>=0xB000)&&(A<=0xE00C)) + { + uint8 ind=((((A&8)|(A>>8))>>3)+2)&7; + uint8 sar=A&4; + chrlo[ind]=(chrlo[ind]&(0xF0>>sar))|((V&0x0F)<>4; + Sync(); + } + else + switch(A) + { + case 0x8010: prg[0]=V; Sync(); break; + case 0xA010: prg[1]=V; Sync(); break; + case 0x9400: mirr=V&3; Sync(); break; + case 0xF000: IRQLatch = (IRQLatch & 0xF0) | (V & 0x0F); break; + case 0xF004: IRQLatch = (IRQLatch & 0x0F) | (V << 4); break; + case 0xF008: + IRQa = V&3; + if(IRQa&2) + { + IRQCount = IRQLatch; + IRQClock = 0; + } + X6502_IRQEnd(FCEU_IQEXT); + break; + } +} + +static void M253Power(void) +{ + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M253Write); +} + +static void M253Close(void) +{ + if(WRAM) + free(WRAM); + if(CHRRAM) + free(CHRRAM); + WRAM=CHRRAM=NULL; +} + +static void M253IRQ(int cycles) +{ + if(IRQa&2) + { + if((IRQClock+=cycles)>=0x71) + { + IRQClock -= 0x71; + if(IRQCount==0xFF) + { + IRQCount = IRQLatch; + IRQa = IRQa|((IRQa&1)<<1); + X6502_IRQBegin(FCEU_IQEXT); + } + else + IRQCount++; + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper253_Init(CartInfo *info) +{ + info->Power=M253Power; + info->Close=M253Close; + MapIRQHook=M253IRQ; + GameStateRestore=StateRestore; + + CHRRAMSIZE=4096; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10,CHRRAM,CHRRAMSIZE,1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/3d-block.c b/fceumm/src-fceumm/boards/3d-block.c new file mode 100644 index 0000000..8d52cf4 --- /dev/null +++ b/fceumm/src-fceumm/boards/3d-block.c @@ -0,0 +1,110 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg[4], IRQa; +static int16 IRQCount, IRQPause; + +static int16 Count = 0x0000; + +static SFORMAT StateRegs[]= +{ + {reg, 4, "REGS"}, + {&IRQa, 1, "IRQA"}, + {&IRQCount, 2, "IRQC"}, + {0} +}; + +static void Sync(void) +{ + setprg32(0x8000,0); + setchr8(0); +} + +/*#define Count 0x1800*/ +#define Pause 0x010 + +static DECLFW(UNL3DBlockWrite) +{ + switch(A) + { +/*4800 32*/ +/*4900 37*/ +/*4a00 01*/ +/*4e00 18*/ + case 0x4800: reg[0]=V; break; + case 0x4900: reg[1]=V; break; + case 0x4a00: reg[2]=V; break; + case 0x4e00: reg[3]=V; IRQCount=Count; IRQPause=Pause; IRQa=1; X6502_IRQEnd(FCEU_IQEXT); break; + } +} + +static void UNL3DBlockPower(void) +{ + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4800,0x4E00,UNL3DBlockWrite); +} + +static void UNL3DBlockReset(void) +{ + Count+=0x10; + FCEU_printf("Count=%04x\n",Count); +} + +static void UNL3DBlockIRQHook(int a) +{ + if(IRQa) + { + if(IRQCount>0) + { + IRQCount-=a; + } + else + { + if(IRQPause>0) + { + IRQPause-=a; + X6502_IRQBegin(FCEU_IQEXT); + } + else + { + IRQCount=Count; + IRQPause=Pause; + X6502_IRQEnd(FCEU_IQEXT); + } + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNL3DBlock_Init(CartInfo *info) +{ + info->Power=UNL3DBlockPower; + info->Reset=UNL3DBlockReset; + MapIRQHook=UNL3DBlockIRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/411120-c.c b/fceumm/src-fceumm/boards/411120-c.c new file mode 100644 index 0000000..decb8a6 --- /dev/null +++ b/fceumm/src-fceumm/boards/411120-c.c @@ -0,0 +1,70 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2008 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* actually cart ID is 811120-C, sorry ;) K-3094 - another ID*/ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 reset_flag = 0; + +static void BMC411120CCW(uint32 A, uint8 V) +{ + setchr1(A,V|((EXPREGS[0]&3)<<7)); +} + +static void BMC411120CPW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&(8|reset_flag)) + setprg32(0x8000,((EXPREGS[0]>>4)&3)|(0x0C)); + else + setprg8(A,(V&0x0F)|((EXPREGS[0]&3)<<4)); +} + +static DECLFW(BMC411120CLoWrite) +{ + EXPREGS[0] = A; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void BMC411120CReset(void) +{ + EXPREGS[0]=0; + reset_flag ^=4; + MMC3RegReset(); +} + +static void BMC411120CPower(void) +{ + EXPREGS[0] = 0; + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,BMC411120CLoWrite); +} + +void BMC411120C_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 128, 8, 0); + pwrap=BMC411120CPW; + cwrap=BMC411120CCW; + info->Power=BMC411120CPower; + info->Reset=BMC411120CReset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} diff --git a/fceumm/src-fceumm/boards/43.c b/fceumm/src-fceumm/boards/43.c new file mode 100644 index 0000000..9739ac4 --- /dev/null +++ b/fceumm/src-fceumm/boards/43.c @@ -0,0 +1,94 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg; +static uint32 IRQCount, IRQa; + +static SFORMAT StateRegs[]= +{ + {&IRQCount, 4, "IRQC"}, + {&IRQa, 1, "IRQA"}, + {®, 1, "REG"}, + {0} +}; + +static void Sync(void) +{ + setprg4(0x5000,16); + setprg8(0x6000,2); + setprg8(0x8000,1); + setprg8(0xa000,0); + setprg8(0xc000,reg); + setprg8(0xe000,9); + setchr8(0); +} + +static DECLFW(M43Write) +{ + int transo[8]={4,3,4,4,4,7,5,6}; + switch(A&0xf1ff) + { + case 0x4022: reg=transo[V&7]; Sync(); break; + case 0x8122: IRQa=V&1; X6502_IRQEnd(FCEU_IQEXT); IRQCount=0; break; + } +} + +static void M43Power(void) +{ + reg=0; + Sync(); + /* SetReadHandler(0x5000,0x5fff,CartBR);*/ + SetReadHandler(0x5000,0xffff,CartBR); + SetWriteHandler(0x4020,0xffff,M43Write); +} + +static void M43Reset(void) +{ +} + +static void M43IRQHook(int a) +{ + IRQCount+=a; + if(IRQa) + if(IRQCount>=4096) + { + IRQa=0; + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper43_Init(CartInfo *info) +{ + info->Reset=M43Reset; + info->Power=M43Power; + MapIRQHook=M43IRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/57.c b/fceumm/src-fceumm/boards/57.c new file mode 100644 index 0000000..09f526b --- /dev/null +++ b/fceumm/src-fceumm/boards/57.c @@ -0,0 +1,92 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "mapinc.h" + +static uint8 prg_reg; +static uint8 chr_reg; +static uint8 hrd_flag; + +static SFORMAT StateRegs[]= +{ + {&hrd_flag, 1, "DIPSW"}, + {&prg_reg, 1, "PRG"}, + {&chr_reg, 1, "CHR"}, + {0} +}; + +static void Sync(void) +{ + if(prg_reg&0x80) + setprg32(0x8000,prg_reg>>6); + else + { + setprg16(0x8000,(prg_reg>>5)&3); + setprg16(0xC000,(prg_reg>>5)&3); + } + setmirror((prg_reg&8)>>3); + setchr8((chr_reg&3)|(prg_reg&7)|((prg_reg&0x10)>>1)); +} + +static DECLFR(M57Read) +{ + return hrd_flag; +} + +static DECLFW(M57Write) +{ + if((A&0x8800)==0x8800) + prg_reg=V; + else + chr_reg=V; + Sync(); +} + +static void M57Power(void) +{ + prg_reg=0; + chr_reg=0; + hrd_flag=0; + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M57Write); + SetReadHandler(0x6000,0x6000,M57Read); + Sync(); +} + +static void M57Reset() +{ + hrd_flag++; + hrd_flag&=3; + FCEU_printf("Select Register = %02x\n",hrd_flag); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper57_Init(CartInfo *info) +{ + info->Power=M57Power; + info->Reset=M57Reset; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/603-5052.c b/fceumm/src-fceumm/boards/603-5052.c new file mode 100644 index 0000000..439c026 --- /dev/null +++ b/fceumm/src-fceumm/boards/603-5052.c @@ -0,0 +1,53 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * SL12 Protected 3-in-1 mapper hardware (VRC2, MMC3, MMC1) + * the same as 603-5052 board (TODO: add reading registers, merge) + * + * Contra Fighter prot board + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 lut[4] = { 0x00, 0x02, 0x02, 0x03 }; + +static DECLFW(UNL6035052ProtWrite) +{ + EXPREGS[0]=lut[V&3]; +} + +static DECLFR(UNL6035052ProtRead) +{ + return EXPREGS[0]; +} + +static void UNL6035052Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x4020,0x7FFF,UNL6035052ProtWrite); + SetReadHandler(0x4020,0x7FFF,UNL6035052ProtRead); +} + +void UNL6035052_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 256, 0, 0); + info->Power=UNL6035052Power; + AddExState(EXPREGS, 6, 0, "EXPR"); +} diff --git a/fceumm/src-fceumm/boards/68.c b/fceumm/src-fceumm/boards/68.c new file mode 100644 index 0000000..dbebd50 --- /dev/null +++ b/fceumm/src-fceumm/boards/68.c @@ -0,0 +1,179 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 chr_reg[4]; +static uint8 kogame, prg_reg, nt1, nt2, mirr; + +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE, count; + +static SFORMAT StateRegs[]= +{ + {&nt1, 1, "NT1"}, + {&nt2, 1, "NT2"}, + {&mirr, 1, "MIRR"}, + {&prg_reg, 1, "PRG"}, + {&kogame, 1, "KOGAME"}, + {&count, 4, "COUNT"}, + {chr_reg, 4, "CHR"}, + {0} +}; + +static void M68NTfix(void) +{ + if((!UNIFchrrama)&&(mirr&0x10)) + { + PPUNTARAM = 0; + switch(mirr&3) + { + case 0: vnapage[0]=vnapage[2]=CHRptr[0]+(((nt1|128)&CHRmask1[0])<<10); + vnapage[1]=vnapage[3]=CHRptr[0]+(((nt2|128)&CHRmask1[0])<<10); + break; + case 1: vnapage[0]=vnapage[1]=CHRptr[0]+(((nt1|128)&CHRmask1[0])<<10); + vnapage[2]=vnapage[3]=CHRptr[0]+(((nt2|128)&CHRmask1[0])<<10); + break; + case 2: vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=CHRptr[0]+(((nt1|128)&CHRmask1[0])<<10); + break; + case 3: vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=CHRptr[0]+(((nt2|128)&CHRmask1[0])<<10); + break; + } + } + else + switch(mirr&3) + { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static void Sync(void) +{ + setchr2(0x0000,chr_reg[0]); + setchr2(0x0800,chr_reg[1]); + setchr2(0x1000,chr_reg[2]); + setchr2(0x1800,chr_reg[3]); + setprg8r(0x10,0x6000,0); + setprg16r((PRGptr[1])?kogame:0,0x8000,prg_reg); + setprg16(0xC000,~0); +} + +static DECLFR(M68Read) +{ + if(!(kogame&8)) + { + count++; + if(count==1784) + setprg16r(0,0x8000,prg_reg); + } + return CartBR(A); +} + +static DECLFW(M68WriteLo) +{ + if(!V) + { + count = 0; + setprg16r((PRGptr[1])?kogame:0,0x8000,prg_reg); + } + CartBW(A,V); +} + +static DECLFW(M68WriteCHR) +{ + chr_reg[(A>>12)&3]=V; + Sync(); +} + +static DECLFW(M68WriteNT1) +{ + nt1 = V; + M68NTfix(); +} + +static DECLFW(M68WriteNT2) +{ + nt2 = V; + M68NTfix(); +} + +static DECLFW(M68WriteMIR) +{ + mirr = V; + M68NTfix(); +} + +static DECLFW(M68WriteROM) +{ + prg_reg = V&7; + kogame = ((V>>3)&1)^1; + Sync(); +} + +static void M68Power(void) +{ + prg_reg = 0; + kogame = 0; + Sync(); + M68NTfix(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xBFFF,M68Read); + SetReadHandler(0xC000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xBFFF,M68WriteCHR); + SetWriteHandler(0xC000,0xCFFF,M68WriteNT1); + SetWriteHandler(0xD000,0xDFFF,M68WriteNT2); + SetWriteHandler(0xE000,0xEFFF,M68WriteMIR); + SetWriteHandler(0xF000,0xFFFF,M68WriteROM); + SetWriteHandler(0x6000,0x6000,M68WriteLo); + SetWriteHandler(0x6001,0x7FFF,CartBW); +} + +static void M68Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); + M68NTfix(); +} + +void Mapper68_Init(CartInfo *info) +{ + info->Power=M68Power; + info->Close=M68Close; + GameStateRestore=StateRestore; + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/8157.c b/fceumm/src-fceumm/boards/8157.c new file mode 100644 index 0000000..c5f4143 --- /dev/null +++ b/fceumm/src-fceumm/boards/8157.c @@ -0,0 +1,81 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint16 cmdreg; +static uint8 invalid_data; +static SFORMAT StateRegs[]= +{ + {&invalid_data, 1, "INVD"}, + {&cmdreg, 2, "CMDREG"}, + {0} +}; + +static void Sync(void) +{ + setprg16r((cmdreg&0x060)>>5,0x8000,(cmdreg&0x01C)>>2); + setprg16r((cmdreg&0x060)>>5,0xC000,(cmdreg&0x200)?(~0):0); + setmirror(((cmdreg&2)>>1)^1); +} + +static DECLFR(UNL8157Read) +{ + if(invalid_data&&cmdreg&0x100) + return 0xFF; + else + return CartBR(A); +} + +static DECLFW(UNL8157Write) +{ + cmdreg=A; + Sync(); +} + +static void UNL8157Power(void) +{ + setchr8(0); + SetWriteHandler(0x8000,0xFFFF,UNL8157Write); + SetReadHandler(0x8000,0xFFFF,UNL8157Read); + cmdreg=0x200; + invalid_data=1; + Sync(); +} + +static void UNL8157Reset(void) +{ + cmdreg=0; + invalid_data^=1; + Sync(); +} + +static void UNL8157Restore(int version) +{ + Sync(); +} + +void UNL8157_Init(CartInfo *info) +{ + info->Power=UNL8157Power; + info->Reset=UNL8157Reset; + GameStateRestore=UNL8157Restore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/8237.c b/fceumm/src-fceumm/boards/8237.c new file mode 100644 index 0000000..a1176a7 --- /dev/null +++ b/fceumm/src-fceumm/boards/8237.c @@ -0,0 +1,206 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Super Game (Sugar Softec) protected mapper + * Pocahontas 2 (Unl) [U][!], etc. + * TODO: 9in1 LION KING HANGS! + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 cmdin; + +static uint8 regperm[8][8] = + { + {0, 1, 2, 3, 4, 5, 6, 7}, + {0, 2, 6, 1, 7, 3, 4, 5}, + {0, 5, 4, 1, 7, 2, 6, 3}, /* unused*/ + {0, 6, 3, 7, 5, 2, 4, 1}, + {0, 2, 5, 3, 6, 1, 7, 4}, + {0, 1, 2, 3, 4, 5, 6, 7}, /* empty*/ + {0, 1, 2, 3, 4, 5, 6, 7}, /* empty*/ + {0, 1, 2, 3, 4, 5, 6, 7}, /* empty*/ + }; + +static uint8 adrperm[8][8] = + { + {0, 1, 2, 3, 4, 5, 6, 7}, + {3, 2, 0, 4, 1, 5, 6, 7}, + {0, 1, 2, 3, 4, 5, 6, 7}, /* unused*/ + {5, 0, 1, 2, 3, 7, 6, 4}, + {3, 1, 0, 5, 2, 4, 6, 7}, + {0, 1, 2, 3, 4, 5, 6, 7}, /* empty*/ + {0, 1, 2, 3, 4, 5, 6, 7}, /* empty*/ + {0, 1, 2, 3, 4, 5, 6, 7}, /* empty*/ + }; + +static void UNL8237CW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + setchr1(A,((EXPREGS[1]&0xc)<<6)|(V&0x7F)|((EXPREGS[1]&0x20)<<2)); + else + setchr1(A,((EXPREGS[1]&0xc)<<6)|V); +} + +static void UNL8237PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + { + uint8 sbank = (EXPREGS[1]&0x10); + if(EXPREGS[0]&0x80) + { + uint8 bank = ((EXPREGS[1]&3)<<4)|(EXPREGS[0]&0x7)|(sbank>>1); + if(EXPREGS[0]&0x20) + setprg32(0x8000,bank>>1); + else + { + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else + setprg8(A,((EXPREGS[1]&3)<<5)|(V&0x0F)|sbank); + } + else + { + if(EXPREGS[0]&0x80) + { + uint8 bank = ((EXPREGS[1]&3)<<4)|(EXPREGS[0]&0xF); + if(EXPREGS[0]&0x20) + setprg32(0x8000,bank>>1); + else + { + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else + setprg8(A,((EXPREGS[1]&3)<<5)|(V&0x1F)); + } +} + +static void UNL8237ACW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + setchr1(A,((EXPREGS[1]&0xE)<<7)|(V&0x7F)|((EXPREGS[1]&0x20)<<2)); + else + setchr1(A,((EXPREGS[1]&0xE)<<7)|V); +} + +static void UNL8237APW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + { + uint8 sbank = (EXPREGS[1]&0x10); + if(EXPREGS[0]&0x80) + { + uint8 bank = ((EXPREGS[1]&3)<<4)|((EXPREGS[1]&8)<<3)|(EXPREGS[0]&0x7)|(sbank>>1); + if(EXPREGS[0]&0x20) { + /* FCEU_printf("8000:%02X\n",bank>>1);*/ + setprg32(0x8000,bank>>1); + } + else + { + /* FCEU_printf("8000-C000:%02X\n",bank);*/ + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else { + /* FCEU_printf("%04x:%02X\n",A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x0F)|sbank);*/ + setprg8(A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x0F)|sbank); + } + } + else + { + if(EXPREGS[0]&0x80) + { + uint8 bank = ((EXPREGS[1]&3)<<4)|((EXPREGS[1]&8)<<3)|(EXPREGS[0]&0xF); + if(EXPREGS[0]&0x20) { + /* FCEU_printf("8000:%02X\n",(bank>>1)&0x07);*/ + setprg32(0x8000,bank>>1); + } + else + { + /* FCEU_printf("8000-C000:%02X\n",bank&0x0F);*/ + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else { + /* FCEU_printf("%04X:%02X\n",A,(((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x1F))&0x1F);*/ + setprg8(A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x1F)); + } + } +} + +static DECLFW(UNL8237Write) +{ + uint8 dat = V; + uint8 adr = adrperm[EXPREGS[2]][((A>>12)&6)|(A&1)]; + uint16 addr = (adr & 1)|((adr & 6)<<12)|0x8000; + if(adr < 4) + { + if(!adr) + dat = (dat & 0xC0)|(regperm[EXPREGS[2]][dat & 7]); + MMC3_CMDWrite(addr,dat); + } + else + MMC3_IRQWrite(addr,dat); +} + +static DECLFW(UNL8237ExWrite) +{ + switch(A) + { + case 0x5000: EXPREGS[0]=V; FixMMC3PRG(MMC3_cmd); break; + case 0x5001: EXPREGS[1]=V; FixMMC3PRG(MMC3_cmd); FixMMC3CHR(MMC3_cmd); break; + case 0x5007: EXPREGS[2]=V; break; + } +} + +static void UNL8237Power(void) +{ + EXPREGS[0]=EXPREGS[2]=0; + EXPREGS[1]=3; + GenMMC3Power(); + SetWriteHandler(0x8000,0xFFFF,UNL8237Write); + SetWriteHandler(0x5000,0x7FFF,UNL8237ExWrite); +} + +void UNL8237_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + cwrap=UNL8237CW; + pwrap=UNL8237PW; + info->Power=UNL8237Power; + AddExState(EXPREGS, 3, 0, "EXPR"); + AddExState(&cmdin, 1, 0, "CMDIN"); +} + +void UNL8237A_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + cwrap=UNL8237ACW; + pwrap=UNL8237APW; + info->Power=UNL8237Power; + AddExState(EXPREGS, 3, 0, "EXPR"); + AddExState(&cmdin, 1, 0, "CMDIN"); +} diff --git a/fceumm/src-fceumm/boards/830118C.c b/fceumm/src-fceumm/boards/830118C.c new file mode 100644 index 0000000..f9f7e0f --- /dev/null +++ b/fceumm/src-fceumm/boards/830118C.c @@ -0,0 +1,80 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2008 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* M-022 MMC3 based 830118C T-106 4M + 4M*/ + +#include "mapinc.h" +#include "mmc3.h" + +static void BMC830118CCW(uint32 A, uint8 V) +{ + setchr1(A,(V&0x7F)|((EXPREGS[0]&0x0c)<<5)); +} + +static void BMC830118CPW(uint32 A, uint8 V) +{ + if((EXPREGS[0]&0x0C)==0x0C) + { + if(A==0x8000) + { + setprg8(A,(V&0x0F)|((EXPREGS[0]&0x0c)<<2)); + setprg8(0xC000,(V&0x0F)|0x32); + } + else if(A==0xA000) + { + setprg8(A,(V&0x0F)|((EXPREGS[0]&0x0c)<<2)); + setprg8(0xE000,(V&0x0F)|0x32); + } + } + else + { + setprg8(A,(V&0x0F)|((EXPREGS[0]&0x0c)<<2)); + } +} + +static DECLFW(BMC830118CLoWrite) +{ + EXPREGS[0] = V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void BMC830118CReset(void) +{ + EXPREGS[0]=0; + MMC3RegReset(); +} + +static void BMC830118CPower(void) +{ + EXPREGS[0] = 0; + GenMMC3Power(); + SetWriteHandler(0x6800,0x68FF,BMC830118CLoWrite); +} + +void BMC830118C_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 128, 8, 0); + pwrap=BMC830118CPW; + cwrap=BMC830118CCW; + info->Power=BMC830118CPower; + info->Reset=BMC830118CReset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} diff --git a/fceumm/src-fceumm/boards/88.c b/fceumm/src-fceumm/boards/88.c new file mode 100644 index 0000000..03fbf5b --- /dev/null +++ b/fceumm/src-fceumm/boards/88.c @@ -0,0 +1,87 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg[8]; +static uint8 mirror, cmd, is154; + +static SFORMAT StateRegs[]= +{ + {&cmd, 1, "CMD"}, + {&mirror, 1, "MIRR"}, + {reg, 8, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setchr2(0x0000,reg[0]>>1); + setchr2(0x0800,reg[1]>>1); + setchr1(0x1000,reg[2]|0x40); + setchr1(0x1400,reg[3]|0x40); + setchr1(0x1800,reg[4]|0x40); + setchr1(0x1C00,reg[5]|0x40); + setprg8(0x8000,reg[6]); + setprg8(0xA000,reg[7]); +} + +static void MSync(void) +{ + if(is154)setmirror(MI_0+(mirror&1)); +} + +static DECLFW(M88Write) +{ + switch(A&0x8001) + { + case 0x8000: cmd=V&7; mirror=V>>6; MSync(); break; + case 0x8001: reg[cmd]=V; Sync(); break; + } +} + +static void M88Power(void) +{ + setprg16(0xC000,~0); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M88Write); +} + +static void StateRestore(int version) +{ + Sync(); + MSync(); +} + +void Mapper88_Init(CartInfo *info) +{ + is154=0; + info->Power=M88Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper154_Init(CartInfo *info) +{ + is154=1; + info->Power=M88Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/90.c b/fceumm/src-fceumm/boards/90.c new file mode 100644 index 0000000..650353c --- /dev/null +++ b/fceumm/src-fceumm/boards/90.c @@ -0,0 +1,509 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" +/*#define DEBUG90*/ + +/* Mapper 090 is simpliest mapper hardware and have not extended nametable control and latched chr banks in 4k mode*/ +/* Mapper 209 much compicated hardware with decribed above features disabled by default and switchable by command*/ +/* Mapper 211 the same mapper 209 but with forced nametable control*/ + +static int is209; +static int is211; + +static uint8 IRQMode; /* from $c001*/ +static uint8 IRQPre; /* from $c004*/ +static uint8 IRQPreSize; /* from $c007*/ +static uint8 IRQCount; /* from $c005*/ +static uint8 IRQXOR; /* Loaded from $C006*/ +static uint8 IRQa; /* $c002, $c003, and $c000*/ + +static uint8 mul[2]; +static uint8 regie; + +static uint8 tkcom[4]; +static uint8 prgb[4]; +static uint8 chrlow[8]; +static uint8 chrhigh[8]; + +static uint8 chr[2]; + +static uint16 names[4]; +static uint8 tekker; + +static SFORMAT Tek_StateRegs[]={ + {&IRQMode, 1, "IRQMODE"}, + {&IRQPre, 1, "IRQPRE"}, + {&IRQPreSize, 1, "IRQPRESIZE"}, + {&IRQCount, 1, "IRQC"}, + {&IRQXOR, 1, "IRQXOR"}, + {&IRQa, 1, "IRQa"}, + {mul, 2, "MUL"}, + {®ie, 1, "REGI"}, + {tkcom, 4, "TKCO"}, + {prgb, 4, "PRGB"}, + {chr, 2, "CHRLATCH"}, + {chrlow, 4, "CHRL"}, + {chrhigh, 8, "CHRH"}, + {&names[0], 2|FCEUSTATE_RLSB, "NMS0"}, + {&names[1], 2|FCEUSTATE_RLSB, "NMS1"}, + {&names[2], 2|FCEUSTATE_RLSB, "NMS2"}, + {&names[3], 2|FCEUSTATE_RLSB, "NMS3"}, + {&tekker, 1, "TEKR"}, + {0} +}; + +static void mira(void) +{ + if((tkcom[0]&0x20&&is209)||is211) + { + int x; + if(tkcom[0]&0x40) /* Name tables are ROM-only*/ + { + for(x=0;x<4;x++) + setntamem(CHRptr[0]+(((names[x])&CHRmask1[0])<<10),0,x); + } + else /* Name tables can be RAM or ROM.*/ + { + for(x=0;x<4;x++) + { + if((tkcom[1]&0x80)==(names[x]&0x80)) /* RAM selected.*/ + setntamem(NTARAM+((names[x]&0x1)<<10),1,x); + else + setntamem(CHRptr[0]+(((names[x])&CHRmask1[0])<<10),0,x); + } + } + } + else + { + switch(tkcom[1]&3) + { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } + } +} + +static void tekprom(void) /* TODO: verify for single, small multi and large multi*/ +{ + uint32 bankmode=((tkcom[3]&6)<<5); + switch(tkcom[0]&7) + { + case 00: if(tkcom[0]&0x80) + setprg8(0x6000,(((prgb[3]<<2)+3)&0x3F)|bankmode); + setprg32(0x8000,(prgb[3]&7)|((tkcom[3]&7)<<3)); + break; + case 01: if(tkcom[0]&0x80) + setprg8(0x6000,(((prgb[3]<<1)+1)&0x3F)|bankmode); + setprg16(0x8000,(prgb[1]&0x0F)|((tkcom[3]&7)<<4)); + setprg16(0xC000,0x0F|((tkcom[3]&7)<<4)); + break; + case 03: /* bit reversion*/ + case 02: + if(tkcom[0]&0x80) + setprg8(0x6000,(prgb[3]&0x1F)|((tkcom[3]&7)<<5)); /* 45in1 multy has different bits, seems board was hacked to support big data banks*/ + setprg8(0x8000,(prgb[0]&0x1F)|((tkcom[3]&7)<<5)); + setprg8(0xa000,(prgb[1]&0x1F)|((tkcom[3]&7)<<5)); + setprg8(0xc000,(prgb[2]&0x1F)|((tkcom[3]&7)<<5)); + setprg8(0xe000,0x1F|((tkcom[3]&7)<<5)); +/* setprg8(0xe000,(prgb[3]&0x0F)|((tkcom[3]&6)<<3));*/ +/* setprg32(0x8000,((prgb[0]&0x0F)>>2)|((tkcom[3]&6)<<3));*/ + break; + case 04: if(tkcom[0]&0x80) + setprg8(0x6000,(((prgb[3]<<2)+3)&0x3F)|bankmode); + setprg32(0x8000,(prgb[3]&0x0F)|((tkcom[3]&6)<<3)); + break; + case 05: if(tkcom[0]&0x80) + setprg8(0x6000,(((prgb[3]<<1)+1)&0x3F)|bankmode); + setprg16(0x8000,(prgb[1]&0x1F)|((tkcom[3]&6)<<4)); + setprg16(0xC000,(prgb[3]&0x1F)|((tkcom[3]&6)<<4)); + break; + case 07: /* bit reversion*/ + case 06: if(tkcom[0]&0x80) + setprg8(0x6000,(prgb[3]&0x3F)|bankmode); + setprg8(0x8000,(prgb[0]&0x3F)|bankmode); + setprg8(0xa000,(prgb[1]&0x3F)|bankmode); + setprg8(0xc000,(prgb[2]&0x3F)|bankmode); + setprg8(0xe000,(prgb[3]&0x3F)|bankmode); + break; + } +} + +static void tekvrom(void) +{ + int x, bank=0, mask=0xFFFF; + if(!(tkcom[3]&0x20)) + { + bank=(tkcom[3]&1)|((tkcom[3]&0x18)>>2); + switch (tkcom[0]&0x18) + { + case 0x00: bank<<=5; mask=0x1F; break; + case 0x08: bank<<=6; mask=0x3F; break; + case 0x10: bank<<=7; mask=0x7F; break; + case 0x18: bank<<=8; mask=0xFF; break; + } + } + switch(tkcom[0]&0x18) + { + case 0x00: /* 8KB*/ + setchr8(((chrlow[0]|(chrhigh[0]<<8))&mask)|bank); + break; + case 0x08: /* 4KB*/ +/* for(x=0;x<8;x+=4)*/ +/* setchr4(x<<10,((chrlow[x]|(chrhigh[x]<<8))&mask)|bank);*/ + setchr4(0x0000,((chrlow[chr[0]]|(chrhigh[chr[0]]<<8))&mask)|bank); + setchr4(0x1000,((chrlow[chr[1]]|(chrhigh[chr[1]]<<8))&mask)|bank); + break; + case 0x10: /* 2KB*/ + for(x=0;x<8;x+=2) + setchr2(x<<10,((chrlow[x]|(chrhigh[x]<<8))&mask)|bank); + break; + case 0x18: /* 1KB*/ + for(x=0;x<8;x++) + setchr1(x<<10,((chrlow[x]|(chrhigh[x]<<8))&mask)|bank); + break; + } +} + +static DECLFW(M90TekWrite) +{ + switch(A&0x5C03) + { + case 0x5800: mul[0]=V; break; + case 0x5801: mul[1]=V; break; + case 0x5803: regie=V; break; + } +} + +static DECLFR(M90TekRead) +{ + switch(A&0x5C03) + { + case 0x5800: return (mul[0]*mul[1]); + case 0x5801: return((mul[0]*mul[1])>>8); + case 0x5803: return (regie); + default: return tekker; + } + return(0xff); +} + +static DECLFW(M90PRGWrite) +{ +/* FCEU_printf("bs %04x %02x\n",A,V);*/ + prgb[A&3]=V; + tekprom(); +} + +static DECLFW(M90CHRlowWrite) +{ +/* FCEU_printf("bs %04x %02x\n",A,V);*/ + chrlow[A&7]=V; + tekvrom(); +} + +static DECLFW(M90CHRhiWrite) +{ +/* FCEU_printf("bs %04x %02x\n",A,V);*/ + chrhigh[A&7]=V; + tekvrom(); +} + +static DECLFW(M90NTWrite) +{ +/* FCEU_printf("bs %04x %02x\n",A,V);*/ + if(A&4) + { + names[A&3]&=0x00FF; + names[A&3]|=V<<8; + } + else + { + names[A&3]&=0xFF00; + names[A&3]|=V; + } + mira(); +} + +static DECLFW(M90IRQWrite) +{ +/* FCEU_printf("bs %04x %02x\n",A,V);*/ + switch(A&7) + { + case 00: /*FCEU_printf("%s IRQ (C000)\n",V&1?"Enable":"Disable");*/ + IRQa=V&1;if(!(V&1)) X6502_IRQEnd(FCEU_IQEXT);break; + case 02: /*FCEU_printf("Disable IRQ (C002) scanline=%d\n", scanline);*/ + IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break; + case 03: /*FCEU_printf("Enable IRQ (C003) scanline=%d\n", scanline);*/ + IRQa=1;break; + case 01: IRQMode=V; + /*FCEU_printf("IRQ Count method: "); + switch (IRQMode&3) + { + case 00: FCEU_printf("M2 cycles\n");break; + case 01: FCEU_printf("PPU A12 toggles\n");break; + case 02: FCEU_printf("PPU reads\n");break; + case 03: FCEU_printf("Writes to CPU space\n");break; + } + FCEU_printf("Counter prescaler size: %s\n",(IRQMode&4)?"3 bits":"8 bits"); + FCEU_printf("Counter prescaler size adjust: %s\n",(IRQMode&8)?"Used C007":"Normal Operation"); + if((IRQMode>>6)==2) FCEU_printf("Counter Down\n"); + else if((IRQMode>>6)==1) FCEU_printf("Counter Up\n"); + else FCEU_printf("Counter Stopped\n");*/ + break; + case 04: /*FCEU_printf("Pre Counter Loaded and Xored wiht C006: %d\n",V^IRQXOR);*/ + IRQPre=V^IRQXOR;break; + case 05: /*FCEU_printf("Main Counter Loaded and Xored wiht C006: %d\n",V^IRQXOR);*/ + IRQCount=V^IRQXOR;break; + case 06: /*FCEU_printf("Xor Value: %d\n",V);*/ + IRQXOR=V;break; + case 07: /*if(!(IRQMode&8)) FCEU_printf("C001 is clear, no effect applied\n");*/ + /* else if(V==0xFF) FCEU_printf("Prescaler is changed for 12bits\n");*/ + /* else FCEU_printf("Counter Stopped\n");*/ + IRQPreSize=V;break; + } +} + +static DECLFW(M90ModeWrite) +{ +/* FCEU_printf("bs %04x %02x\n",A,V);*/ + tkcom[A&3]=V; + tekprom(); + tekvrom(); + mira(); + +#ifdef DEBUG90 + switch (A&3) + { + case 00: FCEU_printf("Main Control Register:\n"); + FCEU_printf(" PGR Banking mode: %d\n",V&7); + FCEU_printf(" CHR Banking mode: %d\n",(V>>3)&3); + FCEU_printf(" 6000-7FFF addresses mapping: %s\n",(V&0x80)?"Yes":"No"); + FCEU_printf(" Nametable control: %s\n",(V&0x20)?"Enabled":"Disabled"); + if(V&0x20) + FCEU_printf(" Nametable can be: %s\n",(V&0x40)?"ROM Only":"RAM or ROM"); + break; + case 01: FCEU_printf("Mirroring mode: "); + switch (V&3) + { + case 0: FCEU_printf("Vertical\n");break; + case 1: FCEU_printf("Horizontal\n");break; + case 2: FCEU_printf("Nametable 0 only\n");break; + case 3: FCEU_printf("Nametable 1 only\n");break; + } + FCEU_printf("Mirroring flag: %s\n",(V&0x80)?"On":"Off"); + break; + case 02: if((((tkcom[0])>>5)&3)==1) + FCEU_printf("Nametable ROM/RAM select mode: %d\n",V>>7); + break; + case 03: + FCEU_printf("CHR Banking mode: %s\n",(V&0x20)?"Entire CHR ROM":"256Kb Switching mode"); + if(!(V&0x20)) FCEU_printf("256K CHR bank number: %02x\n",(V&1)|((V&0x18)>>2)); + FCEU_printf("512K PRG bank number: %d\n",(V&6)>>1); + FCEU_printf("CHR Bank mirroring: %s\n",(V&0x80)?"Swapped":"Normal operate"); + } +#endif +} + +static DECLFW(M90DummyWrite) +{ +/* FCEU_printf("bs %04x %02x\n",A,V);*/ +} + +static void CCL(void) +{ + if((IRQMode>>6) == 1) /* Count Up*/ + { + IRQCount++; + if((IRQCount == 0) && IRQa) + { + X6502_IRQBegin(FCEU_IQEXT); + } + } + else if((IRQMode>>6) == 2) /* Count down*/ + { + IRQCount--; + if((IRQCount == 0xFF) && IRQa) + { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void ClockCounter(void) +{ + uint8 premask; + + if(IRQMode & 0x4) + premask = 0x7; + else + premask = 0xFF; + if((IRQMode>>6) == 1) /* Count up*/ + { + IRQPre++; + if((IRQPre & premask) == 0) CCL(); + } + else if((IRQMode>>6) == 2) /* Count down*/ + { + IRQPre--; + if((IRQPre & premask) == premask) CCL(); + } +} + +void CPUWrap(int a) +{ + int x; + if((IRQMode&3)==0) for(x=0;x>8; + if(h<0x20&&((h&0x0F)==0xF)) + { + l=A&0xF0; + if(l==0xD0) + { + chr[(h&0x10)>>4]=((h&0x10)>>2); + tekvrom(); + } + else if(l==0xE0) + { + chr[(h&0x10)>>4]=((h&0x10)>>2)|2; + tekvrom(); + } + } + } + else + { + chr[0]=0; + chr[1]=4; + } +} + +static void togglie() +{ + tekker+=0x40; + tekker&=0xC0; + FCEU_printf("tekker=%02x\n",tekker); + memset(tkcom,0x00,sizeof(tkcom)); + memset(prgb,0xff,sizeof(prgb)); + tekprom(); + tekvrom(); +} + +static void M90Restore(int version) +{ + tekprom(); + tekvrom(); + mira(); +} + +static void M90Power(void) +{ + SetWriteHandler(0x5000,0x5fff,M90TekWrite); + SetWriteHandler(0x8000,0x8ff0,M90PRGWrite); + SetWriteHandler(0x9000,0x9fff,M90CHRlowWrite); + SetWriteHandler(0xA000,0xAfff,M90CHRhiWrite); + SetWriteHandler(0xB000,0xBfff,M90NTWrite); + SetWriteHandler(0xC000,0xCfff,M90IRQWrite); + SetWriteHandler(0xD000,0xD5ff,M90ModeWrite); + SetWriteHandler(0xE000,0xFfff,M90DummyWrite); + + SetReadHandler(0x5000,0x5fff,M90TekRead); + SetReadHandler(0x6000,0xffff,CartBR); + + mul[0]=mul[1]=regie=0xFF; + + memset(tkcom,0x00,sizeof(tkcom)); + memset(prgb,0xff,sizeof(prgb)); + memset(chrlow,0xff,sizeof(chrlow)); + memset(chrhigh,0xff,sizeof(chrhigh)); + memset(names,0x00,sizeof(names)); + + if(is211) + tekker=0xC0; + else + tekker=0x00; + + tekprom(); + tekvrom(); +} + + +void Mapper90_Init(CartInfo *info) +{ + is211=0; + is209=0; + info->Reset=togglie; + info->Power=M90Power; + PPU_hook=M90PPU; + MapIRQHook=CPUWrap; + GameHBIRQHook2=SLWrap; + GameStateRestore=M90Restore; + AddExState(Tek_StateRegs, ~0, 0, 0); +} + +void Mapper209_Init(CartInfo *info) +{ + is211=0; + is209=1; + info->Reset=togglie; + info->Power=M90Power; + PPU_hook=M90PPU; + MapIRQHook=CPUWrap; + GameHBIRQHook2=SLWrap; + GameStateRestore=M90Restore; + AddExState(Tek_StateRegs, ~0, 0, 0); +} + +void Mapper211_Init(CartInfo *info) +{ + is211=1; + info->Reset=togglie; + info->Power=M90Power; + PPU_hook=M90PPU; + MapIRQHook=CPUWrap; + GameHBIRQHook2=SLWrap; + GameStateRestore=M90Restore; + AddExState(Tek_StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/95.c b/fceumm/src-fceumm/boards/95.c new file mode 100644 index 0000000..86fda8e --- /dev/null +++ b/fceumm/src-fceumm/boards/95.c @@ -0,0 +1,124 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 lastA; +static uint8 DRegs[8]; +static uint8 cmd; +static uint8 MirCache[8]; + +static SFORMAT DB_StateRegs[]={ + {DRegs, 8, "DREG"}, + {&cmd, 1, "CMD"}, + {&lastA, 1, "LAST"}, + {0} +}; + +static void toot(void) +{ + int x; + + MirCache[0]=MirCache[1]=(DRegs[0]>>4)&1; + MirCache[2]=MirCache[3]=(DRegs[1]>>4)&1; + + for(x=0;x<4;x++) + MirCache[4+x]=(DRegs[2+x]>>5)&1; + onemir(MirCache[lastA]); +} + +static void Sync() +{ + setchr2(0x0000,DRegs[0]&0x1F); + setchr2(0x0800,DRegs[1]&0x1F); + setchr1(0x1000,DRegs[2]&0x1F); + setchr1(0x1400,DRegs[3]&0x1F); + setchr1(0x1800,DRegs[4]&0x1F); + setchr1(0x1C00,DRegs[5]&0x1F); + setprg8(0x8000,DRegs[6]&0x1F); + setprg8(0xa000,DRegs[7]&0x1F); + toot(); +} + +static DECLFW(Mapper95_write) +{ + switch(A&0xF001) + { + case 0x8000: cmd = V; break; + case 0x8001: + switch(cmd&0x07) + { + case 0: DRegs[0]=(V&0x3F)>>1; break; + case 1: DRegs[1]=(V&0x3F)>>1; break; + case 2: DRegs[2]=V&0x3F; break; + case 3: DRegs[3]=V&0x3F; break; + case 4: DRegs[4]=V&0x3F; break; + case 5: DRegs[5]=V&0x3F; break; + case 6: DRegs[6]=V&0x3F; break; + case 7: DRegs[7]=V&0x3F; break; + } + Sync(); + } +} + +static void dragonbust_ppu(uint32 A) +{ + static int last=-1; + static uint8 z; + + if(A>=0x2000) return; + + A>>=10; + lastA=A; + z=MirCache[A]; + if(z!=last) + { + onemir(z); + last=z; + } +} + +static void DBPower(void) +{ + memset(DRegs,0x3F,8); + DRegs[0]=DRegs[1]=0x1F; + + Sync(); + + setprg8(0xc000,0x3E); + setprg8(0xe000,0x3F); + + SetReadHandler(0x8000,0xffff,CartBR); + SetWriteHandler(0x8000,0xffff,Mapper95_write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper95_Init(CartInfo *info) +{ + info->Power=DBPower; + AddExState(DB_StateRegs, ~0, 0, 0); + PPU_hook=dragonbust_ppu; + GameStateRestore=StateRestore; +} + diff --git a/fceumm/src-fceumm/boards/KS7012.c b/fceumm/src-fceumm/boards/KS7012.c new file mode 100644 index 0000000..45828c4 --- /dev/null +++ b/fceumm/src-fceumm/boards/KS7012.c @@ -0,0 +1,94 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setprg8r(0x10,0x6000,0); + setprg32(0x8000,reg&1); + setchr8(0); +} + +static DECLFW(UNLKS7012Write) +{ + /* FCEU_printf("bs %04x %02x\n",A,V);*/ + switch(A) + { + case 0xE0A0: reg=0; Sync(); break; + case 0xEE36: reg=1; Sync(); break; + } +} + +static void UNLKS7012Power(void) +{ + reg = ~0; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,UNLKS7012Write); +} + +static void UNLKS7012Reset(void) +{ + reg = ~0; + Sync(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +static void UNLKS7012Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +void UNLKS7012_Init(CartInfo *info) +{ + info->Power=UNLKS7012Power; + info->Reset=UNLKS7012Reset; + info->Close=UNLKS7012Close; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/KS7013.c b/fceumm/src-fceumm/boards/KS7013.c new file mode 100644 index 0000000..8476003 --- /dev/null +++ b/fceumm/src-fceumm/boards/KS7013.c @@ -0,0 +1,84 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Just another pirate cart with pirate mapper, instead of original MMC1 + * Kaiser Highway Star + * + */ + +#include "mapinc.h" + +static uint8 reg, mirr; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REGS"}, + {&mirr, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + setprg16(0x8000,reg); + setprg16(0xc000,~0); + setmirror(mirr); + setchr8(0); +} + +static DECLFW(UNLKS7013BLoWrite) +{ + reg = V; + Sync(); +} + +static DECLFW(UNLKS7013BHiWrite) +{ + mirr = (V & 1) ^ 1; + Sync(); +} + +static void UNLKS7013BPower(void) +{ + reg = 0; + mirr = 0; + Sync(); + SetWriteHandler(0x6000,0x7FFF,UNLKS7013BLoWrite); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,UNLKS7013BHiWrite); +} + +static void UNLKS7013BReset(void) +{ + reg = 0; + Sync(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLKS7013B_Init(CartInfo *info) +{ + info->Power=UNLKS7013BPower; + info->Reset=UNLKS7013BReset; + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/KS7017.c b/fceumm/src-fceumm/boards/KS7017.c new file mode 100644 index 0000000..62ee715 --- /dev/null +++ b/fceumm/src-fceumm/boards/KS7017.c @@ -0,0 +1,134 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg, mirr; +static int32 IRQa, IRQCount, IRQLatch; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {&mirr, 1, "MIRR"}, + {®, 1, "REGS"}, + {&IRQa, 4, "IRQA"}, + {&IRQCount, 4, "IRQC"}, + {&IRQLatch, 4, "IRQL"}, + {0} +}; + +static void Sync(void) +{ + setprg16(0x8000,reg); + setprg16(0xC000,2); + setmirror(mirr); +} + +static DECLFW(UNLKS7017Write) +{ +/* FCEU_printf("bs %04x %02x\n",A,V);*/ + if((A & 0xFF00) == 0x4A00) + { + reg = ((A >> 2) & 3)|((A >> 4) & 4); + } + else if ((A & 0xFF00) == 0x5100) + { + Sync(); + } + else if (A == 0x4020) + { + X6502_IRQEnd(FCEU_IQEXT); + IRQCount&=0xFF00; + IRQCount|=V; + } + else if (A == 0x4021) + { + X6502_IRQEnd(FCEU_IQEXT); + IRQCount&=0xFF; + IRQCount|=V<<8; + IRQa = 1; + } + else if (A == 0x4025) + { + mirr = ((V & 8) >> 3) ^ 1; + } +} + +static DECLFR(FDSRead4030) +{ + X6502_IRQEnd(FCEU_IQEXT); + return X.IRQlow&FCEU_IQEXT?1:0; +} + +static void UNL7017IRQ(int a) +{ + if(IRQa) + { + IRQCount-=a; + if(IRQCount<=0) + { + IRQa=0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void UNLKS7017Power(void) +{ + Sync(); + setchr8(0); + setprg8r(0x10,0x6000,0); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetReadHandler(0x4030,0x4030,FDSRead4030); + SetWriteHandler(0x4020,0x5FFF,UNLKS7017Write); +} + +static void UNLKS7017Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLKS7017_Init(CartInfo *info) +{ + info->Power=UNLKS7017Power; + info->Close=UNLKS7017Close; + MapIRQHook=UNL7017IRQ; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/KS7032.c b/fceumm/src-fceumm/boards/KS7032.c new file mode 100644 index 0000000..e7a2e3e --- /dev/null +++ b/fceumm/src-fceumm/boards/KS7032.c @@ -0,0 +1,97 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg[8], cmd, IRQa = 0, isirqused = 0; +static int32 IRQCount; + +static SFORMAT StateRegs[]= +{ + {&cmd, 1, "CMD"}, + {reg, 8, "REGS"}, + {&IRQa, 1, "IRQA"}, + {&IRQCount, 4, "IRQC"}, + {0} +}; + +static void Sync(void) +{ + setprg8(0x6000,reg[4]); + setprg8(0x8000,reg[1]); + setprg8(0xA000,reg[2]); + setprg8(0xC000,reg[3]); + setprg8(0xE000,~0); + setchr8(0); +} + +static DECLFW(UNLKS7032Write) +{ +/* FCEU_printf("bs %04x %02x\n",A,V);*/ + switch(A&0xF000) + { +/* case 0x8FFF: reg[4]=V; Sync(); break;*/ + case 0x8000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x000F)|(V&0x0F); isirqused = 1; break; + case 0x9000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x00F0)|((V&0x0F)<<4); isirqused = 1; break; + case 0xA000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x0F00)|((V&0x0F)<<8); isirqused = 1; break; + case 0xB000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0xF000)|(V<<12); isirqused = 1; break; + case 0xC000: if(isirqused) { X6502_IRQEnd(FCEU_IQEXT); IRQa=1; } break; + case 0xE000: cmd=V&7; break; + case 0xF000: reg[cmd]=V; Sync(); break; + } +} + +static void UNLSMB2JIRQHook(int a) +{ + if(IRQa) + { + IRQCount+=a; + if(IRQCount>=0xFFFF) + { + IRQa=0; + IRQCount=0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void UNLKS7032Power(void) +{ + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4020,0xFFFF,UNLKS7032Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLKS7032_Init(CartInfo *info) +{ + info->Power=UNLKS7032Power; + MapIRQHook=UNLSMB2JIRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/KS7037.c b/fceumm/src-fceumm/boards/KS7037.c new file mode 100644 index 0000000..bf23b4b --- /dev/null +++ b/fceumm/src-fceumm/boards/KS7037.c @@ -0,0 +1,135 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg[8], cmd; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static void(*WSync)(void); + +static SFORMAT StateRegs[]= +{ + {&cmd, 1, "CMD"}, + {reg, 8, "REGS"}, + {0} +}; + +static void SyncKS7037(void) +{ + setprg4r(0x10,0x6000,0); + setprg4(0x7000,15); + setprg8(0x8000,reg[6]); + setprg4(0xA000,~3); + setprg4r(0x10,0xB000,1); + setprg8(0xC000,reg[7]); + setprg8(0xE000,~0); + setchr8(0); + setmirrorw(reg[2]&1,reg[4]&1,reg[3]&1,reg[5]&1); +} + +static void SyncLH10(void) +{ + setprg8(0x6000,~1); + setprg8(0x8000,reg[6]); + setprg8(0xA000,reg[7]); + setprg8r(0x10,0xC000,0); + setprg8(0xE000,~0); + setchr8(0); + setmirror(0); +} + +static DECLFW(UNLKS7037Write) +{ + switch(A & 0xE001) + { + case 0x8000: cmd = V & 7; break; + case 0x8001: reg[cmd] = V; WSync(); break; + } +} + +static void UNLKS7037Power(void) +{ + reg[0]=reg[1]=reg[2]=reg[3]=reg[4]=reg[5]=reg[6]=reg[7]=0; + WSync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetWriteHandler(0x8000,0x9FFF,UNLKS7037Write); + SetWriteHandler(0xA000,0xBFFF,CartBW); + SetWriteHandler(0xC000,0xFFFF,UNLKS7037Write); +} + +static void LH10Power(void) +{ + reg[0]=reg[1]=reg[2]=reg[3]=reg[4]=reg[5]=reg[6]=reg[7]=0; + WSync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xBFFF,UNLKS7037Write); + SetWriteHandler(0xC000,0xDFFF,CartBW); + SetWriteHandler(0xE000,0xFFFF,UNLKS7037Write); +} + +static void Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + WSync(); +} + +void UNLKS7037_Init(CartInfo *info) +{ + info->Power=UNLKS7037Power; + info->Close=Close; + + WSync = SyncKS7037; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void LH10_Init(CartInfo *info) +{ + info->Power=LH10Power; + info->Close=Close; + + WSync = SyncLH10; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/KS7057.c b/fceumm/src-fceumm/boards/KS7057.c new file mode 100644 index 0000000..eab53a9 --- /dev/null +++ b/fceumm/src-fceumm/boards/KS7057.c @@ -0,0 +1,104 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg[16], reset0 = 0, reset1 = 0; +static SFORMAT StateRegs[]= +{ + {reg, 16, "PRG"}, + {0} +}; + +static void Sync(void) +{ + setprg2(0x6000,reg[4]); /* A.0, 9.1, 9.2*/ + setprg2(0x6800,reg[5]); /* 8.0, 9.3*/ + setprg2(0x7000,reg[6]); /* 8.1*/ + setprg2(0x7800,reg[7]); /* 8.2*/ + setprg2(0x8000,reg[0]); /* 8.3*/ + setprg2(0x8800,reg[1]); /* 9.0*/ + setprg2(0x9000,reg[2]); /* C.2, 3.2, 7.3*/ + setprg2(0x9800,reg[3]); /* C.3*/ + setprg2(0xA000,0x34); /* D.0*/ + setprg2(0xA800,0x35); /* D.1*/ + setprg2(0xB000,0x36); /* D.2*/ + setprg2(0xB800,0x37); /* D.3*/ + setprg2(0xC000,0x28); /* WTF?*/ + setprg2(0xC800,0x29); /* A.1*/ + setprg2(0xD000,0x2A); /* A.2*/ + setprg2(0xD800,0x2B); /* A.3*/ + setprg2(0xE000,0x2C); /* B.0*/ + setprg2(0xE800,0x2D); /* B.1*/ + setprg2(0xF000,0x2E); /* B.2*/ + setprg2(0xF800,0x2F); /* B.3*/ + setchr8(0); + setmirror(MI_V); +} + +static DECLFW(UNLKS7057Write) +{ +/* FCEU_printf("%04X:%02X\n",A,V);*/ + switch(A) { + case 0x9000: reg[16] = V; Sync(); break; + case 0xB000: reg[0] = (reg[0] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xB001: reg[0] = (reg[0] & 0x0F) | (V << 4); Sync(); break; + case 0xB002: reg[1] = (reg[1] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xB003: reg[1] = (reg[1] & 0x0F) | (V << 4); Sync(); break; + case 0xC000: reg[2] = (reg[2] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xC001: reg[2] = (reg[2] & 0x0F) | (V << 4); Sync(); break; + case 0xC002: reg[3] = (reg[3] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xC003: reg[3] = (reg[3] & 0x0F) | (V << 4); Sync(); break; + case 0xD000: reg[4] = (reg[4] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xD001: reg[4] = (reg[4] & 0x0F) | (V << 4); Sync(); break; + case 0xD002: reg[5] = (reg[5] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xD003: reg[5] = (reg[5] & 0x0F) | (V << 4); Sync(); break; + case 0xE000: reg[6] = (reg[6] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xE001: reg[6] = (reg[6] & 0x0F) | (V << 4); Sync(); break; + case 0xE002: reg[7] = (reg[7] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xE003: reg[7] = (reg[7] & 0x0F) | (V << 4); Sync(); break; + } +} + +static void UNLKS7057Power(void) +{ + reset1++; + FCEU_printf("reset1 %02x\n",reset1); + Sync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,UNLKS7057Write); +} + +static void UNLKS7057Reset(void) +{ + reset0++; + FCEU_printf("reset0 %02x\n",reset0); + Sync(); +} + +void UNLKS7057_Init(CartInfo *info) +{ + info->Power=UNLKS7057Power; + info->Reset=UNLKS7057Reset; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/__serial.c.win32 b/fceumm/src-fceumm/boards/__serial.c.win32 new file mode 100644 index 0000000..3b48240 --- /dev/null +++ b/fceumm/src-fceumm/boards/__serial.c.win32 @@ -0,0 +1,124 @@ + +#include "__serial.h" + +HANDLE SerialPort = NULL; // Handle of SerialPort itself. + +BOOL SerialOpen(int port, int baud) +{ + HANDLE Comport; + DCB myDCB; + COMMTIMEOUTS CTout; + char str[100]; + + if (port > 9) + sprintf(str, "\\\\.\\COM%d", port); + else + sprintf(str, "COM%d", port); + + // Open the serial port + if ((Comport = CreateFile(str, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) + return FALSE; + + // Configure Serial port (Setup Comm) + + // Buffer sizes + if (!SetupComm(Comport, 128, 128)) + return FALSE; + + // Setup DCB using current values + if (!GetCommState(Comport, &myDCB)) + return FALSE; + + myDCB.fInX = FALSE; // Turn off xon/xoff handler + myDCB.fOutX = FALSE; + myDCB.fOutxDsrFlow = FALSE; + myDCB.fOutxCtsFlow = FALSE; // no hardware flow control. + myDCB.BaudRate = baud; + myDCB.DCBlength = sizeof(DCB); + myDCB.fBinary = 1; + myDCB.fParity = 0; + myDCB.fDtrControl = DTR_CONTROL_DISABLE; + myDCB.fDsrSensitivity = 0; + myDCB.fTXContinueOnXoff = 1; + myDCB.fNull = 0; + myDCB.fRtsControl = RTS_CONTROL_DISABLE; + myDCB.fDummy2 = 0; + myDCB.wReserved = 0; + myDCB.Parity = NOPARITY; + myDCB.StopBits = ONESTOPBIT; + myDCB.wReserved1 = 0; + myDCB.ByteSize = 8; + + if (!SetCommState(Comport, &myDCB)) + return FALSE; + + // Set timeouts + CTout.ReadIntervalTimeout = 0xffffffff; + CTout.ReadTotalTimeoutMultiplier = 0; + CTout.ReadTotalTimeoutConstant = 0; + CTout.WriteTotalTimeoutMultiplier = 0; + CTout.WriteTotalTimeoutConstant = 5000; // don't hang if CTS is locked, for example + + SetCommTimeouts(Comport, &CTout); + EscapeCommFunction(Comport, SETDTR); + PurgeComm(Comport, PURGE_TXCLEAR | PURGE_RXCLEAR); + + SerialPort = Comport; + + return TRUE; +} + +void SerialClose(void) +{ + if (SerialPort == NULL) return; + + PurgeComm(SerialPort, PURGE_TXCLEAR | PURGE_RXCLEAR); + CloseHandle(SerialPort); + + SerialPort = NULL; +} + +BOOL SerialSendChar(int c) +{ + DWORD cr; + if(WriteFile(SerialPort, &c, 1, (LPDWORD)&cr, NULL) && cr) + return TRUE; + else + return FALSE; +} + +int SerialIsOpen(void) +{ + return (SerialPort != NULL); +} + +int SerialGetChar(void) +{ + uint8 ch; + DWORD cr; + if (SerialPort != NULL) { + if (ReadFile(SerialPort, &ch, 1, (LPDWORD)&cr, NULL) && cr) + return (int)ch; + } + return EOF; +} + +void SendCmd(uint8 *cmd, int size) +{ + int i; + for(i=0; i +#include "../types.h" + +void SendCmd(uint8 *cmd, int size); +int ReadResp(uint8 *resp, int size); + +#define SEND(cmd) SendCmd((uint8 *)&cmd[0], sizeof(cmd)) +#define GET(buf, size) ReadResp((uint8 *)&buf, size) +#define SENDGET(cmd, buf, size) SEND(cmd); GET(buf, size) + +BOOL SerialOpen(int port, int baud); +void SerialClose(void); +BOOL SerialSendChar(int c); +int SerialIsOpen(void); +int SerialGetChar(void); + +#endif diff --git a/fceumm/src-fceumm/boards/a9746.c b/fceumm/src-fceumm/boards/a9746.c new file mode 100644 index 0000000..782713d --- /dev/null +++ b/fceumm/src-fceumm/boards/a9746.c @@ -0,0 +1,80 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" +#include "mmc3.h" + +static DECLFW(UNLA9746Write) +{ +/* FCEU_printf("write raw %04x:%02x\n",A,V);*/ + switch (A&0xE003) + { + case 0x8000: EXPREGS[1]=V; EXPREGS[0]=0; break; + case 0x8002: EXPREGS[0]=V; EXPREGS[1]=0; break; + case 0x8001: { + uint8 bits_rev = ((V&0x20)>>5)|((V&0x10)>>3)|((V&0x08)>>1)|((V&0x04)<<1); + switch(EXPREGS[0]) + { + case 0x26: setprg8(0x8000, bits_rev); break; + case 0x25: setprg8(0xA000, bits_rev); break; + case 0x24: setprg8(0xC000, bits_rev); break; + case 0x23: setprg8(0xE000, bits_rev); break; + } + switch(EXPREGS[1]) + { + case 0x0a: + case 0x08: EXPREGS[2] = (V << 4); break; + case 0x09: setchr1(0x0000, EXPREGS[2]|(V >> 1)); break; + case 0x0b: setchr1(0x0400, EXPREGS[2]|(V >> 1)|1); break; + case 0x0c: + case 0x0e: EXPREGS[2] = (V << 4); break; + case 0x0d: setchr1(0x0800, EXPREGS[2]|(V >> 1)); break; + case 0x0f: setchr1(0x0c00, EXPREGS[2]|(V >> 1)|1); break; + case 0x10: + case 0x12: EXPREGS[2] = (V << 4); break; + case 0x11: setchr1(0x1000, EXPREGS[2]|(V >> 1)); break; + case 0x14: + case 0x16: EXPREGS[2] = (V << 4); break; + case 0x15: setchr1(0x1400, EXPREGS[2]|(V >> 1)); break; + case 0x18: + case 0x1a: EXPREGS[2] = (V << 4); break; + case 0x19: setchr1(0x1800, EXPREGS[2]|(V >> 1)); break; + case 0x1c: + case 0x1e: EXPREGS[2] = (V << 4); break; + case 0x1d: setchr1(0x1c00, EXPREGS[2]|(V >> 1)); break; + } + } + break; + } +} + +static void UNLA9746Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x8000,0xbfff,UNLA9746Write); +} + +void UNLA9746_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 256, 0, 0); + info->Power=UNLA9746Power; + AddExState(EXPREGS, 6, 0, "EXPR"); +} + diff --git a/fceumm/src-fceumm/boards/ac-08.c b/fceumm/src-fceumm/boards/ac-08.c new file mode 100644 index 0000000..9aef6f5 --- /dev/null +++ b/fceumm/src-fceumm/boards/ac-08.c @@ -0,0 +1,74 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg, mirr; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REG"}, + {&mirr, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + setprg8(0x6000, reg); + setprg32r(1, 0x8000, 0); + setchr8(0); + setmirror(mirr); +} + +static DECLFW(AC08Mirr) +{ + mirr = ((V&8)>>3)^1; + Sync(); +} + +static DECLFW(AC08Write) +{ + reg = V & 15; + Sync(); +} + +static void AC08Power(void) +{ + reg = 0; + Sync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x4025,0x4025,AC08Mirr); + SetWriteHandler(0x8000,0xFFFF,AC08Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void AC08_Init(CartInfo *info) +{ + info->Power=AC08Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/addrlatch.c b/fceumm/src-fceumm/boards/addrlatch.c new file mode 100644 index 0000000..6fe31c0 --- /dev/null +++ b/fceumm/src-fceumm/boards/addrlatch.c @@ -0,0 +1,253 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint16 latche, latcheinit; +static uint16 addrreg0, addrreg1; +static void(*WSync)(void); +static readfunc defread; + +static DECLFW(LatchWrite) +{ +/* FCEU_printf("%04x:%02x\n",A,V);*/ + latche=A; + WSync(); +} + +static void LatchReset(void) +{ + latche=latcheinit; + WSync(); +} + +static void LatchPower(void) +{ + latche=latcheinit; + WSync(); + SetReadHandler(0x8000,0xFFFF,defread); + SetWriteHandler(addrreg0,addrreg1,LatchWrite); +} + +static void StateRestore(int version) +{ + WSync(); +} + +static void Latch_Init(CartInfo *info, void (*proc)(void), readfunc func, uint16 init, uint16 adr0, uint16 adr1) +{ + latcheinit=init; + addrreg0=adr0; + addrreg1=adr1; + WSync=proc; + if(func) + defread=func; + else + defread=CartBR; + info->Power=LatchPower; + info->Reset=LatchReset; + GameStateRestore=StateRestore; + AddExState(&latche, 2, 0, "LATC"); +} + +/*------------------ UNLCC21 ---------------------------*/ + +static void UNLCC21Sync(void) +{ + setprg32(0x8000,0); + setchr8(latche&1); + setmirror(MI_0+((latche&2)>>1)); +} + +void UNLCC21_Init(CartInfo *info) +{ + Latch_Init(info, UNLCC21Sync, 0, 0, 0x8000, 0xFFFF); +} + +/*------------------ BMCD1038 ---------------------------*/ + +static uint8 dipswitch; +static void BMCD1038Sync(void) +{ + if(latche&0x80) + { + setprg16(0x8000,(latche&0x70)>>4); + setprg16(0xC000,(latche&0x70)>>4); + } + else + setprg32(0x8000,(latche&0x60)>>5); + setchr8(latche&7); + setmirror(((latche&8)>>3)^1); +} + +static DECLFR(BMCD1038Read) +{ + if(latche&0x100) + return dipswitch; + else + return CartBR(A); +} + +static void BMCD1038Reset(void) +{ + dipswitch++; + dipswitch&=3; +} + +void BMCD1038_Init(CartInfo *info) +{ + Latch_Init(info, BMCD1038Sync, BMCD1038Read, 0, 0x8000, 0xFFFF); + info->Reset=BMCD1038Reset; + AddExState(&dipswitch, 1, 0, "DIPSW"); +} + + +/*------------------ UNL43272 ---------------------------*/ +/* mapper much complex, including 16K bankswitching */ +static void UNL43272Sync(void) +{ + if((latche&0x81) == 0x81) + { + setprg32(0x8000,(latche&0x38)>>3); + } + else + FCEU_printf("unrecognized command %04!\n",latche); + setchr8(0); + setmirror(0); +} + +static DECLFR(UNL43272Read) +{ + if(latche&0x400) + return CartBR(A & 0xFE); + else + return CartBR(A); +} + +static void UNL43272Reset(void) +{ + latche = 0; + UNL43272Sync(); +} + +void UNL43272_Init(CartInfo *info) +{ + Latch_Init(info, UNL43272Sync, UNL43272Read, 0x81, 0x8000, 0xFFFF); + info->Reset=UNL43272Reset; + AddExState(&dipswitch, 1, 0, "DIPSW"); +} + +/*------------------ Map 058 ---------------------------*/ + +static void BMCGK192Sync(void) +{ + if(latche&0x40) + { + setprg16(0x8000,latche&7); + setprg16(0xC000,latche&7); + } + else + setprg32(0x8000,(latche>>1)&3); + setchr8((latche>>3)&7); + setmirror(((latche&0x80)>>7)^1); +} + +void BMCGK192_Init(CartInfo *info) +{ + Latch_Init(info, BMCGK192Sync, 0, 0, 0x8000, 0xFFFF); +} + +/*------------------ Map 200 ---------------------------*/ + +static void M200Sync(void) +{ +/* FCEU_printf("A\n");*/ + setprg16(0x8000,latche&7); + setprg16(0xC000,latche&7); + setchr8(latche&7); + setmirror((latche&8)>>3); +} + +void Mapper200_Init(CartInfo *info) +{ + Latch_Init(info, M200Sync, 0, 0xff, 0x8000, 0xFFFF); +} + +/*------------------ 190in1 ---------------------------*/ + +static void BMC190in1Sync(void) +{ + setprg16(0x8000,(latche>>2)&0x07); + setprg16(0xC000,(latche>>2)&0x07); + setchr8((latche>>2)&0x07); + setmirror((latche&1)^1); +} + +void BMC190in1_Init(CartInfo *info) +{ + Latch_Init(info, BMC190in1Sync, 0, 0, 0x8000, 0xFFFF); +} + +/*-------------- BMC810544-C-A1 ------------------------*/ + +static void BMC810544CA1Sync(void) +{ + uint32 bank = latche>>7; + if(latche&0x40) + setprg32(0x8000,bank); + else + { + setprg16(0x8000,(bank<<1)|((latche>>5)&1)); + setprg16(0xC000,(bank<<1)|((latche>>5)&1)); + } + setchr8(latche&0x0f); + setmirror(((latche>>4)&1)^1); +} + +void BMC810544CA1_Init(CartInfo *info) +{ + Latch_Init(info, BMC810544CA1Sync, 0, 0, 0x8000, 0xFFFF); +} + +/*-------------- BMCNTD-03 ------------------------*/ + +static void BMCNTD03Sync(void) +{ + /* 1PPP Pmcc spxx xccc*/ + /* 1000 0000 0000 0000 v*/ + /* 1001 1100 0000 0100 h*/ + /* 1011 1010 1100 0100*/ + uint32 prg = ((latche>>10)&0x1e); + uint32 chr = ((latche&0x0300)>>5)|(latche&7); + if(latche&0x80) + { + setprg16(0x8000,prg|((latche>>6)&1)); + setprg16(0xC000,prg|((latche>>6)&1)); + } + else + setprg32(0x8000,prg>>1); + setchr8(chr); + setmirror(((latche>>10)&1)^1); +} + +void BMCNTD03_Init(CartInfo *info) +{ + Latch_Init(info, BMCNTD03Sync, 0, 0, 0x8000, 0xFFFF); +} diff --git a/fceumm/src-fceumm/boards/ax5705.c b/fceumm/src-fceumm/boards/ax5705.c new file mode 100644 index 0000000..dd731aa --- /dev/null +++ b/fceumm/src-fceumm/boards/ax5705.c @@ -0,0 +1,107 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Super Bros. Pocker Mali (VRC4 mapper) + */ + +#include "mapinc.h" + +static uint8 IRQCount;/*, IRQPre;*/ +static uint8 IRQa; +static uint8 prg_reg[2]; +static uint8 chr_reg[8]; +static uint8 mirr; + +static SFORMAT StateRegs[]= +{ + {&IRQCount, 1, "IRQC"}, + {&IRQa, 1, "IRQA"}, + {prg_reg, 2, "PRG"}, + {chr_reg, 8, "CHR"}, + {&mirr, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + int i; + setprg8(0x8000,prg_reg[0]); + setprg8(0xA000,prg_reg[1]); + setprg8(0xC000,~1); + setprg8(0xE000,~0); + + for(i=0; i<8; i++) + setchr1(i<<10,chr_reg[i]); + setmirror(mirr^1); +} + +static DECLFW(UNLAX5705Write) +{ + /* if((A>=0xA008)&&(A<=0xE003))*/ + /* {*/ + /* int ind=(((A>>11)-6)|(A&1))&7;*/ + /* int sar=((A&2)<<1);*/ + /* chr_reg[ind]=(chr_reg[ind]&(0xF0>>sar))|((V&0x0F)<>2)|(V&5); break; /* EPROM dump have mixed PRG and CHR banks, data lines to mapper seems to be mixed*/ + case 0x8008: mirr=V&1; break; + case 0xA000: prg_reg[1]=((V&2)<<2)|((V&8)>>2)|(V&5); break; + case 0xA008: chr_reg[0]=(chr_reg[0]&0xF0)|(V&0x0F); break; + case 0xA009: chr_reg[0]=(chr_reg[0]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break; + case 0xA00A: chr_reg[1]=(chr_reg[1]&0xF0)|(V&0x0F); break; + case 0xA00B: chr_reg[1]=(chr_reg[1]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break; + case 0xC000: chr_reg[2]=(chr_reg[2]&0xF0)|(V&0x0F); break; + case 0xC001: chr_reg[2]=(chr_reg[2]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break; + case 0xC002: chr_reg[3]=(chr_reg[3]&0xF0)|(V&0x0F); break; + case 0xC003: chr_reg[3]=(chr_reg[3]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break; + case 0xC008: chr_reg[4]=(chr_reg[4]&0xF0)|(V&0x0F); break; + case 0xC009: chr_reg[4]=(chr_reg[4]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break; + case 0xC00A: chr_reg[5]=(chr_reg[5]&0xF0)|(V&0x0F); break; + case 0xC00B: chr_reg[5]=(chr_reg[5]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break; + case 0xE000: chr_reg[6]=(chr_reg[6]&0xF0)|(V&0x0F); break; + case 0xE001: chr_reg[6]=(chr_reg[6]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break; + case 0xE002: chr_reg[7]=(chr_reg[7]&0xF0)|(V&0x0F); break; + case 0xE003: chr_reg[7]=(chr_reg[7]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break; + } + Sync(); +} + +static void UNLAX5705Power(void) +{ + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,UNLAX5705Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLAX5705_Init(CartInfo *info) +{ + info->Power=UNLAX5705Power; + /* GameHBIRQHook=UNLAX5705IRQ;*/ + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/bandai.c b/fceumm/src-fceumm/boards/bandai.c new file mode 100644 index 0000000..f653bc8 --- /dev/null +++ b/fceumm/src-fceumm/boards/bandai.c @@ -0,0 +1,171 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Bandai mappers + * + */ + +#include "mapinc.h" + +static uint8 reg[16], is153; +static uint8 IRQa; +static int16 IRQCount, IRQLatch; + +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {reg, 16, "REGS"}, + {&IRQa, 1, "IRQA"}, + {&IRQCount, 2, "IRQC"}, + {&IRQLatch, 2, "IRQL"}, /* need for Famicom Jump II - Saikyou no 7 Nin (J) [!]*/ + {0} +}; + +static void BandaiIRQHook(int a) +{ + if(IRQa) + { + IRQCount-=a; + if(IRQCount<0) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + IRQCount=0xFFFF; + } + } +} + +static void BandaiSync(void) +{ + if(is153) + { + int base=(reg[0]&1)<<4; + if(!UNIFchrrama) + { + int i; + for(i=0; i<8; i++) setchr1(i<<10,reg[i]); + } + else + setchr8(0); + setprg16(0x8000,(reg[8]&0x0F)|base); + setprg16(0xC000,0x0F|base); + } + else + { + int i; + for(i=0; i<8; i++) setchr1(i<<10,reg[i]); + setprg16(0x8000,reg[8]); + setprg16(0xC000,~0); + } + switch(reg[9]&3) + { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(BandaiWrite) +{ + A&=0x0F; + if(A<0x0A) + { + reg[A&0x0F]=V; + BandaiSync(); + } + else + switch(A) + { + case 0x0A: X6502_IRQEnd(FCEU_IQEXT); IRQa=V&1; IRQCount=IRQLatch; break; + case 0x0B: IRQLatch&=0xFF00; IRQLatch|=V; break; + case 0x0C: IRQLatch&=0xFF; IRQLatch|=V<<8; break; + case 0x0D: break;/* Serial EEPROM control port */ + } +} + +static void BandaiPower(void) +{ + BandaiSync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0xFFFF,BandaiWrite); +} + +static void M153Power(void) +{ + BandaiSync(); + setprg8r(0x10,0x6000,0); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,BandaiWrite); +} + + +static void M153Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + BandaiSync(); +} + +void Mapper16_Init(CartInfo *info) +{ + is153=0; + info->Power=BandaiPower; + MapIRQHook=BandaiIRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +/* Famicom jump 2:*/ +/* 0-7: Lower bit of data selects which 256KB PRG block is in use.*/ +/* This seems to be a hack on the developers' part, so I'll make emulation*/ +/* of it a hack(I think the current PRG block would depend on whatever the*/ +/* lowest bit of the CHR bank switching register that corresponds to the*/ +/* last CHR address read).*/ + +void Mapper153_Init(CartInfo *info) +{ + is153=1; + info->Power=M153Power; + info->Close=M153Close; + MapIRQHook=BandaiIRQHook; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/bmc13in1jy110.c b/fceumm/src-fceumm/boards/bmc13in1jy110.c new file mode 100644 index 0000000..4909d3f --- /dev/null +++ b/fceumm/src-fceumm/boards/bmc13in1jy110.c @@ -0,0 +1,103 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * BMC 42-in-1 reset switch + */ + +#include "mapinc.h" + +static uint8 bank_mode; +static uint8 bank_value; +static uint8 prgb[4]; +static SFORMAT StateRegs[]= +{ + {0} +}; + +static void Sync(void) +{ + FCEU_printf("%02x: %02x %02x\n", bank_mode, bank_value, prgb[0]); + switch(bank_mode&7) + { + case 0: + setprg32(0x8000,bank_value&7); break; + case 1: + setprg16(0x8000,((8+(bank_value&7))>>1)+prgb[1]); + setprg16(0xC000,(bank_value&7)>>1); + case 4: + setprg32(0x8000,8+(bank_value&7)); break; + case 5: + setprg16(0x8000,((8+(bank_value&7))>>1)+prgb[1]); + setprg16(0xC000,((8+(bank_value&7))>>1)+prgb[3]); + case 2: + setprg8(0x8000,prgb[0]>>2); + setprg8(0xa000,prgb[1]); + setprg8(0xc000,prgb[2]); + setprg8(0xe000,~0); + break; + case 3: + setprg8(0x8000,prgb[0]); + setprg8(0xa000,prgb[1]); + setprg8(0xc000,prgb[2]); + setprg8(0xe000,prgb[3]); + break; + } +} + +static DECLFW(BMC13in1JY110Write) +{ + FCEU_printf("%04x:%04x\n",A,V); + switch(A) + { + case 0x8000: + case 0x8001: + case 0x8002: + case 0x8003: prgb[A&3]=V; break; + case 0xD000: bank_mode=V; break; + case 0xD001: setmirror(V&3); + case 0xD002: break; + case 0xD003: bank_value=V; break; + } + Sync(); +} + +static void BMC13in1JY110Power(void) +{ + prgb[0]=prgb[1]=prgb[2]=prgb[3]=0; + bank_mode=0; + bank_value=0; + setprg32(0x8000,0); + setchr8(0); + SetWriteHandler(0x8000,0xFFFF,BMC13in1JY110Write); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void BMC13in1JY110_Init(CartInfo *info) +{ + info->Power=BMC13in1JY110Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore=StateRestore; +} + + diff --git a/fceumm/src-fceumm/boards/bmc42in1r.c b/fceumm/src-fceumm/boards/bmc42in1r.c new file mode 100644 index 0000000..bbd77eb --- /dev/null +++ b/fceumm/src-fceumm/boards/bmc42in1r.c @@ -0,0 +1,76 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * Copyright (C) 2009 qeed + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * BMC 42-in-1 + * it seems now, mapper not reset-based, + * tested on real hardware and it does menus switch by pressing just Select, not Reset + * new registers behaviour proven this too + * + */ + +#include "mapinc.h" + +static uint8 latche[2]; +static SFORMAT StateRegs[]= +{ + {&latche, sizeof(latche), "LATCHE"}, + {0} +}; + +static void Sync(void) +{ + uint8 bank = (latche[0]&0x1f)|((latche[0]&0x80)>>2)|((latche[1]&1))<<6; + if(!(latche[0] & 0x20)) + setprg32(0x8000,bank >> 1); + else + { + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + setmirror((latche[0]>>6)&1); + setchr8(0); +} + +static DECLFW(M226Write) +{ + latche[A & 1] = V; + Sync(); +} + +static void M226Power(void) +{ + latche[0] = latche[1] = 0; + Sync(); + SetWriteHandler(0x8000,0xFFFF,M226Write); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper226_Init(CartInfo *info) +{ + info->Power=M226Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore=StateRestore; +} + diff --git a/fceumm/src-fceumm/boards/bmc64in1nr.c b/fceumm/src-fceumm/boards/bmc64in1nr.c new file mode 100644 index 0000000..888ef7a --- /dev/null +++ b/fceumm/src-fceumm/boards/bmc64in1nr.c @@ -0,0 +1,93 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * BMC 42-in-1 reset switch + */ + +#include "mapinc.h" + +static uint8 regs[4]; + +static SFORMAT StateRegs[]= +{ + {regs, 4, "REGS"}, + {0} +}; + +static void Sync(void) +{ + if(regs[0]&0x80) + { + if(regs[1]&0x80) + setprg32(0x8000,regs[1]&0x1F); + else + { + int bank=((regs[1]&0x1f)<<1)|((regs[1]>>6)&1); + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else + { + int bank=((regs[1]&0x1f)<<1)|((regs[1]>>6)&1); + setprg16(0xC000,bank); + } + if(regs[0]&0x20) + setmirror(MI_H); + else + setmirror(MI_V); + setchr8((regs[2]<<2)|((regs[0]>>1)&3)); +} + +static DECLFW(BMC64in1nrWriteLo) +{ + regs[A&3]=V; + Sync(); +} + +static DECLFW(BMC64in1nrWriteHi) +{ + regs[3]=V; + Sync(); +} + +static void BMC64in1nrPower(void) +{ + regs[0]=0x80; + regs[1]=0x43; + regs[2]=regs[3]=0; + Sync(); + SetWriteHandler(0x5000,0x5003,BMC64in1nrWriteLo); + SetWriteHandler(0x8000,0xFFFF,BMC64in1nrWriteHi); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void BMC64in1nr_Init(CartInfo *info) +{ + info->Power=BMC64in1nrPower; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore=StateRestore; +} + + diff --git a/fceumm/src-fceumm/boards/bmc70in1.c b/fceumm/src-fceumm/boards/bmc70in1.c new file mode 100644 index 0000000..58be5f6 --- /dev/null +++ b/fceumm/src-fceumm/boards/bmc70in1.c @@ -0,0 +1,130 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 is_large_banks, hw_switch; +static uint8 large_bank; +static uint8 prg_bank; +static uint8 chr_bank; +static uint8 bank_mode; +static uint8 mirroring; +static SFORMAT StateRegs[]= +{ + {&large_bank, 1, "LB"}, + {&hw_switch, 1, "DIPSW"}, + {&prg_bank, 1, "PRG"}, + {&chr_bank, 1, "CHR"}, + {&bank_mode, 1, "BM"}, + {&mirroring, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + switch (bank_mode) + { + case 0x00: + case 0x10: setprg16(0x8000,large_bank|prg_bank); + setprg16(0xC000,large_bank|7); + break; + case 0x20: setprg32(0x8000,(large_bank|prg_bank)>>1); + break; + case 0x30: setprg16(0x8000,large_bank|prg_bank); + setprg16(0xC000,large_bank|prg_bank); + break; + } + setmirror(mirroring); + if(!is_large_banks) + setchr8(chr_bank); +} + +static DECLFR(BMC70in1Read) +{ + if(bank_mode==0x10) + /* if(is_large_banks)*/ + return CartBR((A&0xFFF0)|hw_switch); + /* else*/ + /* return CartBR((A&0xFFF0)|hw_switch);*/ + else + return CartBR(A); +} + +static DECLFW(BMC70in1Write) +{ + if(A&0x4000) + { + bank_mode=A&0x30; + prg_bank=A&7; + } + else + { + mirroring=((A&0x20)>>5)^1; + if(is_large_banks) + large_bank=(A&3)<<3; + else + chr_bank=A&7; + } + Sync(); +} + +static void BMC70in1Reset(void) +{ + bank_mode=0; + large_bank=0; + Sync(); + hw_switch++; + hw_switch&=0xf; +} + +static void BMC70in1Power(void) +{ + setchr8(0); + bank_mode=0; + large_bank=0; + Sync(); + SetReadHandler(0x8000,0xFFFF,BMC70in1Read); + SetWriteHandler(0x8000,0xffff,BMC70in1Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void BMC70in1_Init(CartInfo *info) +{ + is_large_banks=0; + hw_switch=0xd; + info->Power=BMC70in1Power; + info->Reset=BMC70in1Reset; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void BMC70in1B_Init(CartInfo *info) +{ + is_large_banks=1; + hw_switch=0x6; + info->Power=BMC70in1Power; + info->Reset=BMC70in1Reset; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/bonza.c b/fceumm/src-fceumm/boards/bonza.c new file mode 100644 index 0000000..87079ee --- /dev/null +++ b/fceumm/src-fceumm/boards/bonza.c @@ -0,0 +1,138 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +#define CARD_EXTERNAL_INSERED 0x80 + +static uint8 prg_reg; +static uint8 chr_reg; +static SFORMAT StateRegs[]= +{ + {&prg_reg, 1, "PREG"}, + {&chr_reg, 1, "CREG"}, + {0} +}; + +/* + +cmd[0] = response on/off + 0x00 - on + 0x80 - off +cmd[1] = cmd + + +_GET_CHALLENGE: .BYTE 0,$B4, 0, 0,$62 + +_SELECT_FILE_1_0200: .BYTE 0,$A4, 1, 0, 2, 2, 0 +_SELECT_FILE_2_0201: .BYTE 0,$A4, 2, 0, 2, 2, 1 +_SELECT_FILE_2_0203: .BYTE 0,$A4, 2, 0, 2, 2, 3 +_SELECT_FILE_2_0204: .BYTE 0,$A4, 2, 0, 2, 2, 4 +_SELECT_FILE_2_0205: .BYTE 0,$A4, 2, 0, 2, 2, 5 +_SELECT_FILE_2_3F04: .BYTE 0,$A4, 2, 0, 2,$3F, 4 +_SELECT_FILE_2_4F00: .BYTE 0,$A4, 2, 0, 2,$4F, 0 + +_READ_BINARY_5: .BYTE 0,$B0,$85, 0, 2 +_READ_BINARY_6: .BYTE 0,$B0,$86, 0, 4 +_READ_BINARY_6_0: .BYTE 0,$B0,$86, 0,$18 +_READ_BINARY_0: .BYTE 0,$B0, 0, 2, 3 +_READ_BINARY_0_0: .BYTE 0,$B0, 0, 0, 4 +_READ_BINARY_0_1: .BYTE 0,$B0, 0, 0, $C +_READ_BINARY_0_2: .BYTE 0,$B0, 0, 0,$10 + +_UPDATE_BINARY: .BYTE 0,$D6, 0, 0, 4 +_UPDATE_BINARY_0: .BYTE 0,$D6, 0, 0,$10 + +_GET_RESPONSE: .BYTE $80,$C0, 2,$A1, 8 +_GET_RESPONSE_0: .BYTE 0,$C0, 0, 0, 2 +_GET_RESPONSE_1: .BYTE 0,$C0, 0, 0, 6 +_GET_RESPONSE_2: .BYTE 0,$C0, 0, 0, 8 +_GET_RESPONSE_3: .BYTE 0,$C0, 0, 0, $C +_GET_RESPONSE_4: .BYTE 0,$C0, 0, 0,$10 + +byte_8C0B: .BYTE $80,$30, 0, 2, $A, 0, 1 +byte_8C48: .BYTE $80,$32, 0, 1, 4 +byte_8C89: .BYTE $80,$34, 0, 0, 8, 0, 0 +byte_8D01: .BYTE $80,$36, 0, 0, $C +byte_8CA7: .BYTE $80,$38, 0, 2, 4 +byte_8BEC: .BYTE $80,$3A, 0, 3, 0 + +byte_89A0: .BYTE 0,$48, 0, 0, 6 +byte_8808: .BYTE 0,$54, 0, 0,$1C +byte_89BF: .BYTE 0,$58, 0, 0,$1C + +_MANAGE_CHANNEL: .BYTE 0,$70, 0, 0, 8 +byte_8CE5: .BYTE 0,$74, 0, 0,$12 +byte_8C29: .BYTE 0,$76, 0, 0, 8 +byte_8CC6: .BYTE 0,$78, 0, 0,$12 +*/ + +static uint8 sim0reset[0x1F] = { 0x3B, 0xE9, 0x00, 0xFF, 0xC1, 0x10, 0x31, 0xFE, + 0x55, 0xC8, 0x10, 0x20, 0x55, 0x47, 0x4F, 0x53, + 0x56, 0x53, 0x43, 0xAD, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 }; + +static void Sync(void) +{ + setprg32(0x8000, prg_reg); + setchr8(chr_reg); +} + +static void StateRestore(int version) +{ + Sync(); +} + +static DECLFW(M216WriteHi) +{ + prg_reg=A&1; + chr_reg=(A&0x0E)>>1; + Sync(); +} + +static DECLFW(M216Write5000) +{ +/* FCEU_printf("WRITE: %04x:%04x (PC=%02x cnt=%02x)\n",A,V,X.PC,sim0bcnt);*/ +} + +static DECLFR(M216Read5000) +{ +/* FCEU_printf("READ: %04x PC=%04x out=%02x byte=%02x cnt=%02x bit=%02x\n",A,X.PC,sim0out,sim0byte,sim0bcnt,sim0bit);*/ + return 0; +} + +static void Power(void) +{ + prg_reg = 0; + chr_reg = 0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M216WriteHi); + SetWriteHandler(0x5000,0x5000,M216Write5000); + SetReadHandler(0x5000,0x5000,M216Read5000); +} + + +void Mapper216_Init(CartInfo *info) +{ + info->Power=Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/bs-5.c b/fceumm/src-fceumm/boards/bs-5.c new file mode 100644 index 0000000..fbe3a09 --- /dev/null +++ b/fceumm/src-fceumm/boards/bs-5.c @@ -0,0 +1,91 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg_prg[4]; +static uint8 reg_chr[4]; +static uint8 dip_switch; + +static SFORMAT StateRegs[]= +{ + {reg_prg, 4, "PREGS"}, + {reg_chr, 4, "CREGS"}, + {0} +}; + +static void Sync(void) +{ + setprg8(0x8000,reg_prg[0]); + setprg8(0xa000,reg_prg[1]); + setprg8(0xc000,reg_prg[2]); + setprg8(0xe000,reg_prg[3]); + setchr2(0x0000,reg_chr[0]); + setchr2(0x0800,reg_chr[1]); + setchr2(0x1000,reg_chr[2]); + setchr2(0x1800,reg_chr[3]); + setmirror(MI_V); +} + +static DECLFW(MBS5Write) +{ + int bank_sel = (A&0xC00)>>10; + switch (A&0xF000) + { + case 0x8000: + reg_chr[bank_sel]=A&0x1F; + break; + case 0xA000: + if(A&(1<<(dip_switch+4))) + reg_prg[bank_sel]=A&0x0F; + break; + } + Sync(); +} + +static void MBS5Reset(void) +{ + dip_switch++; + dip_switch&=3; + reg_prg[0]=reg_prg[1]=reg_prg[2]=reg_prg[3]=~0; + Sync(); +} + +static void MBS5Power(void) +{ + dip_switch=0; + reg_prg[0]=reg_prg[1]=reg_prg[2]=reg_prg[3]=~0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,MBS5Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void BMCBS5_Init(CartInfo *info) +{ + info->Power=MBS5Power; + info->Reset=MBS5Reset; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/copyfami_emu.c b/fceumm/src-fceumm/boards/copyfami_emu.c new file mode 100644 index 0000000..75aca08 --- /dev/null +++ b/fceumm/src-fceumm/boards/copyfami_emu.c @@ -0,0 +1,378 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef COPYFAMI + +#include "__serial.h" +#include "mapinc.h" +#include "mmc3.h" + +//#define DEBUG_SERIAL + +// *** COPY FAMICOM EMULATION *** + +/* +Êàðòà ïàìÿòè + + $0000-$1FFF Îñíîâíîå ÎÇÓ + $2000-$200F Ðåãèñòðû PPU + $2010-$3FFB Ñèñòåìíîå ÎÇÓ + $3FFC-$3FFF Ñèñòåìíûå ðåãèñòðû + $4000-$7FFF APU ðåãèñòðû/ñâîáîäíî + $8000-$FFF9 CART/ROM + $FFFA-$FFFB CART/Âåêòîð NMI + $FFFE-$FFFF CART/Âåêòîð IRQ + +Ðåãèñòðû + + CTRL R/W $3FFC ---aenic ($00 at reset) + + c - Ðåæèì êàðòðèäæà + 0 - âûêëþ÷åí + 1 - âêëþ÷åí + i - Ðåæèì IRQ âåêòîðà + 0 - îðèãèíàëüíûé âåêòîð + 1 - âåêòîð ïåðåõâà÷åí + n - Ðåæèì NMI âåêòîðà + 0 - îðèãèíàëüíûé âåêòîð + 1 - âåêòîð ïåðåõâà÷åí + e - Çàïðåò NMI + 0 - çàïðåùåí + 1 - ðàçðåøåí + a - Ðåæèì AROM + 0 - âûêëþ÷åí + 1 - âêëþ÷åí + + BANK R/W $3FFD ---mbbbb + + b - Íîìåð áàíêà âíóòðåííåîãî ÏÇÓ + m - Ìèððîðèíã â ðåæèìå ÀROM + + USBDATA R/W $3FFE dddddddd + + d - Áàéò äàííûõ ïðèåìà/ïåðåäà÷è + + STATUS R $3FFF vmnicptr + + r - Ñòàòóñ äàííûõ äëÿ ÷òåíèÿ èç USB + 0 - Åñòü äàííûå + 1 - Íåò äàííûõ + t - Ñòàòóñ áóôåðà äëÿ çàïèñè â USB + 0 - Åñòü ìåñòî + 1 - Íåò ìåñòà + p - Ñòàòóñ ïîäêëþ÷åíèÿ USB êàáåëÿ + 0 - Ïîäêëþ÷åí + 1 - Îòêëþ÷åí + c - Íàëè÷èå êàðòðèäæà â ñëîòå + 0 - Ïðèñóòñòâóåò + 1 - Îòñóòñòâóåò + i - Ñîñòîÿíèå ñèãíàëà IRQ êàðòðèäæà + 0 - Àêòèâåí + 1 - Íåàêòèâåí + n - Ñîñòîÿíèå ñèãíàëà NMI êàðòðèäæà + 0 - Àêòèâåí + 1 - Íåàêòèâåí + m - Ñîñòîÿíèå àäðåñíîé øèíû À10 VRAM (ìèððîðèíã) + v - Ñîñòîÿíèå VRAM + 0 - Âûáðàíà + 1 - Íå âûáðàíà + +Ðåæèì AROM + + Àêòèâèðóåòñÿ âíóòðåííÿÿ VRAM + Ðåãèñòðû áàíêîâ è ìèððîðèíãà íà 8000-FFFF +*/ + +#define CTRL 0x00 +#define CCART 0x01 +#define CVIRQ 0x02 +#define CVNMI 0x04 +#define CDNMI 0x08 +#define CAROM 0x10 +#define BANK 0x01 +#define BMIRR 0x10 +#define USB 0x02 +#define STATUS 0x03 +#define SRX 0x01 +#define STX 0x02 +#define SPEN 0x04 +#define SCART 0x08 +#define SIRQ 0x10 +#define SNMI 0x20 +#define SA10 0x40 +#define SVRAM 0x80 + +#ifdef DEBUG_SERIAL +static uint8 debug_serial_data[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0x00, + 0xDE, 0xAD, 0xBE, 0xEF, 0x01, + + 0x02, + + 0x14, 0x50, 0xB0, + + 0x02, + + 0x14, 0x50, 0xB0, + + 0x02, + + }; +static uint32 debug_serial_data_size = sizeof(debug_serial_data); +static uint32 debug_serial_data_pos; +#endif + +static uint8 *CHRRAM=NULL; +static uint32 CHRRAMSIZE; + +static uint8 regs[4]; + +static readfunc def_read_ram, def_read_rom; +static writefunc def_write_ram; + +static SFORMAT StateRegs[]= +{ + {regs, 4, "CREGS"}, + {0} +}; + +static void Sync() +{ + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void MCopyFamiMMC3PW(uint32 A, uint8 V) +{ + if(regs[CTRL] & CCART) + setprg8(A,V); + else + setprg32r(1,0x8000,(regs[BANK]&0x0F)^0x08); +} + +static void MCopyFamiMMC3CW(uint32 A, uint8 V) +{ + if((regs[STATUS] & SCART) && (regs[CTRL] & CAROM)) + setchr8r(0x10,0); + else + setchr1r(0,A,V); +} + +static void MCopyFamiMMC3MW(uint8 V) +{ + if(regs[CTRL] & CAROM) + { + setmirror(MI_0+((regs[BANK]>>4)&1)); + } + else + { + A000B=V; + setmirror((V&1)^1); + } +} + +static uint32 direction = 0xffffffff; +static uint32 bytes_count = 0; + +static DECLFW(MCopyFamiWriteReg) +{ + if(((A&3) == USB)) + { + if(direction != 0) { + direction = 0; + bytes_count = 0; + FCEU_printf(" >"); + } +#ifndef DEBUG_SERIAL + while (!SerialSendChar(V)) {}; +#endif + bytes_count++; + // FCEU_printf(" %02X",V); + } + else + { + regs[A&3]=V; + Sync(); + } +} + +static DECLFR(MCopyFamiReadReg) +{ +#ifdef DEBUG_SERIAL + if(debug_serial_data_pos == debug_serial_data_size) + regs[STATUS] |= SRX; + else + regs[STATUS] &= ~SRX; +#endif +#ifndef DEBUG_SERIAL + if((A&3) == STATUS) + { + int data; + if((data = SerialGetChar()) == EOF) + regs[STATUS] |= SRX; + else + regs[STATUS] &= ~SRX; + regs[USB] = data & 0xff; + } else +#endif + if((A&3) == USB) + { +#ifdef DEBUG_SERIAL + regs[USB] = debug_serial_data[debug_serial_data_pos++]; +#endif + if(direction != 1) { + if(direction != 0xffffffff) FCEU_printf(" bytes sent: %08x",bytes_count); + direction = 1; + bytes_count = 0; + FCEU_printf("\n<"); + } + FCEU_printf(" %02X",regs[USB]); + } + return regs[A&3]; +} + +static DECLFW(MCopyFamiMMC3Write) +{ + if(regs[CTRL] & CAROM) + { + regs[BANK] = V & 0x1F; + Sync(); + } + else + { + if(A >= 0xC000) + MMC3_IRQWrite(A,V); + else + MMC3_CMDWrite(A,V); + } +} + +static DECLFW(MCopyFamiMMC3WriteNMI) +{ + if(regs[CTRL] & CVNMI) + def_write_ram(0x3FFC + (A & 1), V); + else + MCopyFamiMMC3Write(A, V); +} + +static DECLFW(MCopyFamiMMC3WriteIRQ) +{ + if(regs[CTRL] & CVIRQ) + def_write_ram(0x3FFE + (A & 1), V); + else + MCopyFamiMMC3Write(A, V); +} + +static DECLFR(MCopyFamiReadNMI) +{ + if(regs[CTRL] & CVNMI) + return def_read_ram(0x3FFC + (A & 1)); + else + return def_read_rom(A); +} + +static DECLFR(MCopyFamiReadIRQ) +{ + if(regs[CTRL] & CVIRQ) + return def_read_ram(0x3FFE + (A & 1)); + else + return def_read_rom(A); +} + +static void MCopyFamiMMC3Power(void) +{ + regs[CTRL] = regs[USB] = 0; + regs[STATUS] = SIRQ | SNMI | SVRAM; + regs[BANK] = 0x08; +#ifdef DEBUG_SERIAL + debug_serial_data_pos = 0; +#endif + GenMMC3Power(); + Sync(); + + def_write_ram = GetWriteHandler(0x3FFC); + SetWriteHandler(0x3FFC,0x3FFF,MCopyFamiWriteReg); + def_read_ram = GetReadHandler(0x3FFC); + SetReadHandler(0x3FFC,0x3FFF,MCopyFamiReadReg); + + SetWriteHandler(0x8000,0xFFF9,MCopyFamiMMC3Write); + SetWriteHandler(0xFFFA,0xFFFB,MCopyFamiMMC3WriteNMI); + SetWriteHandler(0xFFFE,0xFFFF,MCopyFamiMMC3WriteIRQ); + + def_read_rom = GetReadHandler(0xFFFA); + SetReadHandler(0xFFFA,0xFFFB,MCopyFamiReadNMI); + SetReadHandler(0xFFFE,0xFFFF,MCopyFamiReadIRQ); +} + +static void MCopyFamiMMC3Reset(void) +{ + regs[CTRL] = regs[USB] = 0; + regs[STATUS] = SIRQ | SNMI | SVRAM; + regs[BANK] = 0x08; +#ifdef DEBUG_SERIAL + debug_serial_data_pos = 0; +#endif + MMC3RegReset(); + Sync(); +} + +static void MCopyFamiClose(void) +{ + if(CHRRAM) + free(CHRRAM); + CHRRAM=NULL; + SerialClose(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void MapperCopyFamiMMC3_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 512, 8, 0); + + cwrap=MCopyFamiMMC3CW; + pwrap=MCopyFamiMMC3PW; + mwrap=MCopyFamiMMC3MW; + + info->Reset=MCopyFamiMMC3Reset; + info->Power=MCopyFamiMMC3Power; + info->Close=MCopyFamiClose; + GameStateRestore=StateRestore; + + CHRRAMSIZE=8192; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10,CHRRAM,CHRRAMSIZE,1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CHRRAM"); + +#ifndef DEBUG_SERIAL + FCEU_printf("WAITING FOR PORT...\n"); + + while(!SerialOpen(20, 921600)) {} + + FCEU_printf("PORT READY.\n"); +#endif + + AddExState(&StateRegs, ~0, 0, 0); +} + +#endif diff --git a/fceumm/src-fceumm/boards/copyfami_hwi.c b/fceumm/src-fceumm/boards/copyfami_hwi.c new file mode 100644 index 0000000..0c0b8b5 --- /dev/null +++ b/fceumm/src-fceumm/boards/copyfami_hwi.c @@ -0,0 +1,600 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* *** COPY FAMICOM HARDWARE INTERFACE ****/ + +#ifdef COPYFAMI + +#define NO_CACHE +#define NO_RAM + +#include "__serial.h" +#include "mapinc.h" + +#define FNV_32_PRIME ((uint32)0x01000193) + +#define CHR_CACHE_SIZE (1024 * 4) +#define WRAM_CACHE_SIZE (1024 / 2) +#define PRG_CACHE_SIZE (1024 / 4) +#define CMD_CACHE_SIZE (1024 * 128) + +#define CMD_MAX_SIZE (5) +#define CMD_MAX_RETEST (16) +#define CMD_MAX_VERIFY (16) + +static uint8 *WRAM = NULL; + +uint8 InitVector[] = {0xDE, 0xAD, 0xBE, 0xEF}; /* args none, return DE AD BE EF*/ +uint8 ResetCmd[] = {0x00}; /* args none, return none*/ +uint8 StateCmd[] = {0x01}; /* args none, return 7 bytes status*/ +uint8 StatusCmd[] = {0x02}; /* args none, return 32 bytes status*/ +uint8 LoadPlugCmd[] = {0x03, 0x00, 0x00}; /* args 2b size, Nb data return none*/ +uint8 RunPlugCmd[] = {0x04}; /* args none, return none*/ +uint8 RunGameCmd[] = {0x05}; /* args none, return none*/ +uint8 NROMSave[] = {0x06}; /* args none, return 16b + 32kb + 8kb*/ + +uint8 PRGWBCmd[] = {0x08, 0x00, 0x00, 0x00}; /* args 2b addr, 1b data return none*/ +uint8 PRGRBCmd[] = {0x09, 0x00, 0x00}; /* args 2b addr return 1b data*/ +uint8 CHRWBCmd[] = {0x0A, 0x00, 0x00, 0x00}; /* args 2b addr, 1b data return none*/ +uint8 CHRRBCmd[] = {0x0B, 0x00, 0x00}; /* args 2b addr, return 1b data*/ + +uint8 PRGSUMCmd[] = {0x10, 0x00, 0x00}; /* args 1b addr, 1b size return (256 * N)b*/ +uint8 PRG32KSUMCmd[] = {0x10, 0x80, 0x80}; /* args 1b addr, 1b size return 32kb*/ +uint8 PRG16KSUMCmd[] = {0x10, 0x00, 0x40}; /* args 1b addr, 1b size return 16kb*/ +uint8 PRG8KSUMCmd[] = {0x10, 0x00, 0x20}; /* args 1b addr, 1b size return 8kb*/ +uint8 PRG4KSUMCmd[] = {0x10, 0x00, 0x10}; /* args 1b addr, 1b size return 4kb*/ + +uint8 CHRSUMCmd[] = {0x11, 0x00, 0x00}; /* args 1b addr, 1b size return (256 * N)b*/ +uint8 CHR8KSUMCmd[] = {0x11, 0x00, 0x20}; /* args 1b addr, 1b size return 8kb*/ +uint8 CHR4KSUMCmd[] = {0x11, 0x00, 0x10}; /* args 1b addr, 1b size return 4kb*/ +uint8 CHR2KSUMCmd[] = {0x11, 0x00, 0x08}; /* args 1b addr, 1b size return 2kb*/ +uint8 CHR1KSUMCmd[] = {0x11, 0x00, 0x04}; /* args 1b addr, 1b size return 1kb*/ + +uint8 PRGGetCmd[] = {0x12, 0x00, 0x00}; /* args 1b addr, 1b size return (256 * N)b*/ +uint8 PRG32KGetCmd[] = {0x12, 0x80, 0x80}; /* args 1b addr, 1b size return 32kb*/ +uint8 PRG16KGetCmd[] = {0x12, 0x00, 0x40}; /* args 1b addr, 1b size return 16kb*/ +uint8 PRG8KGetCmd[] = {0x12, 0x00, 0x20}; /* args 1b addr, 1b size return 8kb*/ +uint8 PRG4KGetCmd[] = {0x12, 0x00, 0x10}; /* args 1b addr, 1b size return 4kb*/ + +uint8 CHRGetCmd[] = {0x13, 0x00, 0x00}; /* args 1b addr, 1b size return (256 * N)b*/ +uint8 CHR8KGetCmd[] = {0x13, 0x00, 0x20}; /* args 1b addr, 1b size return 8kb*/ +uint8 CHR4KGetCmd[] = {0x13, 0x00, 0x10}; /* args 1b addr, 1b size return 4kb*/ +uint8 CHR2KGetCmd[] = {0x13, 0x00, 0x08}; /* args 1b addr, 1b size return 2kb*/ +uint8 CHR1KGetCmd[] = {0x13, 0x00, 0x04}; /* args 1b addr, 1b size return 1kb*/ + +uint8 CPUTestCmd[] = {0x14, 0x00, 0x00}; /* args 1b addr, 1b size return (2b + 1b) * N + 3b*/ + +typedef struct { + int32 mirror; + int32 chrsum[8]; + int32 prgsum[4]; +} SYNC_STATE; + +static SYNC_STATE state_cur, state_new, state_def; + +typedef struct { + uint8 *buf; + int32 count; +} DATA_BANKS; + +static DATA_BANKS chr_data; +static int32 chr_bank[0x10000]; +static DATA_BANKS prg_data; +static int32 prg_bank[0x10000]; + +typedef struct { + SYNC_STATE states[CMD_CACHE_SIZE]; + int32 seqs[CMD_CACHE_SIZE][CMD_MAX_SIZE]; + int32 count; +} SYNC_CMDS; + +typedef struct { + int32 seq[CMD_MAX_SIZE]; + int32 size; + int32 found; + uint32 hash; + uint16 hashf; +} SYNC_CMD; + +static SYNC_CMD cmd; +static SYNC_CMDS cmds; + +typedef struct { + int32 index; + int32 size; + int32 retest; + int32 verify; +} CMD_CACHE; + +static CMD_CACHE cmd_cache[0x10000]; + +static SFORMAT StateRegs[]= +{ + {state_cur.chrsum, sizeof(state_cur.chrsum), "CHRREG"}, + {state_cur.prgsum, sizeof(state_cur.prgsum), "ROMREG"}, + {&state_cur.mirror, sizeof(state_cur.mirror), "MIRREG"}, + {0} +}; + +#define MI_U 4 + +static char *mirror_names[5] = {"Horizontal", "Vertical", "Mirror 0", "Mirror 1", "Unknown mirror"}; +static int32 mirror_modes[16] = { + MI_0, MI_U, MI_U, MI_H, MI_U, MI_V, MI_U, MI_U, + MI_U, MI_U, MI_U, MI_U, MI_U, MI_U, MI_U, MI_1 }; + +#define CHRDEF(slot) (chr_bank[state_def.chrsum[slot]]) +#define PRGDEF(slot) (prg_bank[state_def.prgsum[slot]]) +#define CHRCUR(slot) (chr_bank[state_cur.chrsum[slot]]) +#define PRGCUR(slot) (prg_bank[state_cur.prgsum[slot]]) +#define CHRNEW(slot) (chr_bank[state_new.chrsum[slot]]) +#define PRGNEW(slot) (prg_bank[state_new.prgsum[slot]]) + +static void GetStatus(SYNC_STATE *state) +{ + uint8 resp0; + uint16 resp1, i; + SEND(StatusCmd); + GET(resp0, 1); + state->mirror = resp0; + GET(resp0, 1); + for(i=0; i<8; i++) { + GET(resp1, 2); + state->chrsum[i] = resp1; + } + for(i=0; i<4; i++) { + GET(resp1, 2); + state->prgsum[i] = resp1; + } +} + +static int32 FetchNewCHRBank(int32 slot) +{ + FILE *ofile; + char name[256]; + int32 bank = chr_data.count++; + CHR1KGetCmd[1] = slot << 2; + SENDGET(CHR1KGetCmd, chr_data.buf[bank * 1024], 1024); + sprintf(name,"%04x.chr",bank); + ofile=fopen(name,"wb"); + fwrite((void *)&chr_data.buf[bank * 1024], 1, 1024, ofile); + fclose(ofile); + return bank; +} + +static int32 FetchNewPRGBank(int32 slot) +{ + FILE *ofile; + char name[256]; + int32 bank = prg_data.count++; + PRG8KGetCmd[1] = 0x80 + (slot << 5); + SENDGET(PRG8KGetCmd, prg_data.buf[bank * 8192], 8192); + sprintf(name,"%04x.prg",bank); + ofile=fopen(name,"wb"); + fwrite((void *)&prg_data.buf[bank * 8192], 1, 8192, ofile); + fclose(ofile); + return bank; +} + +static int CheckStatus(void) +{ + int32 i, ischanged = 0; + GetStatus(&state_new); + if(state_cur.mirror != state_new.mirror) { + state_cur.mirror = state_new.mirror; +#ifdef FCEU_LOG + FCEU_printf(">> mirror changed to %s (%02X)\n",mirror_names[mirror_modes[state_cur.mirror]], state_cur.mirror); +#endif + ischanged = 1; + } else { + state_new.mirror = -1; + } + for(i=0; i<8; i++) { + if(state_cur.chrsum[i] != state_new.chrsum[i]) { + state_cur.chrsum[i] = state_new.chrsum[i]; + if(CHRCUR(i) == -1) { + CHRCUR(i) = FetchNewCHRBank(i); +#ifdef FCEU_LOG + FCEU_printf(">> chr[%d] bank %d loaded\n", i, CHRCUR(i)); +#endif + } +#ifdef FCEU_LOG + else + FCEU_printf(">> chr[%d] bank %d switched\n", i, CHRCUR(i)); +#endif + ischanged = 1; + } else { + state_new.chrsum[i] = -1; + } + } + for(i=0; i<4; i++) { + if(state_cur.prgsum[i] != state_new.prgsum[i]) { + state_cur.prgsum[i] = state_new.prgsum[i]; + if(PRGCUR(i) == -1) { + PRGCUR(i) = FetchNewPRGBank(i); +#ifdef FCEU_LOG + FCEU_printf(">> prg[%d] bank %d loaded\n", i, PRGCUR(i)); +#endif + } +#ifdef FCEU_LOG + else + FCEU_printf(">> prg[%d] bank %d switched\n", i, PRGCUR(i)); +#endif + ischanged = 1; + } else { + state_new.prgsum[i] = -1; + } + } + return ischanged; +} + +#ifndef NO_CACHE +static void ApplyStatus() +{ + int32 i; + if ((cmds.states[cmd.found].mirror != -1) && (cmds.states[cmd.found].mirror != state_cur.mirror)) { + state_cur.mirror = cmds.states[cmd.found].mirror; + setmirror(mirror_modes[state_cur.mirror]); +#ifdef FCEU_LOG + FCEU_printf(">> mirror changed to %s (%02X)\n",mirror_names[mirror_modes[state_cur.mirror]], state_cur.mirror); +#endif + } + for(i=0; i<8; i++) { + int32 sum = cmds.states[cmd.found].chrsum[i]; + if (sum != -1) { + if (sum != state_cur.chrsum[i]) { + state_cur.chrsum[i] = sum; + setchr1r(1, i * 1024, CHRCUR(i)); +#ifdef FCEU_LOG + FCEU_printf(">> chr[%d] bank %d switched\n", i, chr_bank[sum]); +#endif + } + else +#ifdef FCEU_LOG + FCEU_printf(">> chr[%d] bank %d switched the same\n", i, chr_bank[sum]); + } +#endif + } + for(i=0; i<4; i++) { + int32 sum = cmds.states[cmd.found].prgsum[i]; + if (sum != -1) { + if (sum != state_cur.prgsum[i]) { + state_cur.prgsum[i] = sum; + setprg8r(2, 0x8000 + (i * 8192), PRGCUR(i)); +#ifdef FCEU_LOG + FCEU_printf(">> prg[%d] bank %d switched\n", i, prg_bank[sum]); +#endif + } + else +#ifdef FCEU_LOG + FCEU_printf(">> prg[%d] bank %d switched the same\n", i, prg_bank[sum]); + } +#endif + } +} + +static void LogCmd() +{ + int32 i; + FCEU_printf(">> new cmd size %d [", cmd_cache[cmd.hashf].size); + for(i=0; i> 16) ^ (cmd.hash & 0xffff); + cmd.found = cmd_cache[cmd.hashf].index; + } +#endif + +static DECLFW(MCopyFamiWrite) +{ +#ifndef NO_CACHE + int32 i; +#endif + +#ifdef FCEU_LOG + FCEU_printf("> WRITE %04X:%02X\n",A,V); +#endif + + PRGWBCmd[1] = A & 0xFF; + PRGWBCmd[2] = A >> 8; + PRGWBCmd[3] = V & 0xFF; + SEND(PRGWBCmd); +#ifdef NO_CACHE + CheckStatus(); + Sync(); +#else + UpdateCmd((A << 8) | V); + /* èùåì êîìàíäó â êåøå*/ + if(cmd.found == -1) { + /* íå íàéäåíà, ïðîâåðÿåì, èçìåíèëîñü ëè ñîñòîÿíèå áàíêîâ*/ + /* ëèáî íå ïðåäåëüíîé ëè îíà äëèíû äëÿ êîìàíäû*/ + cmd_cache[cmd.hashf].index = cmd.found = cmds.count++; + cmd_cache[cmd.hashf].retest = 0; + cmd_cache[cmd.hashf].verify = 0; + for(i=0; i> 8; + SENDGET(PRGRBCmd, result, 1); +#ifdef FCEU_LOG + FCEU_printf("> READ %04X:%02X\n",A,result); +#endif + return result; +} + +static void MCopyFamiReset(void) +{ + state_cur = state_def; + Sync(); +} + +static void MCopyFamiPower(void) +{ +/* uint32 resp, presp;*/ + + FCEU_printf("NOW POWERING... "); + + Sync(); + + SetWriteHandler(0x4018, 0x7fff, MCopyFamiWrite); + SetReadHandler(0x4018, 0x7fff, MCopyFamiRead); +#ifndef NO_RAM + SetWriteHandler(0x6000, 0x7fff, CartBW); + SetReadHandler(0x6000, 0x7fff, CartBR); +#endif + +/* + FCEU_printf("READING MEMORY MAP...\n"); + CPUTestCmd[1] = 0x50; + CPUTestCmd[2] = 0x30; + SEND(CPUTestCmd); + resp = 0; + presp = 0xffffffff; + while (presp != 0x00ff0000) { + GET(resp, 3); + if(presp != 0xffffffff) { + switch(presp & 0x00FF0000) { + case 0x00000000: /* BUS*/ + FCEU_printf(" %04X-%04X OPEN BUS\n",presp & 0x7fff, (resp - 1) & 0x7fff); + break; + case 0x00010000: /* RAM*/ + FCEU_printf(" %04X-%04X RAM\n",presp & 0x7fff, (resp - 1) & 0x7fff); + SetWriteHandler(presp & 0x7fff, (resp - 1) & 0x7fff, CartBW); + SetReadHandler(presp & 0x7fff, (resp - 1) & 0x7fff, CartBR); + break; + } + } + presp = resp; + } +*/ + SetWriteHandler(0x8000, 0xffff, MCopyFamiWrite); + SetReadHandler(0x8000, 0xffff, CartBR); + + FCEU_printf("DONE!\nNOW COLLECTING DATA...\n"); +} + +static void MCopyFamiClose(void) +{ + if(chr_data.buf) + free(chr_data.buf); + chr_data.buf=NULL; + if(prg_data.buf) + free(prg_data.buf); + prg_data.buf=NULL; + if(WRAM) + free(WRAM); + WRAM = NULL; + + SerialClose(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void MapperCopyFami_Init(CartInfo *info) +{ + uint32 resp = 0, i, size; + + memset(chr_bank, -1, sizeof(chr_bank)); + memset(prg_bank, -1, sizeof(chr_bank)); + memset(cmd_cache, -1, sizeof(cmd_cache)); + memset(&cmds, 0, sizeof(cmds)); + memset(&cmd, 0, sizeof(cmd)); + + info->Reset=MCopyFamiReset; + info->Power=MCopyFamiPower; + info->Close=MCopyFamiClose; + GameStateRestore=StateRestore; + + size = 1024 * CHR_CACHE_SIZE; /* ðàçìåð ñòðàíèöû 1êá*/ + chr_data.buf = (uint8*)FCEU_gmalloc(size); + SetupCartCHRMapping(1, chr_data.buf, size, 1); /* ïðîâåðÿòü ïïó ðàì, èíà÷å èãðà ìîæåò ïîðòèòü äàííûå*/ + AddExState(chr_data.buf, size, 0, "COPYCHR"); + + size = 8192; /* ðàçìåð ñòðàíèöû 8êá*/ + WRAM = (uint8*)FCEU_gmalloc(size); + SetupCartPRGMapping(1, WRAM, size, 1); + AddExState(WRAM, size, 0, "COPYWRAM"); + + size = 8192 * PRG_CACHE_SIZE; /* ðàçìåð ñòðàíèöû 8êá*/ + prg_data.buf = (uint8*)FCEU_gmalloc(size); + SetupCartPRGMapping(2, prg_data.buf, size, 0); + AddExState(prg_data.buf, size, 0, "COPYPRG"); + + + FCEU_printf("WAITING FOR SERIAL PORT... "); + while(!SerialOpen(19, 921600)) { Sleep(500); } + FCEU_printf("READY!\n"); + + FCEU_printf("WAITING FOR DEVICE... "); + + while(resp != *(uint32 *)&InitVector[0]) { + SEND(ResetCmd); + SENDGET(InitVector, resp, 4); + Sleep(500); + } + + FCEU_printf("READY!\n"); + FCEU_printf("READING STATUS...\n"); + GetStatus(&state_cur); + FCEU_printf("MIRRORING IS %s (%02X)\n",mirror_names[mirror_modes[state_cur.mirror]], state_cur.mirror); + FCEU_printf("READING CHR...\n INITIAL STATE:"); + + for(i=0; i<8; i++) { + if(CHRCUR(i) == -1) + CHRCUR(i) = FetchNewCHRBank(i); + FCEU_printf(" CHR%d=%02X", i, CHRCUR(i)); + } + FCEU_printf("\n"); + + FCEU_printf("READING PRG...\n INITIAL STATE:"); + for(i=0; i<4; i++) { + if(PRGCUR(i) == -1) + PRGCUR(i) = FetchNewPRGBank(i); + FCEU_printf(" PRG%d=%02X", i, PRGCUR(i)); + } + FCEU_printf("\nDONE!\n"); + + state_def = state_cur; + + AddExState(&StateRegs, ~0, 0, 0); +} + +#endif diff --git a/fceumm/src-fceumm/boards/dance2000.c b/fceumm/src-fceumm/boards/dance2000.c new file mode 100644 index 0000000..a674d0c --- /dev/null +++ b/fceumm/src-fceumm/boards/dance2000.c @@ -0,0 +1,111 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Dance 2000 12-in-1 + * + */ + +#include "mapinc.h" + +static uint8 prg, mirr, prgmode; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {&prg, 1, "REGS"}, + {&mirr, 1, "MIRR"}, + {&prgmode, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + setmirror(mirr); + setprg8r(0x10,0x6000,0); + setchr8(0); + if(prgmode) + setprg32(0x8000,prg&7); + else { + setprg16(0x8000,prg&0x0f); + setprg16(0xC000,0); + } +} + +static DECLFW(UNLD2000Write) +{ + /* FCEU_printf("write %04x:%04x\n",A,V);*/ + switch(A) { + case 0x5000: prg = V; Sync(); break; + case 0x5200: mirr = (V & 1)^1; prgmode = V & 4; Sync(); break; + /* default: FCEU_printf("write %04x:%04x\n",A,V);*/ + } +} + +static DECLFR(UNLD2000Read) +{ + if(prg & 0x40) + return X.DB; + else + return CartBR(A); +} + +static void UNLD2000Power(void) +{ + prg = prgmode = 0; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,UNLD2000Read); + SetWriteHandler(0x4020,0x5FFF,UNLD2000Write); +} + +static void UNLAX5705IRQ(void) +{ + if(scanline > 174) setchr4(0x0000,1); + else setchr4(0x0000,0); +} + +static void UNLD2000Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLD2000_Init(CartInfo *info) +{ + info->Power=UNLD2000Power; + info->Close=UNLD2000Close; + GameHBIRQHook=UNLAX5705IRQ; + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/datalatch.c b/fceumm/src-fceumm/boards/datalatch.c new file mode 100644 index 0000000..4ee6bc0 --- /dev/null +++ b/fceumm/src-fceumm/boards/datalatch.c @@ -0,0 +1,429 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 latche, latcheinit, bus_conflict; +static uint16 addrreg0, addrreg1; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; +static void(*WSync)(void); + +static DECLFW(LatchWrite) +{ +/* FCEU_printf("bs %04x %02x\n",A,V);*/ + if(bus_conflict) + latche=V&CartBR(A); + else + latche=V; + WSync(); +} + +static void LatchPower(void) +{ + latche=latcheinit; + WSync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetWriteHandler(addrreg0,addrreg1,LatchWrite); +} + +static void LatchClose(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + WSync(); +} + +static void Latch_Init(CartInfo *info, void (*proc)(void), uint8 init, uint16 adr0, uint16 adr1, uint8 wram, uint8 busc) +{ + bus_conflict = busc; + latcheinit=init; + addrreg0=adr0; + addrreg1=adr1; + WSync=proc; + info->Power=LatchPower; + info->Close=LatchClose; + GameStateRestore=StateRestore; + if(wram) + { + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + } + AddExState(&latche, 1, 0, "LATC"); +} + +/*------------------ CPROM ---------------------------*/ + +static void CPROMSync(void) +{ + setchr4(0x0000,0); + setchr4(0x1000,latche&3); + setprg32(0x8000,0); +} + +void CPROM_Init(CartInfo *info) +{ + Latch_Init(info, CPROMSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 184 ---------------------------*/ + +static void M184Sync(void) +{ + setchr4(0x0000,latche); + setchr4(0x1000,latche>>4); + setprg32(0x8000,0); +} + +void Mapper184_Init(CartInfo *info) +{ + Latch_Init(info, M184Sync, 0, 0x6000, 0x7FFF, 0, 0); +} + +/*------------------ CNROM ---------------------------*/ + +static void CNROMSync(void) +{ + setchr8(latche); + setprg32(0x8000,0); + setprg8r(0x10,0x6000,0); /* Hayauchy IGO uses 2Kb or RAM*/ +} + +void CNROM_Init(CartInfo *info) +{ + Latch_Init(info, CNROMSync, 0, 0x8000, 0xFFFF, 1, 0); +} + +/*------------------ ANROM ---------------------------*/ + +static void ANROMSync() +{ + setprg32(0x8000,latche&0xf); + setmirror(MI_0+((latche>>4)&1)); + setchr8(0); +} + +void ANROM_Init(CartInfo *info) +{ + Latch_Init(info, ANROMSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 70 ---------------------------*/ + +static void M70Sync() +{ + setprg16(0x8000,latche>>4); + setprg16(0xc000,~0); + setchr8(latche&0xf); +} + +void Mapper70_Init(CartInfo *info) +{ + Latch_Init(info, M70Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 152 ---------------------------*/ + +static void M152Sync() +{ + setprg16(0x8000,(latche>>4)&7); + setprg16(0xc000,~0); + setchr8(latche&0xf); + setmirror(MI_0+((latche>>7)&1)); /* Saint Seiya...hmm. */ +} + +void Mapper152_Init(CartInfo *info) +{ + Latch_Init(info, M152Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 78 ---------------------------*/ +/* Should be two separate emulation functions for this "mapper". Sigh. URGE TO KILL RISING. */ +static void M78Sync() +{ + setprg16(0x8000,(latche&7)); + setprg16(0xc000,~0); + setchr8(latche>>4); + setmirror(MI_0+((latche>>3)&1)); +} + +void Mapper78_Init(CartInfo *info) +{ + Latch_Init(info, M78Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ MHROM ---------------------------*/ + +static void MHROMSync(void) +{ + setprg32(0x8000,latche>>4); + setchr8(latche&0xf); +} + +void MHROM_Init(CartInfo *info) +{ + Latch_Init(info, MHROMSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +void Mapper140_Init(CartInfo *info) +{ + Latch_Init(info, MHROMSync, 0, 0x6000, 0x7FFF, 0, 0); +} + +void Mapper240_Init(CartInfo *info) +{ + Latch_Init(info, MHROMSync, 0, 0x4020, 0x5FFF, 0, 0); + /* need SRAM.*/ +} + +/*------------------ Map 87 ---------------------------*/ + +static void M87Sync(void) +{ + setprg32(0x8000,0); + setchr8(((latche>>1)&1)|((latche<<1)&2)); +} + +void Mapper87_Init(CartInfo *info) +{ + Latch_Init(info, M87Sync, ~0, 0x6000, 0xFFFF, 0, 0); +} + +/*------------------ Map 101 ---------------------------*/ + +static void M101Sync(void) +{ + setprg32(0x8000,0); + setchr8(latche); +} + +void Mapper101_Init(CartInfo *info) +{ + Latch_Init(info, M101Sync, ~0, 0x6000, 0x7FFF, 0, 0); +} + +/*------------------ Map 11 ---------------------------*/ + +static void M11Sync(void) +{ + setprg32(0x8000,latche&0xf); + setchr8(latche>>4); +} + +void Mapper11_Init(CartInfo *info) +{ + Latch_Init(info, M11Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +void Mapper144_Init(CartInfo *info) +{ + Latch_Init(info, M11Sync, 0, 0x8001, 0xFFFF, 0, 0); +} + +/*------------------ Map 38 ---------------------------*/ + +static void M38Sync(void) +{ + setprg32(0x8000,latche&3); + setchr8(latche>>2); +} + +void Mapper38_Init(CartInfo *info) +{ + Latch_Init(info, M38Sync, 0, 0x7000, 0x7FFF, 0, 0); +} + +/*------------------ Map 36 ---------------------------*/ + +static void M36Sync(void) +{ + setprg32(0x8000,latche>>4); + setchr8((latche)&0xF); +} + +void Mapper36_Init(CartInfo *info) +{ + Latch_Init(info, M36Sync, 0, 0x8400, 0xfffe, 0, 0); +} +/*------------------ UNROM ---------------------------*/ + +static void UNROMSync(void) +{ + setprg16(0x8000,latche); + setprg16(0xc000,~0); + setchr8(0); +} + +void UNROM_Init(CartInfo *info) +{ + Latch_Init(info, UNROMSync, 0, 0x8000, 0xFFFF, 0, 1); +} + +/*------------------ Map 93 ---------------------------*/ + +static void SSUNROMSync(void) +{ + setprg16(0x8000,latche>>4); + setprg16(0xc000,~0); + setchr8(0); +} + +void SUNSOFT_UNROM_Init(CartInfo *info) +{ + Latch_Init(info, SSUNROMSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 94 ---------------------------*/ + +static void M94Sync(void) +{ + setprg16(0x8000,latche>>2); + setprg16(0xc000,~0); + setchr8(0); +} + +void Mapper94_Init(CartInfo *info) +{ + Latch_Init(info, M94Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 180 ---------------------------*/ + +static void M180Sync(void) +{ + setprg16(0x8000,0); + setprg16(0xc000,latche); + setchr8(0); +} + +void Mapper180_Init(CartInfo *info) +{ + Latch_Init(info, M180Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 107 ---------------------------*/ + +static void M107Sync(void) +{ + setprg32(0x8000,(latche>>1)&3); + setchr8(latche&7); +} + +void Mapper107_Init(CartInfo *info) +{ + Latch_Init(info, M107Sync, ~0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 113 ---------------------------*/ + +static void M113Sync(void) +{ + setprg32(0x8000,(latche>>3)&7); + setchr8(((latche>>3)&8)|(latche&7)); +/* setmirror(latche>>7); // only for HES 6in1*/ +} + +void Mapper113_Init(CartInfo *info) +{ + Latch_Init(info, M113Sync, 0, 0x4100, 0x7FFF, 0, 0); +} + +/*------------------ A65AS ---------------------------*/ + +/* actually, there is two cart in one... First have extra mirroring*/ +/* mode (one screen) and 32K bankswitching, second one have only*/ +/* 16 bankswitching mode and normal mirroring... But there is no any*/ +/* correlations between modes and they can be used in one mapper code.*/ + +static void BMCA65ASSync(void) +{ + if(latche&0x40) + setprg32(0x8000,(latche>>1)&0x0F); + else + { + setprg16(0x8000,((latche&0x30)>>1)|(latche&7)); + setprg16(0xC000,((latche&0x30)>>1)|7); + } + setchr8(0); + if(latche&0x80) + setmirror(MI_0+(((latche>>5)&1))); + else + setmirror(((latche>>3)&1)^1); +} + +void BMCA65AS_Init(CartInfo *info) +{ + Latch_Init(info, BMCA65ASSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ NROM ---------------------------*/ + +#ifdef DEBUG_MAPPER +static DECLFW(WriteHandler) +{ + FCEU_printf("bs %04x %02x\n",A,V); + CartBW(A,V); +} +#endif + +static void NROMPower(void) +{ + setprg8r(0x10,0x6000,0); /* Famili BASIC (v3.0) need it (uses only 4KB), FP-BASIC uses 8KB*/ + setprg16(0x8000,0); + setprg16(0xC000,~0); + setchr8(0); + + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + + #ifdef DEBUG_MAPPER + SetWriteHandler(0x4020,0xFFFF,WriteHandler); + #endif +} + +void NROM_Init(CartInfo *info) +{ + info->Power=NROMPower; + info->Close=LatchClose; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); +} diff --git a/fceumm/src-fceumm/boards/deirom.c b/fceumm/src-fceumm/boards/deirom.c new file mode 100644 index 0000000..186dffa --- /dev/null +++ b/fceumm/src-fceumm/boards/deirom.c @@ -0,0 +1,82 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 cmd; +static uint8 DRegs[8]; + +static SFORMAT DEI_StateRegs[]= +{ + {&cmd, 1, "CMD"}, + {DRegs, 8, "DREG"}, + {0} +}; + +static void Sync(void) +{ + int x; + setchr2(0x0000,DRegs[0]); + setchr2(0x0800,DRegs[1]); + for(x=0;x<4;x++) + setchr1(0x1000+(x<<10),DRegs[2+x]); + setprg8(0x8000,DRegs[6]); + setprg8(0xa000,DRegs[7]); +} + +static void StateRestore(int version) +{ + Sync(); +} + +static DECLFW(DEIWrite) +{ + switch(A&0x8001) + { + case 0x8000: cmd=V&0x07; break; + case 0x8001: if(cmd<=0x05) + V&=0x3F; + else + V&=0x0F; + if(cmd<=0x01) V>>=1; + DRegs[cmd&0x07]=V; + Sync(); + break; + } +} + +static void DEIPower(void) +{ + setprg8(0xc000,0xE); + setprg8(0xe000,0xF); + cmd=0; + memset(DRegs,0,8); + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,DEIWrite); +} + + +void DEIROM_Init(CartInfo *info) +{ + info->Power=DEIPower; + GameStateRestore=StateRestore; + AddExState(&DEI_StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/dream.c b/fceumm/src-fceumm/boards/dream.c new file mode 100644 index 0000000..cf33afe --- /dev/null +++ b/fceumm/src-fceumm/boards/dream.c @@ -0,0 +1,56 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 latche; + +static void Sync(void) +{ + setprg16(0x8000,latche); + setprg16(0xC000,8); +} + +static DECLFW(DREAMWrite) +{ + latche=V&7; + Sync(); +} + +static void DREAMPower(void) +{ + latche=0; + Sync(); + setchr8(0); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x5020,0x5020,DREAMWrite); +} + +static void Restore(int version) +{ + Sync(); +} + +void DreamTech01_Init(CartInfo *info) +{ + GameStateRestore=Restore; + info->Power=DREAMPower; + AddExState(&latche, 1, 0, "LATCH"); +} diff --git a/fceumm/src-fceumm/boards/dummy_mapper.c b/fceumm/src-fceumm/boards/dummy_mapper.c new file mode 100644 index 0000000..085db96 --- /dev/null +++ b/fceumm/src-fceumm/boards/dummy_mapper.c @@ -0,0 +1,103 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg[8]; +/* +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; +static uint8 *CHRRAM=NULL; +static uint32 CHRRAMSIZE; +*/ + +static SFORMAT StateRegs[]= +{ + {reg, 8, "REGS"}, + {0} +}; + +static void Sync(void) +{ +} + +static DECLFW(MNNNWrite) +{ +} + +static void MNNNPower(void) +{ +/* SetReadHandler(0x6000,0x7fff,CartBR);*/ +/* SetWriteHandler(0x6000,0x7fff,CartBW);*/ + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,MNNNWrite); +} + +static void MNNNReset(void) +{ +} + +/* +static void MNNNClose(void) +{ + if(WRAM) + free(WRAM); + if(CHRRAM) + free(CHRRAM); + WRAM=CHRRAM=NULL; +} +*/ + +static void MNNNIRQHook(void) +{ + X6502_IRQBegin(FCEU_IQEXT); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void MapperNNN_Init(CartInfo *info) +{ + info->Reset=MNNNReset; + info->Power=MNNNPower; + /* info->Close=MNNNClose;*/ + GameHBIRQHook=MNNNIRQHook; + GameStateRestore=StateRestore; + /* + CHRRAMSIZE=8192; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10,CHRRAM,CHRRAMSIZE,1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); + */ + /* + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + */ + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/edu2000.c b/fceumm/src-fceumm/boards/edu2000.c new file mode 100644 index 0000000..e152576 --- /dev/null +++ b/fceumm/src-fceumm/boards/edu2000.c @@ -0,0 +1,84 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "mapinc.h" + +static uint8 *WRAM=NULL; +static uint8 reg; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REG"}, + {0} +}; + +static void Sync(void) +{ + setchr8(0); + setprg8r(0x10,0x6000,(reg&0xC0)>>6); + setprg32(0x8000,reg&0x1F); +/* setmirror(((reg&0x20)>>5));*/ +} + +static DECLFW(UNLEDU2000HiWrite) +{ +/* FCEU_printf("%04x:%02x\n",A,V);*/ + reg=V; + Sync(); +} + +static void UNLEDU2000Power(void) +{ + setmirror(MI_0); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0xFFFF,CartBW); + SetWriteHandler(0x8000,0xFFFF,UNLEDU2000HiWrite); + reg=0; + Sync(); +} + +static void UNLEDU2000Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +static void UNLEDU2000Restore(int version) +{ + Sync(); +} + +void UNLEDU2000_Init(CartInfo *info) +{ + info->Power=UNLEDU2000Power; + info->Close=UNLEDU2000Close; + GameStateRestore=UNLEDU2000Restore; + WRAM=(uint8*)FCEU_gmalloc(32768); + SetupCartPRGMapping(0x10,WRAM,32768,1); + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=32768; + } + AddExState(WRAM, 32768, 0, "WRAM"); + AddExState(StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/fk23c.c b/fceumm/src-fceumm/boards/fk23c.c new file mode 100644 index 0000000..2a84d36 --- /dev/null +++ b/fceumm/src-fceumm/boards/fk23c.c @@ -0,0 +1,222 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 unromchr; +static uint32 dipswitch = 0; +static uint8 *CHRRAM=NULL; +static uint32 CHRRAMSize; + +static void BMCFK23CCW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + setchr8(EXPREGS[2]|unromchr); + else if(EXPREGS[0] & 0x20) + setchr1r(0x10, A, V); + else + { + uint16 base=(EXPREGS[2]&0x7F)<<3; + if(EXPREGS[3]&2) + { + int cbase=(MMC3_cmd&0x80)<<5; + setchr1(A,V|base); + setchr1(0x0000^cbase,DRegBuf[0]|base); + setchr1(0x0400^cbase,EXPREGS[6]|base); + setchr1(0x0800^cbase,DRegBuf[1]|base); + setchr1(0x0c00^cbase,EXPREGS[7]|base); + } + else + setchr1(A,V|base); + } +} + +static void BMCFK23CPW(uint32 A, uint8 V) +{ + uint32 bank = (EXPREGS[1] & 0x1F); + uint32 hiblock = ((EXPREGS[0] & 8) << 4)|((EXPREGS[0] & 0x80) << 1)|(UNIFchrrama?((EXPREGS[2] & 0x40)<<3):0); + uint32 block = (EXPREGS[1] & 0x60) | hiblock; + uint32 extra = (EXPREGS[3] & 2); + switch(EXPREGS[0]&7) + { + case 0: setprg8(A, (block << 1) | (V & 0x3F)); + if(extra) + { + setprg8(0xC000,EXPREGS[4]); + setprg8(0xE000,EXPREGS[5]); + } + break; + case 1: setprg8(A, ((hiblock | (EXPREGS[1] & 0x70)) << 1) | (V & 0x1F)); + if(extra) + { + setprg8(0xC000,EXPREGS[4]); + setprg8(0xE000,EXPREGS[5]); + } + break; + case 2: setprg8(A, ((hiblock | (EXPREGS[1] & 0x78)) << 1) | (V & 0x0F)); + if(extra) + { + setprg8(0xC000,EXPREGS[4]); + setprg8(0xE000,EXPREGS[5]); + } + break; + case 3: setprg16(0x8000,(bank | block)); + setprg16(0xC000,(bank | block)); + break; + case 4: setprg32(0x8000,(bank | block) >> 1); + break; + } + setprg8r(0x10,0x6000,A001B&3); +} + +static DECLFW(BMCFK23CHiWrite) +{ + if(EXPREGS[0]&0x40) + { + if(EXPREGS[0]&0x30) + unromchr=0; + else + { + unromchr=V&3; + FixMMC3CHR(MMC3_cmd); + } + } + else + { + if((A==0x8001)&&(EXPREGS[3]&2)&&(MMC3_cmd&8)) + { + EXPREGS[4|(MMC3_cmd&3)]=V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } + else + if(A<0xC000) { + if(UNIFchrrama) { /* hacky... strange behaviour, must be bit scramble due to pcb layot restrictions*/ + /* check if it not interfer with other dumps*/ + if((A==0x8000)&&(V==0x46)) + V=0x47; + else if((A==0x8000)&&(V==0x47)) + V=0x46; + } + MMC3_CMDWrite(A,V); + FixMMC3PRG(MMC3_cmd); + } + else + MMC3_IRQWrite(A,V); + } +} + +static DECLFW(BMCFK23CWrite) +{ + /* FCEU_printf("lo %04x:%02x\n",A,V);*/ + if(dipswitch) /* íóëåâîé äèï áåðåò ëþáûå çàïèñè ïî äåôîëòó, äàëüøå èäåò âûáîð*/ + { + if(A&(1<<(dipswitch+3))) { + EXPREGS[A&3]=V; + /* FCEU_printf(" reg %d set!\n",A&3);*/ + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } + } + else + { + EXPREGS[A&3]=V; + /* FCEU_printf(" reg %d set!\n",A&3);*/ + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } +} + +static void BMCFK23CReset(void) +{ + if(dipswitch<=8) + dipswitch++; + else + dipswitch=0; + EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0; + EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF; + MMC3RegReset(); + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void BMCFK23CPower(void) +{ + GenMMC3Power(); + EXPREGS[0]=4; + EXPREGS[1]=0xFF; + EXPREGS[2]=EXPREGS[3]=0; + dipswitch = 0; + EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF; + SetWriteHandler(0x5000,0x5fff,BMCFK23CWrite); + SetWriteHandler(0x8000,0xFFFF,BMCFK23CHiWrite); + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void BMCFK23CAPower(void) +{ + GenMMC3Power(); + dipswitch = 0; + EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0; + EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF; + SetWriteHandler(0x5000,0x5fff,BMCFK23CWrite); + SetWriteHandler(0x8000,0xFFFF,BMCFK23CHiWrite); + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void BMCFK23CAClose(void) +{ + if(CHRRAM) + free(CHRRAM); + CHRRAM = NULL; +} + +void BMCFK23C_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 128, 0); + cwrap=BMCFK23CCW; + pwrap=BMCFK23CPW; + info->Power=BMCFK23CPower; + info->Reset=BMCFK23CReset; + AddExState(EXPREGS, 8, 0, "EXPR"); + AddExState(&unromchr, 1, 0, "UNCHR"); + AddExState(&dipswitch, 1, 0, "DIPSW"); +} + +void BMCFK23CA_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 128, 0); + cwrap=BMCFK23CCW; + pwrap=BMCFK23CPW; + info->Power=BMCFK23CAPower; + info->Reset=BMCFK23CReset; + info->Close=BMCFK23CAClose; + + CHRRAMSize=8192; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRRAM"); + AddExState(EXPREGS, 8, 0, "EXPR"); + AddExState(&unromchr, 1, 0, "UNCHR"); + AddExState(&dipswitch, 1, 0, "DIPSW"); +} diff --git a/fceumm/src-fceumm/boards/ghostbusters63in1.c b/fceumm/src-fceumm/boards/ghostbusters63in1.c new file mode 100644 index 0000000..03ba413 --- /dev/null +++ b/fceumm/src-fceumm/boards/ghostbusters63in1.c @@ -0,0 +1,106 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * 63in1 ghostbusters + */ + +#include "mapinc.h" + +static uint8 reg[2], bank; +static uint8 banks[4] = {0, 0, 1, 2}; +static uint8 *CHRROM=NULL; +static uint32 CHRROMSIZE; + +static SFORMAT StateRegs[]= +{ + {reg, 2, "REGS"}, + {&bank, 1, "BANK"}, + {0} +}; + +static void Sync(void) +{ + if(reg[0]&0x20) + { + setprg16r(banks[bank],0x8000,reg[0]&0x1F); + setprg16r(banks[bank],0xC000,reg[0]&0x1F); + } + else + setprg32r(banks[bank],0x8000,(reg[0]>>1)&0x0F); + if(reg[1]&2) + setchr8r(0x10,0); + else + setchr8(0); + setmirror((reg[0]&0x40)>>6); +} + +static DECLFW(BMCGhostbusters63in1Write) +{ + reg[A&1]=V; + bank=((reg[0]&0x80)>>7)|((reg[1]&1)<<1); +/* FCEU_printf("reg[0]=%02x, reg[1]=%02x, bank=%02x\n",reg[0],reg[1],bank);*/ + Sync(); +} + +static DECLFR(BMCGhostbusters63in1Read) +{ + if(bank==1) + return X.DB; + else + return CartBR(A); +} + +static void BMCGhostbusters63in1Power(void) +{ + reg[0]=reg[1]=0; + Sync(); + SetReadHandler(0x8000,0xFFFF,BMCGhostbusters63in1Read); + SetWriteHandler(0x8000,0xFFFF,BMCGhostbusters63in1Write); +} + +static void BMCGhostbusters63in1Reset(void) +{ + reg[0]=reg[1]=0; +} + +static void StateRestore(int version) +{ + Sync(); +} + +static void BMCGhostbusters63in1Close(void) +{ + if(CHRROM) + free(CHRROM); + CHRROM=NULL; +} + +void BMCGhostbusters63in1_Init(CartInfo *info) +{ + info->Reset=BMCGhostbusters63in1Reset; + info->Power=BMCGhostbusters63in1Power; + info->Close=BMCGhostbusters63in1Close; + + CHRROMSIZE=8192; /* dummy CHRROM, VRAM disable*/ + CHRROM=(uint8*)FCEU_gmalloc(CHRROMSIZE); + SetupCartPRGMapping(0x10,CHRROM,CHRROMSIZE,0); + AddExState(CHRROM, CHRROMSIZE, 0, "CHRROM"); + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/gs-2004.c b/fceumm/src-fceumm/boards/gs-2004.c new file mode 100644 index 0000000..17a9ef8 --- /dev/null +++ b/fceumm/src-fceumm/boards/gs-2004.c @@ -0,0 +1,69 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg, mirr; +static SFORMAT StateRegs[]= +{ + {®, 1, "REGS"}, + {&mirr, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + setprg8r(1,0x6000,0); + setprg32(0x8000,reg); + setchr8(0); +} + +static DECLFW(BMCGS2004Write) +{ + reg=V; + Sync(); +} + +static void BMCGS2004Power(void) +{ + reg=~0; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,BMCGS2004Write); +} + +static void BMCGS2004Reset(void) +{ + reg=~0; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void BMCGS2004_Init(CartInfo *info) +{ + info->Reset=BMCGS2004Reset; + info->Power=BMCGS2004Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/gs-2013.c b/fceumm/src-fceumm/boards/gs-2013.c new file mode 100644 index 0000000..027d0ac --- /dev/null +++ b/fceumm/src-fceumm/boards/gs-2013.c @@ -0,0 +1,69 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg, mirr; +static SFORMAT StateRegs[]= +{ + {®, 1, "REGS"}, + {&mirr, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + setprg8r(0,0x6000,~0); + setprg32r((reg&8)>>3,0x8000,reg); + setchr8(0); +} + +static DECLFW(BMCGS2013Write) +{ + reg=V; + Sync(); +} + +static void BMCGS2013Power(void) +{ + reg=~0; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,BMCGS2013Write); +} + +static void BMCGS2013Reset(void) +{ + reg=~0; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void BMCGS2013_Init(CartInfo *info) +{ + info->Reset=BMCGS2013Reset; + info->Power=BMCGS2013Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/h2288.c b/fceumm/src-fceumm/boards/h2288.c new file mode 100644 index 0000000..ec5d96f --- /dev/null +++ b/fceumm/src-fceumm/boards/h2288.c @@ -0,0 +1,80 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" +#include "mmc3.h" + +extern uint8 m114_perm[8]; + +static void H2288PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + { + uint8 bank=(EXPREGS[0]&5)|((EXPREGS[0]&8)>>2)|((EXPREGS[0]&0x20)>>2); + if(EXPREGS[0]&2) + setprg32(0x8000,bank>>1); + else + { + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else + setprg8(A,V&0x3F); +} + +static DECLFW(H2288WriteHi) +{ + switch (A&0x8001) + { + case 0x8000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m114_perm[V&7])); break; + case 0x8001: MMC3_CMDWrite(0x8001,V); break; + } +} + +static DECLFW(H2288WriteLo) +{ + if(A&0x800) + { + if(A&1) + EXPREGS[1]=V; + else + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + } +} + +static void H2288Power(void) +{ + EXPREGS[0]=EXPREGS[1]=0; + GenMMC3Power(); + /* SetReadHandler(0x5000,0x5FFF,H2288Read);*/ + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x5000,0x5FFF,H2288WriteLo); + SetWriteHandler(0x8000,0x9FFF,H2288WriteHi); +} + +void UNLH2288_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap=H2288PW; + info->Power=H2288Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} diff --git a/fceumm/src-fceumm/boards/karaoke.c b/fceumm/src-fceumm/boards/karaoke.c new file mode 100644 index 0000000..e089cda --- /dev/null +++ b/fceumm/src-fceumm/boards/karaoke.c @@ -0,0 +1,71 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +extern uint32 ROM_size; +static uint8 latche; + +static void Sync(void) +{ + if(latche) + { + if(latche&0x10) + setprg16(0x8000,(latche&7)); + else + setprg16(0x8000,(latche&7)|8); + } + else + setprg16(0x8000,7+(ROM_size>>4)); +} + +static DECLFW(M188Write) +{ + latche=V; + Sync(); +} + +static DECLFR(ExtDev) +{ + return(3); +} + +static void Power(void) +{ + latche=0; + Sync(); + setchr8(0); + setprg16(0xc000,0x7); + SetReadHandler(0x6000,0x7FFF,ExtDev); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M188Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper188_Init(CartInfo *info) +{ + info->Power=Power; + GameStateRestore=StateRestore; + AddExState(&latche, 1, 0, "LATCH"); +} diff --git a/fceumm/src-fceumm/boards/kof97.c b/fceumm/src-fceumm/boards/kof97.c new file mode 100644 index 0000000..b124cd8 --- /dev/null +++ b/fceumm/src-fceumm/boards/kof97.c @@ -0,0 +1,50 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" +#include "mmc3.h" + +static DECLFW(UNLKOF97CMDWrite) +{ + V=(V&0xD8)|((V&0x20)>>4)|((V&4)<<3)|((V&2)>>1)|((V&1)<<2); /*76143502*/ + if(A==0x9000) A=0x8001; + MMC3_CMDWrite(A,V); +} + +static DECLFW(UNLKOF97IRQWrite) +{ + V=(V&0xD8)|((V&0x20)>>4)|((V&4)<<3)|((V&2)>>1)|((V&1)<<2); + if(A==0xD000) A=0xC001; + else if(A==0xF000) A=0xE001; + MMC3_IRQWrite(A,V); +} + +static void UNLKOF97Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x8000,0xA000,UNLKOF97CMDWrite); + SetWriteHandler(0xC000,0xF000,UNLKOF97IRQWrite); +} + +void UNLKOF97_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 256, 0, 0); + info->Power=UNLKOF97Power; +} diff --git a/fceumm/src-fceumm/boards/konami-qtai.c b/fceumm/src-fceumm/boards/konami-qtai.c new file mode 100644 index 0000000..a944154 --- /dev/null +++ b/fceumm/src-fceumm/boards/konami-qtai.c @@ -0,0 +1,238 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * CAI Shogakko no Sansu + */ + +#include "mapinc.h" + +static uint8 QTAINTRAM[2048]; +static writefunc old2007wrap; + +static uint16 CHRSIZE = 8192; +static uint16 WRAMSIZE = 8192 + 4096; +static uint8 *CHRRAM = NULL; +static uint8 *WRAM = NULL; + +static uint8 IRQa, K4IRQ; +static uint32 IRQLatch, IRQCount; + +static uint8 regs[16]; +/*static uint8 test[8];*/ +static SFORMAT StateRegs[]= +{ + {&IRQCount, 1, "IRQC"}, + {&IRQLatch, 1, "IRQL"}, + {&IRQa, 1, "IRQA"}, + {&K4IRQ, 1, "K4IRQ"}, + {regs, 16, "REGS"}, + {0} +}; + +static void chrSync(void) +{ + setchr4r(0x10,0x0000,regs[5]&1); + setchr4r(0x10,0x1000,0); +} + +static void Sync(void) +{ + chrSync(); +/* if(regs[0xA]&0x10)*/ +/* {*/ +/* setchr1r(0x10,0x0000,(((regs[5]&1))<<2)+0); + setchr1r(0x10,0x0400,(((regs[5]&1))<<2)+1); + setchr1r(0x10,0x0800,(((regs[5]&1))<<2)+2); + setchr1r(0x10,0x0c00,(((regs[5]&1))<<2)+3); + setchr1r(0x10,0x1000,0); + setchr1r(0x10,0x1400,1); + setchr1r(0x10,0x1800,2); + setchr1r(0x10,0x1c00,3);*/ +/* setchr1r(0x10,0x0000,(((regs[5]&1))<<2)+0); + setchr1r(0x10,0x0400,(((regs[5]&1))<<2)+1); + setchr1r(0x10,0x0800,(((regs[5]&1))<<2)+2); + setchr1r(0x10,0x0c00,(((regs[5]&1))<<2)+3); + setchr1r(0x10,0x1000,(((regs[5]&1)^1)<<2)+4); + setchr1r(0x10,0x1400,(((regs[5]&1)^1)<<2)+5); + setchr1r(0x10,0x1800,(((regs[5]&1)^1)<<2)+6); + setchr1r(0x10,0x1c00,(((regs[5]&1)^1)<<2)+7); +*/ +/* }*/ +/* else*/ +/* {*/ +/* + setchr1r(0x10,0x0000,(((regs[5]&1)^1)<<2)+0); + setchr1r(0x10,0x0400,(((regs[5]&1)^1)<<2)+1); + setchr1r(0x10,0x0800,(((regs[5]&1)^1)<<2)+2); + setchr1r(0x10,0x0c00,(((regs[5]&1)^1)<<2)+3); + setchr1r(0x10,0x1000,(((regs[5]&1))<<2)+4); + setchr1r(0x10,0x1400,(((regs[5]&1))<<2)+5); + setchr1r(0x10,0x1800,(((regs[5]&1))<<2)+6); + setchr1r(0x10,0x1c00,(((regs[5]&1))<<2)+7); +}*/ +/* setchr1r(1,0x0000,test[0]); + setchr1r(1,0x0400,test[1]); + setchr1r(1,0x0800,test[2]); + setchr1r(1,0x0c00,test[3]); + setchr1r(1,0x1000,test[4]); + setchr1r(1,0x1400,test[5]); + setchr1r(1,0x1800,test[6]); + setchr1r(1,0x1c00,test[7]); +*/ + setprg4r(0x10,0x6000,regs[0]&1); + if(regs[2]>=0x40) + setprg8r(1,0x8000,(regs[2]-0x40)); + else + setprg8r(0,0x8000,(regs[2]&0x3F)); + if(regs[3]>=0x40) + setprg8r(1,0xA000,(regs[3]-0x40)); + else + setprg8r(0,0xA000,(regs[3]&0x3F)); + if(regs[4]>=0x40) + setprg8r(1,0xC000,(regs[4]-0x40)); + else + setprg8r(0,0xC000,(regs[4]&0x3F)); + + setprg8r(1,0xE000,~0); + setmirror(MI_V); +} + +/*static DECLFW(TestWrite) +{ + test[A&7] = V; + Sync(); +}*/ + +static DECLFW(M190Write) +{ +/* FCEU_printf("write %04x:%04x %d, %d\n",A,V,scanline,timestamp);*/ + regs[(A&0x0F00)>>8]=V; + switch(A) + { + case 0xd600:IRQLatch&=0xFF00;IRQLatch|=V;break; + case 0xd700:IRQLatch&=0x00FF;IRQLatch|=V<<8;break; + case 0xd900:IRQCount=IRQLatch;IRQa=V&2;K4IRQ=V&1;X6502_IRQEnd(FCEU_IQEXT);break; + case 0xd800:IRQa=K4IRQ;X6502_IRQEnd(FCEU_IQEXT);break; + } + Sync(); +} + +static DECLFR(M190Read) +{ +/* FCEU_printf("read %04x:%04x %d, %d\n",A,regs[(A&0x0F00)>>8],scanline,timestamp);*/ + return regs[(A&0x0F00)>>8]+regs[0x0B]; +} +static void VRC5IRQ(int a) +{ + if(IRQa) + { + IRQCount+=a; + if(IRQCount&0x10000) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount=IRQLatch; + } + } +} + +/*static void Mapper190_PPU(uint32 A)*/ +/*{*/ +/* if(A<0x2000)*/ +/* setchr4r(0x10,0x1000,QTAINTRAM[A&0x1FFF]&1);*/ +/* else*/ +/* chrSync();*/ +/*}*/ + +static DECLFW(M1902007Wrap) +{ + if(A>=0x2000) + { + if(regs[0xA]&1) + QTAINTRAM[A&0x1FFF]=V; + else + old2007wrap(A,V); + } +} + + +static void M190Power(void) +{ +/* test[0]=0; + test[1]=1; + test[2]=2; + test[3]=3; + test[4]=4; + test[5]=5; + test[6]=6; + test[7]=7; +*/ + setprg4r(0x10,0x7000,2); + + old2007wrap=GetWriteHandler(0x2007); + SetWriteHandler(0x2007,0x2007,M1902007Wrap); + + SetReadHandler(0x6000,0xFFFF,CartBR); +/* SetWriteHandler(0x5000,0x5007,TestWrite);*/ + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetWriteHandler(0x8000,0xFFFF,M190Write); + SetReadHandler(0xDC00,0xDC00,M190Read); + SetReadHandler(0xDD00,0xDD00,M190Read); + Sync(); +} + +static void M190Close(void) +{ + if(CHRRAM) + free(CHRRAM); + CHRRAM=NULL; + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper190_Init(CartInfo *info) +{ + info->Power=M190Power; + info->Close=M190Close; + GameStateRestore=StateRestore; + + MapIRQHook=VRC5IRQ; +/* PPU_hook=Mapper190_PPU;*/ + + CHRRAM=(uint8*)FCEU_gmalloc(CHRSIZE); + SetupCartCHRMapping(0x10,CHRRAM,CHRSIZE,1); + AddExState(CHRRAM, CHRSIZE, 0, "CHRRAM"); + + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + if(info->battery) + { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE - 4096; + } + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/le05.c b/fceumm/src-fceumm/boards/le05.c new file mode 100644 index 0000000..a76d787 --- /dev/null +++ b/fceumm/src-fceumm/boards/le05.c @@ -0,0 +1,66 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 chr; +static SFORMAT StateRegs[]= +{ + {&chr, 1, "CHR"}, + {0} +}; + +static void Sync(void) +{ + setprg2r(0,0xE000,0); + setprg2r(0,0xE800,0); + setprg2r(0,0xF000,0); + setprg2r(0,0xF800,0); + + setprg8r(1,0x6000,3); + setprg8r(1,0x8000,0); + setprg8r(1,0xA000,1); + setprg8r(1,0xC000,2); + + setchr8(chr & 1); + setmirror(MI_V); +} + +static DECLFW(LE05Write) +{ + chr = V; + Sync(); +} + +static void LE05Power(void) +{ + Sync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,LE05Write); +} + +void LE05_Init(CartInfo *info) +{ + info->Power=LE05Power; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/malee.c b/fceumm/src-fceumm/boards/malee.c new file mode 100644 index 0000000..f05bd69 --- /dev/null +++ b/fceumm/src-fceumm/boards/malee.c @@ -0,0 +1,45 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 WRAM[2048]; + +static void MALEEPower(void) +{ + setprg2r(0x10,0x7000,0); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetReadHandler(0x6000,0x67FF,CartBR); + SetReadHandler(0x7000,0x77FF,CartBR); + SetWriteHandler(0x7000,0x77FF,CartBW); + setprg2r(1,0x6000,0); + setprg32(0x8000,0); + setchr8(0); +} + +void MALEE_Init(CartInfo *info) +{ + info->Power=MALEEPower; + SetupCartPRGMapping(0x10, WRAM, 2048, 1); + AddExState(WRAM, 2048, 0,"RAM"); +} diff --git a/fceumm/src-fceumm/boards/mapinc.h b/fceumm/src-fceumm/boards/mapinc.h new file mode 100644 index 0000000..489ab41 --- /dev/null +++ b/fceumm/src-fceumm/boards/mapinc.h @@ -0,0 +1,12 @@ +#include "../types.h" +#include "../x6502.h" +#include "../fceu.h" +#include "../ppu.h" +#include "../memory.h" +#include "../sound.h" +#include "../state.h" +#include "../cart.h" +#include "../cheat.h" +#include "../unif.h" +#include +#include diff --git a/fceumm/src-fceumm/boards/mmc1.c b/fceumm/src-fceumm/boards/mmc1.c new file mode 100644 index 0000000..8494fc2 --- /dev/null +++ b/fceumm/src-fceumm/boards/mmc1.c @@ -0,0 +1,445 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 1998 BERO + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static void GenMMC1Power(void); +static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery); + +static uint8 BufferShift,DRegs[4]; +static uint8 Buffer; + +static int mmc1opts; + +static void (*MMC1CHRHook4)(uint32 A, uint8 V); +static void (*MMC1PRGHook16)(uint32 A, uint8 V); + +static uint8 *WRAM=NULL; +static uint8 *CHRRAM=NULL; +static int is155, is171; + +static DECLFW(MBWRAM) +{ + if(!(DRegs[3]&0x10)||is155) + Page[A>>11][A]=V; /* WRAM is enabled.*/ +} + +static DECLFR(MAWRAM) +{ + if((DRegs[3]&0x10)&&!is155) + return X.DB; /* WRAM is disabled*/ + return(Page[A>>11][A]); +} + +static void MMC1CHR(void) +{ + if(mmc1opts&4) + { + if(DRegs[0]&0x10) + setprg8r(0x10,0x6000,(DRegs[1]>>4)&1); + else + setprg8r(0x10,0x6000,(DRegs[1]>>3)&1); + } + + if(MMC1CHRHook4) + { + if(DRegs[0]&0x10) + { + MMC1CHRHook4(0x0000,DRegs[1]); + MMC1CHRHook4(0x1000,DRegs[2]); + } + else + { + MMC1CHRHook4(0x0000,(DRegs[1]&0xFE)); + MMC1CHRHook4(0x1000,DRegs[1]|1); + } + } + else + { + if(DRegs[0]&0x10) + { + setchr4(0x0000,DRegs[1]); + setchr4(0x1000,DRegs[2]); + } + else + setchr8(DRegs[1]>>1); + } +} + +static void MMC1PRG(void) +{ + uint8 offs=DRegs[1]&0x10; + if(MMC1PRGHook16) + { + switch(DRegs[0]&0xC) + { + case 0xC: MMC1PRGHook16(0x8000,(DRegs[3]+offs)); + MMC1PRGHook16(0xC000,0xF+offs); + break; + case 0x8: MMC1PRGHook16(0xC000,(DRegs[3]+offs)); + MMC1PRGHook16(0x8000,offs); + break; + case 0x0: + case 0x4: + MMC1PRGHook16(0x8000,((DRegs[3]&~1)+offs)); + MMC1PRGHook16(0xc000,((DRegs[3]&~1)+offs+1)); + break; + } + } + else + { + switch(DRegs[0]&0xC) + { + case 0xC: setprg16(0x8000,(DRegs[3]+offs)); + setprg16(0xC000,0xF+offs); + break; + case 0x8: setprg16(0xC000,(DRegs[3]+offs)); + setprg16(0x8000,offs); + break; + case 0x0: + case 0x4: + setprg16(0x8000,((DRegs[3]&~1)+offs)); + setprg16(0xc000,((DRegs[3]&~1)+offs+1)); + break; + } + } +} + +static void MMC1MIRROR(void) +{ + if(!is171) + switch(DRegs[0]&3) + { + case 2: setmirror(MI_V); break; + case 3: setmirror(MI_H); break; + case 0: setmirror(MI_0); break; + case 1: setmirror(MI_1); break; + } +} + +static uint64 lreset; +static DECLFW(MMC1_write) +{ + int n=(A>>13)-4; + /*FCEU_DispMessage("%016x",timestampbase+timestamp);*/ +/* FCEU_printf("$%04x:$%02x, $%04x\n",A,V,X.PC);*/ + /*DumpMem("out",0xe000,0xffff);*/ + + /* The MMC1 is busy so ignore the write. */ + /* As of version FCE Ultra 0.81, the timestamp is only + increased before each instruction is executed(in other words + precision isn't that great), but this should still work to + deal with 2 writes in a row from a single RMW instruction. + */ + if((timestampbase+timestamp)<(lreset+2)) + return; +/* FCEU_printf("Write %04x:%02x\n",A,V);*/ + if(V&0x80) + { + DRegs[0]|=0xC; + BufferShift=Buffer=0; + MMC1PRG(); + lreset=timestampbase+timestamp; + return; + } + + Buffer|=(V&1)<<(BufferShift++); + + if(BufferShift==5) + { +/* FCEU_printf("REG[%d]=%02x\n",n,Buffer);*/ + DRegs[n] = Buffer; + BufferShift = Buffer = 0; + switch(n) + { + case 0: MMC1MIRROR(); MMC1CHR(); MMC1PRG(); break; + case 1: MMC1CHR(); MMC1PRG(); break; + case 2: MMC1CHR(); break; + case 3: MMC1PRG(); break; + } + } +} + +static void MMC1_Restore(int version) +{ + MMC1MIRROR(); + MMC1CHR(); + MMC1PRG(); + lreset=0; /* timestamp(base) is not stored in save states. */ +} + +static void MMC1CMReset(void) +{ + int i; + + for(i=0;i<4;i++) + DRegs[i]=0; + Buffer = BufferShift = 0; + DRegs[0]=0x1F; + + DRegs[1]=0; + DRegs[2]=0; /* Should this be something other than 0?*/ + DRegs[3]=0; + + MMC1MIRROR(); + MMC1CHR(); + MMC1PRG(); +} + +static int DetectMMC1WRAMSize(uint32 crc32) +{ + switch(crc32) + { + case 0xc6182024: /* Romance of the 3 Kingdoms */ + case 0x2225c20f: /* Genghis Khan */ + case 0x4642dda6: /* Nobunaga's Ambition */ + case 0x29449ba9: /* "" "" (J) */ + case 0x2b11e0b0: /* "" "" (J) */ + case 0xb8747abf: /* Best Play Pro Yakyuu Special (J) */ + case 0xc9556b36: /* Final Fantasy I & II (J) [!] */ + FCEU_printf(" >8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); + return(16); + break; + default:return(8); + } +} + +static uint32 NWCIRQCount; +static uint8 NWCRec; +#define NWCDIP 0xE + +static void NWCIRQHook(int a) +{ + if(!(NWCRec&0x10)) + { + NWCIRQCount+=a; + if((NWCIRQCount|(NWCDIP<<25))>=0x3e000000) + { + NWCIRQCount=0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void NWCCHRHook(uint32 A, uint8 V) +{ + if((V&0x10)) /* && !(NWCRec&0x10))*/ + { + NWCIRQCount=0; + X6502_IRQEnd(FCEU_IQEXT); + } + + NWCRec=V; + if(V&0x08) + MMC1PRG(); + else + setprg32(0x8000,(V>>1)&3); +} + +static void NWCPRGHook(uint32 A, uint8 V) +{ + if(NWCRec&0x8) + setprg16(A,8|(V&0x7)); + else + setprg32(0x8000,(NWCRec>>1)&3); +} + +static void NWCPower(void) +{ + GenMMC1Power(); + setchr8r(0,0); +} + +void Mapper105_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 256, 8, 0); + MMC1CHRHook4=NWCCHRHook; + MMC1PRGHook16=NWCPRGHook; + MapIRQHook=NWCIRQHook; + info->Power=NWCPower; +} + +static void GenMMC1Power(void) +{ + lreset=0; + if(mmc1opts&1) + { + FCEU_CheatAddRAM(8,0x6000,WRAM); + if(mmc1opts&4) + FCEU_dwmemset(WRAM,0,8192) + else if(!(mmc1opts&2)) + FCEU_dwmemset(WRAM,0,8192); + } + SetWriteHandler(0x8000,0xFFFF,MMC1_write); + SetReadHandler(0x8000,0xFFFF,CartBR); + + if(mmc1opts&1) + { + SetReadHandler(0x6000,0x7FFF,MAWRAM); + SetWriteHandler(0x6000,0x7FFF,MBWRAM); + setprg8r(0x10,0x6000,0); + } + + MMC1CMReset(); +} + +static void GenMMC1Close(void) +{ + if(CHRRAM) + free(CHRRAM); + if(WRAM) + free(WRAM); + CHRRAM=WRAM=NULL; +} + +static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery) +{ + is155=0; + + info->Close=GenMMC1Close; + MMC1PRGHook16=MMC1CHRHook4=0; + mmc1opts=0; + PRGmask16[0]&=(prg>>14)-1; + CHRmask4[0]&=(chr>>12)-1; + CHRmask8[0]&=(chr>>13)-1; + + if(wram) + { + WRAM=(uint8*)FCEU_gmalloc(wram*1024); + mmc1opts|=1; + if(wram>8) mmc1opts|=4; + SetupCartPRGMapping(0x10,WRAM,wram*1024,1); + AddExState(WRAM, wram*1024, 0, "WRAM"); + if(battery) + { + mmc1opts|=2; + info->SaveGame[0]=WRAM+((mmc1opts&4)?8192:0); + info->SaveGameLen[0]=8192; + } + } + if(!chr) + { + CHRRAM=(uint8*)FCEU_gmalloc(8192); + SetupCartCHRMapping(0, CHRRAM, 8192, 1); + AddExState(CHRRAM, 8192, 0, "CHRR"); + } + AddExState(DRegs, 4, 0, "DREG"); + + info->Power=GenMMC1Power; + GameStateRestore=MMC1_Restore; + AddExState(&lreset, 8, 1, "LRST"); +} + +void Mapper1_Init(CartInfo *info) +{ + int ws=DetectMMC1WRAMSize(info->CRC32); + GenMMC1Init(info, 512, 256, ws, info->battery); +} + +/* Same as mapper 1, without respect for WRAM enable bit. */ +void Mapper155_Init(CartInfo *info) +{ + GenMMC1Init(info,512,256,8,info->battery); + is155=1; +} + +/* Same as mapper 1, with different (or without) mirroring control. */ +/* Kaiser KS7058 board, KS203 custom chip */ +void Mapper171_Init(CartInfo *info) +{ + GenMMC1Init(info,32,32,0,0); + is171=1; +} + +void SAROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 128, 64, 8, info->battery); +} + +void SBROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 128, 64, 0, 0); +} + +void SCROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 128, 128, 0, 0); +} + +void SEROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 32, 64, 0, 0); +} + +void SGROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 0, 0, 0); +} + +void SKROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 64, 8, info->battery); +} + +void SLROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 128, 0, 0); +} + +void SL1ROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 128, 128, 0, 0); +} + +/* Begin unknown - may be wrong - perhaps they use different MMC1s from the + similarly functioning boards? +*/ + +void SL2ROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 256, 0, 0); +} + +void SFROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 256, 0, 0); +} + +void SHROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 256, 0, 0); +} + +/* End unknown */ +/* */ +/* */ + +void SNROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 0, 8, info->battery); +} + +void SOROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 0, 16, info->battery); +} + + diff --git a/fceumm/src-fceumm/boards/mmc3.c b/fceumm/src-fceumm/boards/mmc3.c new file mode 100644 index 0000000..50e7083 --- /dev/null +++ b/fceumm/src-fceumm/boards/mmc3.c @@ -0,0 +1,1438 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 1998 BERO + * Copyright (C) 2003 Xodnizel + * Mapper 12 code Copyright (C) 2003 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* Code for emulating iNES mappers 4,12,44,45,47,49,52,74,114,115,116,118, + 119,165,205,245,249,250,254 +*/ + +#include "mapinc.h" +#include "mmc3.h" + +uint8 MMC3_cmd; +uint8 *WRAM; +uint8 *CHRRAM; +uint32 CHRRAMSize; +uint8 DRegBuf[8]; +uint8 EXPREGS[8]; /* For bootleg games, mostly. */ +uint8 A000B,A001B; + +#undef IRQCount +#undef IRQLatch +#undef IRQa +uint8 IRQCount,IRQLatch,IRQa; +uint8 IRQReload; + +static SFORMAT MMC3_StateRegs[]= +{ + {DRegBuf, 8, "REGS"}, + {&MMC3_cmd, 1, "CMD"}, + {&A000B, 1, "A000"}, + {&A001B, 1, "A001"}, + {&IRQReload, 1, "IRQR"}, + {&IRQCount, 1, "IRQC"}, + {&IRQLatch, 1, "IRQL"}, + {&IRQa, 1, "IRQA"}, + {0} +}; + +static int mmc3opts=0; +static int wrams; +static int isRevB=1; + +void (*pwrap)(uint32 A, uint8 V); +void (*cwrap)(uint32 A, uint8 V); +void (*mwrap)(uint8 V); + +void GenMMC3Power(void); +void FixMMC3PRG(int V); +void FixMMC3CHR(int V); + +void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery); + +/* ----------------------------------------------------------------------*/ +/* ------------------------- Generic MM3 Code ---------------------------*/ +/* ----------------------------------------------------------------------*/ + +void FixMMC3PRG(int V) +{ + if(V&0x40) + { + pwrap(0xC000,DRegBuf[6]); + pwrap(0x8000,~1); + } + else + { + pwrap(0x8000,DRegBuf[6]); + pwrap(0xC000,~1); + } + pwrap(0xA000,DRegBuf[7]); + pwrap(0xE000,~0); +} + +void FixMMC3CHR(int V) +{ + int cbase=(V&0x80)<<5; + + cwrap((cbase^0x000),DRegBuf[0]&(~1)); + cwrap((cbase^0x400),DRegBuf[0]|1); + cwrap((cbase^0x800),DRegBuf[1]&(~1)); + cwrap((cbase^0xC00),DRegBuf[1]|1); + + cwrap(cbase^0x1000,DRegBuf[2]); + cwrap(cbase^0x1400,DRegBuf[3]); + cwrap(cbase^0x1800,DRegBuf[4]); + cwrap(cbase^0x1c00,DRegBuf[5]); + + if(mwrap) mwrap(A000B); +} + +void MMC3RegReset(void) +{ + IRQCount=IRQLatch=IRQa=MMC3_cmd=0; + + DRegBuf[0]=0; + DRegBuf[1]=2; + DRegBuf[2]=4; + DRegBuf[3]=5; + DRegBuf[4]=6; + DRegBuf[5]=7; + DRegBuf[6]=0; + DRegBuf[7]=1; + + FixMMC3PRG(0); + FixMMC3CHR(0); +} + +DECLFW(MMC3_CMDWrite) +{ +/* FCEU_printf("bs %04x %02x\n",A,V);*/ + switch(A&0xE001) + { + case 0x8000: + if((V&0x40) != (MMC3_cmd&0x40)) + FixMMC3PRG(V); + if((V&0x80) != (MMC3_cmd&0x80)) + FixMMC3CHR(V); + MMC3_cmd = V; + break; + case 0x8001: + { + int cbase=(MMC3_cmd&0x80)<<5; + DRegBuf[MMC3_cmd&0x7]=V; + switch(MMC3_cmd&0x07) + { + case 0: cwrap((cbase^0x000),V&(~1)); + cwrap((cbase^0x400),V|1); + break; + case 1: cwrap((cbase^0x800),V&(~1)); + cwrap((cbase^0xC00),V|1); + break; + case 2: cwrap(cbase^0x1000,V); + break; + case 3: cwrap(cbase^0x1400,V); + break; + case 4: cwrap(cbase^0x1800,V); + break; + case 5: cwrap(cbase^0x1C00,V); + break; + case 6: + if(MMC3_cmd&0x40) + pwrap(0xC000,V); + else + pwrap(0x8000,V); + break; + case 7: + pwrap(0xA000,V); + break; + } + } + break; + case 0xA000: + if(mwrap) mwrap(V); + break; + case 0xA001: + A001B=V; +/* setprg8r(0x10,0x6000,A001B&3);*/ + break; + } +} + +DECLFW(MMC3_IRQWrite) +{ +/* FCEU_printf("%04x:%04x\n",A,V);*/ + switch(A&0xE001) + { + case 0xC000:IRQLatch=V;break; + case 0xC001:IRQReload=1;break; + case 0xE000:X6502_IRQEnd(FCEU_IQEXT);IRQa=0;break; + case 0xE001:IRQa=1;break; + } +} + +static void ClockMMC3Counter(void) +{ + int count = IRQCount; + if(!count || IRQReload) + { + IRQCount = IRQLatch; + IRQReload = 0; + } + else + IRQCount--; + if((count|isRevB) && !IRQCount) + { + if(IRQa) + { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void MMC3_hb(void) +{ + ClockMMC3Counter(); +} + +static void MMC3_hb_KickMasterHack(void) +{ + if(scanline==238) ClockMMC3Counter(); + ClockMMC3Counter(); +} + +static void MMC3_hb_PALStarWarsHack(void) +{ + if(scanline==240) ClockMMC3Counter(); + ClockMMC3Counter(); +} + +void GenMMC3Restore(int version) +{ + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void GENCWRAP(uint32 A, uint8 V) +{ + setchr1(A,V); /* Business Wars NEEDS THIS for 8K CHR-RAM*/ +} + +static void GENPWRAP(uint32 A, uint8 V) +{ + setprg8(A,V&0x7F); /* [NJ102] Mo Dao Jie (C) has 1024Mb MMC3 BOARD, maybe something other will be broken*/ +} + +static void GENMWRAP(uint8 V) +{ + A000B=V; + setmirror((V&1)^1); +} + +static void GENNOMWRAP(uint8 V) +{ + A000B=V; +} + +static DECLFW(MBWRAMMMC6) +{ + WRAM[A&0x3ff]=V; +} + +static DECLFR(MAWRAMMMC6) +{ + return(WRAM[A&0x3ff]); +} + +void GenMMC3Power(void) +{ + if(UNIFchrrama) setchr8(0); + + SetWriteHandler(0x8000,0xBFFF,MMC3_CMDWrite); + SetWriteHandler(0xC000,0xFFFF,MMC3_IRQWrite); + SetReadHandler(0x8000,0xFFFF,CartBR); + A001B=A000B=0; + setmirror(1); + if(mmc3opts&1) + { + if(wrams==1024) + { + FCEU_CheatAddRAM(1,0x7000,WRAM); + SetReadHandler(0x7000,0x7FFF,MAWRAMMMC6); + SetWriteHandler(0x7000,0x7FFF,MBWRAMMMC6); + } + else + { + FCEU_CheatAddRAM((wrams&0x1fff)>>10,0x6000,WRAM); + SetWriteHandler(0x6000,0x6000 + ((wrams - 1) & 0x1fff),CartBW); + SetReadHandler(0x6000,0x6000 + ((wrams - 1) & 0x1fff),CartBR); + setprg8r(0x10,0x6000,0); + } + if(!(mmc3opts&2)) + FCEU_dwmemset(WRAM,0,wrams); + } + MMC3RegReset(); + if(CHRRAM) + FCEU_dwmemset(CHRRAM,0,CHRRAMSize); +} + +static void GenMMC3Close(void) +{ + if(CHRRAM) + free(CHRRAM); + if(WRAM) + free(WRAM); + CHRRAM=WRAM=NULL; +} + +void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery) +{ + pwrap=GENPWRAP; + cwrap=GENCWRAP; + mwrap=GENMWRAP; + + wrams=wram<<10; + + PRGmask8[0]&=(prg>>13)-1; + CHRmask1[0]&=(chr>>10)-1; + CHRmask2[0]&=(chr>>11)-1; + + if(wram) + { + mmc3opts|=1; + WRAM=(uint8*)FCEU_gmalloc(wrams); + SetupCartPRGMapping(0x10,WRAM,wrams,1); + AddExState(WRAM, wrams, 0, "MMC3WRAM"); + } + + if(battery) + { + mmc3opts|=2; + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=wrams; + } + + AddExState(MMC3_StateRegs, ~0, 0, 0); + + info->Power=GenMMC3Power; + info->Reset=MMC3RegReset; + info->Close=GenMMC3Close; + + if(info->CRC32 == 0x5104833e) /* Kick Master*/ + GameHBIRQHook = MMC3_hb_KickMasterHack; + else if(info->CRC32 == 0x5a6860f1 || info->CRC32 == 0xae280e20) /* Shougi Meikan '92/'93*/ + GameHBIRQHook = MMC3_hb_KickMasterHack; + else if(info->CRC32 == 0xfcd772eb) /* PAL Star Wars, similar problem as Kick Master.*/ + GameHBIRQHook = MMC3_hb_PALStarWarsHack; + else + GameHBIRQHook=MMC3_hb; + GameStateRestore=GenMMC3Restore; +} + +/* ----------------------------------------------------------------------*/ +/* -------------------------- MMC3 Based Code ---------------------------*/ +/* ----------------------------------------------------------------------*/ + +/* ---------------------------- Mapper 4 --------------------------------*/ + +static int hackm4=0;/* For Karnov, maybe others. BLAH. Stupid iNES format.*/ + +static void M4Power(void) +{ + GenMMC3Power(); + A000B=(hackm4^1)&1; + setmirror(hackm4); +} + +void Mapper4_Init(CartInfo *info) +{ + int ws=8; + + if((info->CRC32==0x93991433 || info->CRC32==0xaf65aa84)) + { + FCEU_printf("Low-G-Man can not work normally in the iNES format.\nThis game has been recognized by its CRC32 value, and the appropriate changes will be made so it will run.\nIf you wish to hack this game, you should use the UNIF format for your hack.\n\n"); + ws=0; + } + GenMMC3_Init(info,512,256,ws,info->battery); + info->Power=M4Power; + hackm4=info->mirror; +} + +/* ---------------------------- Mapper 12 -------------------------------*/ + +static void M12CW(uint32 A, uint8 V) +{ + setchr1(A,(EXPREGS[(A&0x1000)>>12]<<8)+V); +} + +static DECLFW(M12Write) +{ + EXPREGS[0]=V&0x01; + EXPREGS[1]=(V&0x10)>>4; +} + +static void M12Power(void) +{ + EXPREGS[0]=EXPREGS[1]=0; + GenMMC3Power(); + SetWriteHandler(0x4100,0x5FFF,M12Write); +} + +void Mapper12_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M12CW; + info->Power=M12Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} + +/* ---------------------------- Mapper 37 -------------------------------*/ + +static void M37PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]!=2) + V&=0x7; + else + V&=0xF; + V|=EXPREGS[0]<<3; + setprg8(A,V); +} + +static void M37CW(uint32 A, uint8 V) +{ + uint32 NV=V; + NV&=0x7F; + NV|=EXPREGS[0]<<6; + setchr1(A,NV); +} + +static DECLFW(M37Write) +{ + EXPREGS[0]=(V&6)>>1; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M37Reset(void) +{ + EXPREGS[0]=0; + MMC3RegReset(); +} + +static void M37Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,M37Write); +} + +void Mapper37_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + pwrap=M37PW; + cwrap=M37CW; + info->Power=M37Power; + info->Reset=M37Reset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +/* ---------------------------- Mapper 44 -------------------------------*/ + +static void M44PW(uint32 A, uint8 V) +{ + uint32 NV=V; + if(EXPREGS[0]>=6) NV&=0x1F; + else NV&=0x0F; + NV|=EXPREGS[0]<<4; + setprg8(A,NV); +} + +static void M44CW(uint32 A, uint8 V) +{ + uint32 NV=V; + if(EXPREGS[0]<6) NV&=0x7F; + NV|=EXPREGS[0]<<7; + setchr1(A,NV); +} + +static DECLFW(M44Write) +{ + if(A&1) + { + EXPREGS[0]=V&7; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } + else + MMC3_CMDWrite(A,V); +} + +static void M44Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); + SetWriteHandler(0xA000,0xBFFF,M44Write); +} + +void Mapper44_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M44CW; + pwrap=M44PW; + info->Power=M44Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +/* ---------------------------- Mapper 45 -------------------------------*/ + +static void M45CW(uint32 A, uint8 V) +{ + if(!UNIFchrrama) + { + uint32 NV=V; + if(EXPREGS[2]&8) + NV&=(1<<((EXPREGS[2]&7)+1))-1; + else + if(EXPREGS[2]) + NV&=0; /* hack ;( don't know exactly how it should be*/ + NV|=EXPREGS[0]|((EXPREGS[2]&0xF0)<<4); + setchr1(A,NV); + } +} + +static void M45PW(uint32 A, uint8 V) +{ + V&=(EXPREGS[3]&0x3F)^0x3F; + V|=EXPREGS[1]; + setprg8(A,V); +} + +static DECLFW(M45Write) +{ + if(EXPREGS[3]&0x40) + { + WRAM[A-0x6000]=V; + return; + } + EXPREGS[EXPREGS[4]]=V; + EXPREGS[4]=(EXPREGS[4]+1)&3; +/* if(!EXPREGS[4]) */ +/* {*/ +/* FCEU_printf("CHROR %02x, PRGOR %02x, CHRAND %02x, PRGAND %02x\n",EXPREGS[0],EXPREGS[1],EXPREGS[2],EXPREGS[3]);*/ +/* FCEU_printf("CHR0 %03x, CHR1 %03x, PRG0 %03x, PRG1 %03x\n",*/ +/* (0x00&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)),*/ +/* (0xFF&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)),*/ +/* (0x00&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1]),*/ +/* (0xFF&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1]));*/ +/* }*/ + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static DECLFR(M45Read) +{ + uint32 addr = 1<<(EXPREGS[5]+4); + if(A&(addr|(addr-1))) + return X.DB | 1; + else + return X.DB; +} + +static void M45Reset(void) +{ + EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=EXPREGS[4]=0; + EXPREGS[5]++; + EXPREGS[5] &= 7; + MMC3RegReset(); +} + +static void M45Power(void) +{ + setchr8(0); + GenMMC3Power(); + EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=EXPREGS[4]=EXPREGS[5]=0; + SetWriteHandler(0x5000,0x7FFF,M45Write); + SetReadHandler(0x5000,0x5FFF,M45Read); +} + +void Mapper45_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M45CW; + pwrap=M45PW; + info->Reset=M45Reset; + info->Power=M45Power; + AddExState(EXPREGS, 5, 0, "EXPR"); +} + +/* ---------------------------- Mapper 47 -------------------------------*/ + +static void M47PW(uint32 A, uint8 V) +{ + V&=0xF; + V|=EXPREGS[0]<<4; + setprg8(A,V); +} + +static void M47CW(uint32 A, uint8 V) +{ + uint32 NV=V; + NV&=0x7F; + NV|=EXPREGS[0]<<7; + setchr1(A,NV); +} + +static DECLFW(M47Write) +{ + EXPREGS[0]=V&1; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M47Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,M47Write); +/* SetReadHandler(0x6000,0x7FFF,0);*/ +} + +void Mapper47_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, 0); + pwrap=M47PW; + cwrap=M47CW; + info->Power=M47Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +/* ---------------------------- Mapper 49 -------------------------------*/ + +static void M49PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&1) + { + V&=0xF; + V|=(EXPREGS[0]&0xC0)>>2; + setprg8(A,V); + } + else + setprg32(0x8000,(EXPREGS[0]>>4)&3); +} + +static void M49CW(uint32 A, uint8 V) +{ + uint32 NV=V; + NV&=0x7F; + NV|=(EXPREGS[0]&0xC0)<<1; + setchr1(A,NV); +} + +static DECLFW(M49Write) +{ + if(A001B&0x80) + { + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } +} + +static void M49Reset(void) +{ + EXPREGS[0]=0; + MMC3RegReset(); +} + +static void M49Power(void) +{ + M49Reset(); + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,M49Write); + SetReadHandler(0x6000,0x7FFF,0); +} + +void Mapper49_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 0, 0); + cwrap=M49CW; + pwrap=M49PW; + info->Reset=M49Reset; + info->Power=M49Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +/* ---------------------------- Mapper 52 -------------------------------*/ + +static void M52PW(uint32 A, uint8 V) +{ + uint32 NV=V; + NV&=0x1F^((EXPREGS[0]&8)<<1); + NV|=((EXPREGS[0]&6)|((EXPREGS[0]>>3)&EXPREGS[0]&1))<<4; + setprg8(A,NV); +} + +static void M52CW(uint32 A, uint8 V) +{ + uint32 NV=V; + NV&=0xFF^((EXPREGS[0]&0x40)<<1); + NV|=(((EXPREGS[0]>>3)&4)|((EXPREGS[0]>>1)&2)|((EXPREGS[0]>>6)&(EXPREGS[0]>>4)&1))<<7; + setchr1(A,NV); +} + +static DECLFW(M52Write) +{ + if(EXPREGS[1]) + { + WRAM[A-0x6000]=V; + return; + } + EXPREGS[1]=1; + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M52Reset(void) +{ + EXPREGS[0]=EXPREGS[1]=0; + MMC3RegReset(); +} + +static void M52Power(void) +{ + M52Reset(); + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,M52Write); +} + +void Mapper52_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M52CW; + pwrap=M52PW; + info->Reset=M52Reset; + info->Power=M52Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} + +/* ---------------------------- Mapper 74 -------------------------------*/ + +static void M74CW(uint32 A, uint8 V) +{ + if((V==8)||(V==9)) /*Di 4 Ci - Ji Qi Ren Dai Zhan (As).nes, Ji Jia Zhan Shi (As).nes*/ + setchr1r(0x10,A,V); + else + setchr1r(0,A,V); +} + +void Mapper74_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M74CW; + CHRRAMSize=2048; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); +} + +/* ---------------------------- Mapper 114 ------------------------------*/ + +static uint8 cmdin; +uint8 m114_perm[8] = {0, 3, 1, 5, 6, 7, 2, 4}; + +static void M114PWRAP(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x80) + { +/* FCEU_printf("8000-C000:%02X\n",EXPREGS[0]&0xF);*/ + setprg16(0x8000,EXPREGS[0]&0xF); + setprg16(0xC000,EXPREGS[0]&0xF); + } + else { +/* FCEU_printf("%04X:%02X\n",A,V&0x3F);*/ + setprg8(A,V&0x3F); + } +} + +static DECLFW(M114Write) +{ + switch(A&0xE001) + { + case 0x8001: MMC3_CMDWrite(0xA000,V); break; + case 0xA000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m114_perm[V&7])); cmdin=1; break; + case 0xC000: if(!cmdin) break; MMC3_CMDWrite(0x8001,V); cmdin=0; break; + case 0xA001: IRQLatch=V; break; + case 0xC001: IRQReload=1; break; + case 0xE000: X6502_IRQEnd(FCEU_IQEXT);IRQa=0; break; + case 0xE001: IRQa=1; break; + } +} + +static DECLFW(M114ExWrite) +{ + if(A<=0x7FFF) + { + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + } +} + +static void M114Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x8000,0xFFFF,M114Write); + SetWriteHandler(0x5000,0x7FFF,M114ExWrite); +} + +static void M114Reset(void) +{ + EXPREGS[0]=0; + MMC3RegReset(); +} + +void Mapper114_Init(CartInfo *info) +{ + isRevB=0; + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap=M114PWRAP; + info->Power=M114Power; + info->Reset=M114Reset; + AddExState(EXPREGS, 1, 0, "EXPR"); + AddExState(&cmdin, 1, 0, "CMDIN"); +} + +/* ---------------------------- Mapper 115 KN-658 board ------------------------------*/ + +static void M115PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x80) + setprg32(0x8000,(EXPREGS[0]&7)>>1); + else + setprg8(A,V); +} + +static void M115CW(uint32 A, uint8 V) +{ + setchr1(A,(uint32)V|((EXPREGS[1]&1)<<8)); +} + +static DECLFW(M115Write) +{ +/* FCEU_printf("%04x:%04x\n",A,V);*/ + if(A==0x5080) EXPREGS[2]=V; + if(A==0x6000) + EXPREGS[0]=V; + else if(A==0x6001) + EXPREGS[1]=V; + FixMMC3PRG(MMC3_cmd); +} + +static DECLFR(M115Read) +{ + return EXPREGS[2]; +} + +static void M115Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x4100,0x7FFF,M115Write); + SetReadHandler(0x5000,0x5FFF,M115Read); +} + +void Mapper115_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 512, 0, 0); + cwrap=M115CW; + pwrap=M115PW; + info->Power=M115Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} + +/* ---------------------------- Mapper 118 ------------------------------*/ + +static uint8 PPUCHRBus; +static uint8 TKSMIR[8]; + +static void TKSPPU(uint32 A) +{ + A&=0x1FFF; + A>>=10; + PPUCHRBus=A; + setmirror(MI_0+TKSMIR[A]); +} + +static void TKSWRAP(uint32 A, uint8 V) +{ + TKSMIR[A>>10]=V>>7; + setchr1(A,V&0x7F); + if(PPUCHRBus==(A>>10)) + setmirror(MI_0+(V>>7)); +} + +/* ---------------------------- Mapper 119 ------------------------------*/ + +static void TQWRAP(uint32 A, uint8 V) +{ + setchr1r((V&0x40)>>2,A,V&0x3F); +} + +void Mapper119_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 64, 0, 0); + cwrap=TQWRAP; + CHRRAMSize=8192; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); +} + +/* ---------------------------- Mapper 134 ------------------------------*/ + +static void M134PW(uint32 A, uint8 V) +{ + setprg8(A,(V&0x1F)|((EXPREGS[0]&2)<<4)); +} + +static void M134CW(uint32 A, uint8 V) +{ + setchr1(A,(V&0xFF)|((EXPREGS[0]&0x20)<<3)); +} + +static DECLFW(M134Write) +{ + EXPREGS[0]=V; + FixMMC3CHR(MMC3_cmd); + FixMMC3PRG(MMC3_cmd); +} + +static void M134Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); + SetWriteHandler(0x6001,0x6001,M134Write); +} + +static void M134Reset(void) +{ + EXPREGS[0]=0; + MMC3RegReset(); +} + +void Mapper134_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap=M134PW; + cwrap=M134CW; + info->Power=M134Power; + info->Reset=M134Reset; + AddExState(EXPREGS, 4, 0, "EXPR"); +} + +/* ---------------------------- Mapper 165 ------------------------------*/ + +static void M165CW(uint32 A, uint8 V) +{ + if(V==0) + setchr4r(0x10,A,0); + else + setchr4(A,V>>2); +} + +static void M165PPUFD(void) +{ + if(EXPREGS[0]==0xFD) + { + M165CW(0x0000,DRegBuf[0]); + M165CW(0x1000,DRegBuf[2]); + } +} + +static void M165PPUFE(void) +{ + if(EXPREGS[0]==0xFE) + { + M165CW(0x0000,DRegBuf[1]); + M165CW(0x1000,DRegBuf[4]); + } +} + +static void M165CWM(uint32 A, uint8 V) +{ + if(((MMC3_cmd&0x7)==0)||((MMC3_cmd&0x7)==2)) + M165PPUFD(); + if(((MMC3_cmd&0x7)==1)||((MMC3_cmd&0x7)==4)) + M165PPUFE(); +} + +static void M165PPU(uint32 A) +{ + if((A&0x1FF0)==0x1FD0) + { + EXPREGS[0]=0xFD; + M165PPUFD(); + } else if((A&0x1FF0)==0x1FE0) + { + EXPREGS[0]=0xFE; + M165PPUFE(); + } +} + +static void M165Power(void) +{ + EXPREGS[0]=0xFD; + GenMMC3Power(); +} + +void Mapper165_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 128, 8, info->battery); + cwrap=M165CWM; + PPU_hook=M165PPU; + info->Power=M165Power; + CHRRAMSize = 4096; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); + AddExState(EXPREGS, 4, 0, "EXPR"); +} + +/* ---------------------------- Mapper 191 ------------------------------*/ + +static void M191CW(uint32 A, uint8 V) +{ + setchr1r((V&0x80)>>3,A,V); +} + +void Mapper191_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 8, info->battery); + cwrap=M191CW; + CHRRAMSize=2048; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); +} + +/* ---------------------------- Mapper 192 -------------------------------*/ + +static void M192CW(uint32 A, uint8 V) +{ + if((V==8)||(V==9)||(V==0xA)||(V==0xB)) /*Ying Lie Qun Xia Zhuan (Chinese),*/ + setchr1r(0x10,A,V); + else + setchr1r(0,A,V); +} + +void Mapper192_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M192CW; + CHRRAMSize=4096; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); +} + +/* ---------------------------- Mapper 194 -------------------------------*/ + +static void M194CW(uint32 A, uint8 V) +{ + if(V<=1) /*Dai-2-Ji - Super Robot Taisen (As).nes*/ + setchr1r(0x10,A,V); + else + setchr1r(0,A,V); +} + +void Mapper194_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M194CW; + CHRRAMSize=2048; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); +} + +/* ---------------------------- Mapper 195 -------------------------------*/ +static uint8 *wramtw; +static uint16 wramsize; + +static void M195CW(uint32 A, uint8 V) +{ + if(V<=3) /* Crystalis (c).nes, Captain Tsubasa Vol 2 - Super Striker (C)*/ + setchr1r(0x10,A,V); + else + setchr1r(0,A,V); +} + +static void M195Power(void) +{ + GenMMC3Power(); + setprg4r(0x10,0x5000,0); + SetWriteHandler(0x5000,0x5fff,CartBW); + SetReadHandler(0x5000,0x5fff,CartBR); +} + +static void M195Close(void) +{ + if(wramtw) + free(wramtw); + wramtw=NULL; +} + +void Mapper195_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M195CW; + info->Power=M195Power; + info->Close=M195Close; + CHRRAMSize=4096; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + wramsize=4096; + wramtw=(uint8*)FCEU_gmalloc(wramsize); + SetupCartPRGMapping(0x10, wramtw, wramsize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); + AddExState(wramtw, wramsize, 0, "WRAMTW"); +} + +/* ---------------------------- Mapper 196 -------------------------------*/ +/* MMC3 board with optional command address line connection, allows to */ +/* make three-four different wirings to IRQ address lines and separately to*/ +/* CMD address line, Mali Boss additionally check if wiring are correct for*/ +/* game */ + +static DECLFW(Mapper196Write) +{ + if(A >= 0xC000) { + A=(A&0xFFFE)|((A>>2)&1)|((A>>3)&1); + MMC3_IRQWrite(A,V); + } + else { + A=(A&0xFFFE)|((A>>2)&1)|((A>>3)&1)|((A>>1)&1); + MMC3_CMDWrite(A,V); + } +} + +static void Mapper196Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x8000,0xFFFF,Mapper196Write); +} + +void Mapper196_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 128, 0, 0); + info->Power=Mapper196Power; +} + +/* ---------------------------- Mapper 197 -------------------------------*/ + +static void M197CW(uint32 A, uint8 V) +{ + if(A==0x0000) + setchr4(0x0000,V>>1); + else if(A==0x1000) + setchr2(0x1000,V); + else if(A==0x1400) + setchr2(0x1800,V); +} + +void Mapper197_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 512, 8, 0); + cwrap=M197CW; +} + +/* ---------------------------- Mapper 198 -------------------------------*/ + +static void M198PW(uint32 A, uint8 V) +{ + if(V>=0x50) /* Tenchi o Kurau II - Shokatsu Koumei Den (J) (C).nes*/ + setprg8(A,V&0x4F); + else + setprg8(A,V); +} + +void Mapper198_Init(CartInfo *info) +{ + GenMMC3_Init(info, 1024, 256, 8, info->battery); + pwrap=M198PW; + info->Power=M195Power; + info->Close=M195Close; + wramsize=4096; + wramtw=(uint8*)FCEU_gmalloc(wramsize); + SetupCartPRGMapping(0x10, wramtw, wramsize, 1); + AddExState(wramtw, wramsize, 0, "WRAMTW"); +} + +/* ---------------------------- Mapper 205 ------------------------------*/ +/* GN-45 BOARD*/ + +static void M205PW(uint32 A, uint8 V) +{ +/* GN-30A - íà÷àëüíàÿ ìàñêà äîëæíà áûòü 1F + àïïàðàòíûé ïåðåêëþ÷àòåëü íà øèíå àäðåñà*/ + setprg8(A,(V&0x0f)|EXPREGS[0]); +} + +static void M205CW(uint32 A, uint8 V) +{ +/* GN-30A - íà÷àëüíàÿ ìàñêà äîëæíà áûòü FF*/ + setchr1(A,(V&0x7F)|(EXPREGS[0]<<3)); +} + +static DECLFW(M205Write) +{ + if(EXPREGS[2] == 0) { + EXPREGS[0] = A & 0x30; + EXPREGS[2] = A & 0x80; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } + else + CartBW(A,V); +} + +static void M205Reset(void) +{ + EXPREGS[0]=EXPREGS[2]=0; + MMC3RegReset(); +} + +static void M205Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x6000,0x6fff,M205Write); +} + +void Mapper205_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 8, 0); + pwrap=M205PW; + cwrap=M205CW; + info->Power=M205Power; + info->Reset=M205Reset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +/* ---------------------------- Mapper 245 ------------------------------*/ + +static void M245CW(uint32 A, uint8 V) +{ + if(!UNIFchrrama) /* Yong Zhe Dou E Long - Dragon Quest VI (As).nes NEEDS THIS for RAM cart*/ + setchr1(A,V&7); + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); +} + +static void M245PW(uint32 A, uint8 V) +{ + setprg8(A,(V&0x3F)|((EXPREGS[0]&2)<<5)); +} + +static void M245Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); +} + +void Mapper245_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M245CW; + pwrap=M245PW; + info->Power=M245Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +/* ---------------------------- Mapper 249 ------------------------------*/ + +static void M249PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x2) + { + if(V<0x20) + V=(V&1)|((V>>3)&2)|((V>>1)&4)|((V<<2)&8)|((V<<2)&0x10); + else + { + V-=0x20; + V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0); + } + } + setprg8(A,V); +} + +static void M249CW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x2) + V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0); + setchr1(A,V); +} + +static DECLFW(M249Write) +{ + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M249Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); + SetWriteHandler(0x5000,0x5000,M249Write); +} + +void Mapper249_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M249CW; + pwrap=M249PW; + info->Power=M249Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +/* ---------------------------- Mapper 250 ------------------------------*/ + +static DECLFW(M250Write) +{ + MMC3_CMDWrite((A&0xE000)|((A&0x400)>>10),A&0xFF); +} + +static DECLFW(M250IRQWrite) +{ + MMC3_IRQWrite((A&0xE000)|((A&0x400)>>10),A&0xFF); +} + +static void M250_Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x8000,0xBFFF,M250Write); + SetWriteHandler(0xC000,0xFFFF,M250IRQWrite); +} + +void Mapper250_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + info->Power=M250_Power; +} + +/* ---------------------------- Mapper 254 ------------------------------*/ + +static DECLFR(MR254WRAM) +{ + if(EXPREGS[0]) + return WRAM[A-0x6000]; + else + return WRAM[A-0x6000]^EXPREGS[1]; +} + +static DECLFW(M254Write) +{ + switch (A) { + case 0x8000: EXPREGS[0]=0xff; + break; + case 0xA001: EXPREGS[1]=V; + } + MMC3_CMDWrite(A,V); +} + +static void M254_Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x8000,0xBFFF,M254Write); + SetReadHandler(0x6000,0x7FFF,MR254WRAM); +} + +void Mapper254_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 128, 8, info->battery); + info->Power=M254_Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} + +/* ---------------------------- UNIF Boards -----------------------------*/ + +void TBROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 64, 64, 0, 0); +} + +void TEROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 32, 32, 0, 0); +} + +void TFROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 64, 0, 0); +} + +void TGROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 0, 0, 0); +} + +void TKROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); +} + +void TLROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 0, 0); +} + +void TSROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, 0); +} + +void TLSROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, 0); + cwrap=TKSWRAP; + mwrap=GENNOMWRAP; + PPU_hook=TKSPPU; + AddExState(&PPUCHRBus, 1, 0, "PPUC"); +} + +void TKSROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=TKSWRAP; + mwrap=GENNOMWRAP; + PPU_hook=TKSPPU; + AddExState(&PPUCHRBus, 1, 0, "PPUC"); +} + +void TQROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 64, 0, 0); + cwrap=TQWRAP; + CHRRAMSize=8192; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); +} + +void HKROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 512, 1, info->battery); +} diff --git a/fceumm/src-fceumm/boards/mmc3.h b/fceumm/src-fceumm/boards/mmc3.h new file mode 100644 index 0000000..a5e03cd --- /dev/null +++ b/fceumm/src-fceumm/boards/mmc3.h @@ -0,0 +1,25 @@ +extern uint8 MMC3_cmd; +extern uint8 A000B; +extern uint8 A001B; +extern uint8 EXPREGS[8]; +extern uint8 DRegBuf[8]; + +#undef IRQCount +#undef IRQLatch +#undef IRQa +extern uint8 IRQCount,IRQLatch,IRQa; +extern uint8 IRQReload; + +extern void (*pwrap)(uint32 A, uint8 V); +extern void (*cwrap)(uint32 A, uint8 V); +extern void (*mwrap)(uint8 V); + +void GenMMC3Power(void); +void GenMMC3Restore(int version); +void MMC3RegReset(void); +void FixMMC3PRG(int V); +void FixMMC3CHR(int V); +DECLFW(MMC3_CMDWrite); +DECLFW(MMC3_IRQWrite); + +void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery); diff --git a/fceumm/src-fceumm/boards/mmc5.c b/fceumm/src-fceumm/boards/mmc5.c new file mode 100644 index 0000000..79cee0f --- /dev/null +++ b/fceumm/src-fceumm/boards/mmc5.c @@ -0,0 +1,831 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* None of this code should use any of the iNES bank switching wrappers. */ + +#include "mapinc.h" + +static void (*sfun)(int P); +static void (*psfun)(void); + +void MMC5RunSound(int Count); +void MMC5RunSoundHQ(void); + +static INLINE void MMC5SPRVROM_BANK1(uint32 A,uint32 V) +{ + if(CHRptr[0]) + { + V&=CHRmask1[0]; + MMC5SPRVPage[(A)>>10]=&CHRptr[0][(V)<<10]-(A); + } +} + +static INLINE void MMC5BGVROM_BANK1(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask1[0];MMC5BGVPage[(A)>>10]=&CHRptr[0][(V)<<10]-(A);}} + +static INLINE void MMC5SPRVROM_BANK2(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask2[0];MMC5SPRVPage[(A)>>10]=MMC5SPRVPage[((A)>>10)+1]=&CHRptr[0][(V)<<11]-(A);}} +static INLINE void MMC5BGVROM_BANK2(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask2[0];MMC5BGVPage[(A)>>10]=MMC5BGVPage[((A)>>10)+1]=&CHRptr[0][(V)<<11]-(A);}} + +static INLINE void MMC5SPRVROM_BANK4(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask4[0];MMC5SPRVPage[(A)>>10]=MMC5SPRVPage[((A)>>10)+1]= MMC5SPRVPage[((A)>>10)+2]=MMC5SPRVPage[((A)>>10)+3]=&CHRptr[0][(V)<<12]-(A);}} +static INLINE void MMC5BGVROM_BANK4(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask4[0];MMC5BGVPage[(A)>>10]=MMC5BGVPage[((A)>>10)+1]=MMC5BGVPage[((A)>>10)+2]=MMC5BGVPage[((A)>>10)+3]=&CHRptr[0][(V)<<12]-(A);}} + +static INLINE void MMC5SPRVROM_BANK8(uint32 V) {if(CHRptr[0]){V&=CHRmask8[0];MMC5SPRVPage[0]=MMC5SPRVPage[1]=MMC5SPRVPage[2]=MMC5SPRVPage[3]=MMC5SPRVPage[4]=MMC5SPRVPage[5]=MMC5SPRVPage[6]=MMC5SPRVPage[7]=&CHRptr[0][(V)<<13];}} +static INLINE void MMC5BGVROM_BANK8(uint32 V) {if(CHRptr[0]){V&=CHRmask8[0];MMC5BGVPage[0]=MMC5BGVPage[1]=MMC5BGVPage[2]=MMC5BGVPage[3]=MMC5BGVPage[4]=MMC5BGVPage[5]=MMC5BGVPage[6]=MMC5BGVPage[7]=&CHRptr[0][(V)<<13];}} + +static uint8 PRGBanks[4]; +static uint8 WRAMPage; +static uint8 CHRBanksA[8], CHRBanksB[4]; +static uint8 WRAMMaskEnable[2]; +static uint8 ABMode; /* A=0, B=1 */ + +static uint8 IRQScanline,IRQEnable; +static uint8 CHRMode, NTAMirroring, NTFill, ATFill; + +static uint8 MMC5IRQR; +static uint8 MMC5LineCounter; +static uint8 mmc5psize, mmc5vsize; +static uint8 mul[2]; + +static uint8 *WRAM=NULL; +static uint8 *MMC5fill=NULL; +static uint8 *ExRAM=NULL; + +static uint8 MMC5WRAMsize; +static uint8 MMC5WRAMIndex[8]; + +static uint8 MMC5ROMWrProtect[4]; +static uint8 MMC5MemIn[5]; + +static void MMC5CHRA(void); +static void MMC5CHRB(void); + +typedef struct __cartdata { + uint32 crc32; + uint8 size; +} cartdata; + + +/* ETROM seems to have 16KB of WRAM, ELROM seems to have 8KB*/ +/* EWROM seems to have 32KB of WRAM*/ + +cartdata MMC5CartList[]= +{ + {0x9c18762b,2}, /* L'Empereur */ + {0x26533405,2}, + {0x6396b988,2}, + + {0xaca15643,2}, /* Uncharted Waters */ + {0xfe3488d1,2}, /* Dai Koukai Jidai */ + + {0x15fe6d0f,2}, /* BKAC */ + {0x39f2ce4b,2}, /* Suikoden */ + + {0x8ce478db,2}, /* Nobunaga's Ambition 2 */ + {0xeee9a682,2}, + {0xf9b4240f,2}, + + {0x1ced086f,2}, /* Ishin no Arashi */ + + {0xf540677b,4}, /* Nobunaga...Bushou Fuuun Roku */ + + {0x6f4e4312,4}, /* Aoki Ookami..Genchou */ + + {0xf011e490,4}, /* Romance of the 3 Kingdoms 2 */ + {0x184c2124,4}, /* Sangokushi 2 */ + {0xee8e6553,4}, +}; + +#define MMC5_NOCARTS (sizeof(MMC5CartList)/sizeof(MMC5CartList[0])) +int DetectMMC5WRAMSize(uint32 crc32) +{ + int x; + for(x=0;x8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); + return(MMC5CartList[x].size*8); + } + return(8); +} + +static void BuildWRAMSizeTable(void) +{ + int x; + for(x=0;x<8;x++) + { + switch(MMC5WRAMsize) + { + case 0: MMC5WRAMIndex[x]=255; break; + case 1: MMC5WRAMIndex[x]=(x>3)?255:0; break; + case 2: MMC5WRAMIndex[x]=(x&4)>>2; break; + case 4: MMC5WRAMIndex[x]=(x>3)?255:(x&3); break; + } + } +} + +static void MMC5CHRA(void) +{ + int x; + switch(mmc5vsize&3) + { + case 0: setchr8(CHRBanksA[7]); + MMC5SPRVROM_BANK8(CHRBanksA[7]); + break; + case 1: setchr4(0x0000,CHRBanksA[3]); + setchr4(0x1000,CHRBanksA[7]); + MMC5SPRVROM_BANK4(0x0000,CHRBanksA[3]); + MMC5SPRVROM_BANK4(0x1000,CHRBanksA[7]); + break; + case 2: setchr2(0x0000,CHRBanksA[1]); + setchr2(0x0800,CHRBanksA[3]); + setchr2(0x1000,CHRBanksA[5]); + setchr2(0x1800,CHRBanksA[7]); + MMC5SPRVROM_BANK2(0x0000,CHRBanksA[1]); + MMC5SPRVROM_BANK2(0x0800,CHRBanksA[3]); + MMC5SPRVROM_BANK2(0x1000,CHRBanksA[5]); + MMC5SPRVROM_BANK2(0x1800,CHRBanksA[7]); + break; + case 3: for(x=0;x<8;x++) + { + setchr1(x<<10,CHRBanksA[x]); + MMC5SPRVROM_BANK1(x<<10,CHRBanksA[x]); + } + break; + } +} + +static void MMC5CHRB(void) +{ + int x; + switch(mmc5vsize&3) + { + case 0: setchr8(CHRBanksB[3]); + MMC5BGVROM_BANK8(CHRBanksB[3]); + break; + case 1: setchr4(0x0000,CHRBanksB[3]); + setchr4(0x1000,CHRBanksB[3]); + MMC5BGVROM_BANK4(0x0000,CHRBanksB[3]); + MMC5BGVROM_BANK4(0x1000,CHRBanksB[3]); + break; + case 2: setchr2(0x0000,CHRBanksB[1]); + setchr2(0x0800,CHRBanksB[3]); + setchr2(0x1000,CHRBanksB[1]); + setchr2(0x1800,CHRBanksB[3]); + MMC5BGVROM_BANK2(0x0000,CHRBanksB[1]); + MMC5BGVROM_BANK2(0x0800,CHRBanksB[3]); + MMC5BGVROM_BANK2(0x1000,CHRBanksB[1]); + MMC5BGVROM_BANK2(0x1800,CHRBanksB[3]); + break; + case 3: for(x=0;x<8;x++) + { + setchr1(x<<10,CHRBanksB[x&3]); + MMC5BGVROM_BANK1(x<<10,CHRBanksB[x&3]); + } + break; + } +} + +static void MMC5WRAM(uint32 A, uint32 V) +{ + /*printf("%02x\n",V);*/ + V=MMC5WRAMIndex[V&7]; + if(V!=255) + { + setprg8r(0x10,A,V); + MMC5MemIn[(A-0x6000)>>13]=1; + } + else + MMC5MemIn[(A-0x6000)>>13]=0; +} + +static void MMC5PRG(void) +{ + int x; + switch(mmc5psize&3) + { + case 0: MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]= + MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1; + setprg32(0x8000,((PRGBanks[1]&0x7F)>>2)); + for(x=0;x<4;x++) + MMC5MemIn[1+x]=1; + break; + case 1: if(PRGBanks[1]&0x80) + { + MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1; + setprg16(0x8000,(PRGBanks[1]>>1)); + MMC5MemIn[1]=MMC5MemIn[2]=1; + } + else + { + MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0; + MMC5WRAM(0x8000,PRGBanks[1]&7&0xFE); + MMC5WRAM(0xA000,(PRGBanks[1]&7&0xFE)+1); + } + MMC5MemIn[3]=MMC5MemIn[4]=1; + MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1; + setprg16(0xC000,(PRGBanks[3]&0x7F)>>1); + break; + case 2: if(PRGBanks[1]&0x80) + { + MMC5MemIn[1]=MMC5MemIn[2]=1; + MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1; + setprg16(0x8000,(PRGBanks[1]&0x7F)>>1); + } + else + { + MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0; + MMC5WRAM(0x8000,PRGBanks[1]&7&0xFE); + MMC5WRAM(0xA000,(PRGBanks[1]&7&0xFE)+1); + } + if(PRGBanks[2]&0x80) + { + MMC5ROMWrProtect[2]=1; + MMC5MemIn[3]=1; + setprg8(0xC000,PRGBanks[2]&0x7F); + } + else + { + MMC5ROMWrProtect[2]=0; + MMC5WRAM(0xC000,PRGBanks[2]&7); + } + MMC5MemIn[4]=1; + MMC5ROMWrProtect[3]=1; + setprg8(0xE000,PRGBanks[3]&0x7F); + break; + case 3: for(x=0;x<3;x++) + if(PRGBanks[x]&0x80) + { + MMC5ROMWrProtect[x]=1; + setprg8(0x8000+(x<<13),PRGBanks[x]&0x7F); + MMC5MemIn[1+x]=1; + } + else + { + MMC5ROMWrProtect[x]=0; + MMC5WRAM(0x8000+(x<<13),PRGBanks[x]&7); + } + MMC5MemIn[4]=1; + MMC5ROMWrProtect[3]=1; + setprg8(0xE000,PRGBanks[3]&0x7F); + break; + } +} + +static DECLFW(Mapper5_write) +{ + if(A>=0x5120&&A<=0x5127) + { + ABMode = 0; + CHRBanksA[A&7]=V; + MMC5CHRA(); + } + else switch(A) + { + case 0x5105: { + int x; + for(x=0;x<4;x++) + { + switch((V>>(x<<1))&3) + { + case 0:PPUNTARAM|=1<>3)&0x1F;break; + case 0x5202: MMC5HackSPPage=V&0x3F;break; + case 0x5203: X6502_IRQEnd(FCEU_IQEXT);IRQScanline=V;break; + case 0x5204: X6502_IRQEnd(FCEU_IQEXT);IRQEnable=V&0x80;break; + case 0x5205: mul[0]=V;break; + case 0x5206: mul[1]=V;break; + } +} + +static DECLFR(MMC5_ReadROMRAM) +{ + if(MMC5MemIn[(A-0x6000)>>13]) + return Page[A>>11][A]; + else + return X.DB; +} + +static DECLFW(MMC5_WriteROMRAM) +{ + if(A>=0x8000) + if(MMC5ROMWrProtect[(A-0x8000)>>13]) return; + if(MMC5MemIn[(A-0x6000)>>13]) + if(((WRAMMaskEnable[0]&3)|((WRAMMaskEnable[1]&3)<<2)) == 6) Page[A>>11][A]=V; +} + +static DECLFW(MMC5_ExRAMWr) +{ + if(MMC5HackCHRMode!=3) + ExRAM[A&0x3ff]=V; +} + +static DECLFR(MMC5_ExRAMRd) +{ + /* Not sure if this is correct, so I'll comment it out for now. */ + /*if(MMC5HackCHRMode>=2)*/ + return ExRAM[A&0x3ff]; + /*else*/ + /* return(X.DB);*/ +} + +static DECLFR(MMC5_read) +{ + switch(A) + { + case 0x5204: X6502_IRQEnd(FCEU_IQEXT); + { + uint8 x; + x=MMC5IRQR; + MMC5IRQR&=0x40; + return x; + } + case 0x5205: return (mul[0]*mul[1]); + case 0x5206: return ((mul[0]*mul[1])>>8); + } + return(X.DB); +} + +void MMC5Synco(void) +{ + int x; + + MMC5PRG(); + for(x=0;x<4;x++) + { + switch((NTAMirroring>>(x<<1))&3) + { + case 0:PPUNTARAM|=1<>4]+=MMC5Sound.raw<<1; +} + +static void Do5PCMHQ() +{ + int32 V; + if(!(MMC5Sound.rawcontrol&0x40) && MMC5Sound.raw) + for(V=MMC5Sound.BC[2];V>2); + MMC5Sound.env[A>>2]=V; + break; + case 0x2: + case 0x6: if(sfun) sfun(A>>2); + MMC5Sound.wl[A>>2]&=~0x00FF; + MMC5Sound.wl[A>>2]|=V&0xFF; + break; + case 0x3: + case 0x7:/*printf("%04x:$%02x\n",A,V>>3);*/ + MMC5Sound.wl[A>>2]&=~0x0700; + MMC5Sound.wl[A>>2]|=(V&0x07)<<8; + MMC5Sound.running|=1<<(A>>2); + break; + case 0x15:if(sfun) + { + sfun(0); + sfun(1); + } + MMC5Sound.running&=V; + MMC5Sound.enable=V; + /*printf("%02x\n",V);*/ + break; + } +} + +static void Do5SQ(int P) +{ + static int tal[4]={1,2,4,6}; + int32 V,amp,rthresh,wl; + int32 start,end; + + start=MMC5Sound.BC[P]; + end=(SOUNDTS<<16)/soundtsinc; + if(end<=start) return; + MMC5Sound.BC[P]=end; + + wl=MMC5Sound.wl[P]+1; + amp=(MMC5Sound.env[P]&0xF)<<4; + rthresh=tal[(MMC5Sound.env[P]&0xC0)>>6]; + + if(wl>=8 && (MMC5Sound.running&(P+1))) + { + int dc,vc; + + wl<<=18; + dc=MMC5Sound.dcount[P]; + vc=MMC5Sound.vcount[P]; + + for(V=start;V>4]+=amp; + vc-=nesincsize; + while(vc<=0) + { + vc+=wl; + dc=(dc+1)&7; + } + } + MMC5Sound.dcount[P]=dc; + MMC5Sound.vcount[P]=vc; + } +} + +static void Do5SQHQ(int P) +{ + static int tal[4]={1,2,4,6}; + int32 V,amp,rthresh,wl; + + wl=MMC5Sound.wl[P]+1; + amp=((MMC5Sound.env[P]&0xF)<<8); + rthresh=tal[(MMC5Sound.env[P]&0xC0)>>6]; + + if(wl>=8 && (MMC5Sound.running&(P+1))) + { + int dc,vc; + + wl<<=1; + + dc=MMC5Sound.dcount[P]; + vc=MMC5Sound.vcount[P]; + for(V=MMC5Sound.BC[P];VPower=GenMMC5Reset; + + if(battery) + { + info->SaveGame[0]=WRAM; + if(wsize<=16) + info->SaveGameLen[0]=8192; + else + info->SaveGameLen[0]=32768; + } + + MMC5HackVROMMask=CHRmask4[0]; + MMC5HackExNTARAMPtr=ExRAM; + MMC5Hack=1; + MMC5HackVROMPTR=CHRptr[0]; + MMC5HackCHRMode=0; + MMC5HackSPMode=MMC5HackSPScroll=MMC5HackSPPage=0; + Mapper5_ESI(); +} + +void Mapper5_Init(CartInfo *info) +{ + GenMMC5_Init(info, DetectMMC5WRAMSize(info->CRC32), info->battery); +} + +/* ELROM seems to have 0KB of WRAM*/ +/* EKROM seems to have 8KB of WRAM*/ +/* ETROM seems to have 16KB of WRAM*/ +/* EWROM seems to have 32KB of WRAM*/ + +/* ETROM and EWROM are battery-backed, EKROM isn't.*/ + +void ETROM_Init(CartInfo *info) +{ + GenMMC5_Init(info, 16,info->battery); +} + +void ELROM_Init(CartInfo *info) +{ + GenMMC5_Init(info,0,0); +} + +void EWROM_Init(CartInfo *info) +{ + GenMMC5_Init(info,32,info->battery); +} + +void EKROM_Init(CartInfo *info) +{ + GenMMC5_Init(info,8,info->battery); +} diff --git a/fceumm/src-fceumm/boards/n106.c b/fceumm/src-fceumm/boards/n106.c new file mode 100644 index 0000000..dc32ccc --- /dev/null +++ b/fceumm/src-fceumm/boards/n106.c @@ -0,0 +1,469 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint16 IRQCount; +static uint8 IRQa; + +static uint8 WRAM[8192]; +static uint8 IRAM[128]; + +static DECLFR(AWRAM) +{ + return(WRAM[A-0x6000]); +} + +static DECLFW(BWRAM) +{ + WRAM[A-0x6000]=V; +} + +void Mapper19_ESI(void); + +static uint8 NTAPage[4]; + +static uint8 dopol; +static uint8 gorfus; +static uint8 gorko; + +static void NamcoSound(int Count); +static void NamcoSoundHack(void); +static void DoNamcoSound(int32 *Wave, int Count); +static void DoNamcoSoundHQ(void); +static void SyncHQ(int32 ts); + +static int is210; /* Lesser mapper. */ + +static uint8 PRG[3]; +static uint8 CHR[8]; + +static SFORMAT N106_StateRegs[]={ + {PRG,3,"PRG"}, + {CHR,8,"CHR"}, + {NTAPage,4,"NTA"}, + {0} +}; + +static void SyncPRG(void) +{ + setprg8(0x8000,PRG[0]); + setprg8(0xa000,PRG[1]); + setprg8(0xc000,PRG[2]); + setprg8(0xe000,0x3F); +} + +static void NamcoIRQHook(int a) +{ + if(IRQa) + { + IRQCount+=a; + if(IRQCount>=0x7FFF) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + IRQCount=0x7FFF; /*7FFF;*/ + } + } +} + +static DECLFR(Namco_Read4800) +{ + uint8 ret=IRAM[dopol&0x7f]; + /* Maybe I should call NamcoSoundHack() here? */ + if(dopol&0x80) + dopol=(dopol&0x80)|((dopol+1)&0x7f); + return ret; +} + +static DECLFR(Namco_Read5000) +{ + return(IRQCount); +} + +static DECLFR(Namco_Read5800) +{ + return(IRQCount>>8); +} + +static void DoNTARAMROM(int w, uint8 V) +{ + NTAPage[w]=V; + if(V>=0xE0) + setntamem(NTARAM+((V&1)<<10), 1, w); + else + { + V&=CHRmask1[0]; + setntamem(CHRptr[0]+(V<<10), 0, w); + } +} + +static void FixNTAR(void) +{ + int x; + for(x=0;x<4;x++) + DoNTARAMROM(x,NTAPage[x]); +} + +static void DoCHRRAMROM(int x, uint8 V) +{ + CHR[x]=V; + if(!is210 && !((gorfus>>((x>>2)+6))&1) && (V>=0xE0)) + { + /* printf("BLAHAHA: %d, %02x\n",x,V);*/ + /*setchr1r(0x10,x<<10,V&7);*/ + } + else + setchr1(x<<10,V); +} + +static void FixCRR(void) +{ + int x; + for(x=0;x<8;x++) + DoCHRRAMROM(x,CHR[x]); +} + +static DECLFW(Mapper19C0D8_write) +{ + DoNTARAMROM((A-0xC000)>>11,V); +} + +static uint32 FreqCache[8]; +static uint32 EnvCache[8]; +static uint32 LengthCache[8]; + +static void FixCache(int a,int V) +{ + int w=(a>>3)&0x7; + switch(a&0x07) + { + case 0x00:FreqCache[w]&=~0x000000FF;FreqCache[w]|=V;break; + case 0x02:FreqCache[w]&=~0x0000FF00;FreqCache[w]|=V<<8;break; + case 0x04:FreqCache[w]&=~0x00030000;FreqCache[w]|=(V&3)<<16; + LengthCache[w]=(8-((V>>2)&7))<<2; + break; + case 0x07:EnvCache[w]=(double)(V&0xF)*576716;break; + } +} + +static DECLFW(Mapper19_write) +{ + A&=0xF800; + if(A>=0x8000 && A<=0xb800) + DoCHRRAMROM((A-0x8000)>>11,V); + else switch(A) + { + case 0x4800: + if(dopol&0x40) + { + if(FSettings.SndRate) + { + NamcoSoundHack(); + GameExpSound.Fill=NamcoSound; + GameExpSound.HiFill=DoNamcoSoundHQ; + GameExpSound.HiSync=SyncHQ; + } + FixCache(dopol,V); + } + IRAM[dopol&0x7f]=V; + if(dopol&0x80) + dopol=(dopol&0x80)|((dopol+1)&0x7f); + break; + case 0xf800: + dopol=V;break; + case 0x5000: + IRQCount&=0xFF00;IRQCount|=V;X6502_IRQEnd(FCEU_IQEXT);break; + case 0x5800: + IRQCount&=0x00ff;IRQCount|=(V&0x7F)<<8; + IRQa=V&0x80; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xE000: + gorko=V&0xC0; + PRG[0]=V&0x3F; + SyncPRG(); + break; + case 0xE800: + gorfus=V&0xC0; + FixCRR(); + PRG[1]=V&0x3F; + SyncPRG(); + break; + case 0xF000: + PRG[2]=V&0x3F; + SyncPRG(); + break; + } +} + +static int dwave=0; + +static void NamcoSoundHack(void) +{ + int32 z,a; +#if SOUND_QUALITY == 1 + DoNamcoSoundHQ(); +#else + z=((SOUNDTS<<16)/soundtsinc)>>4; + a=z-dwave; + if(a) + DoNamcoSound(&Wave[dwave], a); + dwave+=a; +#endif +} + +static void NamcoSound(int Count) +{ + int32 z,a; + z=((SOUNDTS<<16)/soundtsinc)>>4; + a=z-dwave; + if(a) DoNamcoSound(&Wave[dwave], a); + dwave=0; +} + +static uint32 PlayIndex[8]; +static int32 vcount[8]; +static int32 CVBC; + +#define TOINDEX (16+1) + +/* 16:15*/ +static void SyncHQ(int32 ts) +{ + CVBC=ts; +} + + +/* Things to do: + 1 Read freq low + 2 Read freq mid + 3 Read freq high + 4 Read envelope + ...? +*/ + +static INLINE uint32 FetchDuff(uint32 P, uint32 envelope) +{ + uint32 duff; + duff=IRAM[((IRAM[0x46+(P<<3)]+(PlayIndex[P]>>TOINDEX))&0xFF)>>1]; + if((IRAM[0x46+(P<<3)]+(PlayIndex[P]>>TOINDEX))&1) + duff>>=4; + duff&=0xF; + duff=(duff*envelope)>>16; + return(duff); +} + +static void DoNamcoSoundHQ(void) +{ + int32 P,V; + int32 cyclesuck=(((IRAM[0x7F]>>4)&7)+1)*15; + + for(P=7;P>=(7-((IRAM[0x7F]>>4)&7));P--) + { + if((IRAM[0x44+(P<<3)]&0xE0) && (IRAM[0x47+(P<<3)]&0xF)) + { + uint32 freq; + int32 vco; + uint32 duff2,lengo,envelope; + + vco=vcount[P]; + freq=FreqCache[P]; + envelope=EnvCache[P]; + lengo=LengthCache[P]; + + duff2=FetchDuff(P,envelope); + for(V=CVBC<<1;V>1]+=duff2; + if(!vco) + { + PlayIndex[P]+=freq; + while((PlayIndex[P]>>TOINDEX)>=lengo) PlayIndex[P]-=lengo<=7-((IRAM[0x7F]>>4)&7);P--) + { + if((IRAM[0x44+(P<<3)]&0xE0) && (IRAM[0x47+(P<<3)]&0xF)) + { + int32 inc; + uint32 freq; + int32 vco; + uint32 duff,duff2,lengo,envelope; + + vco=vcount[P]; + freq=FreqCache[P]; + envelope=EnvCache[P]; + lengo=LengthCache[P]; + + if(!freq) {/*printf("Ack");*/ continue;} + + { + int c=((IRAM[0x7F]>>4)&7)+1; + inc=(long double)(FSettings.SndRate<<15)/((long double)freq*21477272/((long double)0x400000*c*45)); + } + + duff=IRAM[(((IRAM[0x46+(P<<3)]+PlayIndex[P])&0xFF)>>1)]; + if((IRAM[0x46+(P<<3)]+PlayIndex[P])&1) + duff>>=4; + duff&=0xF; + duff2=(duff*envelope)>>19; + for(V=0;V=inc) + { + PlayIndex[P]++; + if(PlayIndex[P]>=lengo) + PlayIndex[P]=0; + vco-=inc; + duff=IRAM[(((IRAM[0x46+(P<<3)]+PlayIndex[P])&0xFF)>>1)]; + if((IRAM[0x46+(P<<3)]+PlayIndex[P])&1) + duff>>=4; + duff&=0xF; + duff2=(duff*envelope)>>19; + } + Wave[V>>4]+=duff2; + vco+=0x8000; + } + vcount[P]=vco; + } + } +} + +static void Mapper19_StateRestore(int version) +{ + int x; + SyncPRG(); + FixNTAR(); + FixCRR(); + for(x=0x40;x<0x80;x++) + FixCache(x,IRAM[x]); +} + +static void M19SC(void) +{ + if(FSettings.SndRate) + Mapper19_ESI(); +} + +void Mapper19_ESI(void) +{ + GameExpSound.RChange=M19SC; + memset(vcount,0,sizeof(vcount)); + memset(PlayIndex,0,sizeof(PlayIndex)); + CVBC=0; +} + +void NSFN106_Init(void) +{ + SetWriteHandler(0xf800,0xffff,Mapper19_write); + SetWriteHandler(0x4800,0x4fff,Mapper19_write); + SetReadHandler(0x4800,0x4fff,Namco_Read4800); + Mapper19_ESI(); +} + +static int battery=0; + +static void N106_Power(void) +{ + int x; + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xffff,Mapper19_write); + SetWriteHandler(0x4020,0x5fff,Mapper19_write); + if(!is210) + { + SetWriteHandler(0xc000,0xdfff,Mapper19C0D8_write); + SetReadHandler(0x4800,0x4fff,Namco_Read4800); + SetReadHandler(0x5000,0x57ff,Namco_Read5000); + SetReadHandler(0x5800,0x5fff,Namco_Read5800); + NTAPage[0]=NTAPage[1]=NTAPage[2]=NTAPage[3]=0xFF; + FixNTAR(); + } + + SetReadHandler(0x6000,0x7FFF,AWRAM); + SetWriteHandler(0x6000,0x7FFF,BWRAM); + FCEU_CheatAddRAM(8,0x6000,WRAM); + + gorfus=0xFF; + SyncPRG(); + FixCRR(); + + if(!battery) + { + FCEU_dwmemset(WRAM,0,8192); + FCEU_dwmemset(IRAM,0,128); + } + for(x=0x40;x<0x80;x++) + FixCache(x,IRAM[x]); +} + +void Mapper19_Init(CartInfo *info) +{ + is210=0; + battery=info->battery; + info->Power=N106_Power; + + MapIRQHook=NamcoIRQHook; + GameStateRestore=Mapper19_StateRestore; + GameExpSound.RChange=M19SC; + + if(FSettings.SndRate) + Mapper19_ESI(); + + AddExState(WRAM, 8192, 0, "WRAM"); + AddExState(IRAM, 128, 0, "IRAM"); + AddExState(N106_StateRegs, ~0, 0, 0); + + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=8192; + info->SaveGame[1]=IRAM; + info->SaveGameLen[1]=128; + } +} + +static void Mapper210_StateRestore(int version) +{ + SyncPRG(); + FixCRR(); +} + +void Mapper210_Init(CartInfo *info) +{ + is210=1; + GameStateRestore=Mapper210_StateRestore; + info->Power=N106_Power; + AddExState(WRAM, 8192, 0, "WRAM"); + AddExState(N106_StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/n625092.c b/fceumm/src-fceumm/boards/n625092.c new file mode 100644 index 0000000..08501ae --- /dev/null +++ b/fceumm/src-fceumm/boards/n625092.c @@ -0,0 +1,109 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * 700in1 and 400in1 carts + */ + + +#include "mapinc.h" + +static uint16 cmd, bank; + +static SFORMAT StateRegs[]= +{ + {&cmd, 2, "CMD"}, + {&bank, 2, "BANK"}, + {0} +}; + +static void Sync(void) +{ + setmirror((cmd&1)^1); + setchr8(0); + if(cmd&2) + { + if(cmd&0x100) + { + setprg16(0x8000,((cmd&0xfc)>>2)|bank); + setprg16(0xC000,((cmd&0xfc)>>2)|7); + } + else + { + setprg16(0x8000,((cmd&0xfc)>>2)|(bank&6)); + setprg16(0xC000,((cmd&0xfc)>>2)|((bank&6)|1)); + } + } + else + { + setprg16(0x8000,((cmd&0xfc)>>2)|bank); + setprg16(0xC000,((cmd&0xfc)>>2)|bank); + } +} + +static uint16 ass = 0; + +static DECLFW(UNLN625092WriteCommand) +{ + cmd=A; + if(A==0x80F8) + { + setprg16(0x8000,ass); + setprg16(0xC000,ass); + } + else + { + Sync(); + } +} + +static DECLFW(UNLN625092WriteBank) +{ + bank=A&7; + Sync(); +} + +static void UNLN625092Power(void) +{ + cmd=0; + bank=0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xBFFF,UNLN625092WriteCommand); + SetWriteHandler(0xC000,0xFFFF,UNLN625092WriteBank); +} + +static void UNLN625092Reset(void) +{ + cmd=0; + bank=0; + ass++; + FCEU_printf("%04x\n",ass); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLN625092_Init(CartInfo *info) +{ + info->Reset=UNLN625092Reset; + info->Power=UNLN625092Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/novel.c b/fceumm/src-fceumm/boards/novel.c new file mode 100644 index 0000000..26e70ec --- /dev/null +++ b/fceumm/src-fceumm/boards/novel.c @@ -0,0 +1,55 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 latch; + +static void DoNovel(void) +{ + setprg32(0x8000,latch&3); + setchr8(latch&7); +} + +static DECLFW(NovelWrite) +{ + latch=A&0xFF; + DoNovel(); +} + +static void NovelReset(void) +{ + SetWriteHandler(0x8000,0xFFFF,NovelWrite); + SetReadHandler(0x8000,0xFFFF,CartBR); + setprg32(0x8000,0); + setchr8(0); +} + +static void NovelRestore(int version) +{ + DoNovel(); +} + +void Novel_Init(CartInfo *info) +{ + AddExState(&latch, 1, 0,"L1"); + info->Power=NovelReset; + GameStateRestore=NovelRestore; +} diff --git a/fceumm/src-fceumm/boards/onebus.c b/fceumm/src-fceumm/boards/onebus.c new file mode 100644 index 0000000..9812807 --- /dev/null +++ b/fceumm/src-fceumm/boards/onebus.c @@ -0,0 +1,308 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007-2010 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * OneBus system + * Street Dance (Dance pad) (Unl) + * 101-in-1 Arcade Action II + * DreamGEAR 75-in-1 + */ + +#include "mapinc.h" + +static uint8 isDance; +static uint8 regs[16],regc[6]; +static uint8 IRQCount,IRQLatch,IRQa, IRQReload, pcm_enable = 0, pcm_irq = 0; +static int16 pcm_addr, pcm_size, pcm_latch, pcm_clock = 0xF6; +static writefunc old4011write, old4012write, old4013write, old4015write; +static readfunc old4015read; + +static SFORMAT StateRegs[]= +{ + {regc, 6, "REGC"}, + {regs, 16, "REGS"}, + {&IRQReload, 1, "IRQR"}, + {&IRQCount, 1, "IRQC"}, + {&IRQLatch, 1, "IRQL"}, + {&IRQa, 1, "IRQA"}, + {&pcm_enable, 1, "PCME"}, + {&pcm_irq, 1, "PCMIRQ"}, + {&pcm_addr, 2, "PCMADDR"}, + {&pcm_size, 2, "PCMSIZE"}, + {&pcm_latch, 2, "PCMLATCH"}, + {&pcm_clock, 2, "PCMCLOCK"}, + {0} +}; + +static void Sync(void) +{ + uint16 cswap = (regs[0xf] & 0x80) << 5; + uint16 pswap = (regs[0xd]&1)?((regs[0xf] & 0x40) << 8):0; + uint16 pbase = (regs[0]&0xf0)<<4; + uint16 cbase = (((regs[0]&0x0f)<<8)|(regs[0xc]<<1)|((regs[0xd]&0xf8)>>3))<<3; + uint16 pmask = 0x3f>>(regs[0xb]&0xf); + + setchr1(cswap^0x0000,cbase|(regc[0]&(~1))); + setchr1(cswap^0x0400,cbase|(regc[0]|1)); + setchr1(cswap^0x0800,cbase|(regc[1]&(-1))); + setchr1(cswap^0x0c00,cbase|(regc[1]|1)); + setchr1(cswap^0x1000,cbase|(regc[2])); + setchr1(cswap^0x1400,cbase|(regc[3])); + setchr1(cswap^0x1800,cbase|(regc[4])); + setchr1(cswap^0x1c00,cbase|(regc[5])); + + if(regs[0xd]&2) + { + setprg8(pswap^0x8000, pbase|(regs[0x7]&pmask)|(regs[0xa]&(~pmask))); + setprg8( 0xA000, pbase|(regs[0x8]&pmask)|(regs[0xa]&(~pmask))); + setprg8(pswap^0xC000, pbase|(regs[0x9]&pmask)|(regs[0xa]&(~pmask))); + setprg8( 0xE000, pbase|regs[0xa]); + } + else + { + setprg8(pswap^0x8000, pbase|(regs[0x7]&pmask)|(regs[0xa]&(~pmask))); + setprg8( 0xA000, pbase|(regs[0x8]&pmask)|(regs[0xa]&(~pmask))); + setprg8(pswap^0xC000, pbase|((~1)&pmask)|(regs[0xa]&(~pmask))); + setprg8( 0xE000, pbase|((~0)&pmask)|(regs[0xa]&(~pmask))); + } + + setmirror(regs[0xe]); +} + +static DECLFW(UNLOneBusWrite20XX) +{ +/* FCEU_printf("PPU %04x:%04x\n",A,V);*/ + if(A == 0x201A) + regs[0xd] = V; + else if(A == 0x2018) + regs[0xc] = V; + Sync(); +} + +static DECLFW(UNLOneBusWriteExp) +{ +/* FCEU_printf("EXP %04x:%04x\n",A,V);*/ +/* switch(A & 0x0F)*/ +/* {*/ +/* case 2: pcm_latch = pcm_clock; FCEU_printf("write %04x:%04x\n",A,V); break;*/ +/* case 3: pcm_irqa = 0; X6502_IRQEnd(FCEU_IQEXT); pcm_irq = 0; FCEU_printf("write %04x:%04x\n",A,V); break;*/ +/* case 4: pcm_irqa = 1; FCEU_printf("write %04x:%04x\n",A,V); break;*/ +/* default:*/ + regs[A & 0x0F] = V; + Sync(); +/* }*/ +} + +static DECLFW(UNLOneBusWriteDebug) +{ +/* FCEU_printf("write %04x:%04x\n",A,V);*/ +} + +static DECLFW(UNLOneBusWriteMMC) +{ +/* FCEU_printf("MMC %04x:%04x\n",A,V);*/ + switch(A&0xE001) + { + case 0x8000: regs[0xf] = V; Sync(); break; + case 0x8001: + { + uint8 mask = 0xff, mmc3cmd = regs[0xf]&7; + switch(mmc3cmd) + { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + if(regs[0xd]&4) + mask = 0x0f; + else + mask >>= ((regs[0xb]&0xf0)>>4); + regc[mmc3cmd] = V&mask; + break; + case 6: + case 7: + mask = (mask&0x3f)>>(regs[0xb]&0xf); + regs[mmc3cmd+1] = (regs[mmc3cmd+1]&(~mask))|(V&mask); + break; + } + + Sync(); + break; + } + case 0xA000: regs[0xe] = (V & 1)^1; Sync(); break; + case 0xC000: IRQLatch = V&0xfe; break; + case 0xC001: IRQReload = 1; break; + case 0xE000: X6502_IRQEnd(FCEU_IQEXT); IRQa = 0; break; + case 0xE001: IRQa = 1; break; + } +} + +static void UNLOneBusIRQHook(void) +{ + int count = IRQCount; + if(!count || IRQReload) + { + IRQCount = IRQLatch; + IRQReload = 0; + } + else + IRQCount--; + if(count && !IRQCount) + { + if(IRQa) + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static DECLFW(UNLOneBusWriteAPU2) +{ +/* FCEU_printf("APU2 %04x:%04x\n",A,V);*/ + CartBW(A&0xffdf,V); +} + +static DECLFW(UNLOneBusWrite4012) +{ +/* FCEU_printf("write %04x:%04x\n",A,V);*/ + pcm_addr = V << 6; + old4012write(A,V); +} + +static DECLFW(UNLOneBusWrite4013) +{ +/* FCEU_printf("write %04x:%04x\n",A,V);*/ + pcm_size = (V << 4) + 1; + old4013write(A,V); +} + +static DECLFW(UNLOneBusWrite4015) +{ +/* FCEU_printf("write %04x:%04x\n",A,V);*/ + pcm_enable = V&0x10; + if(pcm_irq) + { + X6502_IRQEnd(FCEU_IQEXT); + pcm_irq = 0; + } + if(pcm_enable) + pcm_latch = pcm_clock; + old4015write(A,V&0xEF); +} + +static DECLFR(UNLOneBusRead4015) +{ + uint8 result = (old4015read(A) & 0x7F)|pcm_irq; +/* FCEU_printf("read %04x, %02x\n",A,result);*/ + return result; +} + +static void UNLOneBusCpuHook(int a) +{ + if(pcm_enable) + { + pcm_latch-=a; + if(pcm_latch<=0) + { + pcm_latch+=pcm_clock; + pcm_size--; + if(pcm_size<0) + { + pcm_irq = 0x80; + pcm_enable = 0; + X6502_IRQBegin(FCEU_IQEXT); + } + else + { + uint8 raw_pcm = ARead[pcm_addr](pcm_addr) >> 1; + old4011write(0x4011,raw_pcm); + pcm_addr++; + pcm_addr&=0x7FFF; + } + } + } +} + +static void UNLOneBusPower(void) +{ + IRQCount=IRQLatch=IRQa==0; + regs[0]=regs[1]=regs[1]=regs[2]=regs[3]=regs[4]=regs[5]=regs[6]=0; + regs[7]=regs[8]=regs[11]=regs[12]=regs[13]=regs[14]=regs[15]=0; + regs[0x09]=0x3E; + regs[0x0A]=0x3F; + + SetupCartCHRMapping(0,PRGptr[0],4096 * 1024,0); + + if(isDance) /* quick workaround, TODO: figure out how it works together*/ + { + old4015read=GetReadHandler(0x4015); + SetReadHandler(0x4015,0x4015,UNLOneBusRead4015); + old4011write=GetWriteHandler(0x4011); + old4012write=GetWriteHandler(0x4012); + SetWriteHandler(0x4012,0x4012,UNLOneBusWrite4012); + old4013write=GetWriteHandler(0x4013); + SetWriteHandler(0x4013,0x4013,UNLOneBusWrite4013); + old4015write=GetWriteHandler(0x4015); + SetWriteHandler(0x4015,0x4015,UNLOneBusWrite4015); + } + + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x2009,0x2fff,UNLOneBusWrite20XX); +/* SetWriteHandler(0x4020,0xffff,UNLOneBusWriteDebug);*/ +/* SetWriteHandler(0x4020,0x4040,UNLOneBusWriteAPU2);*/ + SetWriteHandler(0x4100,0x410f,UNLOneBusWriteExp); + SetWriteHandler(0x8000,0xefff,UNLOneBusWriteMMC); + Sync(); +} + +static void UNLOneBusReset(void) +{ + IRQCount=IRQLatch=IRQa=0; + regs[0]=regs[1]=regs[1]=regs[2]=regs[3]=regs[4]=regs[5]=regs[6]=0; + regs[7]=regs[8]=regs[11]=regs[12]=regs[13]=regs[14]=regs[15]=0; + regs[0x09]=0x3E; + regs[0x0A]=0x3F; + Sync(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLOneBus_Init(CartInfo *info) +{ + isDance = 0; + info->Power=UNLOneBusPower; + info->Reset=UNLOneBusReset; + GameHBIRQHook=UNLOneBusIRQHook; +/* MapIRQHook=UNLOneBusCpuHook;*/ + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void UNLDANCE_Init(CartInfo *info) +{ + isDance = 1; + info->Power=UNLOneBusPower; + info->Reset=UNLOneBusReset; + GameHBIRQHook=UNLOneBusIRQHook; + MapIRQHook=UNLOneBusCpuHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/pec-586.c b/fceumm/src-fceumm/boards/pec-586.c new file mode 100644 index 0000000..bec77c7 --- /dev/null +++ b/fceumm/src-fceumm/boards/pec-586.c @@ -0,0 +1,112 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg[2]; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {reg, 2, "REG"}, + {0} +}; + +static uint8 bs_tbl[256] = { + 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, + 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, + 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, + 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, + 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, + 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, + 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x00, 0x10, 0x20, 0x30, + 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, + 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, + 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, + 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, + 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, + 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, + 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, + 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x00, 0x10, 0x20, 0x30, + 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, +}; + +static void Sync(void) +{ + setchr4(0x0000,(reg[0]&0x80) >> 7); + setchr4(0x1000,(reg[0]&0x80) >> 7); + setprg8r(0x10,0x6000,0); + setprg16(0x8000,bs_tbl[reg[0]]>>4); + setprg16(0xc000,bs_tbl[reg[0]]&0xf); + setmirror(MI_V); +} + +static DECLFW(UNLPEC586Write) +{ + reg[A&1]=V; + FCEU_printf("bs %04x %02x\n",A,V); + Sync(); +} + +static void UNLPEC586Power(void) +{ + reg[0]=0x0E; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x5000,0x5fff,UNLPEC586Write); +} + +static void UNLPEC586IRQ(void) +{ + if(scanline==128) + setchr4(0x0000,1); + else + setchr4(0x0000,0); +} + +static void UNLPEC586Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLPEC586Init(CartInfo *info) +{ + info->Power=UNLPEC586Power; + info->Close=UNLPEC586Close; + /* GameHBIRQHook=UNLPEC586IRQ;*/ + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/sachen.c b/fceumm/src-fceumm/boards/sachen.c new file mode 100644 index 0000000..1196495 --- /dev/null +++ b/fceumm/src-fceumm/boards/sachen.c @@ -0,0 +1,470 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 cmd, dip; +static uint8 latch[8]; + +static void S74LS374MSync(uint8 mirr) +{ + switch(mirr&3) + { + case 0:setmirror(MI_V);break; + case 1:setmirror(MI_H);break; + case 2:setmirrorw(0,1,1,1);break; + case 3:setmirror(MI_0);break; + } +} + +static void S74LS374NSynco(void) +{ + setprg32(0x8000,latch[0]); + setchr8(latch[1]|latch[3]|latch[4]); + S74LS374MSync(latch[2]); +} + +static DECLFW(S74LS374NWrite) +{ + A&=0x4101; + if(A==0x4100) + cmd=V&7; + else + { + switch(cmd) + { + case 2:latch[0]=V&1; latch[3]=(V&1)<<3;break; + case 4:latch[4]=(V&1)<<2;break; + case 5:latch[0]=V&7;break; + case 6:latch[1]=V&3;break; + case 7:latch[2]=V>>1;break; + } + S74LS374NSynco(); + } +} + +static DECLFR(S74LS374NRead) +{ + uint8 ret; + if((A&0x4100)==0x4100) +/* ret=(X.DB&0xC0)|((~cmd)&0x3F);*/ + ret=((~cmd)&0x3F)^dip; + else + ret=X.DB; + return ret; +} + +static void S74LS374NPower(void) +{ + dip=0; + latch[0]=latch[1]=latch[2]=latch[3]=latch[4]=0; + S74LS374NSynco(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4100,0x7FFF,S74LS374NWrite); + SetReadHandler(0x4100,0x5fff,S74LS374NRead); +} + +static void S74LS374NReset(void) +{ + dip^=1; + latch[0]=latch[1]=latch[2]=latch[3]=latch[4]=0; + S74LS374NSynco(); +} + +static void S74LS374NRestore(int version) +{ + S74LS374NSynco(); +} + +void S74LS374N_Init(CartInfo *info) +{ + info->Power=S74LS374NPower; + info->Reset=S74LS374NReset; + GameStateRestore=S74LS374NRestore; + AddExState(latch, 5, 0, "LATC"); + AddExState(&cmd, 1, 0, "CMD"); + AddExState(&dip, 1, 0, "DIP"); +} + +static void S74LS374NASynco(void) +{ + setprg32(0x8000,latch[0]); + setchr8(latch[1]); + S74LS374MSync(latch[2]); +} + +static DECLFW(S74LS374NAWrite) +{ + A&=0x4101; + if(A==0x4100) + cmd=V&7; + else + { + switch(cmd) + { + case 0:latch[0]=0;latch[1]=3;break; + case 2:latch[3]=(V&1)<<3;break; + case 4:latch[1]=(latch[1]&6)|(V&3);break; + case 5:latch[0]=V&1;break; + case 6:latch[1]=(latch[1]&1)|latch[3]|((V&3)<<1);break; + case 7:latch[2]=V&1;break; + } + S74LS374NASynco(); + } +} + +static void S74LS374NAPower(void) +{ + latch[0]=latch[2]=latch[3]=latch[4]=0; + latch[1]=3; + S74LS374NASynco(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4100,0x7FFF,S74LS374NAWrite); +} + +void S74LS374NA_Init(CartInfo *info) +{ + info->Power=S74LS374NAPower; + GameStateRestore=S74LS374NRestore; + AddExState(latch, 5, 0, "LATC"); + AddExState(&cmd, 1, 0, "CMD"); +} + +static int type; +static void S8259Synco(void) +{ + int x; + setprg32(0x8000,latch[5]&7); + + if(!UNIFchrrama) /* No CHR RAM? Then BS'ing is ok.*/ + { + for(x=0;x<4;x++) + { + int bank; + if(latch[7]&1) + bank=(latch[0]&0x7)|((latch[4]&7)<<3); + else + bank=(latch[x]&0x7)|((latch[4]&7)<<3); + switch (type) + { + case 00: bank=(bank<<1)|(x&1); setchr2(0x800*x,bank); break; + case 01: setchr2(0x800*x,bank); break; + case 02: bank=(bank<<2)|(x&3); setchr2(0x800*x,bank); break; + case 03: bank=latch[x]&7; + switch (x&3) + { + case 01: bank|=(latch[4]&1)<<4;break; + case 02: bank|=(latch[4]&2)<<3;break; + case 03: bank|=((latch[4]&4)<<2)|((latch[6]&1)<<3);break; + } + setchr1(0x400*x,bank); + setchr4(0x1000,~0); + break; + } + } + } + if(!(latch[7]&1)) + S74LS374MSync(latch[7]>>1); + else + setmirror(MI_V); +} + +static DECLFW(S8259Write) +{ + A&=0x4101; + if(A==0x4100) + cmd=V; + else + { + latch[cmd&7]=V; + S8259Synco(); + } +} + +static void S8259Reset(void) +{ + int x; + cmd=0; + + for(x=0;x<8;x++) latch[x]=0; + setchr8(0); + + S8259Synco(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4100,0x7FFF,S8259Write); +} + +static void S8259Restore(int version) +{ + S8259Synco(); +} + +void S8259A_Init(CartInfo *info) /* Kevin's Horton 141 mapper*/ +{ + info->Power=S8259Reset; + GameStateRestore=S8259Restore; + AddExState(latch, 8, 0, "LATC"); + AddExState(&cmd, 1, 0, "CMD"); + type=0; +} + +void S8259B_Init(CartInfo *info) /* Kevin's Horton 138 mapper*/ +{ + info->Power=S8259Reset; + GameStateRestore=S8259Restore; + AddExState(latch, 8, 0, "LATC"); + AddExState(&cmd, 1, 0, "CMD"); + type=1; +} + +void S8259C_Init(CartInfo *info) /* Kevin's Horton 139 mapper*/ +{ + info->Power=S8259Reset; + GameStateRestore=S8259Restore; + AddExState(latch, 8, 0, "LATC"); + AddExState(&cmd, 1, 0, "CMD"); + type=2; +} + +void S8259D_Init(CartInfo *info) /* Kevin's Horton 137 mapper*/ +{ + info->Power=S8259Reset; + GameStateRestore=S8259Restore; + AddExState(latch, 8, 0, "LATC"); + AddExState(&cmd, 1, 0, "CMD"); + type=3; +} + +static void(*WSync)(void); + +static DECLFW(SAWrite) +{ + if(A&0x100) + { + latch[0]=V; + WSync(); + } +} + +static void SAPower(void) +{ + latch[0]=0; + WSync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4100,0x5FFF,SAWrite); +} + +static void SARestore(int version) +{ + WSync(); +} + +static DECLFW(SADWrite) +{ + latch[0]=V; + WSync(); +} + +static void SADPower(void) +{ + latch[0]=0; + WSync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,SADWrite); +} + +static void SA0161MSynco() +{ + setprg32(0x8000,(latch[0]>>3)&1); + setchr8(latch[0]&7); +} + +static void SA72007Synco() +{ + setprg32(0x8000,0); + setchr8(latch[0]>>7); +} + +static void SA009Synco() +{ + setprg32(0x8000,0); + setchr8(latch[0]&1); +} + +static void SA72008Synco() +{ + setprg32(0x8000,(latch[0]>>2)&1); + setchr8(latch[0]&3); +} + +void SA0161M_Init(CartInfo *info) +{ + WSync=SA0161MSynco; + GameStateRestore=SARestore; + info->Power=SAPower; + AddExState(&latch[0], 1, 0, "LATC"); +} + +void SA72007_Init(CartInfo *info) +{ + WSync=SA72007Synco; + GameStateRestore=SARestore; + info->Power=SAPower; + AddExState(&latch[0], 1, 0, "LATC"); +} + +void SA72008_Init(CartInfo *info) +{ + WSync=SA72008Synco; + GameStateRestore=SARestore; + info->Power=SAPower; + AddExState(&latch[0], 1, 0, "LATC"); +} + +void SA009_Init(CartInfo *info) +{ + WSync=SA009Synco; + GameStateRestore=SARestore; + info->Power=SAPower; + AddExState(&latch[0], 1, 0, "LATC"); +} + +void SA0036_Init(CartInfo *info) +{ + WSync=SA72007Synco; + GameStateRestore=SARestore; + info->Power=SADPower; + AddExState(&latch[0], 1, 0, "LATC"); +} + +void SA0037_Init(CartInfo *info) +{ + WSync=SA0161MSynco; + GameStateRestore=SARestore; + info->Power=SADPower; + AddExState(&latch[0], 1, 0, "LATC"); +} + +/* -----------------------------------------------*/ + +static void TCU01Synco() +{ + setprg32(0x8000,((latch[0]&0x80)>>6)|((latch[0]>>2)&1)); + setchr8((latch[0]>>3)&0xF); +} + +static DECLFW(TCU01Write) +{ + if((A&0x103)==0x102) + { + latch[0]=V; + TCU01Synco(); + } +} + +static void TCU01Power(void) +{ + latch[0]=0; + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4100,0xFFFF,TCU01Write); + TCU01Synco(); +} + +static void TCU01Restore(int version) +{ + TCU01Synco(); +} + +void TCU01_Init(CartInfo *info) +{ + GameStateRestore=TCU01Restore; + info->Power=TCU01Power; + AddExState(&latch[0], 1, 0, "LATC"); +} + +/*-----------------------------------------------*/ + +static void TCU02Synco() +{ + setprg32(0x8000,0); + setchr8(latch[0]&3); +} + +static DECLFW(TCU02Write) +{ + if((A&0x103)==0x102) + { + latch[0]=V+3; + TCU02Synco(); + } +} + +static DECLFR(TCU02Read) +{ + return (latch[0]&0x3F)|(X.DB&0xC0); +} + +static void TCU02Power(void) +{ + latch[0]=0; + SetReadHandler(0x8000,0xFFFF,CartBR); + SetReadHandler(0x4100,0x4100,TCU02Read); + SetWriteHandler(0x4100,0xFFFF,TCU02Write); + TCU02Synco(); +} + +static void TCU02Restore(int version) +{ + TCU02Synco(); +} + +void TCU02_Init(CartInfo *info) +{ + GameStateRestore=TCU02Restore; + info->Power=TCU02Power; + AddExState(&latch[0], 1, 0, "LATC"); +} + +/* ---------------------------------------------*/ + +static DECLFR(TCA01Read) +{ + uint8 ret; + if((A&0x4100)==0x4100) + ret=(X.DB&0xC0)|((~A)&0x3F); + else + ret=X.DB; + return ret; +} + +static void TCA01Power(void) +{ + setprg16(0x8000,0); + setprg16(0xC000,1); + setchr8(0); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetReadHandler(0x4100,0x5FFF,TCA01Read); +} + +void TCA01_Init(CartInfo *info) +{ + info->Power=TCA01Power; +} + diff --git a/fceumm/src-fceumm/boards/sc-127.c b/fceumm/src-fceumm/boards/sc-127.c new file mode 100644 index 0000000..0dbfcab --- /dev/null +++ b/fceumm/src-fceumm/boards/sc-127.c @@ -0,0 +1,125 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Wario Land II (Kirby hack) + */ + +#include "mapinc.h" + +static uint8 reg[8], chr[8]; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; +static uint16 IRQCount, IRQa; + +static SFORMAT StateRegs[]= +{ + {reg, 8, "REGS"}, + {chr, 8, "CHRS"}, + {&IRQCount, 16, "IRQc"}, + {&IRQa, 16, "IRQa"}, + {0} +}; + +static void Sync(void) +{ + int i; + setprg8(0x8000,reg[0]); + setprg8(0xA000,reg[1]); + setprg8(0xC000,reg[2]); + for(i=0; i<8; i++) + setchr1(i << 10,chr[i]); + setmirror(reg[3]^1); +} + +static DECLFW(UNLSC127Write) +{ + switch(A) + { + case 0x8000: reg[0] = V; break; + case 0x8001: reg[1] = V; break; + case 0x8002: reg[2] = V; break; + case 0x9000: chr[0] = V; break; + case 0x9001: chr[1] = V; break; + case 0x9002: chr[2] = V; break; + case 0x9003: chr[3] = V; break; + case 0x9004: chr[4] = V; break; + case 0x9005: chr[5] = V; break; + case 0x9006: chr[6] = V; break; + case 0x9007: chr[7] = V; break; + case 0xC002: IRQa=0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xC005: IRQCount=V; break; + case 0xC003: IRQa=1; break; + case 0xD001: reg[3] = V; break; + } + Sync(); +} + +static void UNLSC127Power(void) +{ + Sync(); + setprg8r(0x10,0x6000,0); + setprg8(0xE000,~0); + SetReadHandler(0x6000,0x7fff,CartBR); + SetWriteHandler(0x6000,0x7fff,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,UNLSC127Write); +} + +static void UNLSC127IRQ(void) +{ + if(IRQa) + { + IRQCount--; + if(IRQCount==0) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + } + } +} + +static void UNLSC127Reset(void) +{ +} + +static void UNLSC127Close(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLSC127_Init(CartInfo *info) +{ + info->Reset=UNLSC127Reset; + info->Power=UNLSC127Power; + info->Close=UNLSC127Close; + GameHBIRQHook=UNLSC127IRQ; + GameStateRestore=StateRestore; + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/sheroes.c b/fceumm/src-fceumm/boards/sheroes.c new file mode 100644 index 0000000..50c2987 --- /dev/null +++ b/fceumm/src-fceumm/boards/sheroes.c @@ -0,0 +1,87 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 *CHRRAM; +static uint8 tekker; + +static void MSHCW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + setchr8r(0x10,0); + else + { + if(A<0x800) + setchr1(A,V|((EXPREGS[0]&8)<<5)); + else if(A<0x1000) + setchr1(A,V|((EXPREGS[0]&4)<<6)); + else if(A<0x1800) + setchr1(A,V|((EXPREGS[0]&1)<<8)); + else + setchr1(A,V|((EXPREGS[0]&2)<<7)); + } +} + +static DECLFW(MSHWrite) +{ + EXPREGS[0]=V; + FixMMC3CHR(MMC3_cmd); +} + +static DECLFR(MSHRead) +{ + return(tekker); +} + +static void MSHReset(void) +{ + MMC3RegReset(); + tekker^=0xFF; +} + +static void MSHPower(void) +{ + tekker=0x00; + GenMMC3Power(); + SetWriteHandler(0x4100,0x4100,MSHWrite); + SetReadHandler(0x4100,0x4100,MSHRead); +} + +static void MSHClose(void) +{ + if(CHRRAM) + free(CHRRAM); + CHRRAM=NULL; +} + +void UNLSHeroes_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 512, 0, 0); + cwrap=MSHCW; + info->Power=MSHPower; + info->Reset=MSHReset; + info->Close=MSHClose; + CHRRAM = (uint8*)FCEU_gmalloc(8192); + SetupCartCHRMapping(0x10, CHRRAM, 8192, 1); + AddExState(EXPREGS, 4, 0, "EXPR"); + AddExState(&tekker, 1, 0, "DIPSW"); +} diff --git a/fceumm/src-fceumm/boards/sl1632.c b/fceumm/src-fceumm/boards/sl1632.c new file mode 100644 index 0000000..df0ab5d --- /dev/null +++ b/fceumm/src-fceumm/boards/sl1632.c @@ -0,0 +1,126 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * SL1632 2-in-1 protected board, similar to SL12 + * Samurai Spirits Rex (Full) + * + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 chrcmd[8], prg0, prg1, bbrk, mirr, swap; +static SFORMAT StateRegs[]= +{ + {chrcmd, 8, "CHRCMD"}, + {&prg0, 1, "PRG0"}, + {&prg1, 1, "PRG1"}, + {&bbrk, 1, "BRK"}, + {&mirr, 1, "MIRR"}, + {&swap, 1, "SWAP"}, + {0} +}; + +static void Sync(void) +{ + int i; + setprg8(0x8000,prg0); + setprg8(0xA000,prg1); + setprg8(0xC000,~1); + setprg8(0xE000,~0); + for(i=0; i<8; i++) + setchr1(i<<10,chrcmd[i]); + setmirror(mirr^1); +} + +static void UNLSL1632CW(uint32 A, uint8 V) +{ + int cbase=(MMC3_cmd&0x80)<<5; + int page0=(bbrk&0x08)<<5; + int page1=(bbrk&0x20)<<3; + int page2=(bbrk&0x80)<<1; + setchr1(cbase^0x0000,page0|(DRegBuf[0]&(~1))); + setchr1(cbase^0x0400,page0|DRegBuf[0]|1); + setchr1(cbase^0x0800,page0|(DRegBuf[1]&(~1))); + setchr1(cbase^0x0C00,page0|DRegBuf[1]|1); + setchr1(cbase^0x1000,page1|DRegBuf[2]); + setchr1(cbase^0x1400,page1|DRegBuf[3]); + setchr1(cbase^0x1800,page2|DRegBuf[4]); + setchr1(cbase^0x1c00,page2|DRegBuf[5]); +} + +static DECLFW(UNLSL1632CMDWrite) +{ + if(A==0xA131) + { + bbrk=V; + } + if(bbrk&2) + { + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + if(A<0xC000) + MMC3_CMDWrite(A,V); + else + MMC3_IRQWrite(A,V); + } + else + { + if((A>=0xB000)&&(A<=0xE003)) + { + int ind=((((A&2)|(A>>10))>>1)+2)&7; + int sar=((A&1)<<2); + chrcmd[ind]=(chrcmd[ind]&(0xF0>>sar))|((V&0x0F)<Power=UNLSL1632Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/smb2j.c b/fceumm/src-fceumm/boards/smb2j.c new file mode 100644 index 0000000..17fd6f5 --- /dev/null +++ b/fceumm/src-fceumm/boards/smb2j.c @@ -0,0 +1,99 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversions + * + * Super Mario Bros 2 J alt version + * as well as "Voleyball" FDS conversion, bank layot is similar but no bankswitching and CHR ROM present + */ + +#include "mapinc.h" + +static uint8 prg, IRQa; +static uint16 IRQCount; + +static SFORMAT StateRegs[]= +{ + {&prg, 1, "PRG"}, + {&IRQa, 1, "IRQA"}, + {&IRQCount, 2, "IRQC"}, + {0} +}; + +static void Sync(void) +{ + setprg4r(1,0x5000,1); + setprg8r(1,0x6000,1); + setprg32(0x8000,prg); + setchr8(0); +} + +static DECLFW(UNLSMB2JWrite) +{ + if(A==0x4022) + { + prg=V&1; + Sync(); + } + if(A==0x4122) + { + IRQa=V; + IRQCount=0; + X6502_IRQEnd(FCEU_IQEXT); + } +} + +static void UNLSMB2JPower(void) +{ + prg=~0; + Sync(); + SetReadHandler(0x5000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4020,0xffff,UNLSMB2JWrite); +} + +static void UNLSMB2JReset(void) +{ + prg=~0; + Sync(); +} + +static void UNLSMB2JIRQHook(int a) +{ + if(IRQa) + { + IRQCount+=a*3; + if((IRQCount>>12)==IRQa) + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLSMB2J_Init(CartInfo *info) +{ + info->Reset=UNLSMB2JReset; + info->Power=UNLSMB2JPower; + MapIRQHook=UNLSMB2JIRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/subor.c b/fceumm/src-fceumm/boards/subor.c new file mode 100644 index 0000000..9f0386d --- /dev/null +++ b/fceumm/src-fceumm/boards/subor.c @@ -0,0 +1,79 @@ +#include "mapinc.h" + +static uint8 mode; +static uint8 DRegs[4]; + +static SFORMAT StateRegs[]= +{ + {DRegs, 4, "DREG"}, + {0} +}; + +static void Sync(void) +{ + int base, bank; + base = ((DRegs[0]^DRegs[1])&0x10)<<1; + bank = (DRegs[2]^DRegs[3])&0x1f; + + if(DRegs[1]&0x08) + { + bank &= 0xfe; + if(mode==0) + { + setprg16(0x8000,base+bank+1); + setprg16(0xC000,base+bank+0); + } + else + { + setprg16(0x8000,base+bank+0); + setprg16(0xC000,base+bank+1); + } + } + else + { + if(DRegs[1]&0x04) + { + setprg16(0x8000,0x1f); + setprg16(0xC000,base+bank); + } + else + { + setprg16(0x8000,base+bank); + if(mode==0) + setprg16(0xC000,0x20); + else + setprg16(0xC000,0x07); + } + } +} + +static DECLFW(Mapper167_write) +{ + DRegs[(A>>13)&0x03]=V; + Sync(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper166_init(void) +{ + mode=1; + DRegs[0]=DRegs[1]=DRegs[2]=DRegs[3]=0; + Sync(); + SetWriteHandler(0x8000,0xFFFF,Mapper167_write); + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper167_init(void) +{ + mode=0; + DRegs[0]=DRegs[1]=DRegs[2]=DRegs[3]=0; + Sync(); + SetWriteHandler(0x8000,0xFFFF,Mapper167_write); + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/super24.c b/fceumm/src-fceumm/boards/super24.c new file mode 100644 index 0000000..27bdedf --- /dev/null +++ b/fceumm/src-fceumm/boards/super24.c @@ -0,0 +1,99 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 *CHRRAM = NULL; +static int masko8[8]={63,31,15,1,3,0,0,0}; + +static void Super24PW(uint32 A, uint8 V) +{ + uint32 NV=V&masko8[EXPREGS[0]&7]; + NV|=(EXPREGS[1]<<1); + setprg8r((NV>>6)&0xF,A,NV); +} + +static void Super24CW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x20) + setchr1r(0x10,A,V); + else + { + uint32 NV=V|(EXPREGS[2]<<3); + setchr1r((NV>>9)&0xF,A,NV); + } +} + +static DECLFW(Super24Write) +{ + switch(A) + { + case 0x5FF0: EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + break; + case 0x5FF1: EXPREGS[1]=V; + FixMMC3PRG(MMC3_cmd); + break; + case 0x5FF2: EXPREGS[2]=V; + FixMMC3CHR(MMC3_cmd); + break; + } +} + +static void Super24Power(void) +{ + EXPREGS[0]=0x24; + EXPREGS[1]=159; + EXPREGS[2]=0; + GenMMC3Power(); + SetWriteHandler(0x5000,0x7FFF,Super24Write); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void Super24Reset(void) +{ + EXPREGS[0]=0x24; + EXPREGS[1]=159; + EXPREGS[2]=0; + MMC3RegReset(); +} + +static void Super24Close(void) +{ + if(CHRRAM) + free(CHRRAM); + CHRRAM = NULL; +} + +void Super24_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 256, 0, 0); + info->Power=Super24Power; + info->Reset=Super24Reset; + info->Close=Super24Close; + cwrap=Super24CW; + pwrap=Super24PW; + CHRRAM=(uint8*)FCEU_gmalloc(8192); + SetupCartCHRMapping(0x10, CHRRAM, 8192, 1); + AddExState(CHRRAM, 8192, 0, "CHRR"); + AddExState(EXPREGS, 3, 0, "BIG2"); +} diff --git a/fceumm/src-fceumm/boards/supervision.c b/fceumm/src-fceumm/boards/supervision.c new file mode 100644 index 0000000..61a373d --- /dev/null +++ b/fceumm/src-fceumm/boards/supervision.c @@ -0,0 +1,74 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 cmd0, cmd1; + +static void DoSuper(void) +{ + setprg8r((cmd0&0xC)>>2,0x6000,((cmd0&0x3)<<4)|0xF); + if(cmd0&0x10) + { + setprg16r((cmd0&0xC)>>2,0x8000,((cmd0&0x3)<<3)|(cmd1&7)); + setprg16r((cmd0&0xC)>>2,0xc000,((cmd0&0x3)<<3)|7); + } + else + setprg32r(4,0x8000,0); + setmirror(((cmd0&0x20)>>5)^1); +} + +static DECLFW(SuperWrite) +{ + if(!(cmd0&0x10)) + { + cmd0=V; + DoSuper(); + } +} + +static DECLFW(SuperHi) +{ + cmd1=V; + DoSuper(); +} + +static void SuperReset(void) +{ + SetWriteHandler(0x6000,0x7FFF,SuperWrite); + SetWriteHandler(0x8000,0xFFFF,SuperHi); + SetReadHandler(0x6000,0xFFFF,CartBR); + cmd0=cmd1=0; + setprg32r(4,0x8000,0); + setchr8(0); +} + +static void SuperRestore(int version) +{ + DoSuper(); +} + +void Supervision16_Init(CartInfo *info) +{ + AddExState(&cmd0, 1, 0,"L1"); + AddExState(&cmd1, 1, 0,"L2"); + info->Power=SuperReset; + GameStateRestore=SuperRestore; +} diff --git a/fceumm/src-fceumm/boards/t-227-1.c b/fceumm/src-fceumm/boards/t-227-1.c new file mode 100644 index 0000000..124db32 --- /dev/null +++ b/fceumm/src-fceumm/boards/t-227-1.c @@ -0,0 +1,118 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2008 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* T-227-1, 820632, MMC3 based, multimenu, 60000in1 (0010) dip switches*/ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 reset_flag = 0x07; + +static void BMCT2271CW(uint32 A, uint8 V) +{ + uint32 va; + + va = V; + if(EXPREGS[0]&0x20) + { + va|=0x200; + va|=(EXPREGS[0]&0x10)<<4; + } + else + { + va&=0x7F; + va|=(EXPREGS[0]&0x18)<<4; + } + setchr1(A,va); +} + +static void BMCT2271PW(uint32 A, uint8 V) +{ + uint32 va = V & 0x3F; + if(EXPREGS[0]&0x20) + { + va&=0x1F; + va|=0x40; + va|=(EXPREGS[0]&0x10)<<1; + } + else + { + va&=0x0F; + va|=(EXPREGS[0]&0x18)<<1; + } + switch(EXPREGS[0]&3) + { + case 0x00: setprg8(A,va); break; + case 0x02: + { + va=(va&0xFD)|((EXPREGS[0]&4)>>1); + if(A<0xC000) + { + setprg16(0x8000,va >> 1); + setprg16(0xC000,va >> 1); + } + break; + } + case 0x01: + case 0x03: if(A<0xC000) setprg32(0x8000,va >> 2); break; + } + +} + +static DECLFW(BMCT2271LoWrite) +{ + if(!(EXPREGS[0]&0x80)) + EXPREGS[0] = A & 0xFF; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static DECLFR(BMCT2271HiRead) +{ + uint32 av = A; + if(EXPREGS[0]&0x40) av = (av & 0xFFF0)|reset_flag; + return CartBR(av); +} + +static void BMCT2271Reset(void) +{ + EXPREGS[0] = 0x00; + reset_flag++; + reset_flag&=0x0F; + MMC3RegReset(); +} + +static void BMCT2271Power(void) +{ + EXPREGS[0] = 0x00; + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,BMCT2271LoWrite); + SetReadHandler(0x8000,0xFFFF,BMCT2271HiRead); +} + +void BMCT2271_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 128, 8, 0); + pwrap=BMCT2271PW; + cwrap=BMCT2271CW; + info->Power=BMCT2271Power; + info->Reset=BMCT2271Reset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} diff --git a/fceumm/src-fceumm/boards/t-262.c b/fceumm/src-fceumm/boards/t-262.c new file mode 100644 index 0000000..16abe99 --- /dev/null +++ b/fceumm/src-fceumm/boards/t-262.c @@ -0,0 +1,84 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint16 addrreg; +static uint8 datareg; +static uint8 busy; +static SFORMAT StateRegs[]= +{ + {&addrreg, 2, "ADDRREG"}, + {&datareg, 1, "DATAREG"}, + {&busy, 1, "BUSY"}, + {0} +}; + +static void Sync(void) +{ + uint16 base=((addrreg&0x60)>>2)|((addrreg&0x100)>>3); + setprg16(0x8000,(datareg&7)|base); + setprg16(0xC000,7|base); + setmirror(((addrreg&2)>>1)^1); +} + +static DECLFW(BMCT262Write) +{ + if(busy||(A==0x8000)) + datareg=V; + else + { + addrreg=A; + busy=1; + } + Sync(); +} + +static void BMCT262Power(void) +{ + setchr8(0); + SetWriteHandler(0x8000,0xFFFF,BMCT262Write); + SetReadHandler(0x8000,0xFFFF,CartBR); + busy=0; + addrreg=0; + datareg=0xff; + Sync(); +} + +static void BMCT262Reset(void) +{ + busy=0; + addrreg=0; + datareg=0; + Sync(); +} + +static void BMCT262Restore(int version) +{ + Sync(); +} + +void BMCT262_Init(CartInfo *info) +{ + info->Power=BMCT262Power; + info->Reset=BMCT262Reset; + GameStateRestore=BMCT262Restore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/tengen.c b/fceumm/src-fceumm/boards/tengen.c new file mode 100644 index 0000000..6fda4b1 --- /dev/null +++ b/fceumm/src-fceumm/boards/tengen.c @@ -0,0 +1,199 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 cmd,mir,rmode,IRQmode; +static uint8 DRegs[11]; +static uint8 IRQCount,IRQa,IRQLatch; + +static SFORMAT Rambo_StateRegs[]={ + {&cmd, 1, "CMD"}, + {&mir, 1, "MIR"}, + {&rmode, 1, "RMOD"}, + {&IRQmode, 1, "IRQM"}, + {&IRQCount, 1, "IRQC"}, + {&IRQa, 1, "IRQA"}, + {&IRQLatch, 1, "IRQL"}, + {DRegs, 11, "DREG"}, + {0} +}; + +static void (*setchr1wrap)(unsigned int A, unsigned int V); +/*static int nomirror;*/ + +static void RAMBO1_IRQHook(int a) +{ + static int smallcount; + if(!IRQmode) return; + + smallcount+=a; + while(smallcount>=4) + { + smallcount-=4; + IRQCount--; + if(IRQCount==0xFF) + if(IRQa) X6502_IRQBegin(FCEU_IQEXT); + } +} + +static void RAMBO1_hb(void) +{ + if(IRQmode) return; + if(scanline==240) return; /* hmm. Maybe that should be an mmc3-only call in fce.c. */ + rmode=0; + IRQCount--; + if(IRQCount==0xFF) + { + if(IRQa) + { + rmode = 1; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void Synco(void) +{ + int x; + + if(cmd&0x20) + { + setchr1wrap(0x0000,DRegs[0]); + setchr1wrap(0x0800,DRegs[1]); + setchr1wrap(0x0400,DRegs[8]); + setchr1wrap(0x0c00,DRegs[9]); + } + else + { + setchr1wrap(0x0000,(DRegs[0]&0xFE)); + setchr1wrap(0x0400,(DRegs[0]&0xFE)|1); + setchr1wrap(0x0800,(DRegs[1]&0xFE)); + setchr1wrap(0x0C00,(DRegs[1]&0xFE)|1); + } + + for(x=0;x<4;x++) + setchr1wrap(0x1000+x*0x400,DRegs[2+x]); + + setprg8(0x8000,DRegs[6]); + setprg8(0xA000,DRegs[7]); + + setprg8(0xC000,DRegs[10]); +} + + +static DECLFW(RAMBO1_write) +{ + switch(A&0xF001) + { + case 0xa000: mir=V&1; +/* if(!nomirror)*/ + setmirror(mir^1); + break; + case 0x8000: cmd = V; + break; + case 0x8001: if((cmd&0xF)<10) + DRegs[cmd&0xF]=V; + else if((cmd&0xF)==0xF) + DRegs[10]=V; + Synco(); + break; + case 0xc000: IRQLatch=V; + if(rmode==1) + IRQCount=IRQLatch; + break; + case 0xc001: rmode=1; + IRQCount=IRQLatch; + IRQmode=V&1; + break; + case 0xE000: IRQa=0; + X6502_IRQEnd(FCEU_IQEXT); + if(rmode==1) + IRQCount=IRQLatch; + break; + case 0xE001: IRQa=1; + if(rmode==1) + IRQCount=IRQLatch; + break; + } +} + +static void RAMBO1_Restore(int version) +{ + Synco(); +/* if(!nomirror)*/ + setmirror(mir^1); +} + +static void RAMBO1_init(void) +{ + int x; + for(x=0;x<11;x++) + DRegs[x]=~0; + cmd=mir=0; +/* if(!nomirror)*/ + setmirror(1); + Synco(); + GameHBIRQHook=RAMBO1_hb; + MapIRQHook=RAMBO1_IRQHook; + GameStateRestore=RAMBO1_Restore; + SetWriteHandler(0x8000,0xffff,RAMBO1_write); + AddExState(Rambo_StateRegs, ~0, 0, 0); +} + +static void CHRWrap(unsigned int A, unsigned int V) +{ + setchr1(A,V); +} + +void Mapper64_init(void) +{ + setchr1wrap=CHRWrap; + /* nomirror=0;*/ + RAMBO1_init(); +} +/* +static int MirCache[8]; +static unsigned int PPUCHRBus; + +static void MirWrap(unsigned int A, unsigned int V) +{ + MirCache[A>>10]=(V>>7)&1; + if(PPUCHRBus==(A>>10)) + setmirror(MI_0+((V>>7)&1)); + setchr1(A,V); +} + +static void MirrorFear(uint32 A) +{ + A&=0x1FFF; + A>>=10; + PPUCHRBus=A; + setmirror(MI_0+MirCache[A]); +} + +void Mapper158_init(void) +{ + setchr1wrap=MirWrap; + PPU_hook=MirrorFear; + nomirror=1; + RAMBO1_init(); +} +*/ diff --git a/fceumm/src-fceumm/boards/tf-1201.c b/fceumm/src-fceumm/boards/tf-1201.c new file mode 100644 index 0000000..fc5c73b --- /dev/null +++ b/fceumm/src-fceumm/boards/tf-1201.c @@ -0,0 +1,124 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Lethal Weapon (VRC4 mapper) + */ + +#include "mapinc.h" + +static uint8 prg0, prg1, mirr, swap; +static uint8 chr[8]; +static uint8 IRQCount; +static uint8 IRQPre; +static uint8 IRQa; + +static SFORMAT StateRegs[]= +{ + {&prg0, 1, "PRG0"}, + {&prg0, 1, "PRG1"}, + {&mirr, 1, "MIRR"}, + {&swap, 1, "SWAP"}, + {chr, 8, "CHR"}, + {&IRQCount, 1, "IRQCOUNT"}, + {&IRQPre, 1, "IRQPRE"}, + {&IRQa, 1, "IRQA"}, + {0} +}; + +static void SyncPrg(void) +{ + if(swap&3) + { + setprg8(0x8000,~1); + setprg8(0xC000,prg0); + } + else + { + setprg8(0x8000,prg0); + setprg8(0xC000,~1); + } + setprg8(0xA000,prg1); + setprg8(0xE000,~0); +} + +static void SyncChr(void) +{ + int i; + for(i=0; i<8; i++) + setchr1(i<<10,chr[i]); + setmirror(mirr^1); +} + +static void StateRestore(int version) +{ + SyncPrg(); + SyncChr(); +} + +static DECLFW(UNLTF1201Write) +{ + A=(A&0xF003)|((A&0xC)>>2); + if((A>=0xB000)&&(A<=0xE003)) + { + int ind=(((A>>11)-6)|(A&1))&7; + int sar=((A&2)<<1); + chr[ind]=(chr[ind]&(0xF0>>sar))|((V&0x0F)<Power=UNLTF1201Power; + GameHBIRQHook=UNLTF1201IRQCounter; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/transformer.c b/fceumm/src-fceumm/boards/transformer.c new file mode 100644 index 0000000..c0b2d81 --- /dev/null +++ b/fceumm/src-fceumm/boards/transformer.c @@ -0,0 +1,103 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +extern const char * GetKeyboard(void); + +static char *TransformerKeys, oldkeys[256]; +static int TransformerCycleCount, TransformerChar = 0; + +static void TransformerIRQHook(int a) +{ + TransformerCycleCount+=a; + if(TransformerCycleCount >= 1000) + { + uint32 i; + TransformerCycleCount -= 1000; + TransformerKeys = GetKeyboard(); + + for(i=0; i<256; i++) { + if(oldkeys[i] != TransformerKeys[i]) { + if(oldkeys[i] == 0) + TransformerChar = i; + else + TransformerChar = i | 0x80; + X6502_IRQBegin(FCEU_IQEXT); + memcpy((void *)&oldkeys[0], (void *)TransformerKeys, 256); + break; + } + } + } +} + +static DECLFR(TransformerRead) +{ + uint8 ret = 0; + switch(A&3) { + case 0: ret = TransformerChar & 15; break; + case 1: ret = (TransformerChar >> 4); break; + case 2: break; + case 4: break; + } + X6502_IRQEnd(FCEU_IQEXT); + return ret; +} + +static void TransformerPower(void) +{ + setprg8r(0x10,0x6000,0); + setprg16(0x8000,0); + setprg16(0xC000,~0); + setchr8(0); + + SetReadHandler(0x5000,0x5004,TransformerRead); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + + MapIRQHook=TransformerIRQHook; +} + +static void TransformerClose(void) +{ + if(WRAM) + free(WRAM); + WRAM=NULL; +} + +void Transformer_Init(CartInfo *info) +{ + info->Power=TransformerPower; + info->Close=TransformerClose; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); +} diff --git a/fceumm/src-fceumm/boards/vrc7.c b/fceumm/src-fceumm/boards/vrc7.c new file mode 100644 index 0000000..67936dd --- /dev/null +++ b/fceumm/src-fceumm/boards/vrc7.c @@ -0,0 +1,134 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * YOKO Mortal Kombat V Pro, VRC7 pirate clone + */ + +#include "mapinc.h" + +static uint8 prg[3], chr[8], mirr; +static uint8 IRQLatch, IRQa, IRQd; +static uint32 IRQCount, CycleCount; + +static SFORMAT StateRegs[]= +{ + {prg, 3, "PRG"}, + {chr, 8, "CHR"}, + {&mirr, 1, "MIRR"}, + {&IRQa, 1, "IRQA"}, + {&IRQd, 1, "IRQD"}, + {&IRQLatch, 1, "IRQC"}, + {&IRQCount, 4, "IRQC"}, + {&CycleCount, 4, "CYCC"}, + {0} +}; + +static void Sync(void) +{ + uint8 i; + setprg8(0x8000,prg[0]); + setprg8(0xa000,prg[1]); + setprg8(0xc000,prg[2]); + setprg8(0xe000,~0); + for(i=0; i<8; i++) + setchr1(i<<10,chr[i]); + switch(mirr&3) + { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(UNLVRC7Write) +{ + switch(A&0xF008) + { + case 0x8000: prg[0]=V; Sync(); break; + case 0x8008: prg[1]=V; Sync(); break; + case 0x9000: prg[2]=V; Sync(); break; + case 0xa000: chr[0]=V; Sync(); break; + case 0xa008: chr[1]=V; Sync(); break; + case 0xb000: chr[2]=V; Sync(); break; + case 0xb008: chr[3]=V; Sync(); break; + case 0xc000: chr[4]=V; Sync(); break; + case 0xc008: chr[5]=V; Sync(); break; + case 0xd000: chr[6]=V; Sync(); break; + case 0xd008: chr[7]=V; Sync(); break; + case 0xe000: mirr=V; Sync(); break; + case 0xe008: + IRQLatch=V; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xf000: + IRQa=V&2; + IRQd=V&1; + if(V&2) + IRQCount=IRQLatch; + CycleCount=0; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xf008: + if(IRQd) + IRQa=1; + else + IRQa=0; + X6502_IRQEnd(FCEU_IQEXT); + break; + } +} + +static void UNLVRC7Power(void) +{ + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,UNLVRC7Write); +} + +static void UNLVRC7IRQHook(int a) +{ + if(IRQa) + { + CycleCount+=a*3; + while(CycleCount>=341) + { + CycleCount-=341; + IRQCount++; + if(IRQCount==248) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount=IRQLatch; + } + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLVRC7_Init(CartInfo *info) +{ + info->Power=UNLVRC7Power; + MapIRQHook=UNLVRC7IRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/boards/yoko.c b/fceumm/src-fceumm/boards/yoko.c new file mode 100644 index 0000000..165ae09 --- /dev/null +++ b/fceumm/src-fceumm/boards/yoko.c @@ -0,0 +1,154 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * YOKO mapper, almost the same as 83, TODO: merge + * + * Mortal Kombat 2 YOKO + * N-CXX(M), XX - ðàçìåðû PRG+CHR, 12 - 128+256, 22 - 256+256, 14 - 128+512 + * + */ + +#include "mapinc.h" + +static uint8 mode, bank, reg[8], low[4], dip, IRQa; +static int32 IRQCount; + +static SFORMAT StateRegs[]= +{ + {&mode, 1, "MODE"}, + {&bank, 1, "BANK"}, + {&IRQCount, 4, "IRQC"}, + {&IRQa, 1, "IRQA"}, + {reg, 8, "REGS"}, + {low, 4, "LOWR"}, + {0} +}; + +static void Sync(void) +{ + setmirror((mode & 1)^1); + setchr2(0x0000,reg[3]); + setchr2(0x0800,reg[4]); + setchr2(0x1000,reg[5]); + setchr2(0x1800,reg[6]); + if(mode & 0x10) + { + uint32 base = (bank & 8) << 1; + setprg8(0x8000,(reg[0]&0x0f)|base); + setprg8(0xA000,(reg[1]&0x0f)|base); + setprg8(0xC000,(reg[2]&0x0f)|base); + setprg8(0xE000,0x0f|base); + } + else + { + if(mode & 8) + setprg32(0x8000,bank >> 1); + else + { + setprg16(0x8000,bank); + setprg16(0xC000,~0); + } + } +} + +static DECLFW(MYOKOWrite) +{ +/* FCEU_printf("bs %04x %02x\n",A,V);*/ + switch(A & 0x8C17) + { + case 0x8000: bank=V; break; + case 0x8400: mode=V; break; + case 0x8800: IRQCount&=0xFF00; IRQCount|=V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x8801: IRQa=mode&0x80; IRQCount&=0xFF; IRQCount|=V<<8; break; + case 0x8c00: reg[0]=V; break; + case 0x8c01: reg[1]=V; break; + case 0x8c02: reg[2]=V; break; + case 0x8c10: reg[3]=V; break; + case 0x8c11: reg[4]=V; break; + case 0x8c16: reg[5]=V; break; + case 0x8c17: reg[6]=V; break; + } + Sync(); +} + +static DECLFR(MYOKOReadDip) +{ +/* FCEU_printf("read %04x\n",A);*/ + return (X.DB&0xFC)|dip; +} + +static DECLFR(MYOKOReadLow) +{ +/* FCEU_printf("read %04x\n",A);*/ + return low[A & 3]; +} + +static DECLFW(MYOKOWriteLow) +{ +/* FCEU_printf("bs %04x\n",A);*/ + low[A & 3] = V; +} + +static void MYOKOPower(void) +{ + mode = bank = 0; + dip = 3; + Sync(); + SetReadHandler(0x5000,0x53FF,MYOKOReadDip); + SetReadHandler(0x5400,0x5FFF,MYOKOReadLow); + SetWriteHandler(0x5400,0x5FFF,MYOKOWriteLow); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,MYOKOWrite); +} + +static void MYOKOReset(void) +{ + dip = (dip + 1)&3; + mode = bank = 0; + Sync(); +} + +static void MYOKOIRQHook(int a) +{ + if(IRQa) + { + IRQCount-=a; + if(IRQCount<0) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + IRQCount=0xFFFF; + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLYOKO_Init(CartInfo *info) +{ + info->Power=MYOKOPower; + info->Reset=MYOKOReset; + MapIRQHook=MYOKOIRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/fceumm/src-fceumm/cart.c b/fceumm/src-fceumm/cart.c new file mode 100644 index 0000000..c155b52 --- /dev/null +++ b/fceumm/src-fceumm/cart.c @@ -0,0 +1,674 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +#include "types.h" +#include "fceu.h" +#include "ppu.h" + +#include "cart.h" +#include "memory.h" +#include "x6502.h" + +#include "general.h" + +/* + This file contains all code for coordinating the mapping in of the + address space external to the NES. + It's also (ab)used by the NSF code. +*/ + +uint8 *Page[32],*VPage[8]; +uint8 **VPageR=VPage; +uint8 *VPageG[8]; +uint8 *MMC5SPRVPage[8]; +uint8 *MMC5BGVPage[8]; + +static uint8 PRGIsRAM[32]; /* This page is/is not PRG RAM. */ + +/* 16 are (sort of) reserved for UNIF/iNES and 16 to map other stuff. */ +static int CHRram[32]; +static int PRGram[32]; + +uint8 *PRGptr[32]; +uint8 *CHRptr[32]; + +uint32 PRGsize[32]; +uint32 CHRsize[32]; + +uint32 PRGmask2[32]; +uint32 PRGmask4[32]; +uint32 PRGmask8[32]; +uint32 PRGmask16[32]; +uint32 PRGmask32[32]; + +uint32 CHRmask1[32]; +uint32 CHRmask2[32]; +uint32 CHRmask4[32]; +uint32 CHRmask8[32]; + +int geniestage=0; + +int modcon; + +uint8 genieval[3]; +uint8 geniech[3]; + +uint32 genieaddr[3]; + +static INLINE void setpageptr(int s, uint32 A, uint8 *p, int ram) +{ + uint32 AB=A>>11; + int x; + + if(p) + for(x=(s>>1)-1;x>=0;x--) + { + PRGIsRAM[AB+x]=ram; + Page[AB+x]=p-A; + } + else + for(x=(s>>1)-1;x>=0;x--) + { + PRGIsRAM[AB+x]=0; + Page[AB+x]=0; + } +} + +static uint8 nothing[8192]; +void ResetCartMapping(void) +{ + int x; + + for(x=0;x<32;x++) + { + Page[x]=nothing-x*2048; + PRGptr[x]=CHRptr[x]=0; + PRGsize[x]=CHRsize[x]=0; + } + for(x=0;x<8;x++) + { + MMC5SPRVPage[x]=MMC5BGVPage[x]=VPageR[x]=nothing-0x400*x; + } + +} + +void SetupCartPRGMapping(int chip, uint8 *p, uint32 size, int ram) +{ + PRGptr[chip]=p; + PRGsize[chip]=size; + + PRGmask2[chip]=(size>>11)-1; + PRGmask4[chip]=(size>>12)-1; + PRGmask8[chip]=(size>>13)-1; + PRGmask16[chip]=(size>>14)-1; + PRGmask32[chip]=(size>>15)-1; + + PRGram[chip]=ram?1:0; +} + +void SetupCartCHRMapping(int chip, uint8 *p, uint32 size, int ram) +{ + CHRptr[chip]=p; + CHRsize[chip]=size; + + CHRmask1[chip]=(size>>10)-1; + CHRmask2[chip]=(size>>11)-1; + CHRmask4[chip]=(size>>12)-1; + CHRmask8[chip]=(size>>13)-1; + + CHRram[chip]=ram; +} + +DECLFR(CartBR) +{ + return Page[A>>11][A]; +} + +DECLFW(CartBW) +{ + /*printf("Ok: %04x:%02x, %d\n",A,V,PRGIsRAM[A>>11]);*/ + if(PRGIsRAM[A>>11] && Page[A>>11]) + Page[A>>11][A]=V; +} + +DECLFR(CartBROB) +{ + if(!Page[A>>11]) return(X.DB); + return Page[A>>11][A]; +} + +void setprg2r(int r, unsigned int A, unsigned int V) +{ + V&=PRGmask2[r]; + setpageptr(2,A,PRGptr[r]?(&PRGptr[r][V<<11]):0,PRGram[r]); +} + +void setprg2(uint32 A, uint32 V) +{ + setprg2r(0,A,V); +} + +void setprg4r(int r, unsigned int A, unsigned int V) +{ + V&=PRGmask4[r]; + setpageptr(4,A,PRGptr[r]?(&PRGptr[r][V<<12]):0,PRGram[r]); +} + +void setprg4(uint32 A, uint32 V) +{ + setprg4r(0,A,V); +} + +void setprg8r(int r, unsigned int A, unsigned int V) +{ + if(PRGsize[r]>=8192) + { + V&=PRGmask8[r]; + setpageptr(8,A,PRGptr[r]?(&PRGptr[r][V<<13]):0,PRGram[r]); + } + else + { + uint32 VA=V<<2; + int x; + for(x=0;x<4;x++) + setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]); + } +} + +void setprg8(uint32 A, uint32 V) +{ + setprg8r(0,A,V); +} + +void setprg16r(int r, unsigned int A, unsigned int V) +{ + if(PRGsize[r]>=16384) + { + V&=PRGmask16[r]; + setpageptr(16,A,PRGptr[r]?(&PRGptr[r][V<<14]):0,PRGram[r]); + } + else + { + uint32 VA=V<<3; + int x; + + for(x=0;x<8;x++) + setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]); + } +} + +void setprg16(uint32 A, uint32 V) +{ + setprg16r(0,A,V); +} + +void setprg32r(int r,unsigned int A, unsigned int V) +{ + if(PRGsize[r]>=32768) + { + V&=PRGmask32[r]; + setpageptr(32,A,PRGptr[r]?(&PRGptr[r][V<<15]):0,PRGram[r]); + } + else + { + uint32 VA=V<<4; + int x; + + for(x=0;x<16;x++) + setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]); + } +} + +void setprg32(uint32 A, uint32 V) +{ + setprg32r(0,A,V); +} + +void setchr1r(int r, unsigned int A, unsigned int V) +{ + if(!CHRptr[r]) return; + FCEUPPU_LineUpdate(); + V&=CHRmask1[r]; + if(CHRram[r]) + PPUCHRRAM|=(1<<(A>>10)); + else + PPUCHRRAM&=~(1<<(A>>10)); + VPageR[(A)>>10]=&CHRptr[r][(V)<<10]-(A); +} + +void setchr2r(int r, unsigned int A, unsigned int V) +{ + if(!CHRptr[r]) return; + FCEUPPU_LineUpdate(); + V&=CHRmask2[r]; + VPageR[(A)>>10]=VPageR[((A)>>10)+1]=&CHRptr[r][(V)<<11]-(A); + if(CHRram[r]) + PPUCHRRAM|=(3<<(A>>10)); + else + PPUCHRRAM&=~(3<<(A>>10)); +} + +void setchr4r(int r, unsigned int A, unsigned int V) +{ + if(!CHRptr[r]) return; + FCEUPPU_LineUpdate(); + V&=CHRmask4[r]; + VPageR[(A)>>10]=VPageR[((A)>>10)+1]= + VPageR[((A)>>10)+2]=VPageR[((A)>>10)+3]=&CHRptr[r][(V)<<12]-(A); + if(CHRram[r]) + PPUCHRRAM|=(15<<(A>>10)); + else + PPUCHRRAM&=~(15<<(A>>10)); +} + +void setchr8r(int r, unsigned int V) +{ + int x; + + if(!CHRptr[r]) return; + FCEUPPU_LineUpdate(); + V&=CHRmask8[r]; + for(x=7;x>=0;x--) + VPageR[x]=&CHRptr[r][V<<13]; + if(CHRram[r]) + PPUCHRRAM|=(255); + else + PPUCHRRAM&=~(255); +} + +void setchr1(unsigned int A, unsigned int V) +{ + setchr1r(0,A,V); +} + +void setchr2(unsigned int A, unsigned int V) +{ + setchr2r(0,A,V); +} + +void setchr4(unsigned int A, unsigned int V) +{ + setchr4r(0,A,V); +} + +void setchr8(unsigned int V) +{ + setchr8r(0,V); +} + +void setvram8(uint8 *p) +{ + int x; + for(x=7;x>=0;x--) + VPageR[x]=p; + PPUCHRRAM|=255; +} + +void setvram4(uint32 A, uint8 *p) +{ + int x; + for(x=3;x>=0;x--) + VPageR[(A>>10)+x]=p-A; + PPUCHRRAM|=(15<<(A>>10)); +} + +void setvramb1(uint8 *p, uint32 A, uint32 b) +{ + FCEUPPU_LineUpdate(); + VPageR[A>>10]=p-A+(b<<10); + PPUCHRRAM|=(1<<(A>>10)); +} + +void setvramb2(uint8 *p, uint32 A, uint32 b) +{ + FCEUPPU_LineUpdate(); + VPageR[(A>>10)]=VPageR[(A>>10)+1]=p-A+(b<<11); + PPUCHRRAM|=(3<<(A>>10)); +} + +void setvramb4(uint8 *p, uint32 A, uint32 b) +{ + int x; + + FCEUPPU_LineUpdate(); + for(x=3;x>=0;x--) + VPageR[(A>>10)+x]=p-A+(b<<12); + PPUCHRRAM|=(15<<(A>>10)); +} + +void setvramb8(uint8 *p, uint32 b) +{ + int x; + + FCEUPPU_LineUpdate(); + for(x=7;x>=0;x--) + VPageR[x]=p+(b<<13); + PPUCHRRAM|=255; +} + +/* This function can be called without calling SetupCartMirroring(). */ + +void setntamem(uint8 *p, int ram, uint32 b) +{ + FCEUPPU_LineUpdate(); + vnapage[b]=p; + PPUNTARAM&=~(1<>3)&1) /* No check*/ + return genieval[2]; + else if(r==geniech[2]) + return genieval[2]; + + return r; +} + +static DECLFR(GenieFix2) +{ + uint8 r=GenieBackup[1](A); + + if((modcon>>2)&1) /* No check*/ + return genieval[1]; + else if(r==geniech[1]) + return genieval[1]; + + return r; +} + +static DECLFR(GenieFix1) +{ + uint8 r=GenieBackup[0](A); + + if((modcon>>1)&1) /* No check*/ + return genieval[0]; + else if(r==geniech[0]) + return genieval[0]; + + return r; +} + +static void FixGenieMap(void) +{ + int x; + + geniestage=2; + + for(x=0;x<8;x++) + VPage[x]=VPageG[x]; + + VPageR=VPage; + FlushGenieRW(); + for(x=0;x<3;x++) + if((modcon>>(4+x))&1) + { + readfunc tmp[3]={GenieFix1,GenieFix2,GenieFix3}; + GenieBackup[x]=GetReadHandler(genieaddr[x]); + SetReadHandler(genieaddr[x],genieaddr[x],tmp[x]); + } +} + +static DECLFW(GenieWrite) +{ + switch(A) + { + case 0x800c: + case 0x8008: + case 0x8004:genieval[((A-4)&0xF)>>2]=V;break; + + case 0x800b: + case 0x8007: + case 0x8003:geniech[((A-3)&0xF)>>2]=V;break; + + case 0x800a: + case 0x8006: + case 0x8002:genieaddr[((A-2)&0xF)>>2]&=0xFF00;genieaddr[((A-2)&0xF)>>2]|=V;break; + + case 0x8009: + case 0x8005: + case 0x8001:genieaddr[((A-1)&0xF)>>2]&=0xFF;genieaddr[((A-1)&0xF)>>2]|=(V|0x80)<<8;break; + + case 0x8000:if(!V) + FixGenieMap(); + else + { + modcon=V^0xFF; + if(V==0x71) + modcon=0; + } + break; + } +} + +void GeniePower(void) +{ + uint32 x; + + if(!geniestage) + return; + + geniestage=1; + for(x=0;x<3;x++) + { + genieval[x]=0xFF; + geniech[x]=0xFF; + genieaddr[x]=0xFFFF; + } + modcon=0; + + SetWriteHandler(0x8000,0xFFFF,GenieWrite); + SetReadHandler(0x8000,0xFFFF,GenieRead); + + for(x=0;x<8;x++) + VPage[x]=GENIEROM+4096-0x400*x; + + if(AllocGenieRW()) + VPageR=VPageG; + else + geniestage=2; +} + + +void FCEU_SaveGameSave(CartInfo *LocalHWInfo) +{ + if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) + { + FILE *sp; + const char * soot=FCEU_MakeFName(FCEUMKF_SAV,0,"sav"); + if((sp=fopen(soot,"wb"))==NULL) + { + FCEU_PrintError("WRAM file \"%s\" cannot be written to.\n",soot); + } + else + { + int x; + + for(x=0;x<4;x++) + if(LocalHWInfo->SaveGame[x]) + fwrite(LocalHWInfo->SaveGame[x],1, LocalHWInfo->SaveGameLen[x],sp); + + fclose(sp); + } + free(soot); + } +} + +void FCEU_LoadGameSave(CartInfo *LocalHWInfo) +{ + if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) + { + FILE *sp; + const char * soot= FCEU_MakeFName(FCEUMKF_SAV,0,"sav"); + sp= fopen(soot,"rb"); + if(sp!=NULL) + { + int x; + for(x=0;x<4;x++) + if(LocalHWInfo->SaveGame[x]) + fread(LocalHWInfo->SaveGame[x],1,LocalHWInfo->SaveGameLen[x],sp); + + fclose(sp); + } + free(soot); + } +} diff --git a/fceumm/src-fceumm/cart.h b/fceumm/src-fceumm/cart.h new file mode 100644 index 0000000..24f90cf --- /dev/null +++ b/fceumm/src-fceumm/cart.h @@ -0,0 +1,100 @@ +typedef struct { + /* Set by mapper/board code: */ + void (*Power)(void); + void (*Reset)(void); + void (*Close)(void); + uint8 *SaveGame[4]; /* Pointers to memory to save/load. */ + uint32 SaveGameLen[4]; /* How much memory to save/load. */ + + /* Set by iNES/UNIF loading code. */ + int mirror; /* As set in the header or chunk. + iNES/UNIF specific. Intended + to help support games like "Karnov" + that are not really MMC3 but are + set to mapper 4. + */ + int battery; /* Presence of an actual battery. */ + uint8 MD5[16]; + uint32 CRC32; /* Should be set by the iNES/UNIF loading + code, used by mapper/board code, maybe + other code in the future. + */ +} CartInfo; + +void FCEU_SaveGameSave(CartInfo *LocalHWInfo); +void FCEU_LoadGameSave(CartInfo *LocalHWInfo); + +extern uint8 *Page[32],*VPage[8],*MMC5SPRVPage[8],*MMC5BGVPage[8]; + +void ResetCartMapping(void); +void SetupCartPRGMapping(int chip, uint8 *p, uint32 size, int ram); +void SetupCartCHRMapping(int chip, uint8 *p, uint32 size, int ram); +void SetupCartMirroring(int m, int hard, uint8 *extra); + +DECLFR(CartBROB); +DECLFR(CartBR); +DECLFW(CartBW); + +extern uint8 *PRGptr[32]; +extern uint8 *CHRptr[32]; + +extern uint32 PRGsize[32]; +extern uint32 CHRsize[32]; + +extern uint32 PRGmask2[32]; +extern uint32 PRGmask4[32]; +extern uint32 PRGmask8[32]; +extern uint32 PRGmask16[32]; +extern uint32 PRGmask32[32]; + +extern uint32 CHRmask1[32]; +extern uint32 CHRmask2[32]; +extern uint32 CHRmask4[32]; +extern uint32 CHRmask8[32]; + +void setprg2(uint32 A, uint32 V); +void setprg4(uint32 A, uint32 V); +void setprg8(uint32 A, uint32 V); +void setprg16(uint32 A, uint32 V); +void setprg32(uint32 A, uint32 V); + +void setprg2r(int r, unsigned int A, unsigned int V); +void setprg4r(int r, unsigned int A, unsigned int V); +void setprg8r(int r, unsigned int A, unsigned int V); +void setprg16r(int r, unsigned int A, unsigned int V); +void setprg32r(int r, unsigned int A, unsigned int V); + +void setchr1r(int r, unsigned int A, unsigned int V); +void setchr2r(int r, unsigned int A, unsigned int V); +void setchr4r(int r, unsigned int A, unsigned int V); +void setchr8r(int r, unsigned int V); + +void setchr1(unsigned int A, unsigned int V); +void setchr2(unsigned int A, unsigned int V); +void setchr4(unsigned int A, unsigned int V); +void setchr8(unsigned int V); + +void setvram4(uint32 A, uint8 *p); +void setvram8(uint8 *p); + +void setvramb1(uint8 *p, uint32 A, uint32 b); +void setvramb2(uint8 *p, uint32 A, uint32 b); +void setvramb4(uint8 *p, uint32 A, uint32 b); +void setvramb8(uint8 *p, uint32 b); + +void setmirror(int t); +void setmirrorw(int a, int b, int c, int d); +void setntamem(uint8 *p, int ram, uint32 b); + +#define MI_H 0 +#define MI_V 1 +#define MI_0 2 +#define MI_1 3 + +extern int geniestage; + +void GeniePower(void); + +void OpenGenie(void); +void CloseGenie(void); +void FCEU_KillGenie(void); diff --git a/fceumm/src-fceumm/cheat.c b/fceumm/src-fceumm/cheat.c new file mode 100644 index 0000000..62c8c0d --- /dev/null +++ b/fceumm/src-fceumm/cheat.c @@ -0,0 +1,673 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include + +#include "types.h" +#include "x6502.h" +#include "cheat.h" +#include "fceu.h" +#include "general.h" +#include "cart.h" +#include "memory.h" + +static uint8 *CheatRPtrs[64]; + +void FCEU_CheatResetRAM(void) +{ + int x; + + for(x=0;x<64;x++) + CheatRPtrs[x]=0; +} + +void FCEU_CheatAddRAM(int s, uint32 A, uint8 *p) +{ + uint32 AB=A>>10; + int x; + + for(x=s-1;x>=0;x--) + CheatRPtrs[AB+x]=p-A; +} + + +struct CHEATF { + struct CHEATF *next; + const char *name; + uint16 addr; + uint8 val; + int compare; /* -1 for no compare. */ + int type; /* 0 for replace, 1 for substitute(GG). */ + int status; +}; + +typedef struct { + uint16 addr; + uint8 val; + int compare; + readfunc PrevRead; +} CHEATF_SUBFAST; + + +static CHEATF_SUBFAST SubCheats[256]; +static int numsubcheats=0; +struct CHEATF *cheats=0,*cheatsl=0; + + +#define CHEATC_NONE 0x8000 +#define CHEATC_EXCLUDED 0x4000 +#define CHEATC_NOSHOW 0xC000 + +static uint16 *CheatComp=0; +static int savecheats; + +static DECLFR(SubCheatsRead) +{ + CHEATF_SUBFAST *s=SubCheats; + int x=numsubcheats; + + do + { + if(s->addr==A) + { + if(s->compare>=0) + { + uint8 pv=s->PrevRead(A); + + if(pv==s->compare) + return(s->val); + else return(pv); + } + else return(s->val); + } + s++; + } while(--x); + return(0); /* We should never get here. */ +} + +void RebuildSubCheats(void) +{ + int x; + struct CHEATF *c=cheats; + + for(x=0;xtype==1 && c->status) + { + if(GetReadHandler(c->addr)==SubCheatsRead) + { + /* Prevent a catastrophe by this check. */ + /*FCEU_DispMessage("oops");*/ + } + else + { + SubCheats[numsubcheats].PrevRead=GetReadHandler(c->addr); + SubCheats[numsubcheats].addr=c->addr; + SubCheats[numsubcheats].val=c->val; + SubCheats[numsubcheats].compare=c->compare; + SetReadHandler(c->addr,c->addr,SubCheatsRead); + numsubcheats++; + } + } + c=c->next; + } +} + +void FCEU_PowerCheats() +{ + numsubcheats=0; /* Quick hack to prevent setting of ancient read addresses. */ + RebuildSubCheats(); +} + +static void CheatMemErr(void) +{ + FCEUD_PrintError("Error allocating memory for cheat data."); +} + +/* This function doesn't allocate any memory for "name" */ +static int AddCheatEntry(const char *name, uint32 addr, uint8 val, int compare, int status, int type) +{ + struct CHEATF *temp; + if(!(temp=(struct CHEATF *)malloc(sizeof(struct CHEATF)))) + { + CheatMemErr(); + return(0); + } + temp->name=name; + temp->addr=addr; + temp->val=val; + temp->status=status; + temp->compare=compare; + temp->type=type; + temp->next=0; + + if(cheats) + { + cheatsl->next=temp; + cheatsl=temp; + } + else + cheats=cheatsl=temp; + + return(1); +} + +void FCEU_LoadGameCheats(FILE *override) +{ + FILE *fp; + unsigned int addr; + unsigned int val; + unsigned int status; + unsigned int type; + unsigned int compare; + int x; + + char linebuf[2048]; + char *namebuf; + int tc=0; + + numsubcheats=savecheats=0; + + if(override) + fp = override; + else + { + const char * fn=FCEU_MakeFName(FCEUMKF_CHEAT,0,0); + fp=fopen(fn,"rb"); + free(fn); + if(!fp) + { + fclose(fp); + return; + } + } + + while(fgets(linebuf,2048,fp)>0) + { + char *tbuf=linebuf; + int doc=0; + + addr=val=compare=status=type=0; + + if(tbuf[0]=='S') + { + tbuf++; + type=1; + } + else type=0; + + if(tbuf[0]=='C') + { + tbuf++; + doc=1; + } + + if(tbuf[0]==':') + { + tbuf++; + status=0; + } + else status=1; + + if(doc) + { + char *neo=&tbuf[4+2+2+1+1+1]; + if(sscanf(tbuf,"%04x%*[:]%02x%*[:]%02x",&addr,&val,&compare)!=3) + continue; + namebuf=malloc(strlen(neo)+1); + strcpy(namebuf,neo); + } + else + { + char *neo=&tbuf[4+2+1+1]; + if(sscanf(tbuf,"%04x%*[:]%02x",&addr,&val)!=2) + continue; + namebuf=malloc(strlen(neo)+1); + strcpy(namebuf,neo); + } + + for(x=0;xnext; + free(last->name); + free(last); + if(!next) break; + } + cheats=cheatsl=0; + } + } + else + { + const char *fn = !override ? FCEU_MakeFName(FCEUMKF_CHEAT,0,0) : 0; + + if(cheats) + { + struct CHEATF *next=cheats; + FILE *fp; + + if(override) + fp = override; + else + fp= fopen(fn,"wb"); + + if(fp) + { + for(;;) + { + struct CHEATF *t; + if(next->type) + fputc('S',fp); + if(next->compare>=0) + fputc('C',fp); + + if(!next->status) + fputc(':',fp); + + if(next->compare>=0) + fprintf(fp,"%04x:%02x:%02x:%s\n",next->addr,next->val,next->compare,next->name); + else + fprintf(fp,"%04x:%02x:%s\n",next->addr,next->val,next->name); + + free(next->name); + t=next; + next=next->next; + free(t); + if(!next) break; + } + if(!override) + fclose(fp); + } + else + FCEUD_PrintError("Error saving cheats."); + cheats=cheatsl=0; + } + else if(!override) + remove(fn); + if(!override) + free(fn); + } + + RebuildSubCheats(); /* Remove memory handlers. */ + +} + + +int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int type) +{ + char *t; + + if(!(t=(char *)malloc(strlen(name)+1))) + { + CheatMemErr(); + return(0); + } + strcpy(t,name); + if(!AddCheatEntry(t,addr,val,compare,1,type)) + { + free(t); + return(0); + } + savecheats=1; + RebuildSubCheats(); + return(1); +} + +int FCEUI_DelCheat(uint32 which) +{ + struct CHEATF *prev; + struct CHEATF *cur; + uint32 x=0; + + for(prev=0,cur=cheats;;) + { + if(x==which) /* Remove this cheat.*/ + { + if(prev) /* Update pointer to this cheat.*/ + { + if(cur->next) /* More cheats.*/ + prev->next=cur->next; + else /* No more.*/ + { + prev->next=0; + cheatsl=prev; /* Set the previous cheat as the last cheat.*/ + } + } + else /* This is the first cheat.*/ + { + if(cur->next) /* More cheats*/ + cheats=cur->next; + else + cheats=cheatsl=0; /* No (more) cheats.*/ + } + free(cur->name); /* Now that all references to this cheat are removed,*/ + free(cur); /* free the memory.*/ + break; + } /* *END REMOVE THIS CHEAT**/ + + + if(!cur->next) /* No more cheats to go through(this shouldn't ever happen...)*/ + return(0); + prev=cur; + cur=prev->next; + x++; + } + + savecheats=1; + RebuildSubCheats(); + + return(1); +} + +void FCEU_ApplyPeriodicCheats(void) +{ + struct CHEATF *cur=cheats; + if(!cur) return; + + for(;;) + { + if(cur->status && !(cur->type)) + if(CheatRPtrs[cur->addr>>10]) + CheatRPtrs[cur->addr>>10][cur->addr]=cur->val; + if(cur->next) + cur=cur->next; + else + break; + } +} + +const char * FCEUI_GetCheatLabel(unsigned int which) +{ + struct CHEATF *next=cheats; + uint32 x=0; + + while(next) + { + if(x==which) + { + return next->name; + } + next=next->next; + x++; + } + return ""; +} + +int FCEUI_GetCheat(uint32 which, char **name, uint32 *a, uint8 *v, int *compare, int *s, int *type) +{ + struct CHEATF *next=cheats; + uint32 x=0; + + while(next) + { + if(x==which) + { + if(name) + *name=next->name; + if(a) + *a=next->addr; + if(v) + *v=next->val; + if(s) + *s=next->status; + if(compare) + *compare=next->compare; + if(type) + *type=next->type; + return(1); + } + next=next->next; + x++; + } + return(0); +} + +static int GGtobin(char c) +{ + static char lets[16]={'A','P','Z','L','G','I','T','Y','E','O','X','U','K','S','V','N'}; + int x; + + for(x=0;x<16;x++) + if(lets[x] == toupper(c)) return(x); + return(0); +} + +/* Returns 1 on success, 0 on failure. Sets *a,*v,*c. */ +int FCEUI_DecodeGG(const char *str, uint16 *a, uint8 *v, int *c) +{ + uint16 A; + uint8 V,C; + uint8 t; + int s; + + A=0x8000; + V=0; + C=0; + + s=strlen(str); + if(s!=6 && s!=8) return(0); + + t=GGtobin(*str++); + V|=(t&0x07); + V|=(t&0x08)<<4; + + t=GGtobin(*str++); + V|=(t&0x07)<<4; + A|=(t&0x08)<<4; + + t=GGtobin(*str++); + A|=(t&0x07)<<4; + /*if(t&0x08) return(0); 8-character code?! */ + + t=GGtobin(*str++); + A|=(t&0x07)<<12; + A|=(t&0x08); + + t=GGtobin(*str++); + A|=(t&0x07); + A|=(t&0x08)<<8; + + if(s==6) + { + t=GGtobin(*str++); + A|=(t&0x07)<<8; + V|=(t&0x08); + + *a=A; + *v=V; + *c=-1; + return(1); + } + else + { + t=GGtobin(*str++); + A|=(t&0x07)<<8; + C|=(t&0x08); + + t=GGtobin(*str++); + C|=(t&0x07); + C|=(t&0x08)<<4; + + t=GGtobin(*str++); + C|=(t&0x07)<<4; + V|=(t&0x08); + *a=A; + *v=V; + *c=C; + return(1); + } + return(0); +} + +int FCEUI_DecodePAR(const char *str, uint16 *a, uint8 *v, int *c, int *type) +{ + int boo[4]; + if(strlen(str)!=8) return(0); + + sscanf(str,"%02x%02x%02x%02x",boo,boo+1,boo+2,boo+3); + + *c=-1; + + if(1) + { + *a=(boo[3]<<8)|(boo[2]+0x7F); + *v=0; + } + else + { + *v=boo[3]; + *a=boo[2]|(boo[1]<<8); + } + /* Zero-page addressing modes don't go through the normal read/write handlers in FCEU, so + we must do the old hacky method of RAM cheats. + */ + if(*a<0x0100) + *type=0; + else + *type=1; + return(1); +} + +/* name can be NULL if the name isn't going to be changed. */ +/* same goes for a, v, and s(except the values of each one must be <0) */ + +int FCEUI_SetCheat(uint32 which, const char *name, int32 a, int32 v, int compare,int s, int type) +{ + struct CHEATF *next=cheats; + uint32 x=0; + + while(next) + { + if(x==which) + { + if(name) + { + char *t; + + if((t=(char *)realloc(next->name,strlen(name+1)))) + { + next->name=t; + strcpy(next->name,name); + } + else + return(0); + } + if(a>=0) + next->addr=a; + if(v>=0) + next->val=v; + if(s>=0) + next->status=s; + if(compare>=0) + next->compare=compare; + next->type=type; + + savecheats=1; + RebuildSubCheats(); + + return(1); + } + next=next->next; + x++; + } + return(0); +} + +/* Convenience function. */ +int FCEUI_ToggleCheat(uint32 which) +{ + struct CHEATF *next=cheats; + uint32 x=0; + + while(next) + { + if(x==which) + { + next->status=!next->status; + savecheats=1; + RebuildSubCheats(); + return(next->status); + } + next=next->next; + x++; + } + + return(-1); +} + +static int InitCheatComp(void) +{ + uint32 x; + + CheatComp=(uint16*)malloc(65536*sizeof(uint16)); + if(!CheatComp) + { + CheatMemErr(); + return(0); + } + for(x=0;x<65536;x++) + CheatComp[x]=CHEATC_NONE; + + return(1); +} + +static int INLINE CAbs(int x) +{ + if(x<0) + return(0-x); + return x; +} diff --git a/fceumm/src-fceumm/cheat.h b/fceumm/src-fceumm/cheat.h new file mode 100644 index 0000000..8325f9f --- /dev/null +++ b/fceumm/src-fceumm/cheat.h @@ -0,0 +1,23 @@ +#ifndef _FCEU_CHEAT_H +#define _FCEU_CHEAT_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void FCEU_CheatResetRAM(void); +void FCEU_CheatAddRAM(int s, uint32 A, uint8 *p); + +void FCEU_LoadGameCheats(FILE *override); +void FCEU_FlushGameCheats(FILE *override, int nosave); +void FCEU_ApplyPeriodicCheats(void); +void FCEU_PowerCheats(void); +const char * FCEUI_GetCheatLabel(unsigned int which); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/fceumm/src-fceumm/crc32.h b/fceumm/src-fceumm/crc32.h new file mode 100644 index 0000000..892dac2 --- /dev/null +++ b/fceumm/src-fceumm/crc32.h @@ -0,0 +1 @@ +uint32 CalcCRC32(uint32 crc, uint8 *buf, uint32 len); diff --git a/fceumm/src-fceumm/driver.h b/fceumm/src-fceumm/driver.h new file mode 100644 index 0000000..590c782 --- /dev/null +++ b/fceumm/src-fceumm/driver.h @@ -0,0 +1,147 @@ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#include "types.h" +#include "git.h" + +/* Video interface */ +void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b); +void FCEUD_GetPalette(uint8 i,uint8 *r, uint8 *g, uint8 *b); + +/* Displays an error. Can block or not. */ +void FCEUD_PrintError(const char *s); +void FCEUD_Message(const char *s); + +void ResetNES(void); +void PowerNES(void); + +void FCEUI_NTSCSELHUE(void); +void FCEUI_NTSCSELTINT(void); +void FCEUI_NTSCDEC(void); +void FCEUI_NTSCINC(void); +void FCEUI_GetNTSCTH(int *tint, int *hue); +void FCEUI_SetNTSCTH(int n, int tint, int hue); + +void FCEUI_SetInput(int port, int type, void *ptr, int attrib); +void FCEUI_SetInputFC(int type, void *ptr, int attrib); +void FCEUI_DisableFourScore(int s); + +#define SI_NONE 0 +#define SI_GAMEPAD 1 +#define SI_ZAPPER 2 +#define SI_POWERPADA 3 +#define SI_POWERPADB 4 +#define SI_ARKANOID 5 +#define SI_MOUSE 6 + +#define SIFC_NONE 0 +#define SIFC_ARKANOID 1 +#define SIFC_SHADOW 2 +#define SIFC_4PLAYER 3 +#define SIFC_FKB 4 +#define SIFC_SUBORKB 5 +#define SIFC_HYPERSHOT 6 +#define SIFC_MAHJONG 7 +#define SIFC_QUIZKING 8 +#define SIFC_FTRAINERA 9 +#define SIFC_FTRAINERB 10 +#define SIFC_OEKAKIDS 11 +#define SIFC_BWORLD 12 +#define SIFC_TOPRIDER 13 + +#define SIS_NONE 0 +#define SIS_DATACH 1 +#define SIS_NWC 2 +#define SIS_VSUNISYSTEM 3 +#define SIS_NSF 4 + +/* New interface functions */ + +/* 0 to keep 8-sprites limitation, 1 to remove it */ +void FCEUI_DisableSpriteLimitation(int a); + +/* name=path and file to load. returns 0 on failure, 1 on success */ +FCEUGI *FCEUI_LoadGame(const char *name); + +#ifdef COPYFAMI +/* Fake UNIF board to start new CFHI instance */ +FCEUGI *FCEUI_CopyFamiStart(); +#endif + +/* allocates memory. 0 on failure, 1 on success. */ +int FCEUI_Initialize(void); + +/* Emulates a frame. */ +void FCEUI_Emulate(uint8 **, int32 **, int32 *); + +/* Closes currently loaded game */ +void FCEUI_CloseGame(void); + +/* Enable/Disable game genie. a=0 disable, a=1 enable */ +void FCEUI_SetGameGenie(int a); + +/* Set video system a=0 NTSC, a=1 PAL */ +void FCEUI_SetVidSystem(int a); + +/* Convenience function; returns currently emulated video system(0=NTSC, 1=PAL). */ +int FCEUI_GetCurrentVidSystem(int *slstart, int *slend); + +/* First and last scanlines to render, for ntsc and pal emulation. */ +void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall); + +/* Sets the base directory(save states, snapshots, etc. are saved in directories + below this directory. */ +void FCEUI_SetBaseDirectory(char *dir); + +/* Tells FCE Ultra to copy the palette data pointed to by pal and use it. + Data pointed to by pal needs to be 64*3 bytes in length. +*/ +void FCEUI_SetPaletteArray(uint8 *pal); + +/* Sets up sound code to render sound at the specified rate, in samples + per second. Only sample rates of 44100, 48000, and 96000 are currently + supported. + If "Rate" equals 0, sound is disabled. +*/ +void FCEUI_Sound(int Rate); +void FCEUI_SetSoundVolume(uint32 volume); + +int FCEUI_DecodePAR(const char *code, uint16 *a, uint8 *v, int *c, int *type); +int FCEUI_DecodeGG(const char *str, uint16 *a, uint8 *v, int *c); +int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int type); +int FCEUI_DelCheat(uint32 which); +int FCEUI_ToggleCheat(uint32 which); + +int FCEUI_GetCheat(uint32 which, char **name, uint32 *a, uint8 *v, int *compare, int *s, int *type); +int FCEUI_SetCheat(uint32 which, const char *name, int32 a, int32 v, int compare,int s, int type); + +#define FCEUIOD_STATE 0 +#define FCEUIOD_SNAPS 1 +#define FCEUIOD_NV 2 +#define FCEUIOD_CHEATS 3 +#define FCEUIOD_MISC 4 +#define FCEUIOD__COUNT 6 + +void FCEUI_SetDirOverride(int which, const char *n); + +uint32 FCEUI_CRC32(uint32 crc, uint8 *buf, uint32 len); + +void FCEUI_VSUniToggleDIPView(void); +void FCEUI_VSUniToggleDIP(int w); +uint8 FCEUI_VSUniGetDIPs(void); +void FCEUI_VSUniSetDIP(int w, int state); +void FCEUI_VSUniCoin(void); + +int FCEUI_FDSInsert(int oride); +int FCEUI_FDSEject(void); +void FCEUI_FDSSelect(void); + +int FCEUI_DatachSet(const uint8 *rcode); + +#ifdef __cplusplus +} +#endif + diff --git a/fceumm/src-fceumm/fceu.c b/fceumm/src-fceumm/fceu.c new file mode 100644 index 0000000..8af5c1a --- /dev/null +++ b/fceumm/src-fceumm/fceu.c @@ -0,0 +1,530 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include + +#include "types.h" +#include "x6502.h" +#include "fceu.h" +#include "ppu.h" +#include "sound.h" +#include "general.h" +#include "myendian.h" +#include "memory.h" + +#include "cart.h" +#include "fds.h" +#include "ines.h" +#include "unif.h" +#include "cheat.h" +#include "palette.h" +#include "state.h" +#include "input.h" +#include "file.h" +#include "crc32.h" +#include "vsuni.h" + +uint64 timestampbase; + + +FCEUGI *FCEUGameInfo = NULL; +void (*GameInterface)(int h); + +void (*GameStateRestore)(int version); + +readfunc ARead[0x10000]; +writefunc BWrite[0x10000]; +static readfunc *AReadG; +static writefunc *BWriteG; +static int RWWrap=0; + +static DECLFW(BNull) +{ + +} + +static DECLFR(ANull) +{ + return(X.DB); +} + +int AllocGenieRW(void) +{ + if(!(AReadG=(readfunc *)FCEU_malloc(0x8000*sizeof(readfunc)))) + return 0; + if(!(BWriteG=(writefunc *)FCEU_malloc(0x8000*sizeof(writefunc)))) + return 0; + RWWrap=1; + return 1; +} + +void FlushGenieRW(void) +{ + int32 x; + + if(RWWrap) + { + for(x=0;x<0x8000;x++) + { + ARead[x+0x8000]=AReadG[x]; + BWrite[x+0x8000]=BWriteG[x]; + } + free(AReadG); + free(BWriteG); + AReadG=0; + BWriteG=0; + RWWrap=0; + } +} + +readfunc GetReadHandler(int32 a) +{ + if(a>=0x8000 && RWWrap) + return AReadG[a-0x8000]; + else + return ARead[a]; +} + +void SetReadHandler(int32 start, int32 end, readfunc func) +{ + int32 x; + + if(!func) + func=ANull; + + if(RWWrap) + for(x=end;x>=start;x--) + { + if(x>=0x8000) + AReadG[x-0x8000]=func; + else + ARead[x]=func; + } + else + + for(x=end;x>=start;x--) + ARead[x]=func; +} + +writefunc GetWriteHandler(int32 a) +{ + if(RWWrap && a>=0x8000) + return BWriteG[a-0x8000]; + else + return BWrite[a]; +} + +void SetWriteHandler(int32 start, int32 end, writefunc func) +{ + int32 x; + + if(!func) + func=BNull; + + if(RWWrap) + for(x=end;x>=start;x--) + { + if(x>=0x8000) + BWriteG[x-0x8000]=func; + else + BWrite[x]=func; + } + else + for(x=end;x>=start;x--) + BWrite[x]=func; +} + +uint8 GameMemBlock[131072]; + +#ifdef COPYFAMI +uint8 RAM[0x4000]; +#else +uint8 RAM[0x800]; +#endif + +uint8 PAL=0; + +static DECLFW(BRAML) +{ + RAM[A]=V; +} + +static DECLFR(ARAML) +{ + return RAM[A]; +} + +#ifndef COPYFAMI +static DECLFW(BRAMH) +{ + RAM[A&0x7FF]=V; +} + +static DECLFR(ARAMH) +{ + return RAM[A&0x7FF]; +} +#endif + +static void CloseGame(void) +{ + if(FCEUGameInfo) + { + if(FCEUGameInfo->name) + { + free(FCEUGameInfo->name); + FCEUGameInfo->name=0; + } + FCEU_FlushGameCheats(0,0); + GameInterface(GI_CLOSE); + ResetExState(0,0); + CloseGenie(); + free(FCEUGameInfo); + FCEUGameInfo = 0; + } +} + +extern uint8 pale; + +void ResetGameLoaded(void) +{ + if(FCEUGameInfo) + CloseGame(); + GameStateRestore=0; + PPU_hook=0; + GameHBIRQHook=0; + if(GameExpSound.Kill) + GameExpSound.Kill(); + memset(&GameExpSound,0,sizeof(GameExpSound)); + MapIRQHook=0; + MMC5Hack=0; + PAL&=1; + pale=0; +} + +int UNIFLoad(const char *name, FCEUFILE *fp); +int iNESLoad(const char *name, FCEUFILE *fp); +int FDSLoad(const char *name, FCEUFILE *fp); + +FCEUGI *FCEUI_LoadGame(const char *name) +{ + char *ipsfn; + FCEUFILE *fp; + + ResetGameLoaded(); + + FCEUGameInfo = malloc(sizeof(FCEUGI)); + memset(FCEUGameInfo, 0, sizeof(FCEUGI)); + + FCEUGameInfo->soundchan = 0; + FCEUGameInfo->soundrate = 0; + FCEUGameInfo->name=0; + FCEUGameInfo->type=GIT_CART; + FCEUGameInfo->vidsys=GIV_USER; + FCEUGameInfo->input[0]=FCEUGameInfo->input[1]=-1; + FCEUGameInfo->inputfc=-1; + FCEUGameInfo->cspecial=0; + +#ifdef FCEU_LOG + FCEU_printf("Loading %s...\n\n",name); +#endif + + GetFileBase(name); + + ipsfn=FCEU_MakeFName(FCEUMKF_IPS,0,0); + fp=FCEU_fopen(name,ipsfn,"rb",0); + free(ipsfn); + + if(!fp) + { + return 0; /*Error opening ROM*/ + } + + if(iNESLoad(name,fp)) + goto endlseq; + if(UNIFLoad(name,fp)) + goto endlseq; + if(FDSLoad(name,fp)) + goto endlseq; + + FCEU_fclose(fp); /*An error occcurred while loading the file*/ + return 0; + +endlseq: + FCEU_fclose(fp); + + FCEU_ResetVidSys(); + if(FSettings.GameGenie) + OpenGenie(); + + PowerNES(); + + FCEU_LoadGamePalette(); + /*FCEU_LoadGameCheats(0);*/ + + FCEU_ResetPalette(); + + return(FCEUGameInfo); +} + +int CopyFamiLoad(void); + +FCEUGI *FCEUI_CopyFamiStart(void) +{ + ResetGameLoaded(); + + FCEUGameInfo = malloc(sizeof(FCEUGI)); + memset(FCEUGameInfo, 0, sizeof(FCEUGI)); + + FCEUGameInfo->soundchan = 0; + FCEUGameInfo->soundrate = 0; + FCEUGameInfo->name="copyfami"; + FCEUGameInfo->type=GIT_CART; + FCEUGameInfo->vidsys=GIV_USER; + FCEUGameInfo->input[0]=FCEUGameInfo->input[1]=-1; + FCEUGameInfo->inputfc=-1; + FCEUGameInfo->cspecial=0; + +#ifdef FCEU_LOG + FCEU_printf("Starting CopyFamicom...\n\n"); +#endif + + if(!CopyFamiLoad()) + return 0; /*An error occurred while starting CopyFamicom*/ + + FCEU_ResetVidSys(); + if(FSettings.GameGenie) + OpenGenie(); + + PowerNES(); + + FCEU_LoadGamePalette(); + FCEU_LoadGameCheats(0); + + FCEU_ResetPalette(); + + return(FCEUGameInfo); +} + +int FCEUI_Initialize(void) +{ + if(!FCEU_InitVirtualVideo()) + return 0; + memset(&FSettings,0,sizeof(FSettings)); + FSettings.UsrFirstSLine[0]=8; + FSettings.UsrFirstSLine[1]=0; + FSettings.UsrLastSLine[0]=231; + FSettings.UsrLastSLine[1]=239; + FSettings.SoundVolume=100; + FCEUPPU_Init(); + X6502_Init(); + return 1; +} + +void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize) +{ + int ssize; + + FCEU_UpdateInput(); + + if(geniestage!=1) + FCEU_ApplyPeriodicCheats(); + + FCEUPPU_Loop(); + + if(timestamp) + ssize = FlushEmulateSound(); + else + ssize = 0; + + timestampbase += timestamp; + + timestamp = 0; + + *pXBuf= XBuf; + *SoundBuf=WaveFinal; + *SoundBufSize=ssize; +} + +void FCEUI_CloseGame(void) +{ + CloseGame(); +} + +void ResetNES(void) +{ + if(!FCEUGameInfo) + return; + GameInterface(GI_RESETM2); + FCEUSND_Reset(); + FCEUPPU_Reset(); + X6502_Reset(); +} + +static void FCEU_MemoryRand(uint8 *ptr, uint32 size) +{ + int x=0; + while(size) + { + *ptr=(x&4)?0x7F:0x00; + x++; + size--; + ptr++; + } +} + +void PowerNES(void) +{ + if(!FCEUGameInfo) + return; + + FCEU_CheatResetRAM(); + FCEU_CheatAddRAM(2,0,RAM); + + GeniePower(); + +#ifndef COPYFAMI + FCEU_MemoryRand(RAM,0x800); +#endif + + SetReadHandler(0x0000,0xFFFF,ANull); + SetWriteHandler(0x0000,0xFFFF,BNull); + +#ifdef COPYFAMI + SetReadHandler(0,0x3FFF,ARAML); + SetWriteHandler(0,0x3FFF,BRAML); +#else + SetReadHandler(0,0x7FF,ARAML); + SetWriteHandler(0,0x7FF,BRAML); + + SetReadHandler(0x800,0x1FFF,ARAMH); /* Part of a little */ + SetWriteHandler(0x800,0x1FFF,BRAMH); /* hack for a small speed boost. */ +#endif + InitializeInput(); + FCEUSND_Power(); + FCEUPPU_Power(); + + /* Have the external game hardware "powered" after the internal NES stuff. + Needed for the NSF code and VS System code. + */ + GameInterface(GI_POWER); + if(FCEUGameInfo->type==GIT_VSUNI) + FCEU_VSUniPower(); + + + timestampbase=0; + X6502_Power(); + FCEU_PowerCheats(); +} + +void FCEU_ResetVidSys(void) +{ + int w; + + if(FCEUGameInfo->vidsys==GIV_NTSC) + w=0; + else if(FCEUGameInfo->vidsys==GIV_PAL) + w=1; + else + w=FSettings.PAL; + + PAL=w?1:0; + FCEUPPU_SetVideoSystem(w); + SetSoundVariables(); +} + +FCEUS FSettings; + +void FCEU_printf(char *format, ...) +{ + FILE *ofile; + char temp[2048]; + + va_list ap; + + va_start(ap,format); + vsprintf(temp,format,ap); + FCEUD_Message(temp); + + ofile=fopen("stdout.txt","ab"); + fwrite(temp,1,strlen(temp),ofile); + fclose(ofile); + + va_end(ap); +} + +void FCEU_PrintError(char *format, ...) +{ + char temp[2048]; + + va_list ap; + + va_start(ap,format); + vsprintf(temp,format,ap); + FCEUD_PrintError(temp); + + va_end(ap); +} + +void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall) +{ + FSettings.UsrFirstSLine[0]=ntscf; + FSettings.UsrLastSLine[0]=ntscl; + FSettings.UsrFirstSLine[1]=palf; + FSettings.UsrLastSLine[1]=pall; + if(PAL) + { + FSettings.FirstSLine=FSettings.UsrFirstSLine[1]; + FSettings.LastSLine=FSettings.UsrLastSLine[1]; + } + else + { + FSettings.FirstSLine=FSettings.UsrFirstSLine[0]; + FSettings.LastSLine=FSettings.UsrLastSLine[0]; + } + +} + +void FCEUI_SetVidSystem(int a) +{ + FSettings.PAL=a?1:0; + if(FCEUGameInfo) + { + FCEU_ResetVidSys(); + FCEU_ResetPalette(); + } +} + +int FCEUI_GetCurrentVidSystem(int *slstart, int *slend) +{ + if(slstart) + *slstart=FSettings.FirstSLine; + if(slend) + *slend=FSettings.LastSLine; + return(PAL); +} + +void FCEUI_SetGameGenie(int a) +{ + FSettings.GameGenie=a?1:0; +} diff --git a/fceumm/src-fceumm/fceu.h b/fceumm/src-fceumm/fceu.h new file mode 100644 index 0000000..11bf8d7 --- /dev/null +++ b/fceumm/src-fceumm/fceu.h @@ -0,0 +1,91 @@ +#ifndef _FCEUH +#define _FCEUH + +#include "types.h" + +void ResetGameLoaded(void); + +#define DECLFR(x) uint8 x (uint32 A) +#define DECLFW(x) void x (uint32 A, uint8 V) + +void SetReadHandler(int32 start, int32 end, readfunc func); +void SetWriteHandler(int32 start, int32 end, writefunc func); +writefunc GetWriteHandler(int32 a); +readfunc GetReadHandler(int32 a); + +int AllocGenieRW(void); +void FlushGenieRW(void); + +void FCEU_ResetVidSys(void); + +void ResetMapping(void); + +extern uint64 timestampbase; +extern uint32 MMC5HackVROMMask; +extern uint8 *MMC5HackExNTARAMPtr; +extern int MMC5Hack; +extern uint8 *MMC5HackVROMPTR; +extern uint8 MMC5HackCHRMode; +extern uint8 MMC5HackSPMode; +extern uint8 MMC5HackSPScroll; +extern uint8 MMC5HackSPPage; + +#ifdef COPYFAMI +extern uint8 RAM[0x4000]; +#else +extern uint8 RAM[0x800]; +#endif + +extern uint8 GameMemBlock[131072]; + +extern readfunc ARead[0x10000]; +extern writefunc BWrite[0x10000]; + +extern void (*GameInterface)(int h); +extern void (*GameStateRestore)(int version); + +#define GI_RESETM2 1 +#define GI_POWER 2 +#define GI_CLOSE 3 + +#include "git.h" +extern FCEUGI *FCEUGameInfo; +extern int GameAttributes; + +extern uint8 PAL; + +#include "driver.h" + +typedef struct { + int PAL; + int SoundVolume; + int GameGenie; + + /* Current first and last rendered scanlines. */ + int FirstSLine; + int LastSLine; + + /* Driver code(user)-specified first and last rendered scanlines. + Usr*SLine[0] is for NTSC, Usr*SLine[1] is for PAL. + */ + int UsrFirstSLine[2]; + int UsrLastSLine[2]; + uint32 SndRate; +} FCEUS; + +extern FCEUS FSettings; + +void SetNESDeemph(uint8 d, int force); + +extern uint8 vsdip; + +#define JOY_A 1 +#define JOY_B 2 +#define JOY_SELECT 4 +#define JOY_START 8 +#define JOY_UP 0x10 +#define JOY_DOWN 0x20 +#define JOY_LEFT 0x40 +#define JOY_RIGHT 0x80 + +#endif diff --git a/fceumm/src-fceumm/fcoeffs.h b/fceumm/src-fceumm/fcoeffs.h new file mode 100644 index 0000000..cbe8a96 --- /dev/null +++ b/fceumm/src-fceumm/fcoeffs.h @@ -0,0 +1,1589 @@ +#define SQ2NCOEFFS 1024 + +static int32 sq2coeffs[SQ2NCOEFFS]; + +static int32 SQ2C44100NTSC[SQ2NCOEFFS/2]= +{ + #include "fir/c44100ntsc.h" +}; + +static int32 SQ2C48000NTSC[SQ2NCOEFFS/2]= +{ + #include "fir/c48000ntsc.h" +}; + +static int32 SQ2C96000NTSC[SQ2NCOEFFS/2]= +{ + #include "fir/c96000ntsc.h" +}; + +static int32 SQ2C44100PAL[SQ2NCOEFFS/2]= +{ + #include "fir/c44100pal.h" +}; + +static int32 SQ2C48000PAL[SQ2NCOEFFS/2]= +{ + #include "fir/c48000pal.h" +}; + +static int32 SQ2C96000PAL[SQ2NCOEFFS/2]= +{ + #include "fir/c96000pal.h" +}; + +#define NCOEFFS 484 + +static int32 coeffs[NCOEFFS]; + +/* 96000hz filter could probably be improved. */ + +/* +Parks-McClellan FIR Filter Design + +Filter type: Low pass +Passband: 0 - 0.016761904 +Order: 483 +Passband ripple: 0.01 dB +Transition band: 0.01005714 +Stopband attenuation: 103.0 dB + +Coefficients: +*/ +static int32 C96000NTSC[NCOEFFS/2]= +{ +/*0*/ 65536*16* -5.9950991853042605E-6 +/*1*/, 65536*16* -3.0394382502604395E-6 +/*2*/, 65536*16* -3.728403434239284E-6 +/*3*/, 65536*16* -4.460351826790638E-6 +/*4*/, 65536*16* -5.2164320385801135E-6 +/*5*/, 65536*16* -5.9787071016806234E-6 +/*6*/, 65536*16* -6.716463411023574E-6 +/*7*/, 65536*16* -7.408551386580002E-6 +/*8*/, 65536*16* -8.023491429829738E-6 +/*9*/, 65536*16* -8.531232892238868E-6 +/*10*/, 65536*16* -8.878741512154837E-6 +/*11*/, 65536*16* -9.046773382992595E-6 +/*12*/, 65536*16* -8.993971214348702E-6 +/*13*/, 65536*16* -8.66944931521744E-6 +/*14*/, 65536*16* -8.049348524459474E-6 +/*15*/, 65536*16* -7.083238646482467E-6 +/*16*/, 65536*16* -5.746762349938464E-6 +/*17*/, 65536*16* -4.005753681691657E-6 +/*18*/, 65536*16* -1.838018035195733E-6 +/*19*/, 65536*16* 7.763983938828864E-7 +/*20*/, 65536*16* 3.842232025916005E-6 +/*21*/, 65536*16* 7.361161707034959E-6 +/*22*/, 65536*16* 1.1325948767988128E-5 +/*23*/, 65536*16* 1.5711486406341978E-5 +/*24*/, 65536*16* 2.0488201424957098E-5 +/*25*/, 65536*16* 2.5608402660083142E-5 +/*26*/, 65536*16* 3.101231858515874E-5 +/*27*/, 65536*16* 3.6630654060842745E-5 +/*28*/, 65536*16* 4.2375439803123404E-5 +/*29*/, 65536*16* 4.815060832963289E-5 +/*30*/, 65536*16* 5.384626411548906E-5 +/*31*/, 65536*16* 5.934549587237094E-5 +/*32*/, 65536*16* 6.451785679907682E-5 +/*33*/, 65536*16* 6.923065879553487E-5 +/*34*/, 65536*16* 7.334304650233838E-5 +/*35*/, 65536*16* 7.671308820252635E-5 +/*36*/, 65536*16* 7.920112989696133E-5 +/*37*/, 65536*16* 8.066793124218096E-5 +/*38*/, 65536*16* 8.098382483962539E-5 +/*39*/, 65536*16* 8.002921154479775E-5 +/*40*/, 65536*16* 7.769789869215064E-5 +/*41*/, 65536*16* 7.390152475899438E-5 +/*42*/, 65536*16* 6.857231550142758E-5 +/*43*/, 65536*16* 6.16673817460573E-5 +/*44*/, 65536*16* 5.3169767940001464E-5 +/*45*/, 65536*16* 4.309495398773014E-5 +/*46*/, 65536*16* 3.148737405995964E-5 +/*47*/, 65536*16* 1.8428415219696232E-5 +/*48*/, 65536*16* 4.0337781533928895E-6 +/*49*/, 65536*16* -1.154525373085283E-5 +/*50*/, 65536*16* -2.8120750949316567E-5 +/*51*/, 65536*16* -4.5470242422149815E-5 +/*52*/, 65536*16* -6.333736379615692E-5 +/*53*/, 65536*16* -8.143489509942166E-5 +/*54*/, 65536*16* -9.94475640226242E-5 +/*55*/, 65536*16* -1.1703729468742291E-4 +/*56*/, 65536*16* -1.3384679191408508E-4 +/*57*/, 65536*16* -1.4950548598267213E-4 +/*58*/, 65536*16* -1.6363792959068823E-4 +/*59*/, 65536*16* -1.7586732627086947E-4 +/*60*/, 65536*16* -1.858264971517669E-4 +/*61*/, 65536*16* -1.9316312487547242E-4 +/*62*/, 65536*16* -1.975494021862538E-4 +/*63*/, 65536*16* -1.9868977868165154E-4 +/*64*/, 65536*16* -1.963293865814053E-4 +/*65*/, 65536*16* -1.9026146175876417E-4 +/*66*/, 65536*16* -1.803352078962109E-4 +/*67*/, 65536*16* -1.66463443436789E-4 +/*68*/, 65536*16* -1.4862710934868261E-4 +/*69*/, 65536*16* -1.2688200452566298E-4 +/*70*/, 65536*16* -1.0136212853169677E-4 +/*71*/, 65536*16* -7.228199463954364E-5 +/*72*/, 65536*16* -3.9939461621236575E-5 +/*73*/, 65536*16* -4.7134932934724E-6 +/*74*/, 65536*16* 3.2936215273699675E-5 +/*75*/, 65536*16* 7.247384833064696E-5 +/*76*/, 65536*16* 1.1329187082792405E-4 +/*77*/, 65536*16* 1.5471948843725746E-4 +/*78*/, 65536*16* 1.9603027714808286E-4 +/*79*/, 65536*16* 2.364532958813608E-4 +/*80*/, 65536*16* 2.751853212246927E-4 +/*81*/, 65536*16* 3.114033208188799E-4 +/*82*/, 65536*16* 3.442804841775461E-4 +/*83*/, 65536*16* 3.7300098840546946E-4 +/*84*/, 65536*16* 3.967764136715296E-4 +/*85*/, 65536*16* 4.148631617351676E-4 +/*86*/, 65536*16* 4.265789297533608E-4 +/*87*/, 65536*16* 4.3132002526188114E-4 +/*88*/, 65536*16* 4.2857701618443636E-4 +/*89*/, 65536*16* 4.179510914969621E-4 +/*90*/, 65536*16* 3.991670037587729E-4 +/*91*/, 65536*16* 3.720870989970653E-4 +/*92*/, 65536*16* 3.367209236003282E-4 +/*93*/, 65536*16* 2.932338231303312E-4 +/*94*/, 65536*16* 2.419533571940393E-4 +/*95*/, 65536*16* 1.8337169647749448E-4 +/*96*/, 65536*16* 1.1814612711310299E-4 +/*97*/, 65536*16* 4.709567952563025E-5 +/*98*/, 65536*16* -2.880519351052945E-5 +/*99*/, 65536*16* -1.08436462295612E-4 +/*100*/, 65536*16* -1.905455293630124E-4 +/*101*/, 65536*16* -2.7376362665015007E-4 +/*102*/, 65536*16* -3.566259161939277E-4 +/*103*/, 65536*16* -4.375928024937683E-4 +/*104*/, 65536*16* -5.150762555847844E-4 +/*105*/, 65536*16* -5.874662774920191E-4 +/*106*/, 65536*16* -6.531605887419429E-4 +/*107*/, 65536*16* -7.105951946653638E-4 +/*108*/, 65536*16* -7.582757639600853E-4 +/*109*/, 65536*16* -7.948096207059845E-4 +/*110*/, 65536*16* -8.189373133065186E-4 +/*111*/, 65536*16* -8.295634640890689E-4 +/*112*/, 65536*16* -8.257854455404298E-4 +/*113*/, 65536*16* -8.069208861135825E-4 +/*114*/, 65536*16* -7.725316214556066E-4 +/*115*/, 65536*16* -7.224442067331338E-4 +/*116*/, 65536*16* -6.567673177902021E-4 +/*117*/, 65536*16* -5.759031970767677E-4 +/*118*/, 65536*16* -4.8055576975832975E-4 +/*119*/, 65536*16* -3.7173219275304865E-4 +/*120*/, 65536*16* -2.507394811359122E-4 +/*121*/, 65536*16* -1.191747608775131E-4 +/*122*/, 65536*16* 2.1089774143064154E-5 +/*123*/, 65536*16* 1.6792832047168277E-4 +/*124*/, 65536*16* 3.189887341095747E-4 +/*125*/, 65536*16* 4.7172479984555337E-4 +/*126*/, 65536*16* 6.234346495766704E-4 +/*127*/, 65536*16* 7.713029674040095E-4 +/*128*/, 65536*16* 9.124478381058291E-4 +/*129*/, 65536*16* 0.0010439713492973299 +/*130*/, 65536*16* 0.0011630121060354824 +/*131*/, 65536*16* 0.0012668003330792172 +/*132*/, 65536*16* 0.0013527131638668246 +/*133*/, 65536*16* 0.0014183305230994348 +/*134*/, 65536*16* 0.0014614889365474647 +/*135*/, 65536*16* 0.0014803340336415063 +/*136*/, 65536*16* 0.0014733688575452508 +/*137*/, 65536*16* 0.001439498243826639 +/*138*/, 65536*16* 0.0013780680098511918 +/*139*/, 65536*16* 0.0012888970057146566 +/*140*/, 65536*16* 0.0011723026532406624 +/*141*/, 65536*16* 0.0010291180003947405 +/*142*/, 65536*16* 8.607001658653358E-4 +/*143*/, 65536*16* 6.689295599970792E-4 +/*144*/, 65536*16* 4.5619928199453885E-4 +/*145*/, 65536*16* 2.253948582736753E-4 +/*146*/, 65536*16* -2.0136349562764177E-5 +/*147*/, 65536*16* -2.766248035657636E-4 +/*148*/, 65536*16* -5.399290507797791E-4 +/*149*/, 65536*16* -8.055939397996815E-4 +/*150*/, 65536*16* -0.0010689177291287714 +/*151*/, 65536*16* -0.0013250265370767429 +/*152*/, 65536*16* -0.0015689549600474482 +/*153*/, 65536*16* -0.0017957322527663085 +/*154*/, 65536*16* -0.002000472024117418 +/*155*/, 65536*16* -0.0021784645223266222 +/*156*/, 65536*16* -0.0023252695222818146 +/*157*/, 65536*16* -0.0024368087083972345 +/*158*/, 65536*16* -0.002509455241851095 +/*159*/, 65536*16* -0.0025401189567937766 +/*160*/, 65536*16* -0.0025263261450844377 +/*161*/, 65536*16* -0.0024662908754217406 +/*162*/, 65536*16* -0.002358977944127433 +/*163*/, 65536*16* -0.002204154401342649 +/*164*/, 65536*16* -0.002002429343138771 +/*165*/, 65536*16* -0.0017552803385372808 +/*166*/, 65536*16* -0.0014650656045065488 +/*167*/, 65536*16* -0.001135021049166992 +/*168*/, 65536*16* -7.692415547098649E-4 +/*169*/, 65536*16* -3.7264671522013244E-4 +/*170*/, 65536*16* 4.906989195928291E-5 +/*171*/, 65536*16* 4.895067103339711E-4 +/*172*/, 65536*16* 9.416355837269647E-4 +/*173*/, 65536*16* 0.001397897684142057 +/*174*/, 65536*16* 0.0018503121614766558 +/*175*/, 65536*16* 0.002290597319733804 +/*176*/, 65536*16* 0.0027103015920374113 +/*177*/, 65536*16* 0.0031009433327120863 +/*178*/, 65536*16* 0.0034541565687980116 +/*179*/, 65536*16* 0.0037618412630103333 +/*180*/, 65536*16* 0.004016315066649496 +/*181*/, 65536*16* 0.004210464374744574 +/*182*/, 65536*16* 0.004337892288164658 +/*183*/, 65536*16* 0.004393060165490985 +/*184*/, 65536*16* 0.004371421226297046 +/*185*/, 65536*16* 0.004269542847715132 +/*186*/, 65536*16* 0.00408521543517564 +/*187*/, 65536*16* 0.0038175457430583526 +/*188*/, 65536*16* 0.00346703221076496 +/*189*/, 65536*16* 0.0030356209846777236 +/*190*/, 65536*16* 0.002526740400739804 +/*191*/, 65536*16* 0.0019453134428630866 +/*192*/, 65536*16* 0.0012977462825954304 +/*193*/, 65536*16* 5.918933555500828E-4 +/*194*/, 65536*16* -1.6300197379338156E-4 +/*195*/, 65536*16* -9.563908629597664E-4 +/*196*/, 65536*16* -0.0017765255338228524 +/*197*/, 65536*16* -0.0026105886000394158 +/*198*/, 65536*16* -0.003444843158936217 +/*199*/, 65536*16* -0.004264802433556331 +/*200*/, 65536*16* -0.00505541655658742 +/*201*/, 65536*16* -0.005801274223045036 +/*202*/, 65536*16* -0.0064868164183708756 +/*203*/, 65536*16* -0.007096559102022994 +/*204*/, 65536*16* -0.007615322236172286 +/*205*/, 65536*16* -0.008028460796606074 +/*206*/, 65536*16* -0.008322095341268461 +/*207*/, 65536*16* -0.008483337773170242 +/*208*/, 65536*16* -0.008500509194641638 +/*209*/, 65536*16* -0.008363346317351387 +/*210*/, 65536*16* -0.008063192746297233 +/*211*/, 65536*16* -0.007593172286363423 +/*212*/, 65536*16* -0.0069483408893122045 +/*213*/, 65536*16* -0.006125814985695579 +/*214*/, 65536*16* -0.005124873148956596 +/*215*/, 65536*16* -0.003947029569132915 +/*216*/, 65536*16* -0.002596077508306772 +/*217*/, 65536*16* -0.0010781012650798818 +/*218*/, 65536*16* 5.985434770618447E-4 +/*219*/, 65536*16* 0.0024232820773754 +/*220*/, 65536*16* 0.004383405101533075 +/*221*/, 65536*16* 0.006464184070028333 +/*222*/, 65536*16* 0.008649017282842432 +/*223*/, 65536*16* 0.010919604285452066 +/*224*/, 65536*16* 0.013256146772932903 +/*225*/, 65536*16* 0.015637573164024095 +/*226*/, 65536*16* 0.018041784432073237 +/*227*/, 65536*16* 0.020445917198990023 +/*228*/, 65536*16* 0.022826621253151515 +/*229*/, 65536*16* 0.025160347111354456 +/*230*/, 65536*16* 0.02742363969736895 +/*231*/, 65536*16* 0.02959343430076011 +/*232*/, 65536*16* 0.03164735012116834 +/*233*/, 65536*16* 0.03356397767681876 +/*234*/, 65536*16* 0.035323155364389396 +/*235*/, 65536*16* 0.03690623176571385 +/*236*/, 65536*16* 0.03829630932788767 +/*237*/, 65536*16* 0.03947846623700253 +/*238*/, 65536*16* 0.040439953107911 +/*239*/, 65536*16* 0.0411703612762271 +/*240*/, 65536*16* 0.04166176091370756 +/*241*/, 65536*16* 0.041908806136461134 +}; + +/* +Parks-McClellan FIR Filter Design + +Filter type: Low pass +Passband: 0 - 0.01804395 +Order: 483 +Passband ripple: 0.01 dB +Transition band: 0.0108263 +Stopband attenuation: 114.0 dB + +Coefficients: +*/ + +static int32 C96000PAL[NCOEFFS/2]= +{ +/*0*/ 65536*16* 3.850781559466991E-7 +/*1*/, 65536*16* -1.280019401722687E-6 +/*2*/, 65536*16* -1.3004583488088965E-6 +/*3*/, 65536*16* -1.7523167437749452E-6 +/*4*/, 65536*16* -2.410249470764872E-6 +/*5*/, 65536*16* -3.2346426554155092E-6 +/*6*/, 65536*16* -4.227271662321092E-6 +/*7*/, 65536*16* -5.3971678027414914E-6 +/*8*/, 65536*16* -6.753444785567694E-6 +/*9*/, 65536*16* -8.302128790766257E-6 +/*10*/, 65536*16* -1.0045896006160685E-5 +/*11*/, 65536*16* -1.1982368218542129E-5 +/*12*/, 65536*16* -1.4104296519058353E-5 +/*13*/, 65536*16* -1.6397945806910793E-5 +/*14*/, 65536*16* -1.8843550708827064E-5 +/*15*/, 65536*16* -2.1413952016264175E-5 +/*16*/, 65536*16* -2.407540699773165E-5 +/*17*/, 65536*16* -2.6786418491045868E-5 +/*18*/, 65536*16* -2.949883620881563E-5 +/*19*/, 65536*16* -3.215685693993941E-5 +/*20*/, 65536*16* -3.4698621200866915E-5 +/*21*/, 65536*16* -3.7055635055088747E-5 +/*22*/, 65536*16* -3.915516367387583E-5 +/*23*/, 65536*16* -4.092005046973106E-5 +/*24*/, 65536*16* -4.227173792151256E-5 +/*25*/, 65536*16* -4.313002076491602E-5 +/*26*/, 65536*16* -4.3416606424857764E-5 +/*27*/, 65536*16* -4.3054793786740716E-5 +/*28*/, 65536*16* -4.1974462257106624E-5 +/*29*/, 65536*16* -4.011236719136458E-5 +/*30*/, 65536*16* -3.7415159397597796E-5 +/*31*/, 65536*16* -3.3846213818414235E-5 +/*32*/, 65536*16* -2.9372757531099172E-5 +/*33*/, 65536*16* -2.3989695934591954E-5 +/*34*/, 65536*16* -1.7705989252101064E-5 +/*35*/, 65536*16* -1.0551320217411096E-5 +/*36*/, 65536*16* -2.5775325043216536E-6 +/*37*/, 65536*16* 6.139645766572715E-6 +/*38*/, 65536*16* 1.5501423038008354E-5 +/*39*/, 65536*16* 2.5384753820737575E-5 +/*40*/, 65536*16* 3.5643398684518664E-5 +/*41*/, 65536*16* 4.6108393091574726E-5 +/*42*/, 65536*16* 5.659011526249589E-5 +/*43*/, 65536*16* 6.68803323899828E-5 +/*44*/, 65536*16* 7.675537622878941E-5 +/*45*/, 65536*16* 8.597960059720824E-5 +/*46*/, 65536*16* 9.430960279897814E-5 +/*47*/, 65536*16* 1.0149893801465577E-4 +/*48*/, 65536*16* 1.0730328189856642E-4 +/*49*/, 65536*16* 1.1148622997923174E-4 +/*50*/, 65536*16* 1.1382511217545132E-4 +/*51*/, 65536*16* 1.141174295909343E-4 +/*52*/, 65536*16* 1.1218671460549208E-4 +/*53*/, 65536*16* 1.078890398041802E-4 +/*54*/, 65536*16* 1.0111839925160891E-4 +/*55*/, 65536*16* 9.181292532691402E-5 +/*56*/, 65536*16* 7.995923739813694E-5 +/*57*/, 65536*16* 6.559772591687974E-5 +/*58*/, 65536*16* 4.882471526869663E-5 +/*59*/, 65536*16* 2.9795861807919456E-5 +/*60*/, 65536*16* 8.727003235393024E-6 +/*61*/, 65536*16* -1.4106777294769694E-5 +/*62*/, 65536*16* -3.836880959229582E-5 +/*63*/, 65536*16* -6.366921149307032E-5 +/*64*/, 65536*16* -8.956481187350594E-5 +/*65*/, 65536*16* -1.1556632861786434E-4 +/*66*/, 65536*16* -1.411455941949306E-4 +/*67*/, 65536*16* -1.657445386231986E-4 +/*68*/, 65536*16* -1.8878427001863077E-4 +/*69*/, 65536*16* -2.0967688285495866E-4 +/*70*/, 65536*16* -2.2783715638612827E-4 +/*71*/, 65536*16* -2.4269587549180196E-4 +/*72*/, 65536*16* -2.5371305459897316E-4 +/*73*/, 65536*16* -2.603919787720978E-4 +/*74*/, 65536*16* -2.6229284265917287E-4 +/*75*/, 65536*16* -2.59046413963889E-4 +/*76*/, 65536*16* -2.503668396740634E-4 +/*77*/, 65536*16* -2.3606367328604213E-4 +/*78*/, 65536*16* -2.160524966650091E-4 +/*79*/, 65536*16* -1.903639226156617E-4 +/*80*/, 65536*16* -1.59150691014015E-4 +/*81*/, 65536*16* -1.2269241610349266E-4 +/*82*/, 65536*16* -8.139812226735764E-5 +/*83*/, 65536*16* -3.5805772732231955E-5 +/*84*/, 65536*16* 1.3420603339835859E-5 +/*85*/, 65536*16* 6.549742374431074E-5 +/*86*/, 65536*16* 1.1953033076822495E-4 +/*87*/, 65536*16* 1.745269622757623E-4 +/*88*/, 65536*16* 2.2941123586808386E-4 +/*89*/, 65536*16* 2.830419125977025E-4 +/*90*/, 65536*16* 3.3423267917052983E-4 +/*91*/, 65536*16* 3.81774499172079E-4 +/*92*/, 65536*16* 4.244616654237554E-4 +/*93*/, 65536*16* 4.611154134679936E-4 +/*94*/, 65536*16* 4.906128810250551E-4 +/*95*/, 65536*16* 5.119138315653597E-4 +/*96*/, 65536*16* 5.240878477917174E-4 +/*97*/, 65536*16* 5.263406012974186E-4 +/*98*/, 65536*16* 5.180395272684202E-4 +/*99*/, 65536*16* 4.987363674123535E-4 +/*100*/, 65536*16* 4.681879119879578E-4 +/*101*/, 65536*16* 4.263728836819278E-4 +/*102*/, 65536*16* 3.735054898141368E-4 +/*103*/, 65536*16* 3.1004425441119956E-4 +/*104*/, 65536*16* 2.3669640454159868E-4 +/*105*/, 65536*16* 1.5441686754990788E-4 +/*106*/, 65536*16* 6.440207419421148E-5 +/*107*/, 65536*16* -3.192198333335273E-5 +/*108*/, 65536*16* -1.3291717686663037E-4 +/*109*/, 65536*16* -2.3675627296534203E-4 +/*110*/, 65536*16* -3.414512496033162E-4 +/*111*/, 65536*16* -4.4488659997924806E-4 +/*112*/, 65536*16* -5.44857304239037E-4 +/*113*/, 65536*16* -6.391106241040588E-4 +/*114*/, 65536*16* -7.253914361418537E-4 +/*115*/, 65536*16* -8.0148962040363E-4 +/*116*/, 65536*16* -8.652895191393541E-4 +/*117*/, 65536*16* -9.148193159968953E-4 +/*118*/, 65536*16* -9.483009583169883E-4 +/*119*/, 65536*16* -9.64197392644944E-4 +/*120*/, 65536*16* -9.612579850877552E-4 +/*121*/, 65536*16* -9.385600118624972E-4 +/*122*/, 65536*16* -8.955444281498081E-4 +/*123*/, 65536*16* -8.320477398703453E-4 +/*124*/, 65536*16* -7.483247067952744E-4 +/*125*/, 65536*16* -6.450648142040654E-4 +/*126*/, 65536*16* -5.234000259248345E-4 +/*127*/, 65536*16* -3.8490357943433983E-4 +/*128*/, 65536*16* -2.3157879639504726E-4 +/*129*/, 65536*16* -6.583909529283622E-5 +/*130*/, 65536*16* 1.0952239530879758E-4 +/*131*/, 65536*16* 2.9137227027685464E-4 +/*132*/, 65536*16* 4.76285797012954E-4 +/*133*/, 65536*16* 6.606041066674581E-4 +/*134*/, 65536*16* 8.404993785845289E-4 +/*135*/, 65536*16* 0.0010120465600366754 +/*136*/, 65536*16* 0.00117130077980147 +/*137*/, 65536*16* 0.0013143787565297594 +/*138*/, 65536*16* 0.0014375429397231808 +/*139*/, 65536*16* 0.0015372865339524395 +/*140*/, 65536*16* 0.0016104178085955662 +/*141*/, 65536*16* 0.0016541417860661317 +/*142*/, 65536*16* 0.0016661374441763997 +/*143*/, 65536*16* 0.0016446287155235182 +/*144*/, 65536*16* 0.0015884472759871292 +/*145*/, 65536*16* 0.0014970858621845143 +/*146*/, 65536*16* 0.0013707399310406382 +/*147*/, 65536*16* 0.0012103371052757787 +/*148*/, 65536*16* 0.0010175519857289184 +/*149*/, 65536*16* 7.94807053668863E-4 +/*150*/, 65536*16* 5.452573395422002E-4 +/*151*/, 65536*16* 2.727594075846488E-4 +/*152*/, 65536*16* -1.8175144027827955E-5 +/*153*/, 65536*16* -3.2244298920455907E-4 +/*154*/, 65536*16* -6.344261333752713E-4 +/*155*/, 65536*16* -9.480839637356165E-4 +/*156*/, 65536*16* -0.001257058056943197 +/*157*/, 65536*16* -0.001554788246611654 +/*158*/, 65536*16* -0.001834637661184569 +/*159*/, 65536*16* -0.0020900256934556468 +/*160*/, 65536*16* -0.0023145651572872143 +/*161*/, 65536*16* -0.0025022020560114683 +/*162*/, 65536*16* -0.002647354498854991 +/*163*/, 65536*16* -0.002745048447695108 +/*164*/, 65536*16* -0.0027910469441460657 +/*165*/, 65536*16* -0.002781970255972488 +/*166*/, 65536*16* -0.0027154038464012363 +/*167*/, 65536*16* -0.002589991713387623 +/*168*/, 65536*16* -0.0024055123883779776 +/*169*/, 65536*16* -0.0021629354924022053 +/*170*/, 65536*16* -0.0018644567566629092 +/*171*/, 65536*16* -0.0015135100031795994 +/*172*/, 65536*16* -0.0011147548631940517 +/*173*/, 65536*16* -6.740394224166433E-4 +/*174*/, 65536*16* -1.9833762845333352E-4 +/*175*/, 65536*16* 3.043386309556266E-4 +/*176*/, 65536*16* 8.250516255359581E-4 +/*177*/, 65536*16* 0.0013540734762851313 +/*178*/, 65536*16* 0.0018810427835111666 +/*179*/, 65536*16* 0.002395141352428365 +/*180*/, 65536*16* 0.002885286937512414 +/*181*/, 65536*16* 0.0033403397957704442 +/*182*/, 65536*16* 0.003749319662913449 +/*183*/, 65536*16* 0.00410162844368435 +/*184*/, 65536*16* 0.00438727601255591 +/*185*/, 65536*16* 0.004597103692808949 +/*186*/, 65536*16* 0.004723001540295747 +/*187*/, 65536*16* 0.004758115147888017 +/*188*/, 65536*16* 0.0046970379302800494 +/*189*/, 65536*16* 0.0045359837766146575 +/*190*/, 65536*16* 0.004272937350956345 +/*191*/, 65536*16* 0.003907777448988567 +/*192*/, 65536*16* 0.0034423707924944227 +/*193*/, 65536*16* 0.0028806330094231125 +/*194*/, 65536*16* 0.0022285548928660825 +/*195*/, 65536*16* 0.0014941919971143964 +/*196*/, 65536*16* 6.876167025638233E-4 +/*197*/, 65536*16* -1.7916781098860902E-4 +/*198*/, 65536*16* -0.001092351250031068 +/*199*/, 65536*16* -0.002036476651580642 +/*200*/, 65536*16* -0.002994635788760751 +/*201*/, 65536*16* -0.003948697212655613 +/*202*/, 65536*16* -0.004879563858611486 +/*203*/, 65536*16* -0.005767456511229176 +/*204*/, 65536*16* -0.006592218979894068 +/*205*/, 65536*16* -0.007333640031607341 +/*206*/, 65536*16* -0.007971787269457032 +/*207*/, 65536*16* -0.008487346947516187 +/*208*/, 65536*16* -0.008861964740105959 +/*209*/, 65536*16* -0.009078580419089913 +/*210*/, 65536*16* -0.009121751784315056 +/*211*/, 65536*16* -0.008977961157199062 +/*212*/, 65536*16* -0.008635898786325313 +/*213*/, 65536*16* -0.008086718339557295 +/*214*/, 65536*16* -0.007324258683042848 +/*215*/, 65536*16* -0.0063452279676933475 +/*216*/, 65536*16* -0.005149346015761238 +/*217*/, 65536*16* -0.0037394415039958702 +/*218*/, 65536*16* -0.0021215012056140783 +/*219*/, 65536*16* -3.046703636518387E-4 +/*220*/, 65536*16* 0.0016987979320526618 +/*221*/, 65536*16* 0.0038736435001752246 +/*222*/, 65536*16* 0.006201749792159754 +/*223*/, 65536*16* 0.00866234250983842 +/*224*/, 65536*16* 0.011232233932071251 +/*225*/, 65536*16* 0.013886109426908738 +/*226*/, 65536*16* 0.016596852190097027 +/*227*/, 65536*16* 0.01933590131308301 +/*228*/, 65536*16* 0.022073637826085922 +/*229*/, 65536*16* 0.024779792715016697 +/*230*/, 65536*16* 0.027423870545765342 +/*231*/, 65536*16* 0.029975581949125456 +/*232*/, 65536*16* 0.03240527801144671 +/*233*/, 65536*16* 0.034684379593278115 +/*234*/, 65536*16* 0.03678579448103684 +/*235*/, 65536*16* 0.03868431571442653 +/*236*/, 65536*16* 0.04035699420925718 +/*237*/, 65536*16* 0.041783479941480954 +/*238*/, 65536*16* 0.04294632536294341 +/*239*/, 65536*16* 0.043831247006285705 +/*240*/, 65536*16* 0.044427339714649856 +/*241*/, 65536*16* 0.04472724072106236 +}; + +/* +Parks-McClellan FIR Filter Design + +Filter type: Low pass +Passband: 0 - 0.0077845 +Order: 483 +Passband ripple: 0.1 dB +Transition band: 0.005625 +Stopband attenuation: 60.0 dB +*/ +static int32 C48000NTSC[NCOEFFS/2]= +{ +/*0*/ 65536*16* -1.2211019733097893E-4 +/*1*/ , 65536*16* 5.374660789759626E-4 +/*2*/ , 65536*16* 1.9882723274804067E-4 +/*3*/ , 65536*16* 1.3631041618360223E-4 +/*4*/ , 65536*16* 1.3153691128499229E-4 +/*5*/ , 65536*16* 1.3886281724158703E-4 +/*6*/ , 65536*16* 1.4887278966773673E-4 +/*7*/ , 65536*16* 1.5943890243162037E-4 +/*8*/ , 65536*16* 1.7020639605259616E-4 +/*9*/ , 65536*16* 1.809192079749018E-4 +/*10*/ , 65536*16* 1.9162093203709557E-4 +/*11*/ , 65536*16* 2.02127312351196E-4 +/*12*/ , 65536*16* 2.1249848894399555E-4 +/*13*/ , 65536*16* 2.2254095363111247E-4 +/*14*/ , 65536*16* 2.323202963851337E-4 +/*15*/ , 65536*16* 2.4163344759163413E-4 +/*16*/ , 65536*16* 2.505472122265602E-4 +/*17*/ , 65536*16* 2.5885306226458603E-4 +/*18*/ , 65536*16* 2.6660828860384193E-4 +/*19*/ , 65536*16* 2.736061193417779E-4 +/*20*/ , 65536*16* 2.79907587492226E-4 +/*21*/ , 65536*16* 2.852884076207648E-4 +/*22*/ , 65536*16* 2.898305905338908E-4 +/*23*/ , 65536*16* 2.93305922863925E-4 +/*24*/ , 65536*16* 2.958004341042564E-4 +/*25*/ , 65536*16* 2.9706939623100196E-4 +/*26*/ , 65536*16* 2.972508466837626E-4 +/*27*/ , 65536*16* 2.960684730022295E-4 +/*28*/ , 65536*16* 2.937123123731801E-4 +/*29*/ , 65536*16* 2.898634667442807E-4 +/*30*/ , 65536*16* 2.8478700978604426E-4 +/*31*/ , 65536*16* 2.7808505097364714E-4 +/*32*/ , 65536*16* 2.7016032300539216E-4 +/*33*/ , 65536*16* 2.6042025835357706E-4 +/*34*/ , 65536*16* 2.496053090718662E-4 +/*35*/ , 65536*16* 2.3660011363209167E-4 +/*36*/ , 65536*16* 2.228827056917728E-4 +/*37*/ , 65536*16* 2.0662381151599093E-4 +/*38*/ , 65536*16* 1.8946729340692708E-4 +/*39*/ , 65536*16* 1.707894290302382E-4 +/*40*/ , 65536*16* 1.4964075656329285E-4 +/*41*/ , 65536*16* 1.2806315562352013E-4 +/*42*/ , 65536*16* 1.0470129333132878E-4 +/*43*/ , 65536*16* 7.952742687952367E-5 +/*44*/ , 65536*16* 5.3080519892589936E-5 +/*45*/ , 65536*16* 2.5960680465529317E-5 +/*46*/ , 65536*16* -2.5651586484338896E-6 +/*47*/ , 65536*16* -3.248840068536756E-5 +/*48*/ , 65536*16* -6.374045088088799E-5 +/*49*/ , 65536*16* -9.575401529845337E-5 +/*50*/ , 65536*16* -1.2853435644071695E-4 +/*51*/ , 65536*16* -1.6188456243132127E-4 +/*52*/ , 65536*16* -1.9591394048834482E-4 +/*53*/ , 65536*16* -2.3037663947407175E-4 +/*54*/ , 65536*16* -2.6523734278928246E-4 +/*55*/ , 65536*16* -3.0020331327926296E-4 +/*56*/ , 65536*16* -3.352268879856044E-4 +/*57*/ , 65536*16* -3.700260022275662E-4 +/*58*/ , 65536*16* -4.045571559416333E-4 +/*59*/ , 65536*16* -4.38534577720557E-4 +/*60*/ , 65536*16* -4.718927645081437E-4 +/*61*/ , 65536*16* -5.043317033789757E-4 +/*62*/ , 65536*16* -5.357994753678582E-4 +/*63*/ , 65536*16* -5.659671580788766E-4 +/*64*/ , 65536*16* -5.947897013020397E-4 +/*65*/ , 65536*16* -6.219384666963997E-4 +/*66*/ , 65536*16* -6.473787936195385E-4 +/*67*/ , 65536*16* -6.707514595741775E-4 +/*68*/ , 65536*16* -6.920680579893526E-4 +/*69*/ , 65536*16* -7.109402066802999E-4 +/*70*/ , 65536*16* -7.274298271538291E-4 +/*71*/ , 65536*16* -7.411375648954899E-4 +/*72*/ , 65536*16* -7.520788343347275E-4 +/*73*/ , 65536*16* -7.600510659768832E-4 +/*74*/ , 65536*16* -7.647430899316486E-4 +/*75*/ , 65536*16* -7.664294191482773E-4 +/*76*/ , 65536*16* -7.644147173692687E-4 +/*77*/ , 65536*16* -7.590920613362674E-4 +/*78*/ , 65536*16* -7.501459543641885E-4 +/*79*/ , 65536*16* -7.373621082253133E-4 +/*80*/ , 65536*16* -7.208964561671388E-4 +/*81*/ , 65536*16* -7.006901755632023E-4 +/*82*/ , 65536*16* -6.764591748580997E-4 +/*83*/ , 65536*16* -6.483697284795448E-4 +/*84*/ , 65536*16* -6.164929718400197E-4 +/*85*/ , 65536*16* -5.806918766677904E-4 +/*86*/ , 65536*16* -5.409344735839229E-4 +/*87*/ , 65536*16* -4.97405373620265E-4 +/*88*/ , 65536*16* -4.502086002815554E-4 +/*89*/ , 65536*16* -3.9932330033988294E-4 +/*90*/ , 65536*16* -3.448028565721092E-4 +/*91*/ , 65536*16* -2.8685420307046736E-4 +/*92*/ , 65536*16* -2.256958038579715E-4 +/*93*/ , 65536*16* -1.615040528190604E-4 +/*94*/ , 65536*16* -9.438524808984473E-5 +/*95*/ , 65536*16* -2.4519303584370608E-5 +/*96*/ , 65536*16* 4.786961616483501E-5 +/*97*/ , 65536*16* 1.2248011782462745E-4 +/*98*/ , 65536*16* 1.990534978611127E-4 +/*99*/ , 65536*16* 2.7728245405517893E-4 +/*100*/ , 65536*16* 3.5690342407690407E-4 +/*101*/ , 65536*16* 4.376002679601721E-4 +/*102*/ , 65536*16* 5.19047629492113E-4 +/*103*/ , 65536*16* 6.008846564336277E-4 +/*104*/ , 65536*16* 6.827617063818499E-4 +/*105*/ , 65536*16* 7.643160551093983E-4 +/*106*/ , 65536*16* 8.451272011819538E-4 +/*107*/ , 65536*16* 9.248890776355356E-4 +/*108*/ , 65536*16* 0.001003072355955673 +/*109*/ , 65536*16* 0.0010794672777372975 +/*110*/ , 65536*16* 0.0011534276232606116 +/*111*/ , 65536*16* 0.0012247823207262698 +/*112*/ , 65536*16* 0.0012929541324917778 +/*113*/ , 65536*16* 0.001357585199795128 +/*114*/ , 65536*16* 0.001418338397346014 +/*115*/ , 65536*16* 0.0014746734285279383 +/*116*/ , 65536*16* 0.0015262884930771822 +/*117*/ , 65536*16* 0.0015728226550844923 +/*118*/ , 65536*16* 0.00161379655898045 +/*119*/ , 65536*16* 0.001648915948444658 +/*120*/ , 65536*16* 0.0016778840108713717 +/*121*/ , 65536*16* 0.0017002560629258679 +/*122*/ , 65536*16* 0.0017157641984855009 +/*123*/ , 65536*16* 0.0017241805985007432 +/*124*/ , 65536*16* 0.001725182645995729 +/*125*/ , 65536*16* 0.0017184841648036691 +/*126*/ , 65536*16* 0.0017039216808435336 +/*127*/ , 65536*16* 0.001681334520841587 +/*128*/ , 65536*16* 0.0016504918660173195 +/*129*/ , 65536*16* 0.0016112687597971862 +/*130*/ , 65536*16* 0.0015636063248128528 +/*131*/ , 65536*16* 0.0015074624593932396 +/*132*/ , 65536*16* 0.0014427699009003175 +/*133*/ , 65536*16* 0.001369527394628539 +/*134*/ , 65536*16* 0.0012878043567412672 +/*135*/ , 65536*16* 0.0011977101442406943 +/*136*/ , 65536*16* 0.0010993686954177168 +/*137*/ , 65536*16* 9.928872878864818E-4 +/*138*/ , 65536*16* 8.784941174786496E-4 +/*139*/ , 65536*16* 7.564288883294911E-4 +/*140*/ , 65536*16* 6.270372159510238E-4 +/*141*/ , 65536*16* 4.905983779660314E-4 +/*142*/ , 65536*16* 3.4754116793679786E-4 +/*143*/ , 65536*16* 1.9816162887093084E-4 +/*144*/ , 65536*16* 4.300342678121075E-5 +/*145*/ , 65536*16* -1.1751370467978956E-4 +/*146*/ , 65536*16* -2.8280605795854083E-4 +/*147*/ , 65536*16* -4.523173545514795E-4 +/*148*/ , 65536*16* -6.255041797790695E-4 +/*149*/ , 65536*16* -8.016355996557292E-4 +/*150*/ , 65536*16* -9.801573426762404E-4 +/*151*/ , 65536*16* -0.0011602954820678437 +/*152*/ , 65536*16* -0.001341343986206184 +/*153*/ , 65536*16* -0.001522571621631356 +/*154*/ , 65536*16* -0.001703172768158951 +/*155*/ , 65536*16* -0.0018823360844618293 +/*156*/ , 65536*16* -0.00205930337901632 +/*157*/ , 65536*16* -0.0022331579230920632 +/*158*/ , 65536*16* -0.002403069015327 +/*159*/ , 65536*16* -0.0025682175666884455 +/*160*/ , 65536*16* -0.002727682820990084 +/*161*/ , 65536*16* -0.002880584481539458 +/*162*/ , 65536*16* -0.003026077683940661 +/*163*/ , 65536*16* -0.00316326704154516 +/*164*/ , 65536*16* -0.003291235176827385 +/*165*/ , 65536*16* -0.0034091436232751705 +/*166*/ , 65536*16* -0.0035161624262765347 +/*167*/ , 65536*16* -0.00361139707788214 +/*168*/ , 65536*16* -0.0036940241232429707 +/*169*/ , 65536*16* -0.003763249197925811 +/*170*/ , 65536*16* -0.0038183138554794805 +/*171*/ , 65536*16* -0.003858413648517434 +/*172*/ , 65536*16* -0.0038828565696081884 +/*173*/ , 65536*16* -0.0038909308779192654 +/*174*/ , 65536*16* -0.0038820231307916493 +/*175*/ , 65536*16* -0.0038554750792844325 +/*176*/ , 65536*16* -0.003810737282493679 +/*177*/ , 65536*16* -0.003747262375484652 +/*178*/ , 65536*16* -0.0036646285078894706 +/*179*/ , 65536*16* -0.0035623728689170597 +/*180*/ , 65536*16* -0.0034401218523635543 +/*181*/ , 65536*16* -0.003297594128579178 +/*182*/ , 65536*16* -0.0031344918897463427 +/*183*/ , 65536*16* -0.0029506999116335536 +/*184*/ , 65536*16* -0.002746012743503227 +/*185*/ , 65536*16* -0.0025204082871514897 +/*186*/ , 65536*16* -0.0022738407863853822 +/*187*/ , 65536*16* -0.0020063873037173175 +/*188*/ , 65536*16* -0.0017182175415557032 +/*189*/ , 65536*16* -0.0014095092681882975 +/*190*/ , 65536*16* -0.0010805220633352567 +/*191*/ , 65536*16* -7.316077716348434E-4 +/*192*/ , 65536*16* -3.631468249678417E-4 +/*193*/ , 65536*16* 2.438177178474359E-5 +/*194*/ , 65536*16* 4.3040711526763105E-4 +/*195*/ , 65536*16* 8.543758511240976E-4 +/*196*/ , 65536*16* 0.0012955688715509065 +/*197*/ , 65536*16* 0.0017532574138845757 +/*198*/ , 65536*16* 0.0022266720975588176 +/*199*/ , 65536*16* 0.0027149312534676365 +/*200*/ , 65536*16* 0.003217102703811305 +/*201*/ , 65536*16* 0.0037322302087511496 +/*202*/ , 65536*16* 0.004259307964559864 +/*203*/ , 65536*16* 0.004797205731205993 +/*204*/ , 65536*16* 0.00534482556712745 +/*205*/ , 65536*16* 0.00590099232932727 +/*206*/ , 65536*16* 0.0064644836497811 +/*207*/ , 65536*16* 0.007034017389280477 +/*208*/ , 65536*16* 0.007608353016621833 +/*209*/ , 65536*16* 0.008186157965561618 +/*210*/ , 65536*16* 0.008766068964147668 +/*211*/ , 65536*16* 0.009346716260147759 +/*212*/ , 65536*16* 0.009926718862388615 +/*213*/ , 65536*16* 0.010504681043184161 +/*214*/ , 65536*16* 0.01107917387309342 +/*215*/ , 65536*16* 0.011648797102049465 +/*216*/ , 65536*16* 0.012212089485935572 +/*217*/ , 65536*16* 0.012767702033610684 +/*218*/ , 65536*16* 0.01331416222058608 +/*219*/ , 65536*16* 0.013850107485964188 +/*220*/ , 65536*16* 0.01437415626494087 +/*221*/ , 65536*16* 0.01488494484218882 +/*222*/ , 65536*16* 0.015381157046388828 +/*223*/ , 65536*16* 0.015861470914555698 +/*224*/ , 65536*16* 0.016324639468324405 +/*225*/ , 65536*16* 0.01676942738258265 +/*226*/ , 65536*16* 0.017194657140859698 +/*227*/ , 65536*16* 0.01759919326505855 +/*228*/ , 65536*16* 0.01798195744932672 +/*229*/ , 65536*16* 0.018341882104229386 +/*230*/ , 65536*16* 0.018678046774501487 +/*231*/ , 65536*16* 0.018989525183852277 +/*232*/ , 65536*16* 0.019275463483745325 +/*233*/ , 65536*16* 0.019535099985330217 +/*234*/ , 65536*16* 0.019767681230128092 +/*235*/ , 65536*16* 0.019972616359274192 +/*236*/ , 65536*16* 0.02014933369102741 +/*237*/ , 65536*16* 0.020297350637687013 +/*238*/ , 65536*16* 0.020416241350314838 +/*239*/ , 65536*16* 0.020505719050281913 +/*240*/ , 65536*16* 0.020565502954380747 +/*241*/ , 65536*16* 0.02059542406883178 +}; + + +/* 44100 NTSC + +Parks-McClellan FIR Filter Design + +Filter type: Low pass +Passband: 0 - 0.006695 +Order: 483 +Passband ripple: 0.2 dB +Transition band: 0.005625 +Stopband attenuation: 66.4 dB + +Coefficients: +*/ + +static int32 C44100NTSC[NCOEFFS/2]= +{ +/*0*/ 65536 *16 * 2.7250584077004043E-4 +/*1*/, 65536 *16 * -5.6651407794062126E-5 +/*2*/, 65536 *16 * -5.387595203270082E-5 +/*3*/, 65536 *16 * -5.3104114528112036E-5 +/*4*/, 65536 *16 * -5.3927905431407917E-5 +/*5*/, 65536 *16 * -5.624810531844495E-5 +/*6*/, 65536 *16 * -5.9753966587005594E-5 +/*7*/, 65536 *16 * -6.443298022976466E-5 +/*8*/, 65536 *16 * -7.002861393823279E-5 +/*9*/, 65536 *16 * -7.658937335809571E-5 +/*10*/, 65536 *16 * -8.388337472693157E-5 +/*11*/, 65536 *16 * -9.20081628039712E-5 +/*12*/, 65536 *16 * -1.007311169050114E-4 +/*13*/, 65536 *16 * -1.1019992230503533E-4 +/*14*/, 65536 *16 * -1.2014773803429516E-4 +/*15*/, 65536 *16 * -1.3080398984366903E-4 +/*16*/, 65536 *16 * -1.4175865072457003E-4 +/*17*/, 65536 *16 * -1.536527853404198E-4 +/*18*/, 65536 *16 * -1.6517054562524376E-4 +/*19*/, 65536 *16 * -1.7797585116596963E-4 +/*20*/, 65536 *16 * -1.909845496405445E-4 +/*21*/, 65536 *16 * -2.0389566936141008E-4 +/*22*/, 65536 *16 * -2.1726846302640957E-4 +/*23*/, 65536 *16 * -2.310008165840215E-4 +/*24*/, 65536 *16 * -2.4506881863360544E-4 +/*25*/, 65536 *16 * -2.5926465655995895E-4 +/*26*/, 65536 *16 * -2.735381275272462E-4 +/*27*/, 65536 *16 * -2.878190904612406E-4 +/*28*/, 65536 *16 * -3.0209388781875723E-4 +/*29*/, 65536 *16 * -3.163448868528516E-4 +/*30*/, 65536 *16 * -3.30514980542584E-4 +/*31*/, 65536 *16 * -3.4458721564408845E-4 +/*32*/, 65536 *16 * -3.5843761692424506E-4 +/*33*/, 65536 *16 * -3.720823326733447E-4 +/*34*/, 65536 *16 * -3.8529611278848583E-4 +/*35*/, 65536 *16 * -3.982435971141635E-4 +/*36*/, 65536 *16 * -4.1054225307421383E-4 +/*37*/, 65536 *16 * -4.223385042208698E-4 +/*38*/, 65536 *16 * -4.3363210365443626E-4 +/*39*/, 65536 *16 * -4.440451096331875E-4 +/*40*/, 65536 *16 * -4.537334227294333E-4 +/*41*/, 65536 *16 * -4.6260960194346025E-4 +/*42*/, 65536 *16 * -4.706224417116799E-4 +/*43*/, 65536 *16 * -4.776010427698281E-4 +/*44*/, 65536 *16 * -4.8350610346281614E-4 +/*45*/, 65536 *16 * -4.8826489934975626E-4 +/*46*/, 65536 *16 * -4.918511387810396E-4 +/*47*/, 65536 *16 * -4.941839548845786E-4 +/*48*/, 65536 *16 * -4.95186572618022E-4 +/*49*/, 65536 *16 * -4.947817087436606E-4 +/*50*/, 65536 *16 * -4.928828353341973E-4 +/*51*/, 65536 *16 * -4.894676199661217E-4 +/*52*/, 65536 *16 * -4.8443244774343773E-4 +/*53*/, 65536 *16 * -4.778002134883142E-4 +/*54*/, 65536 *16 * -4.694896704084311E-4 +/*55*/, 65536 *16 * -4.593928438902496E-4 +/*56*/, 65536 *16 * -4.4763586771533415E-4 +/*57*/, 65536 *16 * -4.3399559196764174E-4 +/*58*/, 65536 *16 * -4.185187519793231E-4 +/*59*/, 65536 *16 * -4.0118338859945383E-4 +/*60*/, 65536 *16 * -3.820043675631783E-4 +/*61*/, 65536 *16 * -3.6090543967085524E-4 +/*62*/, 65536 *16 * -3.379128204177913E-4 +/*63*/, 65536 *16 * -3.130247503897743E-4 +/*64*/, 65536 *16 * -2.8628759491904673E-4 +/*65*/, 65536 *16 * -2.5769205396918157E-4 +/*66*/, 65536 *16 * -2.2726228845123853E-4 +/*67*/, 65536 *16 * -1.9501222414998665E-4 +/*68*/, 65536 *16 * -1.609903786128509E-4 +/*69*/, 65536 *16 * -1.2525258280646142E-4 +/*70*/, 65536 *16 * -8.786088130641809E-5 +/*71*/, 65536 *16 * -4.885883411475722E-5 +/*72*/, 65536 *16 * -8.373566315346232E-6 +/*73*/, 65536 *16 * 3.362843819360238E-5 +/*74*/, 65536 *16 * 7.69302822233031E-5 +/*75*/, 65536 *16 * 1.2151249228835434E-4 +/*76*/, 65536 *16 * 1.6724878315058612E-4 +/*77*/, 65536 *16 * 2.1402171363813576E-4 +/*78*/, 65536 *16 * 2.6167305946436103E-4 +/*79*/, 65536 *16 * 3.10122854445744E-4 +/*80*/, 65536 *16 * 3.5921866691687363E-4 +/*81*/, 65536 *16 * 4.0882826181233784E-4 +/*82*/, 65536 *16 * 4.5876834733749337E-4 +/*83*/, 65536 *16 * 5.089048509923103E-4 +/*84*/, 65536 *16 * 5.590621717784201E-4 +/*85*/, 65536 *16 * 6.090870406928206E-4 +/*86*/, 65536 *16 * 6.587768488216395E-4 +/*87*/, 65536 *16 * 7.079653533691067E-4 +/*88*/, 65536 *16 * 7.56434905175643E-4 +/*89*/, 65536 *16 * 8.040537989021466E-4 +/*90*/, 65536 *16 * 8.505576158388297E-4 +/*91*/, 65536 *16 * 8.958345533585908E-4 +/*92*/, 65536 *16 * 9.396170235698547E-4 +/*93*/, 65536 *16 * 9.817197600520506E-4 +/*94*/, 65536 *16 * 0.0010219440113723856 +/*95*/, 65536 *16 * 0.0010600976395277468 +/*96*/, 65536 *16 * 0.0010959465933076378 +/*97*/, 65536 *16 * 0.0011293213059753442 +/*98*/, 65536 *16 * 0.001160012212002378 +/*99*/, 65536 *16 * 0.0011878334518393636 +/*100*/, 65536 *16 * 0.0012125633172564833 +/*101*/, 65536 *16 * 0.0012340340153475305 +/*102*/, 65536 *16 * 0.0012520523486154733 +/*103*/, 65536 *16 * 0.001266464375255462 +/*104*/, 65536 *16 * 0.001277070934117742 +/*105*/, 65536 *16 * 0.0012837351142488396 +/*106*/, 65536 *16 * 0.0012862625405968798 +/*107*/, 65536 *16 * 0.0012845614834936406 +/*108*/, 65536 *16 * 0.0012784420593778636 +/*109*/, 65536 *16 * 0.0012678178114382621 +/*110*/, 65536 *16 * 0.0012525556826375537 +/*111*/, 65536 *16 * 0.0012325473943852084 +/*112*/, 65536 *16 * 0.0012077126268838676 +/*113*/, 65536 *16 * 0.0011779966448355029 +/*114*/, 65536 *16 * 0.0011433146771737655 +/*115*/, 65536 *16 * 0.0011036347058885887 +/*116*/, 65536 *16 * 0.0010589202139950945 +/*117*/, 65536 *16 * 0.0010091683044254098 +/*118*/, 65536 *16 * 9.543624468571229E-4 +/*119*/, 65536 *16 * 8.945398819399117E-4 +/*120*/, 65536 *16 * 8.297313883125644E-4 +/*121*/, 65536 *16 * 7.600155199968718E-4 +/*122*/, 65536 *16 * 6.854405952299358E-4 +/*123*/, 65536 *16 * 6.061236114458317E-4 +/*124*/, 65536 *16 * 5.221478191516476E-4 +/*125*/, 65536 *16 * 4.336813620599164E-4 +/*126*/, 65536 *16 * 3.408549526515998E-4 +/*127*/, 65536 *16 * 2.438450825114285E-4 +/*128*/, 65536 *16 * 1.428494911857926E-4 +/*129*/, 65536 *16 * 3.8067640594361634E-5 +/*130*/, 65536 *16 * -7.027035111775681E-5 +/*131*/, 65536 *16 * -1.818984143827126E-4 +/*132*/, 65536 *16 * -2.9656343184630157E-4 +/*133*/, 65536 *16 * -4.1397802421901906E-4 +/*134*/, 65536 *16 * -5.33838500742085E-4 +/*135*/, 65536 *16 * -6.558110253978588E-4 +/*136*/, 65536 *16 * -7.795655816897978E-4 +/*137*/, 65536 *16 * -9.047371821667003E-4 +/*138*/, 65536 *16 * -0.001030961345825847 +/*139*/, 65536 *16 * -0.0011578367988084777 +/*140*/, 65536 *16 * -0.0012849810572319298 +/*141*/, 65536 *16 * -0.0014119662266064482 +/*142*/, 65536 *16 * -0.0015383759515758101 +/*143*/, 65536 *16 * -0.001663756794188296 +/*144*/, 65536 *16 * -0.0017876541594460456 +/*145*/, 65536 *16 * -0.001909621722046808 +/*146*/, 65536 *16 * -0.0020291786719378088 +/*147*/, 65536 *16 * -0.002145855089743562 +/*148*/, 65536 *16 * -0.002259171910476534 +/*149*/, 65536 *16 * -0.0023686314802222655 +/*150*/, 65536 *16 * -0.002473745572697707 +/*151*/, 65536 *16 * -0.0025740277587192853 +/*152*/, 65536 *16 * -0.0026689831666099955 +/*153*/, 65536 *16 * -0.0027581124255643377 +/*154*/, 65536 *16 * -0.0028409282136656177 +/*155*/, 65536 *16 * -0.0029169432593640367 +/*156*/, 65536 *16 * -0.002985680612410139 +/*157*/, 65536 *16 * -0.003046658228485494 +/*158*/, 65536 *16 * -0.003099414222252269 +/*159*/, 65536 *16 * -0.0031434902530511595 +/*160*/, 65536 *16 * -0.003178436798255356 +/*161*/, 65536 *16 * -0.0032038260756887147 +/*162*/, 65536 *16 * -0.003219225355080285 +/*163*/, 65536 *16 * -0.0032242502222488744 +/*164*/, 65536 *16 * -0.003218506103318342 +/*165*/, 65536 *16 * -0.003201625222636992 +/*166*/, 65536 *16 * -0.003173259488065382 +/*167*/, 65536 *16 * -0.0031330803817718332 +/*168*/, 65536 *16 * -0.0030807779128908526 +/*169*/, 65536 *16 * -0.0030160821637947783 +/*170*/, 65536 *16 * -0.0029387362752889335 +/*171*/, 65536 *16 * -0.002848510131379585 +/*172*/, 65536 *16 * -0.0027451998188029363 +/*173*/, 65536 *16 * -0.00262863682904045 +/*174*/, 65536 *16 * -0.0024986780420415064 +/*175*/, 65536 *16 * -0.0023552114528323513 +/*176*/, 65536 *16 * -0.0021981491527779964 +/*177*/, 65536 *16 * -0.0020274504745732714 +/*178*/, 65536 *16 * -0.0018430877753141852 +/*179*/, 65536 *16 * -0.0016450910502005863 +/*180*/, 65536 *16 * -0.0014334955802048866 +/*181*/, 65536 *16 * -0.0012083983821827642 +/*182*/, 65536 *16 * -9.699135443572468E-4 +/*183*/, 65536 *16 * -7.181935207475589E-4 +/*184*/, 65536 *16 * -4.534224887286362E-4 +/*185*/, 65536 *16 * -1.758311300125605E-4 +/*186*/, 65536 *16 * 1.1433027008948132E-4 +/*187*/, 65536 *16 * 4.1675921199616097E-4 +/*188*/, 65536 *16 * 7.311320710094336E-4 +/*189*/, 65536 *16 * 0.0010570872458505827 +/*190*/, 65536 *16 * 0.0013942372682560795 +/*191*/, 65536 *16 * 0.001742148094642797 +/*192*/, 65536 *16 * 0.002100362793433286 +/*193*/, 65536 *16 * 0.0024683818857210646 +/*194*/, 65536 *16 * 0.002845695057494279 +/*195*/, 65536 *16 * 0.0032317385772924275 +/*196*/, 65536 *16 * 0.0036259433326630884 +/*197*/, 65536 *16 * 0.0040276894120370626 +/*198*/, 65536 *16 * 0.004436353627556968 +/*199*/, 65536 *16 * 0.004851271439526238 +/*200*/, 65536 *16 * 0.005271762758295799 +/*201*/, 65536 *16 * 0.005697120565601845 +/*202*/, 65536 *16 * 0.006126626859240469 +/*203*/, 65536 *16 * 0.006559527746778011 +/*204*/, 65536 *16 * 0.0069950693344747504 +/*205*/, 65536 *16 * 0.007432470090915211 +/*206*/, 65536 *16 * 0.007870944336430185 +/*207*/, 65536 *16 * 0.008309688701943495 +/*208*/, 65536 *16 * 0.008747898549370043 +/*209*/, 65536 *16 * 0.009184747205291654 +/*210*/, 65536 *16 * 0.009619414724898365 +/*211*/, 65536 *16 * 0.010051063453485451 +/*212*/, 65536 *16 * 0.010478876316671397 +/*213*/, 65536 *16 * 0.010902016899039163 +/*214*/, 65536 *16 * 0.011319665474466693 +/*215*/, 65536 *16 * 0.011730992134403782 +/*216*/, 65536 *16 * 0.012135186113163639 +/*217*/, 65536 *16 * 0.01253143889871197 +/*218*/, 65536 *16 * 0.012918956981226547 +/*219*/, 65536 *16 * 0.013296952886747157 +/*220*/, 65536 *16 * 0.013664665893392403 +/*221*/, 65536 *16 * 0.014021339353548561 +/*222*/, 65536 *16 * 0.014366244972764902 +/*223*/, 65536 *16 * 0.014698670942210527 +/*224*/, 65536 *16 * 0.015017930945351435 +/*225*/, 65536 *16 * 0.015323359168800435 +/*226*/, 65536 *16 * 0.015614322198635518 +/*227*/, 65536 *16 * 0.015890204972590742 +/*228*/, 65536 *16 * 0.016150433344740527 +/*229*/, 65536 *16 * 0.01639445378257351 +/*230*/, 65536 *16 * 0.016621758349582072 +/*231*/, 65536 *16 * 0.01683186471138077 +/*232*/, 65536 *16 * 0.01702432745775747 +/*233*/, 65536 *16 * 0.017198732908190056 +/*234*/, 65536 *16 * 0.017354710361561963 +/*235*/, 65536 *16 * 0.017491928210652433 +/*236*/, 65536 *16 * 0.017610096156964024 +/*237*/, 65536 *16 * 0.017708958417438553 +/*238*/, 65536 *16 * 0.017788304726419644 +/*239*/, 65536 *16 * 0.01784796484627723 +/*240*/, 65536 *16 * 0.017887808513528385 +/*241*/, 65536 *16 * 0.01790775243433271 +}; + +/* 48000 PAL +Parks-McClellan FIR Filter Design + +Filter type: Low pass +Passband: 0 - 0.008810 +Order: 483 +Passband ripple: 0.133 dB +Transition band: 0.005625 +Stopband attenuation: 63.0 dB + +Coefficients: +*/ +static int32 C48000PAL[NCOEFFS/2]= +{ +/*0*/ 65536 *16 * -4.8720337170268194E-4 +/*1*/, 65536 *16 * 7.629902642634879E-7 +/*2*/, 65536 *16 * 2.1378369687164975E-6 +/*3*/, 65536 *16 * 4.2506426520122444E-6 +/*4*/, 65536 *16 * 7.369889860416342E-6 +/*5*/, 65536 *16 * 1.1216062943011637E-5 +/*6*/, 65536 *16 * 1.6073843505677063E-5 +/*7*/, 65536 *16 * 2.1633099120040373E-5 +/*8*/, 65536 *16 * 2.8206508485377597E-5 +/*9*/, 65536 *16 * 3.543629776593455E-5 +/*10*/, 65536 *16 * 4.368764327716006E-5 +/*11*/, 65536 *16 * 5.2518982409171E-5 +/*12*/, 65536 *16 * 6.239757141317561E-5 +/*13*/, 65536 *16 * 7.27096511997309E-5 +/*14*/, 65536 *16 * 8.417180660805913E-5 +/*15*/, 65536 *16 * 9.556951705928003E-5 +/*16*/, 65536 *16 * 1.0902571193097876E-4 +/*17*/, 65536 *16 * 1.227237340685471E-4 +/*18*/, 65536 *16 * 1.3608963828565135E-4 +/*19*/, 65536 *16 * 1.5074291732163737E-4 +/*20*/, 65536 *16 * 1.654957671774518E-4 +/*21*/, 65536 *16 * 1.8094544537755017E-4 +/*22*/, 65536 *16 * 1.9650254639058925E-4 +/*23*/, 65536 *16 * 2.124977005396817E-4 +/*24*/, 65536 *16 * 2.2850169154416925E-4 +/*25*/, 65536 *16 * 2.447269340662641E-4 +/*26*/, 65536 *16 * 2.60813097374866E-4 +/*27*/, 65536 *16 * 2.769089011403406E-4 +/*28*/, 65536 *16 * 2.926838284872595E-4 +/*29*/, 65536 *16 * 3.082587328683191E-4 +/*30*/, 65536 *16 * 3.233018169377691E-4 +/*31*/, 65536 *16 * 3.379664790017549E-4 +/*32*/, 65536 *16 * 3.520147829064225E-4 +/*33*/, 65536 *16 * 3.6489502104188965E-4 +/*34*/, 65536 *16 * 3.771837837785839E-4 +/*35*/, 65536 *16 * 3.8841744550992556E-4 +/*36*/, 65536 *16 * 3.985152578693797E-4 +/*37*/, 65536 *16 * 4.0737410559796126E-4 +/*38*/, 65536 *16 * 4.1485052511765913E-4 +/*39*/, 65536 *16 * 4.2087321591616255E-4 +/*40*/, 65536 *16 * 4.252880030529943E-4 +/*41*/, 65536 *16 * 4.2804175098790727E-4 +/*42*/, 65536 *16 * 4.289792011350111E-4 +/*43*/, 65536 *16 * 4.280677040429387E-4 +/*44*/, 65536 *16 * 4.251526022872329E-4 +/*45*/, 65536 *16 * 4.202312572840644E-4 +/*46*/, 65536 *16 * 4.1313629237647344E-4 +/*47*/, 65536 *16 * 4.0393669855985745E-4 +/*48*/, 65536 *16 * 3.9229544134295797E-4 +/*49*/, 65536 *16 * 3.785081882385653E-4 +/*50*/, 65536 *16 * 3.624387298611128E-4 +/*51*/, 65536 *16 * 3.439609793120755E-4 +/*52*/, 65536 *16 * 3.2317107312926493E-4 +/*53*/, 65536 *16 * 3.0001522643985015E-4 +/*54*/, 65536 *16 * 2.7456037312211196E-4 +/*55*/, 65536 *16 * 2.468022375847908E-4 +/*56*/, 65536 *16 * 2.1682011116032351E-4 +/*57*/, 65536 *16 * 1.846463359087917E-4 +/*58*/, 65536 *16 * 1.5038519581308458E-4 +/*59*/, 65536 *16 * 1.1409999503195986E-4 +/*60*/, 65536 *16 * 7.592602477010921E-5 +/*61*/, 65536 *16 * 3.594949037485983E-5 +/*62*/, 65536 *16 * -5.654205953473915E-6 +/*63*/, 65536 *16 * -4.8796158887641113E-5 +/*64*/, 65536 *16 * -9.324450907374415E-5 +/*65*/, 65536 *16 * -1.3875102646747199E-4 +/*66*/, 65536 *16 * -1.853099936736042E-4 +/*67*/, 65536 *16 * -2.3256519878196182E-4 +/*68*/, 65536 *16 * -2.803629983423417E-4 +/*69*/, 65536 *16 * -3.284299717573991E-4 +/*70*/, 65536 *16 * -3.7655572805983734E-4 +/*71*/, 65536 *16 * -4.244648731259925E-4 +/*72*/, 65536 *16 * -4.7191652130487173E-4 +/*73*/, 65536 *16 * -5.18626812434502E-4 +/*74*/, 65536 *16 * -5.64334322901072E-4 +/*75*/, 65536 *16 * -6.087503654593899E-4 +/*76*/, 65536 *16 * -6.515995849807032E-4 +/*77*/, 65536 *16 * -6.925935510204477E-4 +/*78*/, 65536 *16 * -7.314432865833455E-4 +/*79*/, 65536 *16 * -7.678735923848921E-4 +/*80*/, 65536 *16 * -8.015359919770463E-4 +/*81*/, 65536 *16 * -8.322768680565776E-4 +/*82*/, 65536 *16 * -8.597539203190856E-4 +/*83*/, 65536 *16 * -8.836879776280238E-4 +/*84*/, 65536 *16 * -9.038629010388075E-4 +/*85*/, 65536 *16 * -9.200080217158554E-4 +/*86*/, 65536 *16 * -9.319235257639778E-4 +/*87*/, 65536 *16 * -9.393690949611698E-4 +/*88*/, 65536 *16 * -9.421725179420662E-4 +/*89*/, 65536 *16 * -9.401299048871544E-4 +/*90*/, 65536 *16 * -9.33106896645869E-4 +/*91*/, 65536 *16 * -9.209400636174311E-4 +/*92*/, 65536 *16 * -9.035401279622776E-4 +/*93*/, 65536 *16 * -8.807854817776823E-4 +/*94*/, 65536 *16 * -8.526430615286829E-4 +/*95*/, 65536 *16 * -8.190296190822509E-4 +/*96*/, 65536 *16 * -7.799980167439345E-4 +/*97*/, 65536 *16 * -7.355478199155667E-4 +/*98*/, 65536 *16 * -6.8567697874281E-4 +/*99*/, 65536 *16 * -6.305240657493408E-4 +/*100*/, 65536 *16 * -5.701694385732142E-4 +/*101*/, 65536 *16 * -5.047740591296687E-4 +/*102*/, 65536 *16 * -4.344980221283718E-4 +/*103*/, 65536 *16 * -3.595556715693896E-4 +/*104*/, 65536 *16 * -2.8017864491759883E-4 +/*105*/, 65536 *16 * -1.9664106446578853E-4 +/*106*/, 65536 *16 * -1.0924056590418239E-4 +/*107*/, 65536 *16 * -1.831009861307028E-5 +/*108*/, 65536 *16 * 7.579029921420169E-5 +/*109*/, 65536 *16 * 1.726696848384902E-4 +/*110*/, 65536 *16 * 2.719067221880469E-4 +/*111*/, 65536 *16 * 3.7305728261123155E-4 +/*112*/, 65536 *16 * 4.7562651195605295E-4 +/*113*/, 65536 *16 * 5.791888527128953E-4 +/*114*/, 65536 *16 * 6.831673135667645E-4 +/*115*/, 65536 *16 * 7.870493762901182E-4 +/*116*/, 65536 *16 * 8.902822670362451E-4 +/*117*/, 65536 *16 * 9.923024258505538E-4 +/*118*/, 65536 *16 * 0.0010925350458368308 +/*119*/, 65536 *16 * 0.0011903898503065698 +/*120*/, 65536 *16 * 0.0012852771482304163 +/*121*/, 65536 *16 * 0.0013765956662458894 +/*122*/, 65536 *16 * 0.001463753120426749 +/*123*/, 65536 *16 * 0.001546148019165285 +/*124*/, 65536 *16 * 0.0016231971391851225 +/*125*/, 65536 *16 * 0.0016943089588603764 +/*126*/, 65536 *16 * 0.0017589264521182184 +/*127*/, 65536 *16 * 0.001816477825843157 +/*128*/, 65536 *16 * 0.001866465750234791 +/*129*/, 65536 *16 * 0.001908351881851273 +/*130*/, 65536 *16 * 0.0019416355874888774 +/*131*/, 65536 *16 * 0.0019658912100497094 +/*132*/, 65536 *16 * 0.0019806705540431754 +/*133*/, 65536 *16 * 0.001985602463070219 +/*134*/, 65536 *16 * 0.0019803173347810094 +/*135*/, 65536 *16 * 0.001964518487218229 +/*136*/, 65536 *16 * 0.00193792749109128 +/*137*/, 65536 *16 * 0.0019003361153152295 +/*138*/, 65536 *16 * 0.0018515636696845045 +/*139*/, 65536 *16 * 0.0017915008584460717 +/*140*/, 65536 *16 * 0.0017200735452676211 +/*141*/, 65536 *16 * 0.0016372830430278298 +/*142*/, 65536 *16 * 0.0015431709906056357 +/*143*/, 65536 *16 * 0.0014378573929982352 +/*144*/, 65536 *16 * 0.0013215084987890104 +/*145*/, 65536 *16 * 0.001194328283068528 +/*146*/, 65536 *16 * 0.0010566468386934231 +/*147*/, 65536 *16 * 9.088002025373218E-4 +/*148*/, 65536 *16 * 7.512135584215806E-4 +/*149*/, 65536 *16 * 5.843621536328689E-4 +/*150*/, 65536 *16 * 4.087894375795271E-4 +/*151*/, 65536 *16 * 2.2510227575334467E-4 +/*152*/, 65536 *16 * 3.396239791846655E-5 +/*153*/, 65536 *16 * -1.6390294871759475E-4 +/*154*/, 65536 *16 * -3.6771789280231503E-4 +/*155*/, 65536 *16 * -5.766405458635558E-4 +/*156*/, 65536 *16 * -7.897872933737203E-4 +/*157*/, 65536 *16 * -0.001006209757480115 +/*158*/, 65536 *16 * -0.0012249304977170316 +/*159*/, 65536 *16 * -0.0014449054341312839 +/*160*/, 65536 *16 * -0.0016650898600315796 +/*161*/, 65536 *16 * -0.001884343774622382 +/*162*/, 65536 *16 * -0.0021015342465919864 +/*163*/, 65536 *16 * -0.0023154975831354337 +/*164*/, 65536 *16 * -0.0025250324219407566 +/*165*/, 65536 *16 * -0.0027289312457094736 +/*166*/, 65536 *16 * -0.0029259546931934967 +/*167*/, 65536 *16 * -0.003114871201398419 +/*168*/, 65536 *16 * -0.003294430723892981 +/*169*/, 65536 *16 * -0.003463396424710959 +/*170*/, 65536 *16 * -0.003620525188769811 +/*171*/, 65536 *16 * -0.0037645967189351955 +/*172*/, 65536 *16 * -0.003894396916361478 +/*173*/, 65536 *16 * -0.00400874728567525 +/*174*/, 65536 *16 * -0.004106485394068385 +/*175*/, 65536 *16 * -0.004186497692846864 +/*176*/, 65536 *16 * -0.004247692032125654 +/*177*/, 65536 *16 * -0.004289020763525844 +/*178*/, 65536 *16 * -0.0043095197889136795 +/*179*/, 65536 *16 * -0.004308238489219152 +/*180*/, 65536 *16 * -0.004284317631022625 +/*181*/, 65536 *16 * -0.0042369380515990835 +/*182*/, 65536 *16 * -0.004165372803509635 +/*183*/, 65536 *16 * -0.004068956516951112 +/*184*/, 65536 *16 * -0.003947110543306579 +/*185*/, 65536 *16 * -0.003799332887739826 +/*186*/, 65536 *16 * -0.0036252122359255057 +/*187*/, 65536 *16 * -0.0034244255727248728 +/*188*/, 65536 *16 * -0.0031967441992062605 +/*189*/, 65536 *16 * -0.0029420359603045624 +/*190*/, 65536 *16 * -0.002660262473612329 +/*191*/, 65536 *16 * -0.0023514913391939015 +/*192*/, 65536 *16 * -0.002015874218170038 +/*193*/, 65536 *16 * -0.0016537021922741356 +/*194*/, 65536 *16 * -0.0012653326032471951 +/*195*/, 65536 *16 * -8.512425489658283E-4 +/*196*/, 65536 *16 * -4.12008134196091E-4 +/*197*/, 65536 *16 * 5.169160678832697E-5 +/*198*/, 65536 *16 * 5.3906734093252E-4 +/*199*/, 65536 *16 * 0.0010492444783799305 +/*200*/, 65536 *16 * 0.0015812369440962736 +/*201*/, 65536 *16 * 0.002133975437656693 +/*202*/, 65536 *16 * 0.002706284295633396 +/*203*/, 65536 *16 * 0.003296910987472264 +/*204*/, 65536 *16 * 0.0039045040922850343 +/*205*/, 65536 *16 * 0.004527645156076457 +/*206*/, 65536 *16 * 0.005164822580527953 +/*207*/, 65536 *16 * 0.00581446977998051 +/*208*/, 65536 *16 * 0.00647492818678252 +/*209*/, 65536 *16 * 0.007144495527005753 +/*210*/, 65536 *16 * 0.007821417135435386 +/*211*/, 65536 *16 * 0.008503870707064397 +/*212*/, 65536 *16 * 0.00919000676302643 +/*213*/, 65536 *16 * 0.009877917856582038 +/*214*/, 65536 *16 * 0.010565689475867907 +/*215*/, 65536 *16 * 0.011251366750588049 +/*216*/, 65536 *16 * 0.01193298816023733 +/*217*/, 65536 *16 * 0.012608574497468706 +/*218*/, 65536 *16 * 0.013276151008399953 +/*219*/, 65536 *16 * 0.013933744269275995 +/*220*/, 65536 *16 * 0.014579397589755912 +/*221*/, 65536 *16 * 0.015211171751139368 +/*222*/, 65536 *16 * 0.015827155422328678 +/*223*/, 65536 *16 * 0.01642547256780349 +/*224*/, 65536 *16 * 0.01700428326907068 +/*225*/, 65536 *16 * 0.017561819587529177 +/*226*/, 65536 *16 * 0.018096338432718698 +/*227*/, 65536 *16 * 0.018606183762999433 +/*228*/, 65536 *16 * 0.019089749497960648 +/*229*/, 65536 *16 * 0.019545523698532997 +/*230*/, 65536 *16 * 0.019972069058400564 +/*231*/, 65536 *16 * 0.02036803110561515 +/*232*/, 65536 *16 * 0.020732154475618856 +/*233*/, 65536 *16 * 0.021063275458886234 +/*234*/, 65536 *16 * 0.021360340738775345 +/*235*/, 65536 *16 * 0.02162239534537267 +/*236*/, 65536 *16 * 0.021848603142668337 +/*237*/, 65536 *16 * 0.02203823092181804 +/*238*/, 65536 *16 * 0.022190674411724294 +/*239*/, 65536 *16 * 0.022305434241445123 +/*240*/, 65536 *16 * 0.022382153728111424 +/*241*/, 65536 *16 * 0.022420574751016616 +}; + +/* 44100 PAL +Parks-McClellan FIR Filter Design + +Filter type: Low pass +Passband: 0 - 0.0076373 +Order: 483 +Passband ripple: 0.1 dB +Transition band: 0.005625 +Stopband attenuation: 60.5 dB + +Coefficients: +*/ +static int32 C44100PAL[NCOEFFS/2]= +{ +/*0*/ 65536 *16 * 5.793783958720019E-4 +/*1*/, 65536 *16 * 1.0571291666629312E-4 +/*2*/, 65536 *16 * 1.1459085882755871E-4 +/*3*/, 65536 *16 * 1.2371675029136968E-4 +/*4*/, 65536 *16 * 1.3275170325031607E-4 +/*5*/, 65536 *16 * 1.4207721167879995E-4 +/*6*/, 65536 *16 * 1.5130497600100568E-4 +/*7*/, 65536 *16 * 1.6077227873948047E-4 +/*8*/, 65536 *16 * 1.6990814771316866E-4 +/*9*/, 65536 *16 * 1.79005024990367E-4 +/*10*/, 65536 *16 * 1.8739246068939436E-4 +/*11*/, 65536 *16 * 1.9572039600801667E-4 +/*12*/, 65536 *16 * 2.0352846914404956E-4 +/*13*/, 65536 *16 * 2.1201116607443127E-4 +/*14*/, 65536 *16 * 2.188838839136502E-4 +/*15*/, 65536 *16 * 2.2495686284733203E-4 +/*16*/, 65536 *16 * 2.3149812422937834E-4 +/*17*/, 65536 *16 * 2.363635497444841E-4 +/*18*/, 65536 *16 * 2.410054979130104E-4 +/*19*/, 65536 *16 * 2.445286108284421E-4 +/*20*/, 65536 *16 * 2.474675828550653E-4 +/*21*/, 65536 *16 * 2.4934815214903343E-4 +/*22*/, 65536 *16 * 2.50372333906785E-4 +/*23*/, 65536 *16 * 2.501665763315339E-4 +/*24*/, 65536 *16 * 2.488750795254978E-4 +/*25*/, 65536 *16 * 2.4640153199411455E-4 +/*26*/, 65536 *16 * 2.428720291968876E-4 +/*27*/, 65536 *16 * 2.3801309032826844E-4 +/*28*/, 65536 *16 * 2.3160240772113682E-4 +/*29*/, 65536 *16 * 2.2423402291517938E-4 +/*30*/, 65536 *16 * 2.152856501527123E-4 +/*31*/, 65536 *16 * 2.0488674543318888E-4 +/*32*/, 65536 *16 * 1.9317919544163198E-4 +/*33*/, 65536 *16 * 1.7994016398005858E-4 +/*34*/, 65536 *16 * 1.6541109383681028E-4 +/*35*/, 65536 *16 * 1.4938382649739635E-4 +/*36*/, 65536 *16 * 1.3200975730094075E-4 +/*37*/, 65536 *16 * 1.1313240842725184E-4 +/*38*/, 65536 *16 * 9.296992728984174E-5 +/*39*/, 65536 *16 * 7.143010735440594E-5 +/*40*/, 65536 *16 * 4.8632764324109725E-5 +/*41*/, 65536 *16 * 2.443073549738759E-5 +/*42*/, 65536 *16 * -8.284349612349981E-7 +/*43*/, 65536 *16 * -2.7227387247375577E-5 +/*44*/, 65536 *16 * -5.4818038895146106E-5 +/*45*/, 65536 *16 * -8.330005435111118E-5 +/*46*/, 65536 *16 * -1.1275737974091186E-4 +/*47*/, 65536 *16 * -1.4298620796919756E-4 +/*48*/, 65536 *16 * -1.7390785487074508E-4 +/*49*/, 65536 *16 * -2.054308580401118E-4 +/*50*/, 65536 *16 * -2.37415521983132E-4 +/*51*/, 65536 *16 * -2.697456782629617E-4 +/*52*/, 65536 *16 * -3.022375619849705E-4 +/*53*/, 65536 *16 * -3.348339660959209E-4 +/*54*/, 65536 *16 * -3.673583086741243E-4 +/*55*/, 65536 *16 * -3.996554197363865E-4 +/*56*/, 65536 *16 * -4.3147108191834185E-4 +/*57*/, 65536 *16 * -4.6285023012872966E-4 +/*58*/, 65536 *16 * -4.934440989261961E-4 +/*59*/, 65536 *16 * -5.231720978150925E-4 +/*60*/, 65536 *16 * -5.518656107257292E-4 +/*61*/, 65536 *16 * -5.793049560550073E-4 +/*62*/, 65536 *16 * -6.053792205725333E-4 +/*63*/, 65536 *16 * -6.298765704841736E-4 +/*64*/, 65536 *16 * -6.526402738994988E-4 +/*65*/, 65536 *16 * -6.734722964365358E-4 +/*66*/, 65536 *16 * -6.922485843472661E-4 +/*67*/, 65536 *16 * -7.088111930758961E-4 +/*68*/, 65536 *16 * -7.229789042068006E-4 +/*69*/, 65536 *16 * -7.34572975483669E-4 +/*70*/, 65536 *16 * -7.435049180176613E-4 +/*71*/, 65536 *16 * -7.496258178311876E-4 +/*72*/, 65536 *16 * -7.527294926570751E-4 +/*73*/, 65536 *16 * -7.528075552986548E-4 +/*74*/, 65536 *16 * -7.496410435428715E-4 +/*75*/, 65536 *16 * -7.432054606042111E-4 +/*76*/, 65536 *16 * -7.33375741493331E-4 +/*77*/, 65536 *16 * -7.200753858529672E-4 +/*78*/, 65536 *16 * -7.03226653737734E-4 +/*79*/, 65536 *16 * -6.827921676621563E-4 +/*80*/, 65536 *16 * -6.58752773848678E-4 +/*81*/, 65536 *16 * -6.31061807229375E-4 +/*82*/, 65536 *16 * -5.997124150992168E-4 +/*83*/, 65536 *16 * -5.647352645065657E-4 +/*84*/, 65536 *16 * -5.261799041455252E-4 +/*85*/, 65536 *16 * -4.8402880277824417E-4 +/*86*/, 65536 *16 * -4.3840329475572E-4 +/*87*/, 65536 *16 * -3.893672279202991E-4 +/*88*/, 65536 *16 * -3.37002579326518E-4 +/*89*/, 65536 *16 * -2.8148278838384204E-4 +/*90*/, 65536 *16 * -2.2288467365854118E-4 +/*91*/, 65536 *16 * -1.6140368454103024E-4 +/*92*/, 65536 *16 * -9.718648150744015E-5 +/*93*/, 65536 *16 * -3.046343268277719E-5 +/*94*/, 65536 *16 * 3.859234051837562E-5 +/*95*/, 65536 *16 * 1.0974328274324426E-4 +/*96*/, 65536 *16 * 1.8273974279995372E-4 +/*97*/, 65536 *16 * 2.5730055402762935E-4 +/*98*/, 65536 *16 * 3.3318458939353874E-4 +/*99*/, 65536 *16 * 4.100891270013777E-4 +/*100*/, 65536 *16 * 4.876860015464126E-4 +/*101*/, 65536 *16 * 5.657011755504638E-4 +/*102*/, 65536 *16 * 6.437547403393535E-4 +/*103*/, 65536 *16 * 7.215350856659516E-4 +/*104*/, 65536 *16 * 7.986901321007353E-4 +/*105*/, 65536 *16 * 8.748424228508639E-4 +/*106*/, 65536 *16 * 9.496338070297501E-4 +/*107*/, 65536 *16 * 0.0010226804298925178 +/*108*/, 65536 *16 * 0.001093633836878271 +/*109*/, 65536 *16 * 0.0011620773771650913 +/*110*/, 65536 *16 * 0.001227641045409496 +/*111*/, 65536 *16 * 0.0012899374110895208 +/*112*/, 65536 *16 * 0.001348607725415767 +/*113*/, 65536 *16 * 0.001403236086962171 +/*114*/, 65536 *16 * 0.0014534904370406968 +/*115*/, 65536 *16 * 0.0014989864777827345 +/*116*/, 65536 *16 * 0.0015393672007052272 +/*117*/, 65536 *16 * 0.0015743174329729173 +/*118*/, 65536 *16 * 0.0016034756800234508 +/*119*/, 65536 *16 * 0.0016265420570988364 +/*120*/, 65536 *16 * 0.0016432110467175217 +/*121*/, 65536 *16 * 0.0016532197970121178 +/*122*/, 65536 *16 * 0.0016562968359550962 +/*123*/, 65536 *16 * 0.0016521969919585549 +/*124*/, 65536 *16 * 0.001640721606064916 +/*125*/, 65536 *16 * 0.001621678045313759 +/*126*/, 65536 *16 * 0.0015948992297934834 +/*127*/, 65536 *16 * 0.0015602457924787695 +/*128*/, 65536 *16 * 0.0015176354451292787 +/*129*/, 65536 *16 * 0.0014669598890367775 +/*130*/, 65536 *16 * 0.001408218899058892 +/*131*/, 65536 *16 * 0.001341376545671481 +/*132*/, 65536 *16 * 0.0012664621369705463 +/*133*/, 65536 *16 * 0.0011835425953369801 +/*134*/, 65536 *16 * 0.0010927146027981068 +/*135*/, 65536 *16 * 9.941150953832762E-4 +/*136*/, 65536 *16 * 8.878982163088053E-4 +/*137*/, 65536 *16 * 7.742911468907501E-4 +/*138*/, 65536 *16 * 6.535350381595103E-4 +/*139*/, 65536 *16 * 5.259114487251054E-4 +/*140*/, 65536 *16 * 3.9173611703422796E-4 +/*141*/, 65536 *16 * 2.513813444320677E-4 +/*142*/, 65536 *16 * 1.0522988594595334E-4 +/*143*/, 65536 *16 * -4.627799877161863E-5 +/*144*/, 65536 *16 * -2.0266153878465397E-4 +/*145*/, 65536 *16 * -3.6344539072942917E-4 +/*146*/, 65536 *16 * -5.28061484912101E-4 +/*147*/, 65536 *16 * -6.959549845043866E-4 +/*148*/, 65536 *16 * -8.665108935058429E-4 +/*149*/, 65536 *16 * -0.0010391137133997624 +/*150*/, 65536 *16 * -0.001213088248571412 +/*151*/, 65536 *16 * -0.0013877438142645866 +/*152*/, 65536 *16 * -0.0015623746142961936 +/*153*/, 65536 *16 * -0.001736242850147973 +/*154*/, 65536 *16 * -0.0019085899496564314 +/*155*/, 65536 *16 * -0.002078639823528187 +/*156*/, 65536 *16 * -0.0022456104279907118 +/*157*/, 65536 *16 * -0.002408678368623706 +/*158*/, 65536 *16 * -0.002567052121352872 +/*159*/, 65536 *16 * -0.0027198956481072887 +/*160*/, 65536 *16 * -0.0028663750213148488 +/*161*/, 65536 *16 * -0.0030056713494924794 +/*162*/, 65536 *16 * -0.0031369487365098063 +/*163*/, 65536 *16 * -0.0032593909953083865 +/*164*/, 65536 *16 * -0.0033721594370116153 +/*165*/, 65536 *16 * -0.0034744643621211356 +/*166*/, 65536 *16 * -0.0035654990231207963 +/*167*/, 65536 *16 * -0.003644488024347632 +/*168*/, 65536 *16 * -0.0037106644342197828 +/*169*/, 65536 *16 * -0.0037632989436418352 +/*170*/, 65536 *16 * -0.00380166827783197 +/*171*/, 65536 *16 * -0.0038250950477227447 +/*172*/, 65536 *16 * -0.0038329329853570827 +/*173*/, 65536 *16 * -0.0038245430145814447 +/*174*/, 65536 *16 * -0.0037993625516763766 +/*175*/, 65536 *16 * -0.003756842883124589 +/*176*/, 65536 *16 * -0.0036964913119694686 +/*177*/, 65536 *16 * -0.0036178458358447655 +/*178*/, 65536 *16 * -0.00352050628243193 +/*179*/, 65536 *16 * -0.003404123578517079 +/*180*/, 65536 *16 * -0.003268383375473133 +/*181*/, 65536 *16 * -0.0031130454148921446 +/*182*/, 65536 *16 * -0.002937909773123352 +/*183*/, 65536 *16 * -0.0027428475146560275 +/*184*/, 65536 *16 * -0.0025277729297779944 +/*185*/, 65536 *16 * -0.0022926869206439508 +/*186*/, 65536 *16 * -0.0020376141174133374 +/*187*/, 65536 *16 * -0.0017626719756025908 +/*188*/, 65536 *16 * -0.0014680351622130402 +/*189*/, 65536 *16 * -0.0011539297872750212 +/*190*/, 65536 *16 * -8.206567501069872E-4 +/*191*/, 65536 *16 * -4.685710694984321E-4 +/*192*/, 65536 *16 * -9.811116382477182E-5 +/*193*/, 65536 *16 * 2.902488429495873E-4 +/*194*/, 65536 *16 * 6.959516881166062E-4 +/*195*/, 65536 *16 * 0.0011183883405789612 +/*196*/, 65536 *16 * 0.0015568865209671754 +/*197*/, 65536 *16 * 0.0020107155705137744 +/*198*/, 65536 *16 * 0.002479084293281152 +/*199*/, 65536 *16 * 0.002961149037985776 +/*200*/, 65536 *16 * 0.0034560223628435746 +/*201*/, 65536 *16 * 0.0039627343373741354 +/*202*/, 65536 *16 * 0.0044803036416812955 +/*203*/, 65536 *16 * 0.005007678185806692 +/*204*/, 65536 *16 * 0.00554377521563058 +/*205*/, 65536 *16 * 0.006087456836491167 +/*206*/, 65536 *16 * 0.006637561024809676 +/*207*/, 65536 *16 * 0.007192890398414245 +/*208*/, 65536 *16 * 0.0077522050201042055 +/*209*/, 65536 *16 * 0.008314254820045306 +/*210*/, 65536 *16 * 0.008877749982246051 +/*211*/, 65536 *16 * 0.009441393781470539 +/*212*/, 65536 *16 * 0.010003862886118781 +/*213*/, 65536 *16 * 0.01056383933598836 +/*214*/, 65536 *16 * 0.011119972235266088 +/*215*/, 65536 *16 * 0.011670924253482212 +/*216*/, 65536 *16 * 0.012215363764388693 +/*217*/, 65536 *16 * 0.012751945584822125 +/*218*/, 65536 *16 * 0.013279348664168343 +/*219*/, 65536 *16 * 0.013796251849197938 +/*220*/, 65536 *16 * 0.0143013718962506 +/*221*/, 65536 *16 * 0.014793420656675483 +/*222*/, 65536 *16 * 0.015271157641252524 +/*223*/, 65536 *16 * 0.015733358657288442 +/*224*/, 65536 *16 * 0.016178837288118402 +/*225*/, 65536 *16 * 0.016606446422463023 +/*226*/, 65536 *16 * 0.01701507865820779 +/*227*/, 65536 *16 * 0.017403671672970734 +/*228*/, 65536 *16 * 0.01777119975394863 +/*229*/, 65536 *16 * 0.018116717572056962 +/*230*/, 65536 *16 * 0.01843930362202181 +/*231*/, 65536 *16 * 0.01873811058717855 +/*232*/, 65536 *16 * 0.01901234584784063 +/*233*/, 65536 *16 * 0.019261287195027194 +/*234*/, 65536 *16 * 0.019484271195397335 +/*235*/, 65536 *16 * 0.0196806998422779 +/*236*/, 65536 *16 * 0.019850058102456474 +/*237*/, 65536 *16 * 0.019991882444368586 +/*238*/, 65536 *16 * 0.0201058042761605 +/*239*/, 65536 *16 * 0.02019151207246131 +/*240*/, 65536 *16 * 0.02024878178965319 +/*241*/, 65536 *16 * 0.020277449712345474 +}; diff --git a/fceumm/src-fceumm/fds.c b/fceumm/src-fceumm/fds.c new file mode 100644 index 0000000..d7c6494 --- /dev/null +++ b/fceumm/src-fceumm/fds.c @@ -0,0 +1,862 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +#include "types.h" +#include "x6502.h" +#include "x6502struct.h" +#include "fceu.h" +#include "fds.h" +#include "sound.h" +#include "general.h" +#include "state.h" +#include "file.h" +#include "memory.h" +#include "cart.h" +#include "md5.h" + +/* TODO: Add code to put a delay in between the time a disk is inserted + and the when it can be successfully read/written to. This should + prevent writes to wrong places OR add code to prevent disk ejects + when the virtual motor is on(mmm...virtual motor). +*/ + +static DECLFR(FDSRead4030); +static DECLFR(FDSRead4031); +static DECLFR(FDSRead4032); +static DECLFR(FDSRead4033); + +static DECLFW(FDSWrite); + +static DECLFW(FDSWaveWrite); +static DECLFR(FDSWaveRead); + +static DECLFR(FDSSRead); +static DECLFW(FDSSWrite); +static DECLFR(FDSBIOSRead); +static DECLFR(FDSRAMRead); +static DECLFW(FDSRAMWrite); +static void FDSInit(void); +static void FDSFix(int a); + +#define FDSRAM GameMemBlock +#define CHRRAM (GameMemBlock+32768) + +static uint8 FDSRegs[6]; +static int32 IRQLatch,IRQCount; +static uint8 IRQa; +static void FDSClose(void); + +static uint8 FDSBIOS[8192]; + +/* Original disk data backup, to help in creating save states. */ +static uint8 *diskdatao[8]={0,0,0,0,0,0,0,0}; + +static uint8 *diskdata[8]={0,0,0,0,0,0,0,0}; + +static unsigned int TotalSides; +static uint8 DiskWritten=0; /* Set to 1 if disk was written to. */ +static uint8 writeskip; +static uint32 DiskPtr; +static int32 DiskSeekIRQ; +static uint8 SelectDisk,InDisk; + +#define DC_INC 1 + +void FDSGI(int h) +{ + switch(h) + { + case GI_CLOSE: FDSClose();break; + case GI_POWER: FDSInit();break; + } +} + +static void FDSStateRestore(int version) +{ + int x; + + setmirror(((FDSRegs[5]&8)>>3)^1); + + if(version >= 9810) + for(x=0;x>1,(SelectDisk&1)?"B":"A");*/ + InDisk=SelectDisk; + } + else + { + /*FCEU_DispMessage("Disk %d Side %s Ejected",SelectDisk>>1,(SelectDisk&1)?"B":"A");*/ + InDisk=255; + } +} + +void FCEU_FDSEject(void) +{ + InDisk=255; +} + +void FCEU_FDSSelect(void) +{ + if(InDisk!=255) + { + /*FCEU_DispMessage("Eject disk before selecting.");*/ + return; + } + SelectDisk=((SelectDisk+1)%TotalSides)&3; + /*FCEU_DispMessage("Disk %d Side %s Selected",SelectDisk>>1,(SelectDisk&1)?"B":"A");*/ +} + +static void FDSFix(int a) +{ + if((IRQa&2) && IRQCount) + { + IRQCount-=a; + if(IRQCount<=0) + { + if(!(IRQa&1)) + { + IRQa&=~2; + IRQCount=0;/*IRQLatch=0;*/ + } + else + IRQCount=IRQLatch; + /*IRQCount=IRQLatch; //0xFFFF;*/ + X6502_IRQBegin(FCEU_IQEXT); + /*printf("IRQ: %d\n",timestamp);*/ + /* printf("IRQ: %d\n",scanline);*/ + } + } + if(DiskSeekIRQ>0) + { + DiskSeekIRQ-=a; + if(DiskSeekIRQ<=0) + { + if(FDSRegs[5]&0x80) + { + X6502_IRQBegin(FCEU_IQEXT2); + } + } + } +} + +static DECLFR(FDSRead4030) +{ + uint8 ret=0; + + /* Cheap hack. */ + if(X.IRQlow&FCEU_IQEXT) ret|=1; + if(X.IRQlow&FCEU_IQEXT2) ret|=2; + + X6502_IRQEnd(FCEU_IQEXT); + X6502_IRQEnd(FCEU_IQEXT2); + return ret; +} + +static DECLFR(FDSRead4031) +{ + static uint8 z=0; + if(InDisk!=255) + { + z=diskdata[InDisk][DiskPtr]; + { + if(DiskPtr<64999) DiskPtr++; + DiskSeekIRQ=150; + X6502_IRQEnd(FCEU_IQEXT2); + } + } + return z; +} +static DECLFR(FDSRead4032) +{ + uint8 ret; + + ret=X.DB&~7; + if(InDisk==255) + ret|=5; + + if(InDisk==255 || !(FDSRegs[5]&1) || (FDSRegs[5]&2)) + ret|=2; + return ret; +} + +static DECLFR(FDSRead4033) +{ + return 0x80; /* battery*/ +} + +static DECLFW(FDSRAMWrite) +{ + (FDSRAM-0x6000)[A]=V; +} + +static DECLFR(FDSBIOSRead) +{ + return (FDSBIOS-0xE000)[A]; +} + +static DECLFR(FDSRAMRead) +{ + return (FDSRAM-0x6000)[A]; +} + +/* Begin FDS sound */ + +#define FDSClock (1789772.7272727272727272/2) + +typedef struct { + int64 cycles; /* Cycles per PCM sample*/ + int64 count; /* Cycle counter*/ + int64 envcount; /* Envelope cycle counter*/ + uint32 b19shiftreg60; + uint32 b24adder66; + uint32 b24latch68; + uint32 b17latch76; + int32 clockcount; /* Counter to divide frequency by 8.*/ + uint8 b8shiftreg88; /* Modulation register.*/ + uint8 amplitude[2]; /* Current amplitudes.*/ + uint8 speedo[2]; + uint8 mwcount; + uint8 mwstart; + uint8 mwave[0x20]; /* Modulation waveform*/ + uint8 cwave[0x40]; /* Game-defined waveform(carrier)*/ + uint8 SPSG[0xB]; +} FDSSOUND; + +static FDSSOUND fdso; + +#define SPSG fdso.SPSG +#define b19shiftreg60 fdso.b19shiftreg60 +#define b24adder66 fdso.b24adder66 +#define b24latch68 fdso.b24latch68 +#define b17latch76 fdso.b17latch76 +#define b8shiftreg88 fdso.b8shiftreg88 +#define clockcount fdso.clockcount +#define amplitude fdso.amplitude +#define speedo fdso.speedo + +void FDSSoundStateAdd(void) +{ + AddExState(fdso.cwave,64,0,"WAVE"); + AddExState(fdso.mwave,32,0,"MWAV"); + AddExState(amplitude,2,0,"AMPL"); + AddExState(SPSG,0xB,0,"SPSG"); + + AddExState(&b8shiftreg88,1,0,"B88"); + + AddExState(&clockcount, 4, 1, "CLOC"); + AddExState(&b19shiftreg60,4,1,"B60"); + AddExState(&b24adder66,4,1,"B66"); + AddExState(&b24latch68,4,1,"B68"); + AddExState(&b17latch76,4,1,"B76"); + +} + +static DECLFR(FDSSRead) +{ + switch(A&0xF) + { + case 0x0:return(amplitude[0]|(X.DB&0xC0)); + case 0x2:return(amplitude[1]|(X.DB&0xC0)); + } + return(X.DB); +} + +static DECLFW(FDSSWrite) +{ + if(FSettings.SndRate) + { +#if SOUND_QUALITY == 1 + RenderSoundHQ(); +#else + RenderSound(); +#endif + } + A-=0x4080; + switch(A) + { + case 0x0: + case 0x4: if(V&0x80) + amplitude[(A&0xF)>>2]=V&0x3F; /*)>0x20?0x20:(V&0x3F);*/ + break; + case 0x5:/*printf("$%04x:$%02x\n",A,V);*/ + break; + case 0x7: b17latch76=0;SPSG[0x5]=0;/*printf("$%04x:$%02x\n",A,V);*/ + break; + case 0x8: + b17latch76=0; + /* printf("%d:$%02x, $%02x\n",SPSG[0x5],V,b17latch76);*/ + fdso.mwave[SPSG[0x5]&0x1F]=V&0x7; + SPSG[0x5]=(SPSG[0x5]+1)&0x1F; + break; + } + /*if(A>=0x7 && A!=0x8 && A<=0xF)*/ + /*if(A==0xA || A==0x9)*/ + /*printf("$%04x:$%02x\n",A,V);*/ + SPSG[A]=V; +} + +/* $4080 - Fundamental wave amplitude data register 92*/ +/* $4082 - Fundamental wave frequency data register 58*/ +/* $4083 - Same as $4082($4083 is the upper 4 bits).*/ + +/* $4084 - Modulation amplitude data register 78*/ +/* $4086 - Modulation frequency data register 72*/ +/* $4087 - Same as $4086($4087 is the upper 4 bits)*/ + + +static void DoEnv() +{ + int x; + + for(x=0;x<2;x++) + if(!(SPSG[x<<2]&0x80) && !(SPSG[0x3]&0x40)) + { + static int counto[2]={0,0}; + + if(counto[x]<=0) + { + if(!(SPSG[x<<2]&0x80)) + { + if(SPSG[x<<2]&0x40) + { + if(amplitude[x]<0x3F) + amplitude[x]++; + } + else + { + if(amplitude[x]>0) + amplitude[x]--; + } + } + counto[x]=(SPSG[x<<2]&0x3F); + } + else + counto[x]--; + } +} + +static DECLFR(FDSWaveRead) +{ + return(fdso.cwave[A&0x3f]|(X.DB&0xC0)); +} + +static DECLFW(FDSWaveWrite) +{ + /*printf("$%04x:$%02x, %d\n",A,V,SPSG[0x9]&0x80);*/ + if(SPSG[0x9]&0x80) + fdso.cwave[A&0x3f]=V&0x3F; +} + +static int ta; +static INLINE void ClockRise(void) +{ + if(!clockcount) + { + ta++; + + b19shiftreg60=(SPSG[0x2]|((SPSG[0x3]&0xF)<<8)); + b17latch76=(SPSG[0x6]|((SPSG[0x07]&0xF)<<8))+b17latch76; + + if(!(SPSG[0x7]&0x80)) + { + int t=fdso.mwave[(b17latch76>>13)&0x1F]&7; + int t2=amplitude[1]; + int adj = 0; + + if((t&3)) + { + if((t&4)) + adj -= (t2 * ((4 - (t&3) ) )); + else + adj += (t2 * ( (t&3) )); + } + adj *= 2; + if(adj > 0x7F) adj = 0x7F; + if(adj < -0x80) adj = -0x80; + /*if(adj) printf("%d ",adj);*/ + b8shiftreg88=0x80 + adj; + } + else + { + b8shiftreg88=0x80; + } + } + else + { + b19shiftreg60<<=1; + b8shiftreg88>>=1; + } + /* b24adder66=(b24latch68+b19shiftreg60)&0x3FFFFFF;*/ + b24adder66=(b24latch68+b19shiftreg60)&0x1FFFFFF; +} + +static INLINE void ClockFall(void) +{ + /*if(!(SPSG[0x7]&0x80))*/ + { + if((b8shiftreg88&1)) /* || clockcount==7)*/ + b24latch68=b24adder66; + } + clockcount=(clockcount+1)&7; +} + +static INLINE int32 FDSDoSound(void) +{ + fdso.count+=fdso.cycles; + if(fdso.count>=((int64)1<<40)) + { +dogk: + fdso.count-=(int64)1<<40; + ClockRise(); + ClockFall(); + fdso.envcount--; + if(fdso.envcount<=0) + { + fdso.envcount+=SPSG[0xA]*3; + DoEnv(); + } + } + if(fdso.count>=32768) goto dogk; + + /* Might need to emulate applying the amplitude to the waveform a bit better...*/ + { + int k=amplitude[0]; + if(k>0x20) k=0x20; + return (fdso.cwave[b24latch68>>19]*k)*4/((SPSG[0x9]&0x3)+2); + } +} + +static int32 FBC=0; + +static void RenderSound(void) +{ + int32 end, start; + int32 x; + + start=FBC; + end=(SOUNDTS<<16)/soundtsinc; + if(end<=start) + return; + FBC=end; + + if(!(SPSG[0x9]&0x80)) + for(x=start;x>1; + t>>=4; + Wave[x>>4]+=t; /*(t>>2)-(t>>3); //>>3;*/ + } +} + +static void RenderSoundHQ(void) +{ + int32 x; + + if(!(SPSG[0x9]&0x80)) + for(x=FBC;x>1; + WaveHi[x]+=t; /*(t<<2)-(t<<1);*/ + } + FBC=SOUNDTS; +} + +static void HQSync(int32 ts) +{ + FBC=ts; +} + +void FDSSound(int c) +{ + RenderSound(); + FBC=c; +} + +/* +static DECLFR(FDSBIOSPatch) +{ + if(FDSRegs[5]&0x4) + { + X.X=FDSRead4031(0x4031); + FDSWrite(0x4024,X.A); + X.A=X.X; + return(0x60); + } + else + { + return(0x58); + //puts("Write"); + } +} +*/ + +static void FDS_ESI(void) +{ + if(FSettings.SndRate) + { +#if SOUND_QUALITY == 1 + fdso.cycles=(int64)1<<39; +#else + fdso.cycles=((int64)1<<40)*FDSClock; + fdso.cycles/=FSettings.SndRate *16; +#endif + } + /* fdso.cycles=(int64)32768*FDSClock/(FSettings.SndRate *16);*/ + SetReadHandler(0x4040,0x407f,FDSWaveRead); + SetWriteHandler(0x4040,0x407f,FDSWaveWrite); + SetWriteHandler(0x4080,0x408A,FDSSWrite); + SetReadHandler(0x4090,0x4092,FDSSRead); + + /*SetReadHandler(0xE7A3,0xE7A3,FDSBIOSPatch);*/ +} + +void FDSSoundReset(void) +{ + memset(&fdso,0,sizeof(fdso)); + FDS_ESI(); + GameExpSound.HiSync=HQSync; + GameExpSound.HiFill=RenderSoundHQ; + GameExpSound.Fill=FDSSound; + GameExpSound.RChange=FDS_ESI; +} + +static DECLFW(FDSWrite) +{ + switch(A) + { + case 0x4020: + X6502_IRQEnd(FCEU_IQEXT); + IRQLatch&=0xFF00; + IRQLatch|=V; + /* printf("$%04x:$%02x\n",A,V);*/ + break; + case 0x4021: + X6502_IRQEnd(FCEU_IQEXT); + IRQLatch&=0xFF; + IRQLatch|=V<<8; + /* printf("$%04x:$%02x\n",A,V);*/ + break; + case 0x4022: + X6502_IRQEnd(FCEU_IQEXT); + IRQCount=IRQLatch; + IRQa=V&3; + /* printf("$%04x:$%02x\n",A,V);*/ + break; + case 0x4023:break; + case 0x4024: + if(InDisk!=255 && !(FDSRegs[5]&0x4) && (FDSRegs[3]&0x1)) + { + if(DiskPtr>=0 && DiskPtr<65500) + { + if(writeskip) writeskip--; + else if(DiskPtr>=2) + { + DiskWritten=1; + diskdata[InDisk][DiskPtr-2]=V; + } + } + } + break; + case 0x4025: + X6502_IRQEnd(FCEU_IQEXT2); + if(InDisk!=255) + { + if(!(V&0x40)) + { + if(FDSRegs[5]&0x40 && !(V&0x10)) + { + DiskSeekIRQ=200; + DiskPtr-=2; + } + if(DiskPtr<0) DiskPtr=0; + } + if(!(V&0x4)) writeskip=2; + if(V&2) {DiskPtr=0;DiskSeekIRQ=200;} + if(V&0x40) DiskSeekIRQ=200; + } + setmirror(((V>>3)&1)^1); + break; + } + FDSRegs[A&7]=V; +} + +static void FreeFDSMemory(void) +{ + int x; + + for(x=0;x8) TotalSides=8; + if(TotalSides<1) TotalSides=1; + + for(x=0;xMD5); + return(1); +} + +static void PreSave(void) +{ + int x; + + /*if(DiskWritten)*/ + for(x=0;xtype=GIT_FDS; + GameInterface=FDSGI; + + SelectDisk=0; + InDisk=255; + + ResetExState(PreSave,PostSave); + FDSSoundStateAdd(); + + for(x=0;x +#include +#include +#ifndef _MSC_VER +#include +#else +#define lseek fseek +#endif + +#include +#include "unzip.h" + +#include "types.h" +#include "file.h" +#include "myendian.h" +#include "memory.h" +#include "driver.h" +#include "general.h" + +typedef struct { + uint8 *data; + uint32 size; + uint32 location; +} MEMWRAP; + +void ApplyIPS(FILE *ips, MEMWRAP *dest) +{ + uint8 header[5]; + uint32 count=0; + +#ifdef FCEU_LOG + FCEU_printf(" Applying IPS...\n"); +#endif + if(fread(header,1,5,ips)!=5) + { + fclose(ips); + return; + } + if(memcmp(header,"PATCH",5)) + { + fclose(ips); + return; + } + + while(fread(header,1,3,ips)==3) + { + uint32 offset=(header[0]<<16)|(header[1]<<8)|header[2]; + uint16 size; + + if(!memcmp(header,"EOF",3)) + { + #ifdef FCEU_LOG + FCEU_printf(" IPS EOF: Did %d patches\n\n",count); + #endif + fclose(ips); + return; + } + + size=fgetc(ips)<<8; + size|=fgetc(ips); + if(!size) /* RLE */ + { + uint8 *start; + uint8 b; + size=fgetc(ips)<<8; + size|=fgetc(ips); + + /*FCEU_printf(" Offset: %8d Size: %5d RLE\n",offset,size);*/ + + if((offset+size)>dest->size) + { + uint8 *tmp; + + /* Probably a little slow.*/ + tmp=(uint8 *)realloc(dest->data,offset+size); + if(!tmp) + { + #ifdef FCEU_LOG + FCEU_printf(" Oops. IPS patch %d(type RLE) goes beyond end of file. Could not allocate memory.\n",count); + #endif + fclose(ips); + return; + } + dest->size=offset+size; + dest->data=tmp; + memset(dest->data+dest->size,0,offset+size-dest->size); + } + b=fgetc(ips); + start=dest->data+offset; + do + { + *start=b; + start++; + } while(--size); + } + else /* Normal patch */ + { + /*FCEU_printf(" Offset: %8d Size: %5d\n",offset,size);*/ + if((offset+size)>dest->size) + { + uint8 *tmp; + + /* Probably a little slow.*/ + tmp=(uint8 *)realloc(dest->data,offset+size); + if(!tmp) + { + #ifdef FCEU_LOG + FCEU_printf(" Oops. IPS patch %d(type normal) goes beyond end of file. Could not allocate memory.\n",count); + #endif + fclose(ips); + return; + } + dest->data=tmp; + memset(dest->data+dest->size,0,offset+size-dest->size); + } + fread(dest->data+offset,1,size,ips); + } + count++; + } + fclose(ips); + #ifdef FCEU_LOG + FCEU_printf(" Hard IPS end!\n"); + #endif +} + +static MEMWRAP *MakeMemWrap(void *tz, int type) +{ + MEMWRAP *tmp; + + if(!(tmp=(MEMWRAP *)FCEU_malloc(sizeof(MEMWRAP)))) + goto doret; + tmp->location=0; + + if(type==0) + { + fseek((FILE *)tz,0,SEEK_END); + tmp->size=ftell((FILE *)tz); + fseek((FILE *)tz,0,SEEK_SET); + if(!(tmp->data=(uint8*)FCEU_malloc(tmp->size))) + { + free(tmp); + tmp=0; + goto doret; + } + fread(tmp->data,1,tmp->size,(FILE *)tz); + } + else if(type==1) + { + /* Bleck. The gzip file format has the size of the uncompressed data, + but I can't get to the info with the zlib interface(?). */ + for(tmp->size=0; gzgetc(tz) != EOF; tmp->size++); + gzseek(tz,0,SEEK_SET); + if(!(tmp->data=(uint8 *)FCEU_malloc(tmp->size))) + { + free(tmp); + tmp=0; + goto doret; + } + gzread(tz,tmp->data,tmp->size); + } + else if(type==2) + { + unz_file_info ufo; + unzGetCurrentFileInfo(tz,&ufo,0,0,0,0,0,0); + + tmp->size=ufo.uncompressed_size; + if(!(tmp->data=(uint8 *)FCEU_malloc(ufo.uncompressed_size))) + { + free(tmp); + tmp=0; + goto doret; + } + unzReadCurrentFile(tz,tmp->data,ufo.uncompressed_size); + } + + doret: + if(type==0) + { + fclose((FILE *)tz); + } + else if(type==1) + { + gzclose(tz); + } + else if(type==2) + { + unzCloseCurrentFile(tz); + unzClose(tz); + } + return tmp; +} + +#ifndef __GNUC__ + #define strcasecmp strcmp +#endif + + +FCEUFILE * FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext) +{ + FILE *ipsfile=0; + FCEUFILE *fceufp; + void *t; + + if(strchr(mode,'r')) + ipsfile=fopen(ipsfn,"rb"); + + fceufp=(FCEUFILE *)malloc(sizeof(FCEUFILE)); + + { + unzFile tz; + if((tz=unzOpen(path))) /* If it's not a zip file, use regular file handlers.*/ + /* Assuming file type by extension usually works,*/ + /* but I don't like it. :)*/ + { + if(unzGoToFirstFile(tz)==UNZ_OK) + { + for(;;) + { + char tempu[512]; /* Longer filenames might be possible, but I don't*/ + /* think people would name files that long in zip files...*/ + unzGetCurrentFileInfo(tz,0,tempu,512,0,0,0,0); + tempu[511]=0; + if(strlen(tempu)>=4) + { + char *za=tempu+strlen(tempu)-4; + + if(!ext) + { + if(!strcasecmp(za,".nes") || !strcasecmp(za,".fds") || + !strcasecmp(za,".nsf") || !strcasecmp(za,".unf") || + !strcasecmp(za,".nez")) + break; + } + else if(!strcasecmp(za,ext)) + break; + } + if(strlen(tempu)>=5) + { + if(!strcasecmp(tempu+strlen(tempu)-5,".unif")) + break; + } + if(unzGoToNextFile(tz)!=UNZ_OK) + { + if(unzGoToFirstFile(tz)!=UNZ_OK) goto zpfail; + break; + } + } + if(unzOpenCurrentFile(tz)!=UNZ_OK) + goto zpfail; + } + else + { +zpfail: + free(fceufp); + unzClose(tz); + return 0; + } + if(!(fceufp->fp=MakeMemWrap(tz,2))) + { + free(fceufp); + return(0); + } + fceufp->type=2; + if(ipsfile) + ApplyIPS(ipsfile,(MEMWRAP *)fceufp->fp); + return(fceufp); + } + } + + if((t=fopen(path,"rb"))) + { + uint32 magic; + + magic=fgetc((FILE *)t); + magic|=fgetc((FILE *)t)<<8; + magic|=fgetc((FILE *)t)<<16; + + if(magic!=0x088b1f) /* Not gzip... */ + fclose((FILE *)t); + else /* Probably gzip */ + { + int fd; + + fflush(t); + fd = (fileno( (FILE *)t)); + + lseek(fd, 0, SEEK_SET); + + if((t=gzdopen(fd,mode))) + { + fceufp->type=1; + fceufp->fp=t; + if(ipsfile) + { + fceufp->fp=MakeMemWrap(t,1); + gzclose(t); + + if(fceufp->fp) + { + free(fceufp); + return(0); + } + + fceufp->type=3; + ApplyIPS(ipsfile,(MEMWRAP *)fceufp->fp); + } + return(fceufp); + } + close(fd); + } + + } + + if((t=fopen(path,mode))) + { + fseek((FILE *)t,0,SEEK_SET); + fceufp->type=0; + fceufp->fp=t; + if(ipsfile) + { + if(!(fceufp->fp=MakeMemWrap(t,0))) + { + free(fceufp); + return(0); + } + fceufp->type=3; + ApplyIPS(ipsfile,(MEMWRAP *)fceufp->fp); + } + return(fceufp); + } + + free(fceufp); + return 0; +} + +int FCEU_fclose(FCEUFILE *fp) +{ + if(fp->type==1) + { + gzclose(fp->fp); + } + else if(fp->type>=2) + { + free(((MEMWRAP*)(fp->fp))->data); + ((MEMWRAP*)(fp->fp))->data=0; + free(fp->fp); + fp->fp=0; + } + else + { + fclose((FILE *)fp->fp); + } + free(fp); + fp=0; + return 1; +} + +uint64 FCEU_fread(void *ptr, size_t size, size_t nmemb, FCEUFILE *fp) +{ + if(fp->type==1) + { + return gzread(fp->fp,ptr,size*nmemb); + } + else if(fp->type>=2) + { + MEMWRAP *wz; + uint32 total=size*nmemb; + + wz=(MEMWRAP*)fp->fp; + if(wz->location>=wz->size) return 0; + + if((wz->location+total)>wz->size) + { + int ak=wz->size-wz->location; + memcpy((uint8*)ptr,wz->data+wz->location,ak); + wz->location=wz->size; + return(ak/size); + } + else + { + memcpy((uint8*)ptr,wz->data+wz->location,total); + wz->location+=total; + return nmemb; + } + } + else + { + return fread(ptr,size,nmemb,(FILE *)fp->fp); + } +} + +uint64 FCEU_fwrite(void *ptr, size_t size, size_t nmemb, FCEUFILE *fp) +{ + if(fp->type==1) + { + return gzwrite(fp->fp,ptr,size*nmemb); + } + else if(fp->type>=2) + { + return 0; + } + else + return fwrite(ptr,size,nmemb,(FILE *)fp->fp); +} + +int FCEU_fseek(FCEUFILE *fp, long offset, int whence) +{ + if(fp->type==1) + { + return( (gzseek(fp->fp,offset,whence)>0)?0:-1); + } + else if(fp->type>=2) + { + MEMWRAP *wz; + wz=(MEMWRAP*)fp->fp; + + switch(whence) + { + case SEEK_SET:if(offset>=wz->size) + return(-1); + wz->location=offset;break; + case SEEK_CUR:if(offset+wz->location>wz->size) + return (-1); + wz->location+=offset; + break; + } + return 0; + } + else + return fseek((FILE *)fp->fp,offset,whence); +} + +int FCEU_read16le(uint16 *val, FCEUFILE *fp) +{ + uint8 t[2]; + + if(fp->type>=1) + { + if(fp->type>=2) + { + MEMWRAP *wz; + wz=(MEMWRAP *)fp->fp; + if(wz->location+2>wz->size) + {return 0;} + *(uint32 *)t=*(uint32 *)(wz->data+wz->location); + wz->location+=2; + } + else if(fp->type==1) + if(gzread(fp->fp,&t,2)!=2) return(0); + return(1); + } + else + { + if(fread(t,1,2,(FILE *)fp->fp)!=2) return(0); + } + *val=t[0]|(t[1]<<8); + return(1); +} + +int FCEU_read32le(uint32 *Bufo, FCEUFILE *fp) +{ + if(fp->type>=1) + { + uint8 t[4]; + #ifndef LSB_FIRST + uint8 x[4]; + #endif + if(fp->type>=2) + { + MEMWRAP *wz; + wz=(MEMWRAP *)fp->fp; + if(wz->location+4>wz->size) + {return 0;} + *(uint32 *)t=*(uint32 *)(wz->data+wz->location); + wz->location+=4; + } + else if(fp->type==1) + gzread(fp->fp,&t,4); + #ifndef LSB_FIRST + x[0]=t[3]; + x[1]=t[2]; + x[2]=t[1]; + x[3]=t[0]; + *(uint32*)Bufo=*(uint32*)x; + #else + *(uint32*)Bufo=*(uint32*)t; + #endif + return 1; + } + else + { + return read32le(Bufo,(FILE *)fp->fp); + } +} + +int FCEU_fgetc(FCEUFILE *fp) +{ + if(fp->type==1) + return gzgetc(fp->fp); + else if(fp->type>=2) + { + MEMWRAP *wz; + wz=(MEMWRAP *)fp->fp; + if(wz->locationsize) + return wz->data[wz->location++]; + return EOF; + } + else + return fgetc((FILE *)fp->fp); +} + +uint64 FCEU_fgetsize(FCEUFILE *fp) +{ + if(fp->type==1) + { + int x,t; + t=gztell(fp->fp); + gzrewind(fp->fp); + for(x=0; gzgetc(fp->fp) != EOF; x++); + gzseek(fp->fp,t,SEEK_SET); + return(x); + } + else if(fp->type>=2) + return ((MEMWRAP*)(fp->fp))->size; + else + { + long t,r; + t=ftell((FILE *)fp->fp); + fseek((FILE *)fp->fp,0,SEEK_END); + r=ftell((FILE *)fp->fp); + fseek((FILE *)fp->fp,t,SEEK_SET); + return r; + } +} diff --git a/fceumm/src-fceumm/file.h b/fceumm/src-fceumm/file.h new file mode 100644 index 0000000..e43fd7f --- /dev/null +++ b/fceumm/src-fceumm/file.h @@ -0,0 +1,19 @@ +#ifndef _FCEU_FILE_H +#define _FCEU_FILE_H + +typedef struct { + void *fp; /* FILE* or ptr to ZIPWRAP*/ + uint32 type; /* 0=normal file, 1=gzip, 2=zip*/ +} FCEUFILE; + +FCEUFILE *FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext); +int FCEU_fclose(FCEUFILE*); +uint64 FCEU_fread(void *ptr, size_t size, size_t nmemb, FCEUFILE*); +uint64 FCEU_fwrite(void *ptr, size_t size, size_t nmemb, FCEUFILE*); +int FCEU_fseek(FCEUFILE*, long offset, int whence); +int FCEU_read32le(uint32 *Bufo, FCEUFILE*); +int FCEU_read16le(uint16 *Bufo, FCEUFILE*); +int FCEU_fgetc(FCEUFILE*); +uint64 FCEU_fgetsize(FCEUFILE*); + +#endif diff --git a/fceumm/src-fceumm/fir/Makefile b/fceumm/src-fceumm/fir/Makefile new file mode 100644 index 0000000..a74f918 --- /dev/null +++ b/fceumm/src-fceumm/fir/Makefile @@ -0,0 +1,15 @@ +CC = gcc +%.h: %.coef + cat $< | ./toh > $@ || true + +all: floogie c44100ntsc.h c48000ntsc.h c96000ntsc.h c44100pal.h c48000pal.h c96000pal.h + +#c44100ntsc.h: c44100ntsc.coef +#c48000ntsc.h: c48000ntsc.coef +#c96000ntsc.h: c96000ntsc.coef +#c44100pal.h: c44100pal.coef +#c48000pal.h: c48000pal.coef +#c96000pal.h: c96000pal.coef + +floogie: toh.o + gcc -o toh toh.o diff --git a/fceumm/src-fceumm/fir/c44100ntsc.coef b/fceumm/src-fceumm/fir/c44100ntsc.coef new file mode 100644 index 0000000..8f3faed --- /dev/null +++ b/fceumm/src-fceumm/fir/c44100ntsc.coef @@ -0,0 +1,1039 @@ +;; ***** 44100 NTSC ***** +;; Filter length: 1024 +;; Symmetry: cosine +;; Sampling frequency: 1789772.72727273 +;; Grid density: 10257 +;; Deviation parameter: y=-4.26609210258497e-4 +;; +;; Specifications: +;; (limit > 22050 894886.363636 0 0.5) +;; (limit < 22050 894886.363636 0 0.5) +;; (limit > 0 15000 1 1) +;; (limit < 0 15000 1 1) +;; +;; Coefficients: + +1.11262153794412e-4 +9.1203952189514e-6 +9.4094541490789e-6 +9.63661279581735e-6 +9.84815294136282e-6 +9.96211856753532e-6 +1.00189663896491e-5 +1.00061013360251e-5 +9.93435399969655e-6 +9.78762126385669e-6 +9.55321925729624e-6 +9.24825080375786e-6 +8.85255837386989e-6 +8.3877114761375e-6 +7.82178714333584e-6 +7.1788229094432e-6 +6.44522053069757e-6 +5.62630847050353e-6 +4.71582963040218e-6 +3.72380169562418e-6 +2.64841660044426e-6 +1.49502905722044e-6 +2.5217761121751e-7 +-1.05186474836932e-6 +-2.43551352329469e-6 +-3.89295417250434e-6 +-5.42664110084146e-6 +-7.00566917418741e-6 +-8.6368208569906e-6 +-1.03114527925382e-5 +-1.20443408108932e-5 +-1.38216102337816e-5 +-1.56130215867248e-5 +-1.74276497066345e-5 +-1.9254250127445e-5 +-2.1098626694142e-5 +-2.29097403788758e-5 +-2.47248863743773e-5 +-2.64998143086568e-5 +-2.82478400091917e-5 +-2.99318307877882e-5 +-3.15778370419873e-5 +-3.31419021725666e-5 +-3.46367208626458e-5 +-3.60349486303977e-5 +-3.73560747385557e-5 +-3.85602232740176e-5 +-3.96502202312979e-5 +-4.06110449657408e-5 +-4.14368419481133e-5 +-4.21090019281467e-5 +-4.25993967830844e-5 +-4.29068991904435e-5 +-4.3025032131568e-5 +-4.30140517026991e-5 +-4.28433545718674e-5 +-4.25296899490834e-5 +-4.17374194914376e-5 +-4.10040920794666e-5 +-3.99666912810865e-5 +-3.87371755083029e-5 +-3.72607458775728e-5 +-3.55874669626075e-5 +-3.36986152823895e-5 +-3.16000530912765e-5 +-2.92767128040033e-5 +-2.67371187168457e-5 +-2.40039338911553e-5 +-2.10604880457374e-5 +-1.79335828101573e-5 +-1.46133694055927e-5 +-1.11253968130194e-5 +-7.46614405238464e-6 +-3.64613498607798e-6 +3.02368354254293e-7 +4.39158630158039e-6 +8.58777072285901e-6 +1.28879143039278e-5 +1.72582028358521e-5 +2.16969577994228e-5 +2.61829629831333e-5 +3.06979810398452e-5 +3.52209058193995e-5 +3.97300635833027e-5 +4.42050962120303e-5 +4.86055004649174e-5 +5.29441057028915e-5 +5.71712798076152e-5 +6.1268495205598e-5 +6.52195501855984e-5 +6.90007266683825e-5 +7.25913577445526e-5 +7.59499489511726e-5 +7.90918784345419e-5 +8.19505156283039e-5 +8.45470657873134e-5 +8.68293263041973e-5 +8.88086064198062e-5 +9.041692946077e-5 +9.16797599287126e-5 +9.25599457920887e-5 +9.30552765000977e-5 +9.31313982341795e-5 +9.27936061980597e-5 +9.20420846305276e-5 +9.08521132221629e-5 +8.92085476183645e-5 +8.71017975335516e-5 +8.45414314948811e-5 +8.15311641149105e-5 +7.80711279919507e-5 +7.41574998124299e-5 +6.97895128455476e-5 +6.4947479038247e-5 +5.97479711603871e-5 +5.40630354898453e-5 +4.79856481353068e-5 +4.15182368501593e-5 +3.46802768321681e-5 +2.74958585451822e-5 +1.9976788603383e-5 +1.21472923550567e-5 +4.04120472382678e-6 +-4.30770705476995e-6 +-1.28821872779466e-5 +-2.16320221744917e-5 +-3.05324054839951e-5 +-3.95504446928096e-5 +-4.86452773517834e-5 +-5.7776933929632e-5 +-6.6888917187142e-5 +-7.59839395688362e-5 +-8.49770646155345e-5 +-9.38485765943731e-5 +-1.02535728955288e-4 +-1.11020769697226e-4 +-1.19224175025087e-4 +-1.2712371399013e-4 +-1.34677854331765e-4 +-1.41855973321246e-4 +-1.48585528294192e-4 +-1.54823475008983e-4 +-1.60563784962364e-4 +-1.65737939175439e-4 +-1.70324767136095e-4 +-1.74273576399229e-4 +-1.77562540511869e-4 +-1.80153948404509e-4 +-1.82017783412252e-4 +-1.83125404333719e-4 +-1.83446338947795e-4 +-1.82987530180017e-4 +-1.81703356594349e-4 +-1.79590850554495e-4 +-1.76619461091599e-4 +-1.72815899566497e-4 +-1.68147649678904e-4 +-1.62620596029299e-4 +-1.56237231040979e-4 +-1.49008305143425e-4 +-1.40957023196796e-4 +-1.32072008950485e-4 +-1.22389162483219e-4 +-1.11934088499394e-4 +-1.00737065257502e-4 +-8.88160519212646e-5 +-7.61930807071772e-5 +-6.29496222727675e-5 +-4.91050367300618e-5 +-3.4718130025881e-5 +-1.98160195514693e-5 +-4.45731586994588e-6 +1.12803144028591e-5 +2.73309987906755e-5 +4.36737905686176e-5 +6.01909058617092e-5 +7.68545149813897e-5 +9.35675866162103e-5 +1.10269459400764e-4 +1.26883165335663e-4 +1.43335855360237e-4 +1.5954241113618e-4 +1.7543332757703e-4 +1.90940022499485e-4 +2.05960757764001e-4 +2.20430019515099e-4 +2.34260760602835e-4 +2.47409140535342e-4 +2.59761075613858e-4 +2.71275815558309e-4 +2.81867857874407e-4 +2.91473514559014e-4 +3.00005851286105e-4 +3.07432616093836e-4 +3.136935557549e-4 +3.18736128450691e-4 +3.22478991985463e-4 +3.24900573947518e-4 +3.25973108476246e-4 +3.25641186246162e-4 +3.23884645760423e-4 +3.20666060011718e-4 +3.15989435094453e-4 +3.09830843773395e-4 +3.02185552345498e-4 +2.93038759521248e-4 +2.82430889955413e-4 +2.70353445973182e-4 +2.56830966886862e-4 +2.41887536833496e-4 +2.25571633496883e-4 +2.07916002422089e-4 +1.88968510710595e-4 +1.68789504787793e-4 +1.47443939450696e-4 +1.24981317138686e-4 +1.01499245340524e-4 +7.70572862247137e-5 +5.17676358522932e-5 +2.57118134228229e-5 +-1.01754062817161e-6 +-2.83262175890525e-5 +-5.60999252995387e-5 +-8.41915010649744e-5 +-1.1252906652508e-4 +-1.40975352908305e-4 +-1.69434579431538e-4 +-1.97729073916177e-4 +-2.25769653344743e-4 +-2.53411042361576e-4 +-2.80565122507133e-4 +-3.07036438304828e-4 +-3.32753626249541e-4 +-3.57541896186656e-4 +-3.81307666526521e-4 +-4.0391150118367e-4 +-4.25231243203619e-4 +-4.45145780258752e-4 +-4.63545025829737e-4 +-4.80322675164487e-4 +-4.95350782085733e-4 +-5.08549438324035e-4 +-5.1980265947403e-4 +-5.29043766376402e-4 +-5.36172525139055e-4 +-5.41133538554177e-4 +-5.43848643414634e-4 +-5.44256723291212e-4 +-5.42320002202435e-4 +-5.37993404337165e-4 +-5.3125334500245e-4 +-5.22075219690071e-4 +-5.10445445493085e-4 +-4.96377734888716e-4 +-4.79880717778625e-4 +-4.60971283056312e-4 +-4.39684651488982e-4 +-4.16063905823169e-4 +-3.90177619816529e-4 +-3.62085220183381e-4 +-3.31863091675268e-4 +-2.99597107541406e-4 +-2.65413754083361e-4 +-2.29377222808396e-4 +-1.91654451928034e-4 +-1.52344557932817e-4 +-1.11608104095083e-4 +-6.95603957788035e-5 +-2.64016442748731e-5 +1.7724163386627e-5 +6.26416184275484e-5 +1.08189979248416e-4 +1.54147272535691e-4 +2.00349856093844e-4 +2.46587459314576e-4 +2.92670674130578e-4 +3.38391411475662e-4 +3.83540211401206e-4 +4.27913576964888e-4 +4.71300626361147e-4 +5.13512876149826e-4 +5.54323952929787e-4 +5.93537470537219e-4 +6.3093434662098e-4 +6.66344965329304e-4 +6.99565407441501e-4 +7.30423799872388e-4 +7.58708693685015e-4 +7.8427979033147e-4 +8.06945553271288e-4 +8.26584756687851e-4 +8.43031977801634e-4 +8.56156258972257e-4 +8.65836592594565e-4 +8.71968746552343e-4 +8.74461813660048e-4 +8.73231202274345e-4 +8.68218292668308e-4 +8.59348624025311e-4 +8.46612447774565e-4 +8.29979222422541e-4 +8.09446427744043e-4 +7.85031357561925e-4 +7.56766215319943e-4 +7.2470699047867e-4 +6.88883919685657e-4 +6.49416331024001e-4 +6.06391057283913e-4 +5.59935330476022e-4 +5.10167371200662e-4 +4.57252072332643e-4 +4.01354265598951e-4 +3.42656496994208e-4 +2.81355941136781e-4 +2.17670656870967e-4 +1.51832975264559e-4 +8.40749859869234e-5 +1.46584064604961e-5 +-5.61496056174954e-5 +-1.28086904625854e-4 +-2.00818433548331e-4 +-2.7409972137809e-4 +-3.47601002332966e-4 +-4.21031974632111e-4 +-4.94030730396776e-4 +-5.66317666429227e-4 +-6.37548654873925e-4 +-7.07408810891205e-4 +-7.75547530396904e-4 +-8.41675004612485e-4 +-9.05453133996662e-4 +-9.66558548716224e-4 +-0.00102466993047469 +-0.00107948243327616 +-0.00113072204795905 +-0.0011780892664915 +-0.0012212925453813 +-0.00126007236261203 +-0.00129417936102408 +-0.00132338623135961 +-0.0013474534440369 +-0.0013662023453885 +-0.00137942837511788 +-0.00138698055366682 +-0.00138870045367779 +-0.00138448957970039 +-0.00137424428374859 +-0.00135788629777192 +-0.00133536298920924 +-0.00130665165054127 +-0.0012717543272168 +-0.00123070624585239 +-0.00118356717926831 +-0.00113040319129687 +-0.00107131700797982 +-0.00100646498239645 +-9.35995104217189e-4 +-8.60096571782921e-4 +-7.78998336060133e-4 +-6.92940701872996e-4 +-6.02182768095548e-4 +-5.07003036815179e-4 +-4.07757323218773e-4 +-3.04760010372766e-4 +-1.98383609989422e-4 +-8.89918915329279e-5 +2.29793702787778e-5 +1.37122990345803e-4 +2.5299360795038e-4 +3.70143341115017e-4 +4.88088953030987e-4 +6.06342750948422e-4 +7.24424959757904e-4 +8.41821410938308e-4 +9.58029848643689e-4 +0.00107251650886565 +0.00118475391682864 +0.00129425308462396 +0.00140047084052004 +0.0015028980384223 +0.00160100966703419 +0.00169431442637767 +0.00178229788006395 +0.00186449094208792 +0.00194041558775561 +0.00200963542959276 +0.00207169741768017 +0.00212618334414435 +0.00217270035390745 +0.00221088750080458 +0.00224042087255895 +0.00226095514052231 +0.00227220321739892 +0.00227394132978118 +0.00226594070088644 +0.00224802424476919 +0.00222001601735845 +0.00218185426405224 +0.00213342446297001 +0.00207473710872034 +0.00200576081219353 +0.00192660143920357 +0.00183730661827725 +0.00173804987265467 +0.00162899296733253 +0.00151036806619154 +0.00138244091224245 +0.00124553715590493 +0.00110001314361977 +9.46246978211101e-4 +7.84695240224382e-4 +6.15844939874971e-4 +4.4020774824205e-4 +2.58345305088762e-4 +7.08612579074651e-5 +-1.21606350631308e-4 +-3.18395388345862e-4 +-5.1879155790156e-4 +-7.22062937747848e-4 +-9.27451114779463e-4 +-0.00113416157741747 +-0.00134138689888361 +-0.00154827070291184 +-0.00175397288566918 +-0.0019576116273234 +-0.00215831253617746 +-0.00235515587055034 +-0.00254724254904768 +-0.00273366690374425 +-0.00291350898429464 +-0.00308585950693817 +-0.00324979222163811 +-0.00340441875730436 +-0.00354884211798964 +-0.00368218571253443 +-0.00380358990740782 +-0.00391221887526166 +-0.00400723057140825 +-0.00408785624750138 +-0.004153333003793 +-0.00420292395555919 +-0.00423593387073267 +-0.00425171118587346 +-0.00424964450870412 +-0.00422915907860119 +-0.0041897356858097 +-0.0041309026307971 +-0.00405221509383098 +-0.00395331866912401 +-0.00383391116350846 +-0.00369371631770201 +-0.00353253640058538 +-0.00335022403053123 +-0.00314672640265953 +-0.00292200117900966 +-0.00267612720029126 +-0.0024091787521236 +-0.00212137053496313 +-0.00181290180786275 +-0.00148412961640828 +-0.0011353892343628 +-7.67128314412436e-4 +-3.79839813513112e-4 +2.59043686551276e-5 +4.494860301294e-4 +8.90225310173371e-4 +0.00134736056332534 +0.00182009665332689 +0.00230757943767435 +0.00280890399487952 +0.00332310364103925 +0.00384915066180797 +0.00438599870804931 +0.00493254091385408 +0.00548765927782258 +0.00605013603781409 +0.00661878037036735 +0.00719234109024943 +0.00776954418385769 +0.008349090387754 +0.0089296683452915 +0.00950994984323646 +0.0100885721308606 +0.0106641926633217 +0.0112354494946774 +0.0118009885819235 +0.0123594520486416 +0.0129094923924999 +0.0134497740224004 +0.0139789646616159 +0.0144957819012448 +0.0149989403071262 +0.0154871953429542 +0.0159593047296737 +0.0164141332589184 +0.0168504983748113 +0.0172673032190162 +0.0176634911539869 +0.0180380745830505 +0.018390088086466 +0.0187186209562544 +0.0190228378422047 +0.0193019578242075 +0.0195552647135139 +0.0197821099505764 +0.0199819035649561 +0.0201541247940216 +0.0202983267902526 +0.0204141411144792 +0.0205012617098339 +0.0205594794331608 +0.0205886274212954 +0.0205886274212954 +0.0205594794331608 +0.0205012617098339 +0.0204141411144792 +0.0202983267902526 +0.0201541247940216 +0.0199819035649561 +0.0197821099505764 +0.0195552647135139 +0.0193019578242075 +0.0190228378422047 +0.0187186209562544 +0.018390088086466 +0.0180380745830505 +0.0176634911539869 +0.0172673032190162 +0.0168504983748113 +0.0164141332589184 +0.0159593047296737 +0.0154871953429542 +0.0149989403071262 +0.0144957819012448 +0.0139789646616159 +0.0134497740224004 +0.0129094923924999 +0.0123594520486416 +0.0118009885819235 +0.0112354494946774 +0.0106641926633217 +0.0100885721308606 +0.00950994984323646 +0.0089296683452915 +0.008349090387754 +0.00776954418385769 +0.00719234109024943 +0.00661878037036735 +0.00605013603781409 +0.00548765927782258 +0.00493254091385408 +0.00438599870804931 +0.00384915066180797 +0.00332310364103925 +0.00280890399487952 +0.00230757943767435 +0.00182009665332689 +0.00134736056332534 +8.90225310173371e-4 +4.494860301294e-4 +2.59043686551276e-5 +-3.79839813513112e-4 +-7.67128314412436e-4 +-0.0011353892343628 +-0.00148412961640828 +-0.00181290180786275 +-0.00212137053496313 +-0.0024091787521236 +-0.00267612720029126 +-0.00292200117900966 +-0.00314672640265953 +-0.00335022403053123 +-0.00353253640058538 +-0.00369371631770201 +-0.00383391116350846 +-0.00395331866912401 +-0.00405221509383098 +-0.0041309026307971 +-0.0041897356858097 +-0.00422915907860119 +-0.00424964450870412 +-0.00425171118587346 +-0.00423593387073267 +-0.00420292395555919 +-0.004153333003793 +-0.00408785624750138 +-0.00400723057140825 +-0.00391221887526166 +-0.00380358990740782 +-0.00368218571253443 +-0.00354884211798964 +-0.00340441875730436 +-0.00324979222163811 +-0.00308585950693817 +-0.00291350898429464 +-0.00273366690374425 +-0.00254724254904768 +-0.00235515587055034 +-0.00215831253617746 +-0.0019576116273234 +-0.00175397288566918 +-0.00154827070291184 +-0.00134138689888361 +-0.00113416157741747 +-9.27451114779463e-4 +-7.22062937747848e-4 +-5.1879155790156e-4 +-3.18395388345862e-4 +-1.21606350631308e-4 +7.08612579074651e-5 +2.58345305088762e-4 +4.4020774824205e-4 +6.15844939874971e-4 +7.84695240224382e-4 +9.46246978211101e-4 +0.00110001314361977 +0.00124553715590493 +0.00138244091224245 +0.00151036806619154 +0.00162899296733253 +0.00173804987265467 +0.00183730661827725 +0.00192660143920357 +0.00200576081219353 +0.00207473710872034 +0.00213342446297001 +0.00218185426405224 +0.00222001601735845 +0.00224802424476919 +0.00226594070088644 +0.00227394132978118 +0.00227220321739892 +0.00226095514052231 +0.00224042087255895 +0.00221088750080458 +0.00217270035390745 +0.00212618334414435 +0.00207169741768017 +0.00200963542959276 +0.00194041558775561 +0.00186449094208792 +0.00178229788006395 +0.00169431442637767 +0.00160100966703419 +0.0015028980384223 +0.00140047084052004 +0.00129425308462396 +0.00118475391682864 +0.00107251650886565 +9.58029848643689e-4 +8.41821410938308e-4 +7.24424959757904e-4 +6.06342750948422e-4 +4.88088953030987e-4 +3.70143341115017e-4 +2.5299360795038e-4 +1.37122990345803e-4 +2.29793702787778e-5 +-8.89918915329279e-5 +-1.98383609989422e-4 +-3.04760010372766e-4 +-4.07757323218773e-4 +-5.07003036815179e-4 +-6.02182768095548e-4 +-6.92940701872996e-4 +-7.78998336060133e-4 +-8.60096571782921e-4 +-9.35995104217189e-4 +-0.00100646498239645 +-0.00107131700797982 +-0.00113040319129687 +-0.00118356717926831 +-0.00123070624585239 +-0.0012717543272168 +-0.00130665165054127 +-0.00133536298920924 +-0.00135788629777192 +-0.00137424428374859 +-0.00138448957970039 +-0.00138870045367779 +-0.00138698055366682 +-0.00137942837511788 +-0.0013662023453885 +-0.0013474534440369 +-0.00132338623135961 +-0.00129417936102408 +-0.00126007236261203 +-0.0012212925453813 +-0.0011780892664915 +-0.00113072204795905 +-0.00107948243327616 +-0.00102466993047469 +-9.66558548716224e-4 +-9.05453133996662e-4 +-8.41675004612485e-4 +-7.75547530396904e-4 +-7.07408810891205e-4 +-6.37548654873925e-4 +-5.66317666429227e-4 +-4.94030730396776e-4 +-4.21031974632111e-4 +-3.47601002332966e-4 +-2.7409972137809e-4 +-2.00818433548331e-4 +-1.28086904625854e-4 +-5.61496056174954e-5 +1.46584064604961e-5 +8.40749859869234e-5 +1.51832975264559e-4 +2.17670656870967e-4 +2.81355941136781e-4 +3.42656496994208e-4 +4.01354265598951e-4 +4.57252072332643e-4 +5.10167371200662e-4 +5.59935330476022e-4 +6.06391057283913e-4 +6.49416331024001e-4 +6.88883919685657e-4 +7.2470699047867e-4 +7.56766215319943e-4 +7.85031357561925e-4 +8.09446427744043e-4 +8.29979222422541e-4 +8.46612447774565e-4 +8.59348624025311e-4 +8.68218292668308e-4 +8.73231202274345e-4 +8.74461813660048e-4 +8.71968746552343e-4 +8.65836592594565e-4 +8.56156258972257e-4 +8.43031977801634e-4 +8.26584756687851e-4 +8.06945553271288e-4 +7.8427979033147e-4 +7.58708693685015e-4 +7.30423799872388e-4 +6.99565407441501e-4 +6.66344965329304e-4 +6.3093434662098e-4 +5.93537470537219e-4 +5.54323952929787e-4 +5.13512876149826e-4 +4.71300626361147e-4 +4.27913576964888e-4 +3.83540211401206e-4 +3.38391411475662e-4 +2.92670674130578e-4 +2.46587459314576e-4 +2.00349856093844e-4 +1.54147272535691e-4 +1.08189979248416e-4 +6.26416184275484e-5 +1.7724163386627e-5 +-2.64016442748731e-5 +-6.95603957788035e-5 +-1.11608104095083e-4 +-1.52344557932817e-4 +-1.91654451928034e-4 +-2.29377222808396e-4 +-2.65413754083361e-4 +-2.99597107541406e-4 +-3.31863091675268e-4 +-3.62085220183381e-4 +-3.90177619816529e-4 +-4.16063905823169e-4 +-4.39684651488982e-4 +-4.60971283056312e-4 +-4.79880717778625e-4 +-4.96377734888716e-4 +-5.10445445493085e-4 +-5.22075219690071e-4 +-5.3125334500245e-4 +-5.37993404337165e-4 +-5.42320002202435e-4 +-5.44256723291212e-4 +-5.43848643414634e-4 +-5.41133538554177e-4 +-5.36172525139055e-4 +-5.29043766376402e-4 +-5.1980265947403e-4 +-5.08549438324035e-4 +-4.95350782085733e-4 +-4.80322675164487e-4 +-4.63545025829737e-4 +-4.45145780258752e-4 +-4.25231243203619e-4 +-4.0391150118367e-4 +-3.81307666526521e-4 +-3.57541896186656e-4 +-3.32753626249541e-4 +-3.07036438304828e-4 +-2.80565122507133e-4 +-2.53411042361576e-4 +-2.25769653344743e-4 +-1.97729073916177e-4 +-1.69434579431538e-4 +-1.40975352908305e-4 +-1.1252906652508e-4 +-8.41915010649744e-5 +-5.60999252995387e-5 +-2.83262175890525e-5 +-1.01754062817161e-6 +2.57118134228229e-5 +5.17676358522932e-5 +7.70572862247137e-5 +1.01499245340524e-4 +1.24981317138686e-4 +1.47443939450696e-4 +1.68789504787793e-4 +1.88968510710595e-4 +2.07916002422089e-4 +2.25571633496883e-4 +2.41887536833496e-4 +2.56830966886862e-4 +2.70353445973182e-4 +2.82430889955413e-4 +2.93038759521248e-4 +3.02185552345498e-4 +3.09830843773395e-4 +3.15989435094453e-4 +3.20666060011718e-4 +3.23884645760423e-4 +3.25641186246162e-4 +3.25973108476246e-4 +3.24900573947518e-4 +3.22478991985463e-4 +3.18736128450691e-4 +3.136935557549e-4 +3.07432616093836e-4 +3.00005851286105e-4 +2.91473514559014e-4 +2.81867857874407e-4 +2.71275815558309e-4 +2.59761075613858e-4 +2.47409140535342e-4 +2.34260760602835e-4 +2.20430019515099e-4 +2.05960757764001e-4 +1.90940022499485e-4 +1.7543332757703e-4 +1.5954241113618e-4 +1.43335855360237e-4 +1.26883165335663e-4 +1.10269459400764e-4 +9.35675866162103e-5 +7.68545149813897e-5 +6.01909058617092e-5 +4.36737905686176e-5 +2.73309987906755e-5 +1.12803144028591e-5 +-4.45731586994588e-6 +-1.98160195514693e-5 +-3.4718130025881e-5 +-4.91050367300618e-5 +-6.29496222727675e-5 +-7.61930807071772e-5 +-8.88160519212646e-5 +-1.00737065257502e-4 +-1.11934088499394e-4 +-1.22389162483219e-4 +-1.32072008950485e-4 +-1.40957023196796e-4 +-1.49008305143425e-4 +-1.56237231040979e-4 +-1.62620596029299e-4 +-1.68147649678904e-4 +-1.72815899566497e-4 +-1.76619461091599e-4 +-1.79590850554495e-4 +-1.81703356594349e-4 +-1.82987530180017e-4 +-1.83446338947795e-4 +-1.83125404333719e-4 +-1.82017783412252e-4 +-1.80153948404509e-4 +-1.77562540511869e-4 +-1.74273576399229e-4 +-1.70324767136095e-4 +-1.65737939175439e-4 +-1.60563784962364e-4 +-1.54823475008983e-4 +-1.48585528294192e-4 +-1.41855973321246e-4 +-1.34677854331765e-4 +-1.2712371399013e-4 +-1.19224175025087e-4 +-1.11020769697226e-4 +-1.02535728955288e-4 +-9.38485765943731e-5 +-8.49770646155345e-5 +-7.59839395688362e-5 +-6.6888917187142e-5 +-5.7776933929632e-5 +-4.86452773517834e-5 +-3.95504446928096e-5 +-3.05324054839951e-5 +-2.16320221744917e-5 +-1.28821872779466e-5 +-4.30770705476995e-6 +4.04120472382678e-6 +1.21472923550567e-5 +1.9976788603383e-5 +2.74958585451822e-5 +3.46802768321681e-5 +4.15182368501593e-5 +4.79856481353068e-5 +5.40630354898453e-5 +5.97479711603871e-5 +6.4947479038247e-5 +6.97895128455476e-5 +7.41574998124299e-5 +7.80711279919507e-5 +8.15311641149105e-5 +8.45414314948811e-5 +8.71017975335516e-5 +8.92085476183645e-5 +9.08521132221629e-5 +9.20420846305276e-5 +9.27936061980597e-5 +9.31313982341795e-5 +9.30552765000977e-5 +9.25599457920887e-5 +9.16797599287126e-5 +9.041692946077e-5 +8.88086064198062e-5 +8.68293263041973e-5 +8.45470657873134e-5 +8.19505156283039e-5 +7.90918784345419e-5 +7.59499489511726e-5 +7.25913577445526e-5 +6.90007266683825e-5 +6.52195501855984e-5 +6.1268495205598e-5 +5.71712798076152e-5 +5.29441057028915e-5 +4.86055004649174e-5 +4.42050962120303e-5 +3.97300635833027e-5 +3.52209058193995e-5 +3.06979810398452e-5 +2.61829629831333e-5 +2.16969577994228e-5 +1.72582028358521e-5 +1.28879143039278e-5 +8.58777072285901e-6 +4.39158630158039e-6 +3.02368354254293e-7 +-3.64613498607798e-6 +-7.46614405238464e-6 +-1.11253968130194e-5 +-1.46133694055927e-5 +-1.79335828101573e-5 +-2.10604880457374e-5 +-2.40039338911553e-5 +-2.67371187168457e-5 +-2.92767128040033e-5 +-3.16000530912765e-5 +-3.36986152823895e-5 +-3.55874669626075e-5 +-3.72607458775728e-5 +-3.87371755083029e-5 +-3.99666912810865e-5 +-4.10040920794666e-5 +-4.17374194914376e-5 +-4.25296899490834e-5 +-4.28433545718674e-5 +-4.30140517026991e-5 +-4.3025032131568e-5 +-4.29068991904435e-5 +-4.25993967830844e-5 +-4.21090019281467e-5 +-4.14368419481133e-5 +-4.06110449657408e-5 +-3.96502202312979e-5 +-3.85602232740176e-5 +-3.73560747385557e-5 +-3.60349486303977e-5 +-3.46367208626458e-5 +-3.31419021725666e-5 +-3.15778370419873e-5 +-2.99318307877882e-5 +-2.82478400091917e-5 +-2.64998143086568e-5 +-2.47248863743773e-5 +-2.29097403788758e-5 +-2.1098626694142e-5 +-1.9254250127445e-5 +-1.74276497066345e-5 +-1.56130215867248e-5 +-1.38216102337816e-5 +-1.20443408108932e-5 +-1.03114527925382e-5 +-8.6368208569906e-6 +-7.00566917418741e-6 +-5.42664110084146e-6 +-3.89295417250434e-6 +-2.43551352329469e-6 +-1.05186474836932e-6 +2.5217761121751e-7 +1.49502905722044e-6 +2.64841660044426e-6 +3.72380169562418e-6 +4.71582963040218e-6 +5.62630847050353e-6 +6.44522053069757e-6 +7.1788229094432e-6 +7.82178714333584e-6 +8.3877114761375e-6 +8.85255837386989e-6 +9.24825080375786e-6 +9.55321925729624e-6 +9.78762126385669e-6 +9.93435399969655e-6 +1.00061013360251e-5 +1.00189663896491e-5 +9.96211856753532e-6 +9.84815294136282e-6 +9.63661279581735e-6 +9.4094541490789e-6 +9.1203952189514e-6 +1.11262153794412e-4 diff --git a/fceumm/src-fceumm/fir/c44100ntsc.h b/fceumm/src-fceumm/fir/c44100ntsc.h new file mode 100644 index 0000000..0ac08ef --- /dev/null +++ b/fceumm/src-fceumm/fir/c44100ntsc.h @@ -0,0 +1,512 @@ +116, +9, +9, +10, +10, +10, +10, +10, +10, +10, +10, +9, +9, +8, +8, +7, +6, +5, +4, +3, +2, +1, +0, +-1, +-2, +-4, +-5, +-7, +-9, +-10, +-12, +-14, +-16, +-18, +-20, +-22, +-24, +-25, +-27, +-29, +-31, +-33, +-34, +-36, +-37, +-39, +-40, +-41, +-42, +-43, +-44, +-44, +-44, +-45, +-45, +-44, +-44, +-43, +-42, +-41, +-40, +-39, +-37, +-35, +-33, +-30, +-28, +-25, +-22, +-18, +-15, +-11, +-7, +-3, +0, +4, +9, +13, +18, +22, +27, +32, +36, +41, +46, +50, +55, +59, +64, +68, +72, +76, +79, +82, +85, +88, +91, +93, +94, +96, +97, +97, +97, +97, +96, +95, +93, +91, +88, +85, +81, +77, +73, +68, +62, +56, +50, +43, +36, +28, +20, +12, +4, +-4, +-13, +-22, +-32, +-41, +-51, +-60, +-70, +-79, +-89, +-98, +-107, +-116, +-125, +-133, +-141, +-148, +-155, +-162, +-168, +-173, +-178, +-182, +-186, +-188, +-190, +-192, +-192, +-191, +-190, +-188, +-185, +-181, +-176, +-170, +-163, +-156, +-147, +-138, +-128, +-117, +-105, +-93, +-79, +-66, +-51, +-36, +-20, +-4, +11, +28, +45, +63, +80, +98, +115, +133, +150, +167, +183, +200, +215, +231, +245, +259, +272, +284, +295, +305, +314, +322, +328, +334, +338, +340, +341, +341, +339, +336, +331, +324, +316, +307, +296, +283, +269, +253, +236, +218, +198, +176, +154, +131, +106, +80, +54, +26, +-1, +-29, +-58, +-88, +-117, +-147, +-177, +-207, +-236, +-265, +-294, +-321, +-348, +-374, +-399, +-423, +-445, +-466, +-486, +-503, +-519, +-533, +-545, +-554, +-562, +-567, +-570, +-570, +-568, +-564, +-557, +-547, +-535, +-520, +-503, +-483, +-461, +-436, +-409, +-379, +-347, +-314, +-278, +-240, +-200, +-159, +-117, +-72, +-27, +18, +65, +113, +161, +210, +258, +306, +354, +402, +448, +494, +538, +581, +622, +661, +698, +733, +765, +795, +822, +846, +866, +883, +897, +907, +914, +916, +915, +910, +901, +887, +870, +848, +823, +793, +759, +722, +680, +635, +587, +534, +479, +420, +359, +295, +228, +159, +88, +15, +-58, +-134, +-210, +-287, +-364, +-441, +-518, +-593, +-668, +-741, +-813, +-882, +-949, +-1013, +-1074, +-1131, +-1185, +-1235, +-1280, +-1321, +-1357, +-1387, +-1412, +-1432, +-1446, +-1454, +-1456, +-1451, +-1440, +-1423, +-1400, +-1370, +-1333, +-1290, +-1241, +-1185, +-1123, +-1055, +-981, +-901, +-816, +-726, +-631, +-531, +-427, +-319, +-208, +-93, +24, +143, +265, +388, +511, +635, +759, +882, +1004, +1124, +1242, +1357, +1468, +1575, +1678, +1776, +1868, +1955, +2034, +2107, +2172, +2229, +2278, +2318, +2349, +2370, +2382, +2384, +2376, +2357, +2327, +2287, +2237, +2175, +2103, +2020, +1926, +1822, +1708, +1583, +1449, +1306, +1153, +992, +822, +645, +461, +270, +74, +-127, +-333, +-543, +-757, +-972, +-1189, +-1406, +-1623, +-1839, +-2052, +-2263, +-2469, +-2670, +-2866, +-3055, +-3235, +-3407, +-3569, +-3721, +-3861, +-3988, +-4102, +-4201, +-4286, +-4355, +-4407, +-4441, +-4458, +-4456, +-4434, +-4393, +-4331, +-4249, +-4145, +-4020, +-3873, +-3704, +-3512, +-3299, +-3063, +-2806, +-2526, +-2224, +-1900, +-1556, +-1190, +-804, +-398, +27, +471, +933, +1412, +1908, +2419, +2945, +3484, +4036, +4599, +5172, +5754, +6344, +6940, +7541, +8146, +8754, +9363, +9971, +10578, +11182, +11781, +12374, +12959, +13536, +14103, +14658, +15199, +15727, +16239, +16734, +17211, +17669, +18106, +18521, +18914, +19283, +19627, +19946, +20239, +20505, +20743, +20952, +21133, +21284, +21405, +21497, +21558, +21588, diff --git a/fceumm/src-fceumm/fir/c44100ntsc.scm b/fceumm/src-fceumm/fir/c44100ntsc.scm new file mode 100644 index 0000000..0810944 --- /dev/null +++ b/fceumm/src-fceumm/fir/c44100ntsc.scm @@ -0,0 +1,12 @@ +(title "44100 NTSC") + +(verbose #t) + +(cosine-symmetry) +(filter-length 1024) +(sampling-frequency 1789772.727272727272) +(limit-= (band 0 15000) 1) +(limit-= (band 22050 894886.363636) 0 .5) +(output-file "c44100ntsc.coef") +(plot-file "c44100ntsc.plot") +(go) diff --git a/fceumm/src-fceumm/fir/c44100pal.coef b/fceumm/src-fceumm/fir/c44100pal.coef new file mode 100644 index 0000000..0398f00 --- /dev/null +++ b/fceumm/src-fceumm/fir/c44100pal.coef @@ -0,0 +1,1039 @@ +;; ***** 44100 PAL ***** +;; Filter length: 1024 +;; Symmetry: cosine +;; Sampling frequency: 1662607.125 +;; Grid density: 10257 +;; Deviation parameter: y=-4.28595835756995e-4 +;; +;; Specifications: +;; (limit > 22050 831303.5625 0 0.5) +;; (limit < 22050 831303.5625 0 0.5) +;; (limit > 0 15500 1 1) +;; (limit < 0 15500 1 1) +;; +;; Coefficients: + +-1.11200257011025e-4 +-7.94996380288693e-6 +-8.13285647140816e-6 +-8.24614335450001e-6 +-8.28726470313328e-6 +-8.24897818906316e-6 +-8.13579312269827e-6 +-7.93678154525632e-6 +-7.66363813247865e-6 +-7.28830988147217e-6 +-6.83300292562487e-6 +-6.27926662890536e-6 +-5.63180592699196e-6 +-4.90087590625251e-6 +-4.08336036205811e-6 +-3.16293668294449e-6 +-2.15293957076619e-6 +-1.06608354010604e-6 +1.17779154321068e-7 +1.36339097208028e-6 +2.70697389916737e-6 +4.13545107510629e-6 +5.6127107530343e-6 +7.15216767756425e-6 +8.76565171236067e-6 +1.04110267491666e-5 +1.209928683708e-5 +1.3807553643137e-5 +1.55498084717804e-5 +1.73113519018396e-5 +1.90726123593194e-5 +2.08203230001769e-5 +2.25533698766556e-5 +2.42417431818782e-5 +2.59088069682988e-5 +2.75097685821301e-5 +2.90529184467942e-5 +3.05258134239308e-5 +3.1906749021575e-5 +3.31955898421991e-5 +3.43727119744575e-5 +3.54234983372247e-5 +3.63431784582818e-5 +3.71120880500224e-5 +3.77205312917436e-5 +3.81506665317904e-5 +3.84008667836707e-5 +3.84617902622245e-5 +3.83356611921185e-5 +3.80172027315447e-5 +3.74882685294917e-5 +3.67702946218063e-5 +3.58419705572146e-5 +3.46879785388071e-5 +3.32641657027279e-5 +3.14968254692446e-5 +2.98205583919132e-5 +2.77079444336199e-5 +2.54270156775404e-5 +2.29383213938169e-5 +2.02427147104623e-5 +1.73385589814633e-5 +1.42538741163702e-5 +1.0974704577089e-5 +7.5345671480003e-6 +3.92576081368077e-6 +1.83369853607622e-7 +-3.6781367339795e-6 +-7.66697534902539e-6 +-1.17479928711011e-5 +-1.58899910541553e-5 +-2.00875350281883e-5 +-2.43269194651492e-5 +-2.85687842714339e-5 +-3.28189740432224e-5 +-3.70047365577994e-5 +-4.11243186584193e-5 +-4.51827880544111e-5 +-4.91366464792378e-5 +-5.29228769501386e-5 +-5.6577177841953e-5 +-6.00407527379607e-5 +-6.33015334642338e-5 +-6.6321066975926e-5 +-6.90803733771612e-5 +-7.1551714886712e-5 +-7.37245485134222e-5 +-7.55586426528957e-5 +-7.70803234827881e-5 +-7.81982347188838e-5 +-7.89408927811607e-5 +-7.92941109743888e-5 +-7.92348985225341e-5 +-7.87415759361739e-5 +-7.78153743941276e-5 +-7.64300985875165e-5 +-7.46031420059581e-5 +-7.23191346398865e-5 +-6.95708993868544e-5 +-6.63607831282715e-5 +-6.27086197063989e-5 +-5.86124087120698e-5 +-5.40735813007961e-5 +-4.91146153453121e-5 +-4.37274299935917e-5 +-3.796629483321e-5 +-3.17982121227615e-5 +-2.52841084140995e-5 +-1.84333267027672e-5 +-1.13023888811976e-5 +-3.91269277424297e-6 +3.78856288808815e-6 +1.16356826931571e-5 +1.96757362744974e-5 +2.78537134537647e-5 +3.61195928120633e-5 +4.44322494738248e-5 +5.27623610515163e-5 +6.1053941504231e-5 +6.92572576428739e-5 +7.7331248720778e-5 +8.52344475900456e-5 +9.2926888863339e-5 +1.00334146579291e-4 +1.07431425645115e-4 +1.1416670963617e-4 +1.20489431734329e-4 +1.26354387911283e-4 +1.31720166830177e-4 +1.36538713088326e-4 +1.40793996948262e-4 +1.44431432682464e-4 +1.47393924564116e-4 +1.49667322189054e-4 +1.51240640106038e-4 +1.52049596360267e-4 +1.52081469279039e-4 +1.51330637705528e-4 +1.49757451217301e-4 +1.47362931428648e-4 +1.44140529279305e-4 +1.40080755562269e-4 +1.35181216701032e-4 +1.29425084953382e-4 +1.22873714879804e-4 +1.15510843581741e-4 +1.07326364837661e-4 +9.83786335794599e-5 +8.86945777859818e-5 +7.82876287061222e-5 +6.7224812176488e-5 +5.55089298390305e-5 +4.32026588267973e-5 +3.0365713255082e-5 +1.70475989751417e-5 +3.29372966720524e-6 +-1.08241832988715e-5 +-2.52343906526312e-5 +-3.98841814115523e-5 +-5.46823094969964e-5 +-6.95847998647964e-5 +-8.44762835454931e-5 +-9.93135063167747e-5 +-1.13988295988881e-4 +-1.28441297371119e-4 +-1.4257904039858e-4 +-1.5632814652685e-4 +-1.69596926160502e-4 +-1.82304197147325e-4 +-1.94375475955832e-4 +-2.05729261288574e-4 +-2.16294796061533e-4 +-2.25986416409321e-4 +-2.34733017787645e-4 +-2.42489478192021e-4 +-2.49164314249808e-4 +-2.54710160797573e-4 +-2.59055230879128e-4 +-2.62163331622264e-4 +-2.63980952682017e-4 +-2.64483868515565e-4 +-2.63625449149133e-4 +-2.61381251495432e-4 +-2.57733197100289e-4 +-2.52658112953211e-4 +-2.4615901828968e-4 +-2.38226811903974e-4 +-2.28884870924857e-4 +-2.18140483365099e-4 +-2.06019172507064e-4 +-1.9254469774914e-4 +-1.77785719247505e-4 +-1.61739992805436e-4 +-1.4451846040208e-4 +-1.26149587549934e-4 +-1.06709031104119e-4 +-8.62669952337453e-5 +-6.49336478463108e-5 +-4.27728447441012e-5 +-1.98970247861957e-5 +3.61164973426469e-6 +2.75939454346297e-5 +5.19905050322827e-5 +7.66611814451522e-5 +1.01478414196256e-4 +1.26339943357148e-4 +1.51085348502373e-4 +1.75595678238513e-4 +1.99742079669349e-4 +2.23388522276371e-4 +2.46394584033161e-4 +2.68636208374242e-4 +2.89982341455338e-4 +3.10294458286738e-4 +3.29443424793821e-4 +3.47313309870382e-4 +3.6377364605836e-4 +3.78710912554491e-4 +3.9202650014604e-4 +4.03608977052316e-4 +4.13354985071458e-4 +4.2116122650496e-4 +4.26988609123688e-4 +4.30738794863119e-4 +4.32336229285393e-4 +4.31759427084928e-4 +4.2893275128775e-4 +4.23845616813245e-4 +4.16470263567494e-4 +4.06783273414362e-4 +3.94804321373921e-4 +3.80535441649663e-4 +3.6401636005173e-4 +3.4529014942601e-4 +3.24391189898946e-4 +3.01376781077692e-4 +2.76343301836257e-4 +2.4936486879876e-4 +2.20548944074394e-4 +1.90007301298934e-4 +1.57842659191524e-4 +1.24220152772481e-4 +8.92685161781954e-5 +5.31339845287204e-5 +1.59816963628024e-5 +-2.19908840946184e-5 +-6.06534567846234e-5 +-9.97630661046562e-5 +-1.39179726975758e-4 +-1.78679270880486e-4 +-2.1805919019443e-4 +-2.57108546253423e-4 +-2.95641094902746e-4 +-3.33403666779113e-4 +-3.70254587494631e-4 +-4.05911568827225e-4 +-4.4022838615012e-4 +-4.72955839415529e-4 +-5.0391796703662e-4 +-5.32914238319358e-4 +-5.59744514364898e-4 +-5.84238077102726e-4 +-6.06224526249333e-4 +-6.25539846131288e-4 +-6.42027789895408e-4 +-6.5555230038567e-4 +-6.65977498710118e-4 +-6.7318950015647e-4 +-6.77091605863607e-4 +-6.77614237688126e-4 +-6.74643387824144e-4 +-6.681810692764e-4 +-6.58148553515012e-4 +-6.44548593096861e-4 +-6.27372049258136e-4 +-6.06651646698617e-4 +-5.82419271110313e-4 +-5.54718009495967e-4 +-5.23626832014741e-4 +-4.8926746405434e-4 +-4.51699986733748e-4 +-4.11106675639873e-4 +-3.67606528939805e-4 +-3.21382862239143e-4 +-2.72607382898212e-4 +-2.21497157339506e-4 +-1.68258628656205e-4 +-1.13130227471391e-4 +-5.63383710913267e-5 +1.82703643648985e-6 +6.11059297587035e-5 +1.21227953996855e-4 +1.81881505870662e-4 +2.42786733495668e-4 +3.03615254629841e-4 +3.64050987977855e-4 +4.23804182290753e-4 +4.82537070178806e-4 +5.39916161965727e-4 +5.95641281700095e-4 +6.49402169641121e-4 +7.00854505724994e-4 +7.4971795695236e-4 +7.95682703239628e-4 +8.38445709493196e-4 +8.77748678164893e-4 +9.13311645337574e-4 +9.44886650093644e-4 +9.72247670017337e-4 +9.95115178537146e-4 +0.00101336913401633 +0.00102677501507253 +0.00103518648644738 +0.00103846440012199 +0.00103648919038668 +0.00102917891064352 +0.0010164716114175 +9.98315800820138e-4 +9.74705065755381e-4 +9.45660726451063e-4 +9.11220671795009e-4 +8.71464226265813e-4 +8.26493006790482e-4 +7.76428186484775e-4 +7.2141888229852e-4 +6.61697436756462e-4 +5.9741912245776e-4 +5.28873675826444e-4 +4.56291683005437e-4 +3.79985318339895e-4 +3.00269695262299e-4 +2.17487142122525e-4 +1.31991772965616e-4 +4.41879631490349e-5 +-4.55545140015219e-5 +-1.36775307453412e-4 +-2.29072500656193e-4 +-3.21982815448816e-4 +-4.15050766626564e-4 +-5.0777980705733e-4 +-5.99729527875493e-4 +-6.90384622866925e-4 +-7.79287829793652e-4 +-8.65926265038561e-4 +-9.49836926138828e-4 +-0.00103052577700171 +-0.0011075193071442 +-0.00118036874439703 +-0.00124859930815059 +-0.00131180178646339 +-0.00136953952393335 +-0.00142140513653781 +-0.00146703736814346 +-0.00150608163518545 +-0.00153818964747658 +-0.00156307825078861 +-0.0015804778819231 +-0.0015901634714776 +-0.00159189434514815 +-0.00158555114709596 +-0.00157096689703477 +-0.00154807524691094 +-0.00151680067268875 +-0.00147716260085239 +-0.001429198787489 +-0.00137294453725215 +-0.00130854205285008 +-0.00123616307121754 +-0.00115598693403096 +-0.00106828307283493 +-9.73328815012761e-4 +-8.71455057796053e-4 +-7.63043529919569e-4 +-6.48499103297409e-4 +-5.28275515871108e-4 +-4.02868466889883e-4 +-2.72797605270643e-4 +-1.38620034875188e-4 +-9.39779893315131e-7 +1.39630165237839e-4 +2.8245890419115e-4 +4.26851878411663e-4 +5.72128676056236e-4 +7.17555283175031e-4 +8.62419664123234e-4 +0.00100599136178572 +0.00114749964897685 +0.00128619716461828 +0.00142133896436276 +0.00155215453934691 +0.00167789165485006 +0.00179782254312389 +0.00191119051397053 +0.00201730596666936 +0.00211548603714526 +0.00220503610710518 +0.00228534178059485 +0.00235576204962984 +0.0024157435894097 +0.00246475064259446 +0.0025022831737163 +0.00252789297770596 +0.00254116769788057 +0.00254176992461642 +0.00252938841718385 +0.00250379536745675 +0.00246480413845626 +0.00241227787677937 +0.00234617618821264 +0.00226649941700418 +0.00217330314170672 +0.00206673238197944 +0.00194696407580016 +0.0018143173361094 +0.00166908671482331 +0.00151170100656022 +0.00134262363203965 +0.00116240941365375 +9.71632852686666e-4 +7.70995591058202e-4 +5.61217875060209e-4 +3.43102377440826e-4 +1.17486802048521e-4 +-1.14695107246174e-4 +-3.52499536963163e-4 +-5.9490463003285e-4 +-8.40850949031332e-4 +-0.00108922785396699 +-0.00133888418878215 +-0.00158864742890517 +-0.0018373063114507 +-0.00208361779036314 +-0.0023263150988098 +-0.00256412644472558 +-0.00279574533789046 +-0.00301988207803446 +-0.00323521397538706 +-0.00344046688386521 +-0.00363433985468964 +-0.00381554830386696 +-0.00398282823032301 +-0.0041349694223421 +-0.00427073396319018 +-0.00438896904598832 +-0.00448852839147268 +-0.00456836880890372 +-0.004627400257634 +-0.00466470470414415 +-0.00467932298600597 +-0.00467041907819992 +-0.00463720779225358 +-0.00457898303537998 +-0.00449512222942258 +-0.00438507069238121 +-0.00424834585547379 +-0.00408459615492852 +-0.0038935194962581 +-0.0036749355234766 +-0.00342874251403819 +-0.00315493309153929 +-0.00285361231552705 +-0.00252496859694177 +-0.00216931316953576 +-0.0017870143203001 +-0.00137859287897444 +-9.44633240898953e-4 +-4.85835090373757e-4 +-2.9962514126255e-6 +5.03012372252255e-4 +0.0010312109513981 +0.00158050717151511 +0.00214976554763945 +0.00273772736746413 +0.00334306999099584 +0.0039644076312235 +0.00460023689832775 +0.00524903833016921 +0.00590919805593498 +0.00657904898248033 +0.00725688057525865 +0.00794091363222304 +0.00862934675318832 +0.00932034748070898 +0.0100120457135665 +0.0107025377765967 +0.011389916307798 +0.0120722612532503 +0.0127476582242783 +0.0134141882202367 +0.0140699467449269 +0.0147130285913083 +0.0153416010646532 +0.0159537971993272 +0.0165478416438899 +0.0171219834943615 +0.0176745067361407 +0.018203769229927 +0.0187082111673434 +0.0191862910393147 +0.0196366013582463 +0.0200577339311999 +0.0204484730566774 +0.0208075842002215 +0.021134001566882 +0.0214267119717681 +0.0216848382317027 +0.0219075680887292 +0.022094238422553 +0.0222442604033734 +0.0223571935299417 +0.0224326657161866 +0.0224704675290829 +0.0224704675290829 +0.0224326657161866 +0.0223571935299417 +0.0222442604033734 +0.022094238422553 +0.0219075680887292 +0.0216848382317027 +0.0214267119717681 +0.021134001566882 +0.0208075842002215 +0.0204484730566774 +0.0200577339311999 +0.0196366013582463 +0.0191862910393147 +0.0187082111673434 +0.018203769229927 +0.0176745067361407 +0.0171219834943615 +0.0165478416438899 +0.0159537971993272 +0.0153416010646532 +0.0147130285913083 +0.0140699467449269 +0.0134141882202367 +0.0127476582242783 +0.0120722612532503 +0.011389916307798 +0.0107025377765967 +0.0100120457135665 +0.00932034748070898 +0.00862934675318832 +0.00794091363222304 +0.00725688057525865 +0.00657904898248033 +0.00590919805593498 +0.00524903833016921 +0.00460023689832775 +0.0039644076312235 +0.00334306999099584 +0.00273772736746413 +0.00214976554763945 +0.00158050717151511 +0.0010312109513981 +5.03012372252255e-4 +-2.9962514126255e-6 +-4.85835090373757e-4 +-9.44633240898953e-4 +-0.00137859287897444 +-0.0017870143203001 +-0.00216931316953576 +-0.00252496859694177 +-0.00285361231552705 +-0.00315493309153929 +-0.00342874251403819 +-0.0036749355234766 +-0.0038935194962581 +-0.00408459615492852 +-0.00424834585547379 +-0.00438507069238121 +-0.00449512222942258 +-0.00457898303537998 +-0.00463720779225358 +-0.00467041907819992 +-0.00467932298600597 +-0.00466470470414415 +-0.004627400257634 +-0.00456836880890372 +-0.00448852839147268 +-0.00438896904598832 +-0.00427073396319018 +-0.0041349694223421 +-0.00398282823032301 +-0.00381554830386696 +-0.00363433985468964 +-0.00344046688386521 +-0.00323521397538706 +-0.00301988207803446 +-0.00279574533789046 +-0.00256412644472558 +-0.0023263150988098 +-0.00208361779036314 +-0.0018373063114507 +-0.00158864742890517 +-0.00133888418878215 +-0.00108922785396699 +-8.40850949031332e-4 +-5.9490463003285e-4 +-3.52499536963163e-4 +-1.14695107246174e-4 +1.17486802048521e-4 +3.43102377440826e-4 +5.61217875060209e-4 +7.70995591058202e-4 +9.71632852686666e-4 +0.00116240941365375 +0.00134262363203965 +0.00151170100656022 +0.00166908671482331 +0.0018143173361094 +0.00194696407580016 +0.00206673238197944 +0.00217330314170672 +0.00226649941700418 +0.00234617618821264 +0.00241227787677937 +0.00246480413845626 +0.00250379536745675 +0.00252938841718385 +0.00254176992461642 +0.00254116769788057 +0.00252789297770596 +0.0025022831737163 +0.00246475064259446 +0.0024157435894097 +0.00235576204962984 +0.00228534178059485 +0.00220503610710518 +0.00211548603714526 +0.00201730596666936 +0.00191119051397053 +0.00179782254312389 +0.00167789165485006 +0.00155215453934691 +0.00142133896436276 +0.00128619716461828 +0.00114749964897685 +0.00100599136178572 +8.62419664123234e-4 +7.17555283175031e-4 +5.72128676056236e-4 +4.26851878411663e-4 +2.8245890419115e-4 +1.39630165237839e-4 +-9.39779893315131e-7 +-1.38620034875188e-4 +-2.72797605270643e-4 +-4.02868466889883e-4 +-5.28275515871108e-4 +-6.48499103297409e-4 +-7.63043529919569e-4 +-8.71455057796053e-4 +-9.73328815012761e-4 +-0.00106828307283493 +-0.00115598693403096 +-0.00123616307121754 +-0.00130854205285008 +-0.00137294453725215 +-0.001429198787489 +-0.00147716260085239 +-0.00151680067268875 +-0.00154807524691094 +-0.00157096689703477 +-0.00158555114709596 +-0.00159189434514815 +-0.0015901634714776 +-0.0015804778819231 +-0.00156307825078861 +-0.00153818964747658 +-0.00150608163518545 +-0.00146703736814346 +-0.00142140513653781 +-0.00136953952393335 +-0.00131180178646339 +-0.00124859930815059 +-0.00118036874439703 +-0.0011075193071442 +-0.00103052577700171 +-9.49836926138828e-4 +-8.65926265038561e-4 +-7.79287829793652e-4 +-6.90384622866925e-4 +-5.99729527875493e-4 +-5.0777980705733e-4 +-4.15050766626564e-4 +-3.21982815448816e-4 +-2.29072500656193e-4 +-1.36775307453412e-4 +-4.55545140015219e-5 +4.41879631490349e-5 +1.31991772965616e-4 +2.17487142122525e-4 +3.00269695262299e-4 +3.79985318339895e-4 +4.56291683005437e-4 +5.28873675826444e-4 +5.9741912245776e-4 +6.61697436756462e-4 +7.2141888229852e-4 +7.76428186484775e-4 +8.26493006790482e-4 +8.71464226265813e-4 +9.11220671795009e-4 +9.45660726451063e-4 +9.74705065755381e-4 +9.98315800820138e-4 +0.0010164716114175 +0.00102917891064352 +0.00103648919038668 +0.00103846440012199 +0.00103518648644738 +0.00102677501507253 +0.00101336913401633 +9.95115178537146e-4 +9.72247670017337e-4 +9.44886650093644e-4 +9.13311645337574e-4 +8.77748678164893e-4 +8.38445709493196e-4 +7.95682703239628e-4 +7.4971795695236e-4 +7.00854505724994e-4 +6.49402169641121e-4 +5.95641281700095e-4 +5.39916161965727e-4 +4.82537070178806e-4 +4.23804182290753e-4 +3.64050987977855e-4 +3.03615254629841e-4 +2.42786733495668e-4 +1.81881505870662e-4 +1.21227953996855e-4 +6.11059297587035e-5 +1.82703643648985e-6 +-5.63383710913267e-5 +-1.13130227471391e-4 +-1.68258628656205e-4 +-2.21497157339506e-4 +-2.72607382898212e-4 +-3.21382862239143e-4 +-3.67606528939805e-4 +-4.11106675639873e-4 +-4.51699986733748e-4 +-4.8926746405434e-4 +-5.23626832014741e-4 +-5.54718009495967e-4 +-5.82419271110313e-4 +-6.06651646698617e-4 +-6.27372049258136e-4 +-6.44548593096861e-4 +-6.58148553515012e-4 +-6.681810692764e-4 +-6.74643387824144e-4 +-6.77614237688126e-4 +-6.77091605863607e-4 +-6.7318950015647e-4 +-6.65977498710118e-4 +-6.5555230038567e-4 +-6.42027789895408e-4 +-6.25539846131288e-4 +-6.06224526249333e-4 +-5.84238077102726e-4 +-5.59744514364898e-4 +-5.32914238319358e-4 +-5.0391796703662e-4 +-4.72955839415529e-4 +-4.4022838615012e-4 +-4.05911568827225e-4 +-3.70254587494631e-4 +-3.33403666779113e-4 +-2.95641094902746e-4 +-2.57108546253423e-4 +-2.1805919019443e-4 +-1.78679270880486e-4 +-1.39179726975758e-4 +-9.97630661046562e-5 +-6.06534567846234e-5 +-2.19908840946184e-5 +1.59816963628024e-5 +5.31339845287204e-5 +8.92685161781954e-5 +1.24220152772481e-4 +1.57842659191524e-4 +1.90007301298934e-4 +2.20548944074394e-4 +2.4936486879876e-4 +2.76343301836257e-4 +3.01376781077692e-4 +3.24391189898946e-4 +3.4529014942601e-4 +3.6401636005173e-4 +3.80535441649663e-4 +3.94804321373921e-4 +4.06783273414362e-4 +4.16470263567494e-4 +4.23845616813245e-4 +4.2893275128775e-4 +4.31759427084928e-4 +4.32336229285393e-4 +4.30738794863119e-4 +4.26988609123688e-4 +4.2116122650496e-4 +4.13354985071458e-4 +4.03608977052316e-4 +3.9202650014604e-4 +3.78710912554491e-4 +3.6377364605836e-4 +3.47313309870382e-4 +3.29443424793821e-4 +3.10294458286738e-4 +2.89982341455338e-4 +2.68636208374242e-4 +2.46394584033161e-4 +2.23388522276371e-4 +1.99742079669349e-4 +1.75595678238513e-4 +1.51085348502373e-4 +1.26339943357148e-4 +1.01478414196256e-4 +7.66611814451522e-5 +5.19905050322827e-5 +2.75939454346297e-5 +3.61164973426469e-6 +-1.98970247861957e-5 +-4.27728447441012e-5 +-6.49336478463108e-5 +-8.62669952337453e-5 +-1.06709031104119e-4 +-1.26149587549934e-4 +-1.4451846040208e-4 +-1.61739992805436e-4 +-1.77785719247505e-4 +-1.9254469774914e-4 +-2.06019172507064e-4 +-2.18140483365099e-4 +-2.28884870924857e-4 +-2.38226811903974e-4 +-2.4615901828968e-4 +-2.52658112953211e-4 +-2.57733197100289e-4 +-2.61381251495432e-4 +-2.63625449149133e-4 +-2.64483868515565e-4 +-2.63980952682017e-4 +-2.62163331622264e-4 +-2.59055230879128e-4 +-2.54710160797573e-4 +-2.49164314249808e-4 +-2.42489478192021e-4 +-2.34733017787645e-4 +-2.25986416409321e-4 +-2.16294796061533e-4 +-2.05729261288574e-4 +-1.94375475955832e-4 +-1.82304197147325e-4 +-1.69596926160502e-4 +-1.5632814652685e-4 +-1.4257904039858e-4 +-1.28441297371119e-4 +-1.13988295988881e-4 +-9.93135063167747e-5 +-8.44762835454931e-5 +-6.95847998647964e-5 +-5.46823094969964e-5 +-3.98841814115523e-5 +-2.52343906526312e-5 +-1.08241832988715e-5 +3.29372966720524e-6 +1.70475989751417e-5 +3.0365713255082e-5 +4.32026588267973e-5 +5.55089298390305e-5 +6.7224812176488e-5 +7.82876287061222e-5 +8.86945777859818e-5 +9.83786335794599e-5 +1.07326364837661e-4 +1.15510843581741e-4 +1.22873714879804e-4 +1.29425084953382e-4 +1.35181216701032e-4 +1.40080755562269e-4 +1.44140529279305e-4 +1.47362931428648e-4 +1.49757451217301e-4 +1.51330637705528e-4 +1.52081469279039e-4 +1.52049596360267e-4 +1.51240640106038e-4 +1.49667322189054e-4 +1.47393924564116e-4 +1.44431432682464e-4 +1.40793996948262e-4 +1.36538713088326e-4 +1.31720166830177e-4 +1.26354387911283e-4 +1.20489431734329e-4 +1.1416670963617e-4 +1.07431425645115e-4 +1.00334146579291e-4 +9.2926888863339e-5 +8.52344475900456e-5 +7.7331248720778e-5 +6.92572576428739e-5 +6.1053941504231e-5 +5.27623610515163e-5 +4.44322494738248e-5 +3.61195928120633e-5 +2.78537134537647e-5 +1.96757362744974e-5 +1.16356826931571e-5 +3.78856288808815e-6 +-3.91269277424297e-6 +-1.13023888811976e-5 +-1.84333267027672e-5 +-2.52841084140995e-5 +-3.17982121227615e-5 +-3.796629483321e-5 +-4.37274299935917e-5 +-4.91146153453121e-5 +-5.40735813007961e-5 +-5.86124087120698e-5 +-6.27086197063989e-5 +-6.63607831282715e-5 +-6.95708993868544e-5 +-7.23191346398865e-5 +-7.46031420059581e-5 +-7.64300985875165e-5 +-7.78153743941276e-5 +-7.87415759361739e-5 +-7.92348985225341e-5 +-7.92941109743888e-5 +-7.89408927811607e-5 +-7.81982347188838e-5 +-7.70803234827881e-5 +-7.55586426528957e-5 +-7.37245485134222e-5 +-7.1551714886712e-5 +-6.90803733771612e-5 +-6.6321066975926e-5 +-6.33015334642338e-5 +-6.00407527379607e-5 +-5.6577177841953e-5 +-5.29228769501386e-5 +-4.91366464792378e-5 +-4.51827880544111e-5 +-4.11243186584193e-5 +-3.70047365577994e-5 +-3.28189740432224e-5 +-2.85687842714339e-5 +-2.43269194651492e-5 +-2.00875350281883e-5 +-1.58899910541553e-5 +-1.17479928711011e-5 +-7.66697534902539e-6 +-3.6781367339795e-6 +1.83369853607622e-7 +3.92576081368077e-6 +7.5345671480003e-6 +1.0974704577089e-5 +1.42538741163702e-5 +1.73385589814633e-5 +2.02427147104623e-5 +2.29383213938169e-5 +2.54270156775404e-5 +2.77079444336199e-5 +2.98205583919132e-5 +3.14968254692446e-5 +3.32641657027279e-5 +3.46879785388071e-5 +3.58419705572146e-5 +3.67702946218063e-5 +3.74882685294917e-5 +3.80172027315447e-5 +3.83356611921185e-5 +3.84617902622245e-5 +3.84008667836707e-5 +3.81506665317904e-5 +3.77205312917436e-5 +3.71120880500224e-5 +3.63431784582818e-5 +3.54234983372247e-5 +3.43727119744575e-5 +3.31955898421991e-5 +3.1906749021575e-5 +3.05258134239308e-5 +2.90529184467942e-5 +2.75097685821301e-5 +2.59088069682988e-5 +2.42417431818782e-5 +2.25533698766556e-5 +2.08203230001769e-5 +1.90726123593194e-5 +1.73113519018396e-5 +1.55498084717804e-5 +1.3807553643137e-5 +1.209928683708e-5 +1.04110267491666e-5 +8.76565171236067e-6 +7.15216767756425e-6 +5.6127107530343e-6 +4.13545107510629e-6 +2.70697389916737e-6 +1.36339097208028e-6 +1.17779154321068e-7 +-1.06608354010604e-6 +-2.15293957076619e-6 +-3.16293668294449e-6 +-4.08336036205811e-6 +-4.90087590625251e-6 +-5.63180592699196e-6 +-6.27926662890536e-6 +-6.83300292562487e-6 +-7.28830988147217e-6 +-7.66363813247865e-6 +-7.93678154525632e-6 +-8.13579312269827e-6 +-8.24897818906316e-6 +-8.28726470313328e-6 +-8.24614335450001e-6 +-8.13285647140816e-6 +-7.94996380288693e-6 +-1.11200257011025e-4 diff --git a/fceumm/src-fceumm/fir/c44100pal.h b/fceumm/src-fceumm/fir/c44100pal.h new file mode 100644 index 0000000..b9f0132 --- /dev/null +++ b/fceumm/src-fceumm/fir/c44100pal.h @@ -0,0 +1,512 @@ +-116, +-8, +-8, +-8, +-8, +-8, +-8, +-8, +-8, +-7, +-7, +-6, +-5, +-5, +-4, +-3, +-2, +-1, +0, +1, +2, +4, +5, +7, +9, +10, +12, +14, +16, +18, +19, +21, +23, +25, +27, +28, +30, +32, +33, +34, +36, +37, +38, +38, +39, +40, +40, +40, +40, +39, +39, +38, +37, +36, +34, +33, +31, +29, +26, +24, +21, +18, +14, +11, +7, +4, +0, +-3, +-8, +-12, +-16, +-21, +-25, +-29, +-34, +-38, +-43, +-47, +-51, +-55, +-59, +-62, +-66, +-69, +-72, +-75, +-77, +-79, +-80, +-81, +-82, +-83, +-83, +-82, +-81, +-80, +-78, +-75, +-72, +-69, +-65, +-61, +-56, +-51, +-45, +-39, +-33, +-26, +-19, +-11, +-4, +3, +12, +20, +29, +37, +46, +55, +64, +72, +81, +89, +97, +105, +112, +119, +126, +132, +138, +143, +147, +151, +154, +156, +158, +159, +159, +158, +157, +154, +151, +146, +141, +135, +128, +121, +112, +103, +93, +82, +70, +58, +45, +31, +17, +3, +-11, +-26, +-41, +-57, +-72, +-88, +-104, +-119, +-134, +-149, +-163, +-177, +-191, +-203, +-215, +-226, +-236, +-246, +-254, +-261, +-267, +-271, +-274, +-276, +-277, +-276, +-274, +-270, +-264, +-258, +-249, +-240, +-228, +-216, +-201, +-186, +-169, +-151, +-132, +-111, +-90, +-68, +-44, +-20, +3, +28, +54, +80, +106, +132, +158, +184, +209, +234, +258, +281, +304, +325, +345, +364, +381, +397, +411, +423, +433, +441, +447, +451, +453, +452, +449, +444, +436, +426, +413, +399, +381, +362, +340, +316, +289, +261, +231, +199, +165, +130, +93, +55, +16, +-23, +-63, +-104, +-145, +-187, +-228, +-269, +-310, +-349, +-388, +-425, +-461, +-495, +-528, +-558, +-586, +-612, +-635, +-655, +-673, +-687, +-698, +-705, +-709, +-710, +-707, +-700, +-690, +-675, +-657, +-636, +-610, +-581, +-549, +-513, +-473, +-431, +-385, +-336, +-285, +-232, +-176, +-118, +-59, +1, +64, +127, +190, +254, +318, +381, +444, +505, +566, +624, +680, +734, +786, +834, +879, +920, +957, +990, +1019, +1043, +1062, +1076, +1085, +1088, +1086, +1079, +1065, +1046, +1022, +991, +955, +913, +866, +814, +756, +693, +626, +554, +478, +398, +314, +228, +138, +46, +-47, +-143, +-240, +-337, +-435, +-532, +-628, +-723, +-817, +-907, +-995, +-1080, +-1161, +-1237, +-1309, +-1375, +-1436, +-1490, +-1538, +-1579, +-1612, +-1639, +-1657, +-1667, +-1669, +-1662, +-1647, +-1623, +-1590, +-1548, +-1498, +-1439, +-1372, +-1296, +-1212, +-1120, +-1020, +-913, +-800, +-680, +-553, +-422, +-286, +-145, +0, +146, +296, +447, +599, +752, +904, +1054, +1203, +1348, +1490, +1627, +1759, +1885, +2004, +2115, +2218, +2312, +2396, +2470, +2533, +2584, +2623, +2650, +2664, +2665, +2652, +2625, +2584, +2529, +2460, +2376, +2278, +2167, +2041, +1902, +1750, +1585, +1407, +1218, +1018, +808, +588, +359, +123, +-120, +-369, +-623, +-881, +-1142, +-1403, +-1665, +-1926, +-2184, +-2439, +-2688, +-2931, +-3166, +-3392, +-3607, +-3810, +-4000, +-4176, +-4335, +-4478, +-4602, +-4706, +-4790, +-4852, +-4891, +-4906, +-4897, +-4862, +-4801, +-4713, +-4598, +-4454, +-4283, +-4082, +-3853, +-3595, +-3308, +-2992, +-2647, +-2274, +-1873, +-1445, +-990, +-509, +-3, +527, +1081, +1657, +2254, +2870, +3505, +4156, +4823, +5504, +6196, +6898, +7609, +8326, +9048, +9773, +10498, +11222, +11943, +12658, +13366, +14065, +14753, +15427, +16086, +16728, +17351, +17953, +18533, +19088, +19616, +20118, +20590, +21032, +21441, +21818, +22160, +22467, +22738, +22971, +23167, +23324, +23443, +23522, +23561, diff --git a/fceumm/src-fceumm/fir/c44100pal.scm b/fceumm/src-fceumm/fir/c44100pal.scm new file mode 100644 index 0000000..7bd4cc1 --- /dev/null +++ b/fceumm/src-fceumm/fir/c44100pal.scm @@ -0,0 +1,12 @@ +(title "44100 PAL") + +(verbose #t) + +(cosine-symmetry) +(filter-length 1024) +(sampling-frequency 1662607.125) +(limit-= (band 0 15500) 1) +(limit-= (band 22050 831303.5625) 0 .5) +(output-file "c44100pal.coef") +(plot-file "c44100pal.plot") +(go) diff --git a/fceumm/src-fceumm/fir/c48000ntsc.coef b/fceumm/src-fceumm/fir/c48000ntsc.coef new file mode 100644 index 0000000..ba8beb4 --- /dev/null +++ b/fceumm/src-fceumm/fir/c48000ntsc.coef @@ -0,0 +1,1039 @@ +;; ***** Simple test filter ***** +;; Filter length: 1024 +;; Symmetry: cosine +;; Sampling frequency: 1789772.72727273 +;; Grid density: 10257 +;; Deviation parameter: y=-4.15334587672572e-4 +;; +;; Specifications: +;; (limit > 24000 894886.363636 0 0.5) +;; (limit < 24000 894886.363636 0 0.5) +;; (limit > 0 17000 1 1) +;; (limit < 0 17000 1 1) +;; +;; Coefficients: + +-1.09949811042225e-4 +-1.22806738594947e-5 +-1.2856649387849e-5 +-1.33942943882967e-5 +-1.38759188766186e-5 +-1.42903486313313e-5 +-1.46314856397791e-5 +-1.48912662330057e-5 +-1.50872358926362e-5 +-1.51736783706926e-5 +-1.51920174272043e-5 +-1.50946540712042e-5 +-1.4906159571695e-5 +-1.46043232504438e-5 +-1.41826804115075e-5 +-1.3656619477754e-5 +-1.30159730761761e-5 +-1.22550097006306e-5 +-1.13887071556529e-5 +-1.03867032653885e-5 +-9.28900860776593e-6 +-8.04914399027275e-6 +-6.71896085473064e-6 +-5.26687936275949e-6 +-3.70827372384805e-6 +-2.05782362044426e-6 +-3.07184084317173e-7 +1.56196204778674e-6 +3.49335533222506e-6 +5.50094513191646e-6 +7.58454405677602e-6 +9.73122206351426e-6 +1.1925384533121e-5 +1.41723759116143e-5 +1.64486730093282e-5 +1.87185665617164e-5 +2.10193314554571e-5 +2.32868013030244e-5 +2.553385658201e-5 +2.77448936592136e-5 +2.98938550558335e-5 +3.19813209008917e-5 +3.39767566092725e-5 +3.58854777832478e-5 +3.77083338973254e-5 +3.93896125185267e-5 +4.09448701284991e-5 +4.2335041675049e-5 +4.355182102547e-5 +4.45811599449272e-5 +4.53754087968507e-5 +4.5963991898548e-5 +4.63912768895152e-5 +4.66332273332272e-5 +4.6623761079951e-5 +4.61449042224772e-5 +4.56999092246609e-5 +4.48566415488991e-5 +4.37716646911701e-5 +4.24332940559181e-5 +4.08053879668338e-5 +3.88924305216162e-5 +3.67371834848531e-5 +3.42871968756067e-5 +3.16108049585284e-5 +2.86477428425672e-5 +2.54397360410253e-5 +2.19995003725315e-5 +1.83235898190551e-5 +1.44365831918759e-5 +1.0347151946393e-5 +6.06550691029756e-6 +1.62938066833157e-6 +-2.97932202860966e-6 +-7.69928040586833e-6 +-1.25326516699612e-5 +-1.74386499250263e-5 +-2.24193699837587e-5 +-2.74121537882667e-5 +-3.2420323875298e-5 +-3.74096430792575e-5 +-4.23517165718808e-5 +-4.71910843635185e-5 +-5.19552722226438e-5 +-5.65526133942226e-5 +-6.09864135270981e-5 +-6.52252080560519e-5 +-6.92340008906634e-5 +-7.29676421256746e-5 +-7.64220773917906e-5 +-7.957469184604e-5 +-8.23723520198843e-5 +-8.48145294498788e-5 +-8.68637280156417e-5 +-8.847590640524e-5 +-8.96579831689903e-5 +-9.03754273981505e-5 +-9.06277650874391e-5 +-9.0390962049786e-5 +-8.96295019021089e-5 +-8.83699462608486e-5 +-8.65929014634202e-5 +-8.42777636122367e-5 +-8.1438947139124e-5 +-7.80310589482434e-5 +-7.4130290344153e-5 +-6.97213148895689e-5 +-6.47743915798445e-5 +-5.93190057095397e-5 +-5.3369300678592e-5 +-4.70020380599523e-5 +-4.01241085336933e-5 +-3.28791381626816e-5 +-2.52335267849121e-5 +-1.72013052766137e-5 +-8.85204247806303e-6 +-2.36203952998983e-7 +8.65426060083348e-6 +1.77326837630105e-5 +2.70119909588562e-5 +3.63935730200405e-5 +4.58302978650995e-5 +5.53120362349631e-5 +6.47532841902274e-5 +7.41091974779693e-5 +8.33336809092267e-5 +9.23584465403365e-5 +1.0115262933884e-4 +1.09631128039229e-4 +1.17757486894641e-4 +1.25489570576103e-4 +1.32754230059236e-4 +1.39503431050419e-4 +1.45701107814038e-4 +1.51259946463513e-4 +1.56172084911138e-4 +1.6038874820501e-4 +1.63870537117991e-4 +1.66539506236844e-4 +1.68421511031107e-4 +1.69442548025091e-4 +1.69579877038768e-4 +1.6881612357465e-4 +1.67142961466588e-4 +1.64531403910968e-4 +1.60985251495646e-4 +1.56489605383482e-4 +1.5103863824127e-4 +1.44638439288558e-4 +1.3732499213528e-4 +1.29095155164885e-4 +1.19970934485128e-4 +1.09972583377882e-4 +9.91339782697809e-5 +8.75139349992027e-5 +7.51413396638277e-5 +6.20524024461875e-5 +4.83301074719599e-5 +3.39882067477733e-5 +1.91401658681103e-5 +3.81291646780894e-6 +-1.18969312223288e-5 +-2.79091174901399e-5 +-4.41757419681384e-5 +-6.06051695381194e-5 +-7.70882672632681e-5 +-9.35502837597759e-5 +-1.09925493394208e-4 +-1.26105817993473e-4 +-1.41986602739464e-4 +-1.57477825556515e-4 +-1.72511116490329e-4 +-1.86975264016647e-4 +-2.0078755537738e-4 +-2.13836321481426e-4 +-2.26049064513734e-4 +-2.37368218087728e-4 +-2.47667060725941e-4 +-2.56892753723085e-4 +-2.64968427146944e-4 +-2.71811293915514e-4 +-2.77368381437469e-4 +-2.81573581193851e-4 +-2.84371752243438e-4 +-2.85739766097855e-4 +-2.85600433310225e-4 +-2.83955117995654e-4 +-2.80740799593234e-4 +-2.75948247317517e-4 +-2.69611626635144e-4 +-2.61691007650807e-4 +-2.52188089302722e-4 +-2.41138311003691e-4 +-2.28565411014119e-4 +-2.14482121588247e-4 +-1.9895360017079e-4 +-1.8201715772697e-4 +-1.63736603204964e-4 +-1.44183596994227e-4 +-1.23436201666099e-4 +-1.01558928824961e-4 +-7.86622769828866e-5 +-5.48472741191755e-5 +-3.02274887834648e-5 +-4.9052508479435e-6 +2.10064626953057e-5 +4.73692357955313e-5 +7.40576789101123e-5 +1.00930166818208e-4 +1.27850827966983e-4 +1.54673624437643e-4 +1.81245925229617e-4 +2.07459909036642e-4 +2.33129240741297e-4 +2.58109799089455e-4 +2.82247208675082e-4 +3.05421790075743e-4 +3.27480832505477e-4 +3.48269568065021e-4 +3.6763827845558e-4 +3.85499646838909e-4 +4.01682103671787e-4 +4.16086785395773e-4 +4.28597839023261e-4 +4.39097519078108e-4 +4.47510063482399e-4 +4.53732616193564e-4 +4.57673475015079e-4 +4.59289837761018e-4 +4.5850639594641e-4 +4.55297854632095e-4 +4.49607814238691e-4 +4.41429940481748e-4 +4.30750173165062e-4 +4.17571750776714e-4 +4.01921059289583e-4 +3.83832134824733e-4 +3.63333748980151e-4 +3.40524023663407e-4 +3.15436084161991e-4 +2.88188541554642e-4 +2.58843348650986e-4 +2.2755513753174e-4 +1.94439484002676e-4 +1.59617684118401e-4 +1.23249634741989e-4 +8.5510700519544e-5 +4.65441005957331e-5 +6.57031586978297e-6 +-3.42428951570416e-5 +-7.5699448554351e-5 +-1.17574026058653e-4 +-1.59659853873827e-4 +-2.01745572207549e-4 +-2.4360492525437e-4 +-2.8501090249108e-4 +-3.25733846890315e-4 +-3.65540766223455e-4 +-4.04206100994041e-4 +-4.41510228555032e-4 +-4.77213532040263e-4 +-5.11116556934743e-4 +-5.42986611641292e-4 +-5.72614695207158e-4 +-5.99800201510281e-4 +-6.24363710833356e-4 +-6.46126331992769e-4 +-6.64897970015276e-4 +-6.8052501770588e-4 +-6.92886060830722e-4 +-7.01833451901113e-4 +-7.07250228969443e-4 +-7.09057753989528e-4 +-7.07154827552179e-4 +-7.01496865293485e-4 +-6.92021891429721e-4 +-6.78737292920809e-4 +-6.61615877709466e-4 +-6.40668301834071e-4 +-6.15954503334807e-4 +-5.87516953638343e-4 +-5.5543054818097e-4 +-5.19817664992314e-4 +-4.80761718393648e-4 +-4.38443435457234e-4 +-3.92999331139588e-4 +-3.44607011339858e-4 +-2.9348321650997e-4 +-2.3983421051813e-4 +-1.83896811789197e-4 +-1.2592231659735e-4 +-6.61594042730277e-5 +-4.9252546289175e-6 +5.75175579438193e-5 +1.20840816301453e-4 +1.84748121533308e-4 +2.48893569837659e-4 +3.12957694717443e-4 +3.76586747195116e-4 +4.39458057575329e-4 +5.01208720002647e-4 +5.61505630848618e-4 +6.19978340175428e-4 +6.76328791582876e-4 +7.30187225165355e-4 +7.81228789019675e-4 +8.29133676742072e-4 +8.73586107685454e-4 +9.14292826672621e-4 +9.50980660353665e-4 +9.8335580172593e-4 +0.00101117365679917 +0.0010342034115958 +0.00105223766601628 +0.0010650850759155 +0.00107259035326429 +0.00107459393770505 +0.00107099171776075 +0.0010616907401631 +0.00104663727550016 +0.00102579422906041 +9.99174270226947e-4 +9.66796775092314e-4 +9.28727841773456e-4 +8.85038362639593e-4 +8.35888033960542e-4 +7.81415464948617e-4 +7.21781542997729e-4 +6.5723033289136e-4 +5.88002310491308e-4 +5.14363552961592e-4 +4.36612788588694e-4 +3.55077835414929e-4 +2.70131130639128e-4 +1.82143163521255e-4 +9.15090743372197e-5 +-1.33605757547524e-6 +-9.59647394963337e-5 +-1.91891614650009e-4 +-2.88666748710662e-4 +-3.85790985377778e-4 +-4.82744482577328e-4 +-5.79040781433632e-4 +-6.74149659110707e-4 +-7.67559001801454e-4 +-8.58757697345997e-4 +-9.47196836410621e-4 +-0.00103237718183087 +-0.00111379514944025 +-0.00119095339891772 +-0.00126336405490239 +-0.0013305487657181 +-0.00139205895696274 +-0.00144748189993549 +-0.00149637609832828 +-0.00153838019191627 +-0.00157313252823261 +-0.00160031824966766 +-0.00161963448121335 +-0.00163083428806327 +-0.00163368043294617 +-0.00162801106822713 +-0.00161369463758679 +-0.001590627176841 +-0.00155873704279726 +-0.00151802687039672 +-0.00146852840940013 +-0.00141032303015301 +-0.00134354264387151 +-0.00126835601060216 +-0.00118498680408603 +-0.00109369844655022 +-9.94796296696515e-4 +-8.8865052983109e-4 +-7.75668795643321e-4 +-6.56296891780576e-4 +-5.31000918141328e-4 +-4.00317796479334e-4 +-2.64818077987588e-4 +-1.25114221854341e-4 +1.81841346036177e-5 +1.64393641166078e-4 +3.12811847712545e-4 +4.62729945674983e-4 +6.13406073593611e-4 +7.64065647645698e-4 +9.13943516660458e-4 +0.00106223039501543 +0.00120813812086204 +0.00135086874684724 +0.00148959926942261 +0.00162354046408344 +0.00175189262820587 +0.00187387246188932 +0.00198871017104844 +0.00209565287683832 +0.0021939767567535 +0.00228297968827271 +0.00236200869351783 +0.00243042754510312 +0.00248762788988958 +0.0025330698432872 +0.00256626682234492 +0.00258674212159455 +0.00259411104319052 +0.00258801693114338 +0.0025681874145284 +0.00253439944797282 +0.0024864849067166 +0.00242436415305489 +0.00234800707561149 +0.00225745930340907 +0.00215285442473657 +0.00203435432097337 +0.00190222275978058 +0.00175681593792146 +0.00159852537978592 +0.0014278366643269 +0.00124529939623188 +0.00105153398032655 +8.47243678747333e-4 +6.33180470845124e-4 +4.10182654032466e-4 +1.79134409511786e-4 +-5.90060425716582e-5 +-3.03246569572555e-4 +-5.52504441714844e-4 +-8.05662799984435e-4 +-0.00106155482217139 +-0.00131898406132897 +-0.00157669465967831 +-0.00183340910297136 +-0.00208780837793107 +-0.00233856516182173 +-0.00258431370577947 +-0.00282368901281709 +-0.00305532603599211 +-0.00327782955235904 +-0.00348982317700461 +-0.00368994504305836 +-0.00387684142913267 +-0.00404917288620234 +-0.00420563779140244 +-0.00434495904267169 +-0.00446589522922125 +-0.00456726636733209 +-0.0046479215365105 +-0.00470677650973429 +-0.00474281564445811 +-0.00475506485728163 +-0.00474262236885261 +-0.00470469762343002 +-0.00464054556498023 +-0.00454951664806806 +-0.00443104181074602 +-0.0042846470727934 +-0.00410997073193062 +-0.00390671622712066 +-0.00367472523350812 +-0.00341390471257351 +-0.00312428955884935 +-0.0028060183794834 +-0.00245932446744169 +-0.00208454478573285 +-0.00168215159474978 +-0.00125270028130292 +-7.96876227266184e-4 +-3.15420122431397e-4 +1.90771392553303e-4 +7.20722841875099e-4 +0.00127336018779148 +0.00184749620984379 +0.00244188239334642 +0.00305516500721029 +0.00368588762187621 +0.00433255328849199 +0.00499354206149272 +0.00566720184348075 +0.0063517971761537 +0.00704553740219523 +0.00774656770503074 +0.00845301860954979 +0.00916293528892598 +0.00987436353423422 +0.0105853002711883 +0.0112937615141001 +0.0119976912030812 +0.0126950714702282 +0.0133838628629058 +0.0140620731478666 +0.0147276747542291 +0.015378682266711 +0.0160131634096303 +0.0166292108981782 +0.0172249492566478 +0.0177985839161102 +0.0183483448715057 +0.0188725570567793 +0.019369603943763 +0.0198379424297359 +0.020276126356732 +0.0206827991478066 +0.0210566858163425 +0.0213966117522584 +0.0217015035994142 +0.0219704341407132 +0.0222025359487478 +0.0223970968853833 +0.0225534819131259 +0.0226711961954482 +0.0227498857420413 +0.0227892926322558 +0.0227892926322558 +0.0227498857420413 +0.0226711961954482 +0.0225534819131259 +0.0223970968853833 +0.0222025359487478 +0.0219704341407132 +0.0217015035994142 +0.0213966117522584 +0.0210566858163425 +0.0206827991478066 +0.020276126356732 +0.0198379424297359 +0.019369603943763 +0.0188725570567793 +0.0183483448715057 +0.0177985839161102 +0.0172249492566478 +0.0166292108981782 +0.0160131634096303 +0.015378682266711 +0.0147276747542291 +0.0140620731478666 +0.0133838628629058 +0.0126950714702282 +0.0119976912030812 +0.0112937615141001 +0.0105853002711883 +0.00987436353423422 +0.00916293528892598 +0.00845301860954979 +0.00774656770503074 +0.00704553740219523 +0.0063517971761537 +0.00566720184348075 +0.00499354206149272 +0.00433255328849199 +0.00368588762187621 +0.00305516500721029 +0.00244188239334642 +0.00184749620984379 +0.00127336018779148 +7.20722841875099e-4 +1.90771392553303e-4 +-3.15420122431397e-4 +-7.96876227266184e-4 +-0.00125270028130292 +-0.00168215159474978 +-0.00208454478573285 +-0.00245932446744169 +-0.0028060183794834 +-0.00312428955884935 +-0.00341390471257351 +-0.00367472523350812 +-0.00390671622712066 +-0.00410997073193062 +-0.0042846470727934 +-0.00443104181074602 +-0.00454951664806806 +-0.00464054556498023 +-0.00470469762343002 +-0.00474262236885261 +-0.00475506485728163 +-0.00474281564445811 +-0.00470677650973429 +-0.0046479215365105 +-0.00456726636733209 +-0.00446589522922125 +-0.00434495904267169 +-0.00420563779140244 +-0.00404917288620234 +-0.00387684142913267 +-0.00368994504305836 +-0.00348982317700461 +-0.00327782955235904 +-0.00305532603599211 +-0.00282368901281709 +-0.00258431370577947 +-0.00233856516182173 +-0.00208780837793107 +-0.00183340910297136 +-0.00157669465967831 +-0.00131898406132897 +-0.00106155482217139 +-8.05662799984435e-4 +-5.52504441714844e-4 +-3.03246569572555e-4 +-5.90060425716582e-5 +1.79134409511786e-4 +4.10182654032466e-4 +6.33180470845124e-4 +8.47243678747333e-4 +0.00105153398032655 +0.00124529939623188 +0.0014278366643269 +0.00159852537978592 +0.00175681593792146 +0.00190222275978058 +0.00203435432097337 +0.00215285442473657 +0.00225745930340907 +0.00234800707561149 +0.00242436415305489 +0.0024864849067166 +0.00253439944797282 +0.0025681874145284 +0.00258801693114338 +0.00259411104319052 +0.00258674212159455 +0.00256626682234492 +0.0025330698432872 +0.00248762788988958 +0.00243042754510312 +0.00236200869351783 +0.00228297968827271 +0.0021939767567535 +0.00209565287683832 +0.00198871017104844 +0.00187387246188932 +0.00175189262820587 +0.00162354046408344 +0.00148959926942261 +0.00135086874684724 +0.00120813812086204 +0.00106223039501543 +9.13943516660458e-4 +7.64065647645698e-4 +6.13406073593611e-4 +4.62729945674983e-4 +3.12811847712545e-4 +1.64393641166078e-4 +1.81841346036177e-5 +-1.25114221854341e-4 +-2.64818077987588e-4 +-4.00317796479334e-4 +-5.31000918141328e-4 +-6.56296891780576e-4 +-7.75668795643321e-4 +-8.8865052983109e-4 +-9.94796296696515e-4 +-0.00109369844655022 +-0.00118498680408603 +-0.00126835601060216 +-0.00134354264387151 +-0.00141032303015301 +-0.00146852840940013 +-0.00151802687039672 +-0.00155873704279726 +-0.001590627176841 +-0.00161369463758679 +-0.00162801106822713 +-0.00163368043294617 +-0.00163083428806327 +-0.00161963448121335 +-0.00160031824966766 +-0.00157313252823261 +-0.00153838019191627 +-0.00149637609832828 +-0.00144748189993549 +-0.00139205895696274 +-0.0013305487657181 +-0.00126336405490239 +-0.00119095339891772 +-0.00111379514944025 +-0.00103237718183087 +-9.47196836410621e-4 +-8.58757697345997e-4 +-7.67559001801454e-4 +-6.74149659110707e-4 +-5.79040781433632e-4 +-4.82744482577328e-4 +-3.85790985377778e-4 +-2.88666748710662e-4 +-1.91891614650009e-4 +-9.59647394963337e-5 +-1.33605757547524e-6 +9.15090743372197e-5 +1.82143163521255e-4 +2.70131130639128e-4 +3.55077835414929e-4 +4.36612788588694e-4 +5.14363552961592e-4 +5.88002310491308e-4 +6.5723033289136e-4 +7.21781542997729e-4 +7.81415464948617e-4 +8.35888033960542e-4 +8.85038362639593e-4 +9.28727841773456e-4 +9.66796775092314e-4 +9.99174270226947e-4 +0.00102579422906041 +0.00104663727550016 +0.0010616907401631 +0.00107099171776075 +0.00107459393770505 +0.00107259035326429 +0.0010650850759155 +0.00105223766601628 +0.0010342034115958 +0.00101117365679917 +9.8335580172593e-4 +9.50980660353665e-4 +9.14292826672621e-4 +8.73586107685454e-4 +8.29133676742072e-4 +7.81228789019675e-4 +7.30187225165355e-4 +6.76328791582876e-4 +6.19978340175428e-4 +5.61505630848618e-4 +5.01208720002647e-4 +4.39458057575329e-4 +3.76586747195116e-4 +3.12957694717443e-4 +2.48893569837659e-4 +1.84748121533308e-4 +1.20840816301453e-4 +5.75175579438193e-5 +-4.9252546289175e-6 +-6.61594042730277e-5 +-1.2592231659735e-4 +-1.83896811789197e-4 +-2.3983421051813e-4 +-2.9348321650997e-4 +-3.44607011339858e-4 +-3.92999331139588e-4 +-4.38443435457234e-4 +-4.80761718393648e-4 +-5.19817664992314e-4 +-5.5543054818097e-4 +-5.87516953638343e-4 +-6.15954503334807e-4 +-6.40668301834071e-4 +-6.61615877709466e-4 +-6.78737292920809e-4 +-6.92021891429721e-4 +-7.01496865293485e-4 +-7.07154827552179e-4 +-7.09057753989528e-4 +-7.07250228969443e-4 +-7.01833451901113e-4 +-6.92886060830722e-4 +-6.8052501770588e-4 +-6.64897970015276e-4 +-6.46126331992769e-4 +-6.24363710833356e-4 +-5.99800201510281e-4 +-5.72614695207158e-4 +-5.42986611641292e-4 +-5.11116556934743e-4 +-4.77213532040263e-4 +-4.41510228555032e-4 +-4.04206100994041e-4 +-3.65540766223455e-4 +-3.25733846890315e-4 +-2.8501090249108e-4 +-2.4360492525437e-4 +-2.01745572207549e-4 +-1.59659853873827e-4 +-1.17574026058653e-4 +-7.5699448554351e-5 +-3.42428951570416e-5 +6.57031586978297e-6 +4.65441005957331e-5 +8.5510700519544e-5 +1.23249634741989e-4 +1.59617684118401e-4 +1.94439484002676e-4 +2.2755513753174e-4 +2.58843348650986e-4 +2.88188541554642e-4 +3.15436084161991e-4 +3.40524023663407e-4 +3.63333748980151e-4 +3.83832134824733e-4 +4.01921059289583e-4 +4.17571750776714e-4 +4.30750173165062e-4 +4.41429940481748e-4 +4.49607814238691e-4 +4.55297854632095e-4 +4.5850639594641e-4 +4.59289837761018e-4 +4.57673475015079e-4 +4.53732616193564e-4 +4.47510063482399e-4 +4.39097519078108e-4 +4.28597839023261e-4 +4.16086785395773e-4 +4.01682103671787e-4 +3.85499646838909e-4 +3.6763827845558e-4 +3.48269568065021e-4 +3.27480832505477e-4 +3.05421790075743e-4 +2.82247208675082e-4 +2.58109799089455e-4 +2.33129240741297e-4 +2.07459909036642e-4 +1.81245925229617e-4 +1.54673624437643e-4 +1.27850827966983e-4 +1.00930166818208e-4 +7.40576789101123e-5 +4.73692357955313e-5 +2.10064626953057e-5 +-4.9052508479435e-6 +-3.02274887834648e-5 +-5.48472741191755e-5 +-7.86622769828866e-5 +-1.01558928824961e-4 +-1.23436201666099e-4 +-1.44183596994227e-4 +-1.63736603204964e-4 +-1.8201715772697e-4 +-1.9895360017079e-4 +-2.14482121588247e-4 +-2.28565411014119e-4 +-2.41138311003691e-4 +-2.52188089302722e-4 +-2.61691007650807e-4 +-2.69611626635144e-4 +-2.75948247317517e-4 +-2.80740799593234e-4 +-2.83955117995654e-4 +-2.85600433310225e-4 +-2.85739766097855e-4 +-2.84371752243438e-4 +-2.81573581193851e-4 +-2.77368381437469e-4 +-2.71811293915514e-4 +-2.64968427146944e-4 +-2.56892753723085e-4 +-2.47667060725941e-4 +-2.37368218087728e-4 +-2.26049064513734e-4 +-2.13836321481426e-4 +-2.0078755537738e-4 +-1.86975264016647e-4 +-1.72511116490329e-4 +-1.57477825556515e-4 +-1.41986602739464e-4 +-1.26105817993473e-4 +-1.09925493394208e-4 +-9.35502837597759e-5 +-7.70882672632681e-5 +-6.06051695381194e-5 +-4.41757419681384e-5 +-2.79091174901399e-5 +-1.18969312223288e-5 +3.81291646780894e-6 +1.91401658681103e-5 +3.39882067477733e-5 +4.83301074719599e-5 +6.20524024461875e-5 +7.51413396638277e-5 +8.75139349992027e-5 +9.91339782697809e-5 +1.09972583377882e-4 +1.19970934485128e-4 +1.29095155164885e-4 +1.3732499213528e-4 +1.44638439288558e-4 +1.5103863824127e-4 +1.56489605383482e-4 +1.60985251495646e-4 +1.64531403910968e-4 +1.67142961466588e-4 +1.6881612357465e-4 +1.69579877038768e-4 +1.69442548025091e-4 +1.68421511031107e-4 +1.66539506236844e-4 +1.63870537117991e-4 +1.6038874820501e-4 +1.56172084911138e-4 +1.51259946463513e-4 +1.45701107814038e-4 +1.39503431050419e-4 +1.32754230059236e-4 +1.25489570576103e-4 +1.17757486894641e-4 +1.09631128039229e-4 +1.0115262933884e-4 +9.23584465403365e-5 +8.33336809092267e-5 +7.41091974779693e-5 +6.47532841902274e-5 +5.53120362349631e-5 +4.58302978650995e-5 +3.63935730200405e-5 +2.70119909588562e-5 +1.77326837630105e-5 +8.65426060083348e-6 +-2.36203952998983e-7 +-8.85204247806303e-6 +-1.72013052766137e-5 +-2.52335267849121e-5 +-3.28791381626816e-5 +-4.01241085336933e-5 +-4.70020380599523e-5 +-5.3369300678592e-5 +-5.93190057095397e-5 +-6.47743915798445e-5 +-6.97213148895689e-5 +-7.4130290344153e-5 +-7.80310589482434e-5 +-8.1438947139124e-5 +-8.42777636122367e-5 +-8.65929014634202e-5 +-8.83699462608486e-5 +-8.96295019021089e-5 +-9.0390962049786e-5 +-9.06277650874391e-5 +-9.03754273981505e-5 +-8.96579831689903e-5 +-8.847590640524e-5 +-8.68637280156417e-5 +-8.48145294498788e-5 +-8.23723520198843e-5 +-7.957469184604e-5 +-7.64220773917906e-5 +-7.29676421256746e-5 +-6.92340008906634e-5 +-6.52252080560519e-5 +-6.09864135270981e-5 +-5.65526133942226e-5 +-5.19552722226438e-5 +-4.71910843635185e-5 +-4.23517165718808e-5 +-3.74096430792575e-5 +-3.2420323875298e-5 +-2.74121537882667e-5 +-2.24193699837587e-5 +-1.74386499250263e-5 +-1.25326516699612e-5 +-7.69928040586833e-6 +-2.97932202860966e-6 +1.62938066833157e-6 +6.06550691029756e-6 +1.0347151946393e-5 +1.44365831918759e-5 +1.83235898190551e-5 +2.19995003725315e-5 +2.54397360410253e-5 +2.86477428425672e-5 +3.16108049585284e-5 +3.42871968756067e-5 +3.67371834848531e-5 +3.88924305216162e-5 +4.08053879668338e-5 +4.24332940559181e-5 +4.37716646911701e-5 +4.48566415488991e-5 +4.56999092246609e-5 +4.61449042224772e-5 +4.6623761079951e-5 +4.66332273332272e-5 +4.63912768895152e-5 +4.5963991898548e-5 +4.53754087968507e-5 +4.45811599449272e-5 +4.355182102547e-5 +4.2335041675049e-5 +4.09448701284991e-5 +3.93896125185267e-5 +3.77083338973254e-5 +3.58854777832478e-5 +3.39767566092725e-5 +3.19813209008917e-5 +2.98938550558335e-5 +2.77448936592136e-5 +2.553385658201e-5 +2.32868013030244e-5 +2.10193314554571e-5 +1.87185665617164e-5 +1.64486730093282e-5 +1.41723759116143e-5 +1.1925384533121e-5 +9.73122206351426e-6 +7.58454405677602e-6 +5.50094513191646e-6 +3.49335533222506e-6 +1.56196204778674e-6 +-3.07184084317173e-7 +-2.05782362044426e-6 +-3.70827372384805e-6 +-5.26687936275949e-6 +-6.71896085473064e-6 +-8.04914399027275e-6 +-9.28900860776593e-6 +-1.03867032653885e-5 +-1.13887071556529e-5 +-1.22550097006306e-5 +-1.30159730761761e-5 +-1.3656619477754e-5 +-1.41826804115075e-5 +-1.46043232504438e-5 +-1.4906159571695e-5 +-1.50946540712042e-5 +-1.51920174272043e-5 +-1.51736783706926e-5 +-1.50872358926362e-5 +-1.48912662330057e-5 +-1.46314856397791e-5 +-1.42903486313313e-5 +-1.38759188766186e-5 +-1.33942943882967e-5 +-1.2856649387849e-5 +-1.22806738594947e-5 +-1.09949811042225e-4 diff --git a/fceumm/src-fceumm/fir/c48000ntsc.h b/fceumm/src-fceumm/fir/c48000ntsc.h new file mode 100644 index 0000000..c48926f --- /dev/null +++ b/fceumm/src-fceumm/fir/c48000ntsc.h @@ -0,0 +1,512 @@ +-115, +-12, +-13, +-14, +-14, +-14, +-15, +-15, +-15, +-15, +-15, +-15, +-15, +-15, +-14, +-14, +-13, +-12, +-11, +-10, +-9, +-8, +-7, +-5, +-3, +-2, +0, +1, +3, +5, +7, +10, +12, +14, +17, +19, +22, +24, +26, +29, +31, +33, +35, +37, +39, +41, +42, +44, +45, +46, +47, +48, +48, +48, +48, +48, +47, +47, +45, +44, +42, +40, +38, +35, +33, +30, +26, +23, +19, +15, +10, +6, +1, +-3, +-8, +-13, +-18, +-23, +-28, +-33, +-39, +-44, +-49, +-54, +-59, +-63, +-68, +-72, +-76, +-80, +-83, +-86, +-88, +-91, +-92, +-94, +-94, +-95, +-94, +-93, +-92, +-90, +-88, +-85, +-81, +-77, +-73, +-67, +-62, +-55, +-49, +-42, +-34, +-26, +-18, +-9, +0, +9, +18, +28, +38, +48, +57, +67, +77, +87, +96, +106, +114, +123, +131, +139, +146, +152, +158, +163, +168, +171, +174, +176, +177, +177, +177, +175, +172, +168, +164, +158, +151, +143, +135, +125, +115, +103, +91, +78, +65, +50, +35, +20, +3, +-12, +-29, +-46, +-63, +-80, +-98, +-115, +-132, +-148, +-165, +-180, +-196, +-210, +-224, +-237, +-248, +-259, +-269, +-277, +-285, +-290, +-295, +-298, +-299, +-299, +-297, +-294, +-289, +-282, +-274, +-264, +-252, +-239, +-224, +-208, +-190, +-171, +-151, +-129, +-106, +-82, +-57, +-31, +-5, +22, +49, +77, +105, +134, +162, +190, +217, +244, +270, +295, +320, +343, +365, +385, +404, +421, +436, +449, +460, +469, +475, +479, +481, +480, +477, +471, +462, +451, +437, +421, +402, +380, +357, +330, +302, +271, +238, +203, +167, +129, +89, +48, +6, +-35, +-79, +-123, +-167, +-211, +-255, +-298, +-341, +-383, +-423, +-462, +-500, +-535, +-569, +-600, +-628, +-654, +-677, +-697, +-713, +-726, +-735, +-741, +-743, +-741, +-735, +-725, +-711, +-693, +-671, +-645, +-616, +-582, +-545, +-504, +-459, +-412, +-361, +-307, +-251, +-192, +-132, +-69, +-5, +60, +126, +193, +260, +328, +394, +460, +525, +588, +650, +709, +765, +819, +869, +916, +958, +997, +1031, +1060, +1084, +1103, +1116, +1124, +1126, +1123, +1113, +1097, +1075, +1047, +1013, +973, +928, +876, +819, +756, +689, +616, +539, +457, +372, +283, +190, +95, +-1, +-100, +-201, +-302, +-404, +-506, +-607, +-706, +-804, +-900, +-993, +-1082, +-1167, +-1248, +-1324, +-1395, +-1459, +-1517, +-1569, +-1613, +-1649, +-1678, +-1698, +-1710, +-1713, +-1707, +-1692, +-1667, +-1634, +-1591, +-1539, +-1478, +-1408, +-1329, +-1242, +-1146, +-1043, +-931, +-813, +-688, +-556, +-419, +-277, +-131, +19, +172, +328, +485, +643, +801, +958, +1113, +1266, +1416, +1561, +1702, +1836, +1964, +2085, +2197, +2300, +2393, +2476, +2548, +2608, +2656, +2690, +2712, +2720, +2713, +2692, +2657, +2607, +2542, +2462, +2367, +2257, +2133, +1994, +1842, +1676, +1497, +1305, +1102, +888, +663, +430, +187, +-61, +-317, +-579, +-844, +-1113, +-1383, +-1653, +-1922, +-2189, +-2452, +-2709, +-2960, +-3203, +-3437, +-3659, +-3869, +-4065, +-4245, +-4409, +-4556, +-4682, +-4789, +-4873, +-4935, +-4973, +-4986, +-4972, +-4933, +-4865, +-4770, +-4646, +-4492, +-4309, +-4096, +-3853, +-3579, +-3276, +-2942, +-2578, +-2185, +-1763, +-1313, +-835, +-330, +200, +755, +1335, +1937, +2560, +3203, +3864, +4543, +5236, +5942, +6660, +7387, +8122, +8863, +9608, +10354, +11099, +11842, +12580, +13311, +14033, +14745, +15443, +16125, +16791, +17436, +18061, +18663, +19239, +19789, +20310, +20801, +21261, +21687, +22079, +22435, +22755, +23037, +23281, +23485, +23649, +23772, +23854, +23896, diff --git a/fceumm/src-fceumm/fir/c48000ntsc.scm b/fceumm/src-fceumm/fir/c48000ntsc.scm new file mode 100644 index 0000000..8ec2a39 --- /dev/null +++ b/fceumm/src-fceumm/fir/c48000ntsc.scm @@ -0,0 +1,12 @@ +(title "48000 NTSC") + +(verbose #t) + +(cosine-symmetry) +(filter-length 1024) +(sampling-frequency 1789772.727272727272) +(limit-= (band 0 17000) 1) +(limit-= (band 24000 894886.363636) 0 .5) +(output-file "c48000ntsc.coef") +(plot-file "c48000ntsc.plot") +(go) diff --git a/fceumm/src-fceumm/fir/c48000pal.coef b/fceumm/src-fceumm/fir/c48000pal.coef new file mode 100644 index 0000000..4a8a5f9 --- /dev/null +++ b/fceumm/src-fceumm/fir/c48000pal.coef @@ -0,0 +1,1039 @@ +;; ***** 48000 PAL ***** +;; Filter length: 1024 +;; Symmetry: cosine +;; Sampling frequency: 1662607.125 +;; Grid density: 10257 +;; Deviation parameter: y=-4.04456123260461e-4 +;; +;; Specifications: +;; (limit > 24000 831303.5625 0 0.5) +;; (limit < 24000 831303.5625 0 0.5) +;; (limit > 0 17500 1 1) +;; (limit < 0 17500 1 1) +;; +;; Coefficients: + +1.0783172932896e-4 +1.3561475850253e-5 +1.43150420416283e-5 +1.49886363377349e-5 +1.56015105099026e-5 +1.61381192401086e-5 +1.66025516801309e-5 +1.69644855111871e-5 +1.72420268548982e-5 +1.74096049850514e-5 +1.7466907549538e-5 +1.74305599416104e-5 +1.72624970620822e-5 +1.69512561328662e-5 +1.65342695578314e-5 +1.59775197454088e-5 +1.52766280693198e-5 +1.44428101292738e-5 +1.34684866379703e-5 +1.23509418255071e-5 +1.1081808312081e-5 +9.68440865212042e-6 +8.15580831379911e-6 +6.49256056198478e-6 +4.70330948990956e-6 +2.7936406340967e-6 +7.85613395286448e-7 +-1.32808013796309e-6 +-3.52876960484536e-6 +-5.8080561629844e-6 +-8.15813413487457e-6 +-1.05512845558752e-5 +-1.30105356059099e-5 +-1.54617489968656e-5 +-1.79517990398971e-5 +-2.04397035642729e-5 +-2.28952912040035e-5 +-2.53180967028265e-5 +-2.76813804395839e-5 +-2.99602884421574e-5 +-3.21440371766843e-5 +-3.42144286692688e-5 +-3.61550983136946e-5 +-3.7936448702778e-5 +-3.95673425206259e-5 +-4.10009072283261e-5 +-4.22696474647012e-5 +-4.330258187421e-5 +-4.41187219554721e-5 +-4.46550647769792e-5 +-4.49347491986505e-5 +-4.49183030848856e-5 +-4.46584800684937e-5 +-4.41642416915663e-5 +-4.33946068310562e-5 +-4.20871716501139e-5 +-4.07538528085648e-5 +-3.89585839480776e-5 +-3.69098747867203e-5 +-3.45543123183317e-5 +-3.18949347092464e-5 +-2.89523632049071e-5 +-2.57213276898428e-5 +-2.22202644601619e-5 +-1.84617206755275e-5 +-1.44991867492458e-5 +-1.02613766503818e-5 +-5.85405894330665e-6 +-1.27028212217224e-6 +3.4875707995152e-6 +8.36526659552602e-6 +1.33338533249663e-5 +1.8385703423788e-5 +2.34769030974947e-5 +2.85812390861387e-5 +3.36580878548364e-5 +3.86654975743835e-5 +4.3578901034037e-5 +4.83892064467925e-5 +5.29979535540185e-5 +5.74271144638819e-5 +6.16215703975737e-5 +6.55395388635905e-5 +6.91595354640541e-5 +7.24387952032281e-5 +7.53549961562705e-5 +7.78768810641327e-5 +7.99367008803979e-5 +8.15775690813463e-5 +8.27210398644824e-5 +8.336395615943e-5 +8.34873471492661e-5 +8.3069518826596e-5 +8.20987920151301e-5 +8.05698418267922e-5 +7.84588588088235e-5 +7.57790438357932e-5 +7.25271257954213e-5 +6.869107843266e-5 +6.42839469147515e-5 +5.93705790211257e-5 +5.38840838876231e-5 +4.7915115002444e-5 +4.14264390433695e-5 +3.44799673466393e-5 +2.70923034925926e-5 +1.93377097998663e-5 +1.12230483582735e-5 +2.77563609884032e-6 +-5.95253220278385e-6 +-1.48596469580734e-5 +-2.39905698155697e-5 +-3.31928444133421e-5 +-4.24774078883453e-5 +-5.17561952024819e-5 +-6.09681170673795e-5 +-7.00816711966441e-5 +-7.89965327587163e-5 +-8.76739937512259e-5 +-9.60257665780481e-5 +-1.040422410093e-4 +-1.1158288385138e-4 +-1.18671435004228e-4 +-1.25189526359341e-4 +-1.31095577074443e-4 +-1.3633898735937e-4 +-1.40872811972437e-4 +-1.44637497417931e-4 +-1.47604758781598e-4 +-1.49721217177156e-4 +-1.50937788247908e-4 +-1.51260723345739e-4 +-1.50640490277245e-4 +-1.49027129666833e-4 +-1.46478116043421e-4 +-1.4290837237091e-4 +-1.38355651240051e-4 +-1.32821684691922e-4 +-1.26301014847642e-4 +-1.18832774313583e-4 +-1.10412614981825e-4 +-1.01079807360939e-4 +-9.08863150937633e-5 +-7.9855536779786e-5 +-6.80420533998678e-5 +-5.55036002160919e-5 +-4.23070943880991e-5 +-2.85100491723636e-5 +-1.41910602190798e-5 +5.74159896625749e-7 +1.5685350087147e-5 +3.10821961290075e-5 +4.66746733164285e-5 +6.23410430656923e-5 +7.79838341733242e-5 +9.35400846529469e-5 +1.08858050814022e-4 +1.23885745586263e-4 +1.38490587292571e-4 +1.52569798991098e-4 +1.6602735554204e-4 +1.78757451082868e-4 +1.90662487656944e-4 +2.0165164397247e-4 +2.11641859228633e-4 +2.20511364369255e-4 +2.2822201475425e-4 +2.34662780276811e-4 +2.39770894383923e-4 +2.43490345927973e-4 +2.45765411178182e-4 +2.46534390337095e-4 +2.45775167592942e-4 +2.43426392718766e-4 +2.39499784238424e-4 +2.33967252721536e-4 +2.2684189259918e-4 +2.18093865253775e-4 +2.0779413468937e-4 +1.95927141401289e-4 +1.82552706187548e-4 +1.67719946286442e-4 +1.5149295655487e-4 +1.33932663941035e-4 +1.15116784735802e-4 +9.51630411589421e-5 +7.41353615298954e-5 +5.21718190054817e-5 +2.93810695999424e-5 +5.86942660727624e-6 +-1.81928117661243e-5 +-4.26953547177328e-5 +-6.74884760425993e-5 +-9.24000620732457e-5 +-1.17306452222934e-4 +-1.42028053706926e-4 +-1.6641748536327e-4 +-1.90295327481145e-4 +-2.13526648772877e-4 +-2.35920378174742e-4 +-2.57335540622496e-4 +-2.77618149216888e-4 +-2.96599532917617e-4 +-3.14140693377271e-4 +-3.30094800932447e-4 +-3.44339603052102e-4 +-3.56739336123611e-4 +-3.67174212136651e-4 +-3.75531849424532e-4 +-3.81724589486029e-4 +-3.85657939336761e-4 +-3.87265732840677e-4 +-3.86491839797252e-4 +-3.83275416154692e-4 +-3.7760973646446e-4 +-3.69439578879e-4 +-3.58799773629522e-4 +-3.45691587198199e-4 +-3.30143612933627e-4 +-3.12196804269503e-4 +-2.91948940195075e-4 +-2.6941592693139e-4 +-2.4475129607813e-4 +-2.18033329216043e-4 +-1.89400291263887e-4 +-1.59001839727708e-4 +-1.26964645968482e-4 +-9.3468599675526e-5 +-5.87099485768434e-5 +-2.28718895559617e-5 +1.38661453336005e-5 +5.12504716648456e-5 +8.90765541567582e-5 +1.27141536384486e-4 +1.6517131814265e-4 +2.02945866294048e-4 +2.40219213745026e-4 +2.76746123957115e-4 +3.12293133420806e-4 +3.46593092375836e-4 +3.79424363443158e-4 +4.1054132937402e-4 +4.39736117650459e-4 +4.66739582083122e-4 +4.91387907517869e-4 +5.1345669379648e-4 +5.32755361807803e-4 +5.4909940710768e-4 +5.62348662402172e-4 +5.72345993122783e-4 +5.7896654574189e-4 +5.82090419479584e-4 +5.81654406347142e-4 +5.77562548184356e-4 +5.69788762315823e-4 +5.58298302006844e-4 +5.43090048796913e-4 +5.24193502963293e-4 +5.0164051079223e-4 +4.75510033518712e-4 +4.45905690887374e-4 +4.12931250800377e-4 +3.76718492573694e-4 +3.37454368210552e-4 +2.95309158288872e-4 +2.50487407773454e-4 +2.03239263665977e-4 +1.53785113286668e-4 +1.02426054275038e-4 +4.94039771196527e-5 +-4.9436684286017e-6 +-6.03298616514903e-5 +-1.16406402480797e-4 +-1.72843182266513e-4 +-2.29302160827241e-4 +-2.85424280783829e-4 +-3.40849878416515e-4 +-3.95231606514409e-4 +-4.4818593119753e-4 +-4.99366108188115e-4 +-5.48439341418767e-4 +-5.95017923651795e-4 +-6.38796736934187e-4 +-6.79430579536826e-4 +-7.16620285053831e-4 +-7.50034221495514e-4 +-7.79437560472454e-4 +-8.0454137082786e-4 +-8.25108701083097e-4 +-8.40934131367373e-4 +-8.51820948123654e-4 +-8.57609584970445e-4 +-8.58175472793311e-4 +-8.53390483100241e-4 +-8.43209551079894e-4 +-8.27590879655203e-4 +-8.06510409502537e-4 +-7.79995072230027e-4 +-7.48155417238511e-4 +-7.11020274128235e-4 +-6.68770312317841e-4 +-6.21544132125251e-4 +-5.69560032134081e-4 +-5.13047603992703e-4 +-4.52260267743927e-4 +-3.87511758268314e-4 +-3.19128561449503e-4 +-2.47461748174838e-4 +-1.72891786174927e-4 +-9.58451800481746e-5 +-1.67437726740921e-5 +6.39622864075221e-5 +1.45802914515735e-4 +2.28276969072054e-4 +3.10881168326302e-4 +3.931285095721e-4 +4.74478553853189e-4 +5.54406623481691e-4 +6.32405031540309e-4 +7.07946519860834e-4 +7.80505190513501e-4 +8.49580370607698e-4 +9.14664923660729e-4 +9.75306400682111e-4 +0.00103102014646356 +0.00108137261722973 +0.00112594391364669 +0.00116436209978936 +0.00119625989249914 +0.00122130266875817 +0.00123924969043022 +0.00124980344180312 +0.00125278240951216 +0.00124802165372955 +0.00123540269762469 +0.00121484756393481 +0.0011863534276383 +0.00114991049765994 +0.00110562855369365 +0.0010536068934269 +9.94030202153522e-4 +9.27120376158647e-4 +8.53156860257162e-4 +7.72454365212224e-4 +6.85390250514192e-4 +5.92375082207849e-4 +4.9387876727933e-4 +3.90393002098172e-4 +2.82480107088887e-4 +1.7070831244188e-4 +5.56879005104824e-5 +-6.1906284350905e-5 +-1.81415283544607e-4 +-3.02142730803428e-4 +-4.2333875391934e-4 +-5.44296445422888e-4 +-6.64236400947683e-4 +-7.82407565044765e-4 +-8.98051026608098e-4 +-0.00101038113005766 +-0.00111866302268561 +-0.0012221295410412 +-0.0013200609608465 +-0.00141171609738229 +-0.00149643580490023 +-0.00157354248105082 +-0.00164240522652266 +-0.00170243934737355 +-0.00175309370471778 +-0.00179387496858474 +-0.00182430930810295 +-0.00184402395447169 +-0.00185266724915187 +-0.00184997271570004 +-0.00183570586409282 +-0.00180972121663046 +-0.00177195203127539 +-0.00172237368010418 +-0.00166105454652476 +-0.00158811703816067 +-0.00150378726049984 +-0.00140832762076639 +-0.0013020899508538 +-0.00118551225223178 +-0.00105910322772149 +-9.23393236851473e-4 +-7.79055327805226e-4 +-6.26768212465557e-4 +-4.67302931140705e-4 +-3.01491270723501e-4 +-1.30195855297908e-4 +4.56401652766111e-5 +2.25027067508283e-4 +4.06972972690671e-4 +5.90405019516109e-4 +7.74216306706467e-4 +9.57318662226946e-4 +0.00113855626997318 +0.00131678634527204 +0.0014908552858621 +0.00165959118483483 +0.00182185835208505 +0.00197650815267658 +0.00212242280398454 +0.00225851246246872 +0.00238371539035943 +0.00249702508323125 +0.00259744117052929 +0.0026840846677887 +0.00275607645257497 +0.00281263432325704 +0.0028530403230186 +0.0028766569205693 +0.00288293135970344 +0.00287140344532155 +0.00284168448509905 +0.00279352301691183 +0.00272673120228367 +0.00264124885341234 +0.00253711261587615 +0.00241447127968604 +0.00227360193577821 +0.00211485651002808 +0.00193873386299929 +0.00174582789013106 +0.00153686167145326 +0.00131264246333188 +0.00107412717117761 +8.22324668075117e-4 +5.58399255126717e-4 +2.83585936906761e-4 +-7.91653518883316e-7 +-2.93275867453424e-4 +-5.92385560905748e-4 +-8.96504293668282e-4 +-0.0012039962137455 +-0.00151310994118933 +-0.00182206762040076 +-0.00212903602637386 +-0.00243213041621861 +-0.00272944724644087 +-0.00301904353935261 +-0.0032989847822554 +-0.00356729741889108 +-0.00382205238995045 +-0.0040612825745775 +-0.00428310710833949 +-0.0044856335950343 +-0.00466702696411301 +-0.00482550437652975 +-0.0049593584042375 +-0.00506692577218407 +-0.00514666052596478 +-0.0051970785659304 +-0.00521680784237087 +-0.0052045920045337 +-0.00515926816288351 +-0.00507981542203718 +-0.00496534580148461 +-0.00481509247434497 +-0.00462843395985089 +-0.00440489964062938 +-0.00414419512168892 +-0.0038461191704701 +-0.00351070824147442 +-0.00313809095768648 +-0.00272861114037865 +-0.00228275272798312 +-0.0018011488246512 +-0.00128463575154861 +-7.34189492529516e-4 +-1.50939392418879e-4 +4.63827670998463e-4 +0.001108634043237 +0.00178191442074677 +0.00248189327531725 +0.00320672778303872 +0.0039543772472654 +0.00472272054027297 +0.0055095123033422 +0.00631238695466698 +0.00712888111691215 +0.00795646562805878 +0.0087925100600243 +0.00963433252114155 +0.0104791770461524 +0.0113242494156599 +0.0121667411979553 +0.0130037845552242 +0.0138325371327049 +0.0146501343342719 +0.015453752838051 +0.0162405643560213 +0.0170077895549428 +0.017752734005397 +0.0184727026611722 +0.0191651536375909 +0.0198275436619083 +0.0204575091596416 +0.0210527297897325 +0.021611049283905 +0.0221303981307109 +0.0226088947033753 +0.0230447502475501 +0.023436353984896 +0.0237822666417811 +0.0240811879818443 +0.0243320190632054 +0.0245338129670568 +0.0246858223616 +0.0247874779906384 +0.0248384026328523 +0.0248384026328523 +0.0247874779906384 +0.0246858223616 +0.0245338129670568 +0.0243320190632054 +0.0240811879818443 +0.0237822666417811 +0.023436353984896 +0.0230447502475501 +0.0226088947033753 +0.0221303981307109 +0.021611049283905 +0.0210527297897325 +0.0204575091596416 +0.0198275436619083 +0.0191651536375909 +0.0184727026611722 +0.017752734005397 +0.0170077895549428 +0.0162405643560213 +0.015453752838051 +0.0146501343342719 +0.0138325371327049 +0.0130037845552242 +0.0121667411979553 +0.0113242494156599 +0.0104791770461524 +0.00963433252114155 +0.0087925100600243 +0.00795646562805878 +0.00712888111691215 +0.00631238695466698 +0.0055095123033422 +0.00472272054027297 +0.0039543772472654 +0.00320672778303872 +0.00248189327531725 +0.00178191442074677 +0.001108634043237 +4.63827670998463e-4 +-1.50939392418879e-4 +-7.34189492529516e-4 +-0.00128463575154861 +-0.0018011488246512 +-0.00228275272798312 +-0.00272861114037865 +-0.00313809095768648 +-0.00351070824147442 +-0.0038461191704701 +-0.00414419512168892 +-0.00440489964062938 +-0.00462843395985089 +-0.00481509247434497 +-0.00496534580148461 +-0.00507981542203718 +-0.00515926816288351 +-0.0052045920045337 +-0.00521680784237087 +-0.0051970785659304 +-0.00514666052596478 +-0.00506692577218407 +-0.0049593584042375 +-0.00482550437652975 +-0.00466702696411301 +-0.0044856335950343 +-0.00428310710833949 +-0.0040612825745775 +-0.00382205238995045 +-0.00356729741889108 +-0.0032989847822554 +-0.00301904353935261 +-0.00272944724644087 +-0.00243213041621861 +-0.00212903602637386 +-0.00182206762040076 +-0.00151310994118933 +-0.0012039962137455 +-8.96504293668282e-4 +-5.92385560905748e-4 +-2.93275867453424e-4 +-7.91653518883316e-7 +2.83585936906761e-4 +5.58399255126717e-4 +8.22324668075117e-4 +0.00107412717117761 +0.00131264246333188 +0.00153686167145326 +0.00174582789013106 +0.00193873386299929 +0.00211485651002808 +0.00227360193577821 +0.00241447127968604 +0.00253711261587615 +0.00264124885341234 +0.00272673120228367 +0.00279352301691183 +0.00284168448509905 +0.00287140344532155 +0.00288293135970344 +0.0028766569205693 +0.0028530403230186 +0.00281263432325704 +0.00275607645257497 +0.0026840846677887 +0.00259744117052929 +0.00249702508323125 +0.00238371539035943 +0.00225851246246872 +0.00212242280398454 +0.00197650815267658 +0.00182185835208505 +0.00165959118483483 +0.0014908552858621 +0.00131678634527204 +0.00113855626997318 +9.57318662226946e-4 +7.74216306706467e-4 +5.90405019516109e-4 +4.06972972690671e-4 +2.25027067508283e-4 +4.56401652766111e-5 +-1.30195855297908e-4 +-3.01491270723501e-4 +-4.67302931140705e-4 +-6.26768212465557e-4 +-7.79055327805226e-4 +-9.23393236851473e-4 +-0.00105910322772149 +-0.00118551225223178 +-0.0013020899508538 +-0.00140832762076639 +-0.00150378726049984 +-0.00158811703816067 +-0.00166105454652476 +-0.00172237368010418 +-0.00177195203127539 +-0.00180972121663046 +-0.00183570586409282 +-0.00184997271570004 +-0.00185266724915187 +-0.00184402395447169 +-0.00182430930810295 +-0.00179387496858474 +-0.00175309370471778 +-0.00170243934737355 +-0.00164240522652266 +-0.00157354248105082 +-0.00149643580490023 +-0.00141171609738229 +-0.0013200609608465 +-0.0012221295410412 +-0.00111866302268561 +-0.00101038113005766 +-8.98051026608098e-4 +-7.82407565044765e-4 +-6.64236400947683e-4 +-5.44296445422888e-4 +-4.2333875391934e-4 +-3.02142730803428e-4 +-1.81415283544607e-4 +-6.1906284350905e-5 +5.56879005104824e-5 +1.7070831244188e-4 +2.82480107088887e-4 +3.90393002098172e-4 +4.9387876727933e-4 +5.92375082207849e-4 +6.85390250514192e-4 +7.72454365212224e-4 +8.53156860257162e-4 +9.27120376158647e-4 +9.94030202153522e-4 +0.0010536068934269 +0.00110562855369365 +0.00114991049765994 +0.0011863534276383 +0.00121484756393481 +0.00123540269762469 +0.00124802165372955 +0.00125278240951216 +0.00124980344180312 +0.00123924969043022 +0.00122130266875817 +0.00119625989249914 +0.00116436209978936 +0.00112594391364669 +0.00108137261722973 +0.00103102014646356 +9.75306400682111e-4 +9.14664923660729e-4 +8.49580370607698e-4 +7.80505190513501e-4 +7.07946519860834e-4 +6.32405031540309e-4 +5.54406623481691e-4 +4.74478553853189e-4 +3.931285095721e-4 +3.10881168326302e-4 +2.28276969072054e-4 +1.45802914515735e-4 +6.39622864075221e-5 +-1.67437726740921e-5 +-9.58451800481746e-5 +-1.72891786174927e-4 +-2.47461748174838e-4 +-3.19128561449503e-4 +-3.87511758268314e-4 +-4.52260267743927e-4 +-5.13047603992703e-4 +-5.69560032134081e-4 +-6.21544132125251e-4 +-6.68770312317841e-4 +-7.11020274128235e-4 +-7.48155417238511e-4 +-7.79995072230027e-4 +-8.06510409502537e-4 +-8.27590879655203e-4 +-8.43209551079894e-4 +-8.53390483100241e-4 +-8.58175472793311e-4 +-8.57609584970445e-4 +-8.51820948123654e-4 +-8.40934131367373e-4 +-8.25108701083097e-4 +-8.0454137082786e-4 +-7.79437560472454e-4 +-7.50034221495514e-4 +-7.16620285053831e-4 +-6.79430579536826e-4 +-6.38796736934187e-4 +-5.95017923651795e-4 +-5.48439341418767e-4 +-4.99366108188115e-4 +-4.4818593119753e-4 +-3.95231606514409e-4 +-3.40849878416515e-4 +-2.85424280783829e-4 +-2.29302160827241e-4 +-1.72843182266513e-4 +-1.16406402480797e-4 +-6.03298616514903e-5 +-4.9436684286017e-6 +4.94039771196527e-5 +1.02426054275038e-4 +1.53785113286668e-4 +2.03239263665977e-4 +2.50487407773454e-4 +2.95309158288872e-4 +3.37454368210552e-4 +3.76718492573694e-4 +4.12931250800377e-4 +4.45905690887374e-4 +4.75510033518712e-4 +5.0164051079223e-4 +5.24193502963293e-4 +5.43090048796913e-4 +5.58298302006844e-4 +5.69788762315823e-4 +5.77562548184356e-4 +5.81654406347142e-4 +5.82090419479584e-4 +5.7896654574189e-4 +5.72345993122783e-4 +5.62348662402172e-4 +5.4909940710768e-4 +5.32755361807803e-4 +5.1345669379648e-4 +4.91387907517869e-4 +4.66739582083122e-4 +4.39736117650459e-4 +4.1054132937402e-4 +3.79424363443158e-4 +3.46593092375836e-4 +3.12293133420806e-4 +2.76746123957115e-4 +2.40219213745026e-4 +2.02945866294048e-4 +1.6517131814265e-4 +1.27141536384486e-4 +8.90765541567582e-5 +5.12504716648456e-5 +1.38661453336005e-5 +-2.28718895559617e-5 +-5.87099485768434e-5 +-9.3468599675526e-5 +-1.26964645968482e-4 +-1.59001839727708e-4 +-1.89400291263887e-4 +-2.18033329216043e-4 +-2.4475129607813e-4 +-2.6941592693139e-4 +-2.91948940195075e-4 +-3.12196804269503e-4 +-3.30143612933627e-4 +-3.45691587198199e-4 +-3.58799773629522e-4 +-3.69439578879e-4 +-3.7760973646446e-4 +-3.83275416154692e-4 +-3.86491839797252e-4 +-3.87265732840677e-4 +-3.85657939336761e-4 +-3.81724589486029e-4 +-3.75531849424532e-4 +-3.67174212136651e-4 +-3.56739336123611e-4 +-3.44339603052102e-4 +-3.30094800932447e-4 +-3.14140693377271e-4 +-2.96599532917617e-4 +-2.77618149216888e-4 +-2.57335540622496e-4 +-2.35920378174742e-4 +-2.13526648772877e-4 +-1.90295327481145e-4 +-1.6641748536327e-4 +-1.42028053706926e-4 +-1.17306452222934e-4 +-9.24000620732457e-5 +-6.74884760425993e-5 +-4.26953547177328e-5 +-1.81928117661243e-5 +5.86942660727624e-6 +2.93810695999424e-5 +5.21718190054817e-5 +7.41353615298954e-5 +9.51630411589421e-5 +1.15116784735802e-4 +1.33932663941035e-4 +1.5149295655487e-4 +1.67719946286442e-4 +1.82552706187548e-4 +1.95927141401289e-4 +2.0779413468937e-4 +2.18093865253775e-4 +2.2684189259918e-4 +2.33967252721536e-4 +2.39499784238424e-4 +2.43426392718766e-4 +2.45775167592942e-4 +2.46534390337095e-4 +2.45765411178182e-4 +2.43490345927973e-4 +2.39770894383923e-4 +2.34662780276811e-4 +2.2822201475425e-4 +2.20511364369255e-4 +2.11641859228633e-4 +2.0165164397247e-4 +1.90662487656944e-4 +1.78757451082868e-4 +1.6602735554204e-4 +1.52569798991098e-4 +1.38490587292571e-4 +1.23885745586263e-4 +1.08858050814022e-4 +9.35400846529469e-5 +7.79838341733242e-5 +6.23410430656923e-5 +4.66746733164285e-5 +3.10821961290075e-5 +1.5685350087147e-5 +5.74159896625749e-7 +-1.41910602190798e-5 +-2.85100491723636e-5 +-4.23070943880991e-5 +-5.55036002160919e-5 +-6.80420533998678e-5 +-7.9855536779786e-5 +-9.08863150937633e-5 +-1.01079807360939e-4 +-1.10412614981825e-4 +-1.18832774313583e-4 +-1.26301014847642e-4 +-1.32821684691922e-4 +-1.38355651240051e-4 +-1.4290837237091e-4 +-1.46478116043421e-4 +-1.49027129666833e-4 +-1.50640490277245e-4 +-1.51260723345739e-4 +-1.50937788247908e-4 +-1.49721217177156e-4 +-1.47604758781598e-4 +-1.44637497417931e-4 +-1.40872811972437e-4 +-1.3633898735937e-4 +-1.31095577074443e-4 +-1.25189526359341e-4 +-1.18671435004228e-4 +-1.1158288385138e-4 +-1.040422410093e-4 +-9.60257665780481e-5 +-8.76739937512259e-5 +-7.89965327587163e-5 +-7.00816711966441e-5 +-6.09681170673795e-5 +-5.17561952024819e-5 +-4.24774078883453e-5 +-3.31928444133421e-5 +-2.39905698155697e-5 +-1.48596469580734e-5 +-5.95253220278385e-6 +2.77563609884032e-6 +1.12230483582735e-5 +1.93377097998663e-5 +2.70923034925926e-5 +3.44799673466393e-5 +4.14264390433695e-5 +4.7915115002444e-5 +5.38840838876231e-5 +5.93705790211257e-5 +6.42839469147515e-5 +6.869107843266e-5 +7.25271257954213e-5 +7.57790438357932e-5 +7.84588588088235e-5 +8.05698418267922e-5 +8.20987920151301e-5 +8.3069518826596e-5 +8.34873471492661e-5 +8.336395615943e-5 +8.27210398644824e-5 +8.15775690813463e-5 +7.99367008803979e-5 +7.78768810641327e-5 +7.53549961562705e-5 +7.24387952032281e-5 +6.91595354640541e-5 +6.55395388635905e-5 +6.16215703975737e-5 +5.74271144638819e-5 +5.29979535540185e-5 +4.83892064467925e-5 +4.3578901034037e-5 +3.86654975743835e-5 +3.36580878548364e-5 +2.85812390861387e-5 +2.34769030974947e-5 +1.8385703423788e-5 +1.33338533249663e-5 +8.36526659552602e-6 +3.4875707995152e-6 +-1.27028212217224e-6 +-5.85405894330665e-6 +-1.02613766503818e-5 +-1.44991867492458e-5 +-1.84617206755275e-5 +-2.22202644601619e-5 +-2.57213276898428e-5 +-2.89523632049071e-5 +-3.18949347092464e-5 +-3.45543123183317e-5 +-3.69098747867203e-5 +-3.89585839480776e-5 +-4.07538528085648e-5 +-4.20871716501139e-5 +-4.33946068310562e-5 +-4.41642416915663e-5 +-4.46584800684937e-5 +-4.49183030848856e-5 +-4.49347491986505e-5 +-4.46550647769792e-5 +-4.41187219554721e-5 +-4.330258187421e-5 +-4.22696474647012e-5 +-4.10009072283261e-5 +-3.95673425206259e-5 +-3.7936448702778e-5 +-3.61550983136946e-5 +-3.42144286692688e-5 +-3.21440371766843e-5 +-2.99602884421574e-5 +-2.76813804395839e-5 +-2.53180967028265e-5 +-2.28952912040035e-5 +-2.04397035642729e-5 +-1.79517990398971e-5 +-1.54617489968656e-5 +-1.30105356059099e-5 +-1.05512845558752e-5 +-8.15813413487457e-6 +-5.8080561629844e-6 +-3.52876960484536e-6 +-1.32808013796309e-6 +7.85613395286448e-7 +2.7936406340967e-6 +4.70330948990956e-6 +6.49256056198478e-6 +8.15580831379911e-6 +9.68440865212042e-6 +1.1081808312081e-5 +1.23509418255071e-5 +1.34684866379703e-5 +1.44428101292738e-5 +1.52766280693198e-5 +1.59775197454088e-5 +1.65342695578314e-5 +1.69512561328662e-5 +1.72624970620822e-5 +1.74305599416104e-5 +1.7466907549538e-5 +1.74096049850514e-5 +1.72420268548982e-5 +1.69644855111871e-5 +1.66025516801309e-5 +1.61381192401086e-5 +1.56015105099026e-5 +1.49886363377349e-5 +1.43150420416283e-5 +1.3561475850253e-5 +1.0783172932896e-4 diff --git a/fceumm/src-fceumm/fir/c48000pal.h b/fceumm/src-fceumm/fir/c48000pal.h new file mode 100644 index 0000000..c72849f --- /dev/null +++ b/fceumm/src-fceumm/fir/c48000pal.h @@ -0,0 +1,512 @@ +113, +14, +15, +15, +16, +16, +17, +17, +18, +18, +18, +18, +18, +17, +17, +16, +16, +15, +14, +12, +11, +10, +8, +6, +4, +2, +0, +-1, +-3, +-6, +-8, +-11, +-13, +-16, +-18, +-21, +-24, +-26, +-29, +-31, +-33, +-35, +-37, +-39, +-41, +-42, +-44, +-45, +-46, +-46, +-47, +-47, +-46, +-46, +-45, +-44, +-42, +-40, +-38, +-36, +-33, +-30, +-26, +-23, +-19, +-15, +-10, +-6, +-1, +3, +8, +13, +19, +24, +29, +35, +40, +45, +50, +55, +60, +64, +68, +72, +75, +79, +81, +83, +85, +86, +87, +87, +87, +86, +84, +82, +79, +76, +72, +67, +62, +56, +50, +43, +36, +28, +20, +11, +2, +-6, +-15, +-25, +-34, +-44, +-54, +-63, +-73, +-82, +-91, +-100, +-109, +-117, +-124, +-131, +-137, +-142, +-147, +-151, +-154, +-156, +-158, +-158, +-157, +-156, +-153, +-149, +-145, +-139, +-132, +-124, +-115, +-105, +-95, +-83, +-71, +-58, +-44, +-29, +-14, +0, +16, +32, +48, +65, +81, +98, +114, +129, +145, +159, +174, +187, +199, +211, +221, +231, +239, +246, +251, +255, +257, +258, +257, +255, +251, +245, +237, +228, +217, +205, +191, +175, +158, +140, +120, +99, +77, +54, +30, +6, +-19, +-44, +-70, +-96, +-123, +-148, +-174, +-199, +-223, +-247, +-269, +-291, +-311, +-329, +-346, +-361, +-374, +-385, +-393, +-400, +-404, +-406, +-405, +-401, +-395, +-387, +-376, +-362, +-346, +-327, +-306, +-282, +-256, +-228, +-198, +-166, +-133, +-98, +-61, +-23, +14, +53, +93, +133, +173, +212, +251, +290, +327, +363, +397, +430, +461, +489, +515, +538, +558, +575, +589, +600, +607, +610, +609, +605, +597, +585, +569, +549, +526, +498, +467, +432, +395, +353, +309, +262, +213, +161, +107, +51, +-5, +-63, +-122, +-181, +-240, +-299, +-357, +-414, +-469, +-523, +-575, +-623, +-669, +-712, +-751, +-786, +-817, +-843, +-865, +-881, +-893, +-899, +-899, +-894, +-884, +-867, +-845, +-817, +-784, +-745, +-701, +-651, +-597, +-537, +-474, +-406, +-334, +-259, +-181, +-100, +-17, +67, +152, +239, +325, +412, +497, +581, +663, +742, +818, +890, +959, +1022, +1081, +1133, +1180, +1220, +1254, +1280, +1299, +1310, +1313, +1308, +1295, +1273, +1243, +1205, +1159, +1104, +1042, +972, +894, +809, +718, +621, +517, +409, +296, +179, +58, +-64, +-190, +-316, +-443, +-570, +-696, +-820, +-941, +-1059, +-1173, +-1281, +-1384, +-1480, +-1569, +-1649, +-1722, +-1785, +-1838, +-1881, +-1912, +-1933, +-1942, +-1939, +-1924, +-1897, +-1858, +-1806, +-1741, +-1665, +-1576, +-1476, +-1365, +-1243, +-1110, +-968, +-816, +-657, +-490, +-316, +-136, +47, +235, +426, +619, +811, +1003, +1193, +1380, +1563, +1740, +1910, +2072, +2225, +2368, +2499, +2618, +2723, +2814, +2889, +2949, +2991, +3016, +3022, +3010, +2979, +2929, +2859, +2769, +2660, +2531, +2384, +2217, +2032, +1830, +1611, +1376, +1126, +862, +585, +297, +0, +-307, +-621, +-940, +-1262, +-1586, +-1910, +-2232, +-2550, +-2862, +-3165, +-3459, +-3740, +-4007, +-4258, +-4491, +-4703, +-4893, +-5059, +-5200, +-5313, +-5396, +-5449, +-5470, +-5457, +-5409, +-5326, +-5206, +-5048, +-4853, +-4618, +-4345, +-4032, +-3681, +-3290, +-2861, +-2393, +-1888, +-1347, +-769, +-158, +486, +1162, +1868, +2602, +3362, +4146, +4952, +5777, +6619, +7475, +8342, +9219, +10102, +10988, +11874, +12757, +13635, +14504, +15361, +16204, +17029, +17833, +18615, +19370, +20096, +20790, +21451, +22075, +22660, +23205, +23707, +24164, +24574, +24937, +25250, +25513, +25725, +25884, +25991, +26044, diff --git a/fceumm/src-fceumm/fir/c48000pal.scm b/fceumm/src-fceumm/fir/c48000pal.scm new file mode 100644 index 0000000..4722b8d --- /dev/null +++ b/fceumm/src-fceumm/fir/c48000pal.scm @@ -0,0 +1,12 @@ +(title "48000 PAL") + +(verbose #t) + +(cosine-symmetry) +(filter-length 1024) +(sampling-frequency 1662607.125) +(limit-= (band 0 17500) 1) +(limit-= (band 24000 831303.5625) 0 .5) +(output-file "c48000pal.coef") +(plot-file "c48000pal.plot") +(go) diff --git a/fceumm/src-fceumm/fir/c96000ntsc.coef b/fceumm/src-fceumm/fir/c96000ntsc.coef new file mode 100644 index 0000000..a6b9201 --- /dev/null +++ b/fceumm/src-fceumm/fir/c96000ntsc.coef @@ -0,0 +1,1039 @@ +;; ***** 96000 NTSC ***** +;; Filter length: 1024 +;; Symmetry: cosine +;; Sampling frequency: 1789772.72727273 +;; Grid density: 10257 +;; Deviation parameter: y=-3.41994150089587e-6 +;; +;; Specifications: +;; (limit > 48000 894886.363636 0 0.5) +;; (limit < 48000 894886.363636 0 0.5) +;; (limit > 0 36000 1 1) +;; (limit < 0 36000 1 1) +;; +;; Coefficients: + +6.25765784406859e-7 +-5.74349474884059e-7 +-4.38563052056152e-7 +-4.2275208095965e-7 +-4.22986843582035e-7 +-4.62591739880567e-7 +-4.87548260748437e-7 +-5.09702102203457e-7 +-5.53575138212173e-7 +-5.58776629837758e-7 +-5.61504899335206e-7 +-5.87512127558038e-7 +-5.61361967225389e-7 +-5.3712751262779e-7 +-5.01344341031087e-7 +-4.53511011468631e-7 +-3.38624331418706e-7 +-2.44517851394823e-7 +-1.54707945258839e-7 +-5.05264098238236e-9 +1.44876241366308e-7 +2.81681324083492e-7 +4.3227430974949e-7 +6.00075575484758e-7 +7.75112423789865e-7 +9.21520058445204e-7 +1.09935217260167e-6 +1.25500772923897e-6 +1.34551951148203e-6 +1.46860535142565e-6 +1.55182559228546e-6 +1.60770440406623e-6 +1.6294811644839e-6 +1.61363975974438e-6 +1.53782569699597e-6 +1.43132387640668e-6 +1.28959869628182e-6 +1.10621331781889e-6 +8.5785768415765e-7 +6.04567255230193e-7 +2.96426729531177e-7 +-5.24862218589967e-8 +-4.3476366150865e-7 +-8.17500360283736e-7 +-1.21281774093872e-6 +-1.6246903514035e-6 +-2.03191995568737e-6 +-2.42034886505034e-6 +-2.77710918199585e-6 +-3.08872255757467e-6 +-3.34868062209883e-6 +-3.54951933335568e-6 +-3.67684205210421e-6 +-3.75096178007138e-6 +-3.73781668478926e-6 +-3.62820827681515e-6 +-3.40106555337159e-6 +-3.10558378787101e-6 +-2.73085981209485e-6 +-2.23880629643428e-6 +-1.66299764538256e-6 +-1.01450351451109e-6 +-2.9897580679925e-7 +4.778230486617e-7 +1.30134942732076e-6 +2.15698996474846e-6 +3.01139455704895e-6 +3.83150595451006e-6 +4.6486553085021e-6 +5.39866854742161e-6 +6.0633779344053e-6 +6.64505288826461e-6 +7.10620984925846e-6 +7.42554420262448e-6 +7.5921592957585e-6 +7.59604323829658e-6 +7.4322223638238e-6 +7.07019338593616e-6 +6.5530535251783e-6 +5.81138982456196e-6 +4.93125339021914e-6 +3.84118987018593e-6 +2.62399132900517e-6 +1.28261796938256e-6 +-1.84404808868073e-7 +-1.73983144001699e-6 +-3.33935604298266e-6 +-4.96530162809768e-6 +-6.55816909846896e-6 +-8.09156481962559e-6 +-9.54514698333832e-6 +-1.08541688245874e-5 +-1.19812039266178e-5 +-1.29258356094021e-5 +-1.35864741790705e-5 +-1.40143363153509e-5 +-1.41096581487199e-5 +-1.39167543346076e-5 +-1.33693589565357e-5 +-1.25232516456216e-5 +-1.12945331543608e-5 +-9.75795645920384e-6 +-7.94061043444157e-6 +-5.82669848029968e-6 +-3.46810975732889e-6 +-8.98080427581192e-7 +1.83157780808837e-6 +4.65462384661346e-6 +7.49499200727654e-6 +1.03647465427585e-5 +1.31179949559878e-5 +1.57239303578456e-5 +1.80905523657776e-5 +2.0183001663178e-5 +2.19109883335264e-5 +2.3237064442004e-5 +2.41135213673391e-5 +2.44756148778194e-5 +2.42814484952927e-5 +2.35477964026005e-5 +2.22346916834176e-5 +2.03698259249784e-5 +1.79397096215955e-5 +1.49707237863667e-5 +1.15270292808691e-5 +7.67266645113299e-6 +3.44948129599163e-6 +-1.07237403409055e-6 +-5.75008290742105e-6 +-1.05566723150875e-5 +-1.53239936200644e-5 +-1.99867517520571e-5 +-2.44092890499766e-5 +-2.8476946106292e-5 +-3.21077759116387e-5 +-3.51664827487924e-5 +-3.75869046571029e-5 +-3.92567099728606e-5 +-4.01135752080094e-5 +-4.01278786536825e-5 +-3.92125256039437e-5 +-3.73919246991607e-5 +-3.46200271022937e-5 +-3.09755908244563e-5 +-2.64479100675461e-5 +-2.11542725315722e-5 +-1.50963566347366e-5 +-8.47653619728616e-6 +-1.37057784993502e-6 +6.08602710173464e-6 +1.37140404419924e-5 +2.13787482610813e-5 +2.88933776644191e-5 +3.60545970430637e-5 +4.27456382286692e-5 +4.87313166822799e-5 +5.38887103915501e-5 +5.8058617211836e-5 +6.10944817720679e-5 +6.28816258498489e-5 +6.3320088392269e-5 +6.2383362148182e-5 +5.99917552478514e-5 +5.61760181265976e-5 +5.08935610500647e-5 +4.42950092732983e-5 +3.6439179398353e-5 +2.74298095627849e-5 +1.74547874668573e-5 +6.66515424198749e-6 +-4.68762174381739e-6 +-1.63848253814674e-5 +-2.8182112834728e-5 +-3.98156943957032e-5 +-5.10302848833116e-5 +-6.15260332171321e-5 +-7.10668055624751e-5 +-7.9381160780839e-5 +-8.6241178990473e-5 +-9.14514657680923e-5 +-9.48068546980327e-5 +-9.61699375283378e-5 +-9.54489884121157e-5 +-9.25431334779362e-5 +-8.74787550676798e-5 +-8.02605459808726e-5 +-7.09737795002089e-5 +-5.97576234894939e-5 +-4.67784017657438e-5 +-3.22960637446588e-5 +-1.65036203311736e-5 +1.8211835731409e-7 +1.75262241794632e-5 +3.50927801023099e-5 +5.25300164078023e-5 +6.94390025027894e-5 +8.53884090898411e-5 +1.00039703633977e-4 +1.12981102411937e-4 +1.23877401105374e-4 +1.32393120309911e-4 +1.38242615396576e-4 +1.41266585644598e-4 +1.4121817567785e-4 +1.38042535292926e-4 +1.31649152408872e-4 +1.22120271607441e-4 +1.09537433110581e-4 +9.40746256399753e-5 +7.59553413177967e-5 +5.55488335464633e-5 +3.31799427308997e-5 +9.3129309380048e-6 +-1.55984918923049e-5 +-4.10035600300493e-5 +-6.63607029679837e-5 +-9.11217498548619e-5 +-1.14693160653602e-4 +-1.3649515371509e-4 +-1.56012871346288e-4 +-1.72712890799109e-4 +-1.86143587824593e-4 +-1.95867813754568e-4 +-2.01564656263033e-4 +-2.02972759290336e-4 +-1.99940581124459e-4 +-1.92322259909184e-4 +-1.80218777351567e-4 +-1.63698996808348e-4 +-1.43003280779161e-4 +-1.18465320314384e-4 +-9.04917696812033e-5 +-5.95982432996934e-5 +-2.64033774281263e-5 +8.46197218886673e-6 +4.42652590354071e-5 +8.02019609117841e-5 +1.15541252681312e-4 +1.49425273628651e-4 +1.81062455609401e-4 +2.09683164935054e-4 +2.34566545855999e-4 +2.55025900468172e-4 +2.70467901918912e-4 +2.80406359763515e-4 +2.84407406120996e-4 +2.82264151028901e-4 +2.73776828577359e-4 +2.5895765641908e-4 +2.37953443006062e-4 +2.1102114984442e-4 +1.78588106227681e-4 +1.41212212859299e-4 +9.95536562423676e-5 +5.44472498542575e-5 +6.75449572476166e-6 +-4.25222554328811e-5 +-9.23549576825794e-5 +-1.41631593345759e-4 +-1.89235824337239e-4 +-2.34097670788864e-4 +-2.75097479638622e-4 +-3.11248660924794e-4 +-3.41546210305275e-4 +-3.6520512783402e-4 +-3.81480006450086e-4 +-3.89787045113193e-4 +-3.89714320620699e-4 +-3.80996818757606e-4 +-3.63624442874326e-4 +-3.37695073721237e-4 +-3.03528513188856e-4 +-2.61672595277376e-4 +-2.12805216855414e-4 +-1.5784688743622e-4 +-9.77861652078604e-5 +-3.38688510549031e-5 +3.2648755958072e-5 +1.0033481570486e-4 +1.67733200025968e-4 +2.33335865754758e-4 +2.95634963180971e-4 +3.53183000686343e-4 +4.0453284744819e-4 +4.48399130268426e-4 +4.83572426498987e-4 +5.09056494666997e-4 +5.24013376631556e-4 +5.27803269367299e-4 +5.20044733952871e-4 +5.00570452769771e-4 +4.69520604910353e-4 +4.27212976261102e-4 +3.74332302277009e-4 +3.11719405101292e-4 +2.4049642873856e-4 +1.62018623241135e-4 +7.77972401313209e-5 +-1.0421191823049e-5 +-1.00812954839322e-4 +-1.91461604856559e-4 +-2.80316135283874e-4 +-3.65416962259402e-4 +-4.44738742737373e-4 +-5.16388437211181e-4 +-5.7857587894405e-4 +-6.29661563116967e-4 +-6.68237124788548e-4 +-6.93099922163973e-4 +-7.03317710030114e-4 +-6.98306631998326e-4 +-6.77769213150651e-4 +-6.41708348696407e-4 +-5.90559386915195e-4 +-5.25007863899402e-4 +-4.46146123054525e-4 +-3.55373132320712e-4 +-2.54360156353956e-4 +-1.45071717361813e-4 +-2.97162036859542e-5 +8.93270297991375e-5 +2.09526647266989e-4 +3.28243937050044e-4 +4.42825108572239e-4 +5.50664563111469e-4 +6.49142096052024e-4 +7.35899347492255e-4 +8.08678813372905e-4 +8.65523171991587e-4 +9.04777569323206e-4 +9.25107116181618e-4 +9.25552318316001e-4 +9.05640042608797e-4 +8.65234115911146e-4 +8.0473337889979e-4 +7.24942146452377e-4 +6.27117586694952e-4 +5.12950399686843e-4 +3.84563786119676e-4 +2.44411218574473e-4 +9.52682661182032e-5 +-5.97889332973182e-5 +-2.17502222608939e-4 +-3.7445891759764e-4 +-5.27167441451825e-4 +-6.72193393846827e-4 +-8.06079651608051e-4 +-9.25663256011369e-4 +-0.00102787495695661 +-0.00111008900761353 +-0.00116992392499094 +-0.00120551745886091 +-0.00121548371811249 +-0.0011989248218485 +-0.0011555522393021 +-0.00108561639886755 +-9.9000582500186e-4 +-8.70172856666792e-4 +-7.28120340175158e-4 +-5.66433876277261e-4 +-3.88151392209041e-4 +-1.96801980103244e-4 +3.75093312325743e-6 +2.09322095650866e-4 +4.1549713716762e-4 +6.17799794351121e-4 +8.11620934737964e-4 +9.92538248565781e-4 +0.00115617378867886 +0.00129855548399389 +0.00141597287741981 +0.0015052170871903 +0.00156360378300213 +0.00158905340455267 +0.00158018090872272 +0.00153629897219207 +0.00145746643569152 +0.00134453135703501 +0.00119910939952723 +0.00102353850722866 +8.20937608545406e-4 +5.95027095905744e-4 +3.50205434101682e-4 +9.13465860120201e-5 +-1.7622097696941e-4 +-4.46838493896153e-4 +-7.14664538170732e-4 +-9.73687424753197e-4 +-0.00121805258911382 +-0.00144196600754232 +-0.0016399967811266 +-0.00180713029567505 +-0.001938830336207 +-0.00203135511114057 +-0.00208158044812268 +-0.00208731796144981 +-0.00204724366396365 +-0.00196104442646158 +-0.00182936323384608 +-0.00165389169291624 +-0.0014372985389836 +-0.00118323635265763 +-8.96271981083588e-4 +-5.81806731072718e-4 +-2.45983969131179e-4 +1.04393268705522e-4 +4.62058789535929e-4 +8.19362766165076e-4 +0.00116846046706454 +0.00150147763859084 +0.00181068622281172 +0.00208861201086775 +0.00232834378817504 +0.00252349896511836 +0.00266859591166639 +0.00275902790411783 +0.00279124340926817 +0.00276288498825251 +0.00267283848815515 +0.00252129596374058 +0.00230975956455204 +0.00204114448975825 +0.00171962024485907 +0.00135067945010547 +9.40962894913222e-4 +4.98221383153697e-4 +3.11253989827009e-5 +-4.50834653780459e-4 +-9.37594792361491e-4 +-0.00141868069476593 +-0.00188337795207629 +-0.00232105491343088 +-0.00272131689968742 +-0.00307423050019428 +-0.00337059265933034 +-0.00360213033363967 +-0.0037616846970991 +-0.00384345278070074 +-0.00384308253291384 +-0.00375783644187481 +-0.00358674852203873 +-0.0033306360078639 +-0.00299217530772653 +-0.00257588667746325 +-0.00208809554811269 +-0.00153691651385721 +-9.32052699698408e-4 +-2.84731720800277e-4 +3.92575824923933e-4 +0.00108624395731248 +0.00178184935779994 +0.002464387302064 +0.0031185876084081 +0.003729182192749 +0.00428124852326713 +0.00476054551468834 +0.00515380348662816 +0.00544899423639641 +0.00563571869175492 +0.00570538540965876 +0.00565150400549031 +0.00546990291198768 +0.00515881834238826 +0.00471916302694636 +0.00415449166195703 +0.00347110481638838 +0.00267799125626014 +0.00178683880102889 +8.11802943926725e-4 +-2.30562873065775e-4 +-0.00132153102743281 +-0.00244054733990411 +-0.00356539492058686 +-0.00467268587078703 +-0.00573814176089155 +-0.00673696915030418 +-0.00764439443252765 +-0.00843600526449621 +-0.00908818810332266 +-0.00957862488505226 +-0.00988665936971963 +-0.0099937068885515 +-0.00988371464077663 +-0.00954336583418968 +-0.00896253186591292 +-0.00813442269973128 +-0.00705586455196647 +-0.00572741237854925 +-0.00415349209382152 +-0.00234233959454067 +-3.06098977672814e-4 +0.00193941933088424 +0.00437477465814811 +0.00697721762570139 +0.00972087552164101 +0.0125771999157822 +0.0155152397694249 +0.0185021810309104 +0.021503710104957 +0.0244845910618796 +0.0274091350854231 +0.0302417753259086 +0.0329475282481102 +0.0354926172612528 +0.0378449140820321 +0.039974473230549 +0.0418539747756063 +0.0434591523630184 +0.0447691888654274 +0.0457670156843866 +0.046439581452649 +0.0467780781663164 +0.0467780781663164 +0.046439581452649 +0.0457670156843866 +0.0447691888654274 +0.0434591523630184 +0.0418539747756063 +0.039974473230549 +0.0378449140820321 +0.0354926172612528 +0.0329475282481102 +0.0302417753259086 +0.0274091350854231 +0.0244845910618796 +0.021503710104957 +0.0185021810309104 +0.0155152397694249 +0.0125771999157822 +0.00972087552164101 +0.00697721762570139 +0.00437477465814811 +0.00193941933088424 +-3.06098977672814e-4 +-0.00234233959454067 +-0.00415349209382152 +-0.00572741237854925 +-0.00705586455196647 +-0.00813442269973128 +-0.00896253186591292 +-0.00954336583418968 +-0.00988371464077663 +-0.0099937068885515 +-0.00988665936971963 +-0.00957862488505226 +-0.00908818810332266 +-0.00843600526449621 +-0.00764439443252765 +-0.00673696915030418 +-0.00573814176089155 +-0.00467268587078703 +-0.00356539492058686 +-0.00244054733990411 +-0.00132153102743281 +-2.30562873065775e-4 +8.11802943926725e-4 +0.00178683880102889 +0.00267799125626014 +0.00347110481638838 +0.00415449166195703 +0.00471916302694636 +0.00515881834238826 +0.00546990291198768 +0.00565150400549031 +0.00570538540965876 +0.00563571869175492 +0.00544899423639641 +0.00515380348662816 +0.00476054551468834 +0.00428124852326713 +0.003729182192749 +0.0031185876084081 +0.002464387302064 +0.00178184935779994 +0.00108624395731248 +3.92575824923933e-4 +-2.84731720800277e-4 +-9.32052699698408e-4 +-0.00153691651385721 +-0.00208809554811269 +-0.00257588667746325 +-0.00299217530772653 +-0.0033306360078639 +-0.00358674852203873 +-0.00375783644187481 +-0.00384308253291384 +-0.00384345278070074 +-0.0037616846970991 +-0.00360213033363967 +-0.00337059265933034 +-0.00307423050019428 +-0.00272131689968742 +-0.00232105491343088 +-0.00188337795207629 +-0.00141868069476593 +-9.37594792361491e-4 +-4.50834653780459e-4 +3.11253989827009e-5 +4.98221383153697e-4 +9.40962894913222e-4 +0.00135067945010547 +0.00171962024485907 +0.00204114448975825 +0.00230975956455204 +0.00252129596374058 +0.00267283848815515 +0.00276288498825251 +0.00279124340926817 +0.00275902790411783 +0.00266859591166639 +0.00252349896511836 +0.00232834378817504 +0.00208861201086775 +0.00181068622281172 +0.00150147763859084 +0.00116846046706454 +8.19362766165076e-4 +4.62058789535929e-4 +1.04393268705522e-4 +-2.45983969131179e-4 +-5.81806731072718e-4 +-8.96271981083588e-4 +-0.00118323635265763 +-0.0014372985389836 +-0.00165389169291624 +-0.00182936323384608 +-0.00196104442646158 +-0.00204724366396365 +-0.00208731796144981 +-0.00208158044812268 +-0.00203135511114057 +-0.001938830336207 +-0.00180713029567505 +-0.0016399967811266 +-0.00144196600754232 +-0.00121805258911382 +-9.73687424753197e-4 +-7.14664538170732e-4 +-4.46838493896153e-4 +-1.7622097696941e-4 +9.13465860120201e-5 +3.50205434101682e-4 +5.95027095905744e-4 +8.20937608545406e-4 +0.00102353850722866 +0.00119910939952723 +0.00134453135703501 +0.00145746643569152 +0.00153629897219207 +0.00158018090872272 +0.00158905340455267 +0.00156360378300213 +0.0015052170871903 +0.00141597287741981 +0.00129855548399389 +0.00115617378867886 +9.92538248565781e-4 +8.11620934737964e-4 +6.17799794351121e-4 +4.1549713716762e-4 +2.09322095650866e-4 +3.75093312325743e-6 +-1.96801980103244e-4 +-3.88151392209041e-4 +-5.66433876277261e-4 +-7.28120340175158e-4 +-8.70172856666792e-4 +-9.9000582500186e-4 +-0.00108561639886755 +-0.0011555522393021 +-0.0011989248218485 +-0.00121548371811249 +-0.00120551745886091 +-0.00116992392499094 +-0.00111008900761353 +-0.00102787495695661 +-9.25663256011369e-4 +-8.06079651608051e-4 +-6.72193393846827e-4 +-5.27167441451825e-4 +-3.7445891759764e-4 +-2.17502222608939e-4 +-5.97889332973182e-5 +9.52682661182032e-5 +2.44411218574473e-4 +3.84563786119676e-4 +5.12950399686843e-4 +6.27117586694952e-4 +7.24942146452377e-4 +8.0473337889979e-4 +8.65234115911146e-4 +9.05640042608797e-4 +9.25552318316001e-4 +9.25107116181618e-4 +9.04777569323206e-4 +8.65523171991587e-4 +8.08678813372905e-4 +7.35899347492255e-4 +6.49142096052024e-4 +5.50664563111469e-4 +4.42825108572239e-4 +3.28243937050044e-4 +2.09526647266989e-4 +8.93270297991375e-5 +-2.97162036859542e-5 +-1.45071717361813e-4 +-2.54360156353956e-4 +-3.55373132320712e-4 +-4.46146123054525e-4 +-5.25007863899402e-4 +-5.90559386915195e-4 +-6.41708348696407e-4 +-6.77769213150651e-4 +-6.98306631998326e-4 +-7.03317710030114e-4 +-6.93099922163973e-4 +-6.68237124788548e-4 +-6.29661563116967e-4 +-5.7857587894405e-4 +-5.16388437211181e-4 +-4.44738742737373e-4 +-3.65416962259402e-4 +-2.80316135283874e-4 +-1.91461604856559e-4 +-1.00812954839322e-4 +-1.0421191823049e-5 +7.77972401313209e-5 +1.62018623241135e-4 +2.4049642873856e-4 +3.11719405101292e-4 +3.74332302277009e-4 +4.27212976261102e-4 +4.69520604910353e-4 +5.00570452769771e-4 +5.20044733952871e-4 +5.27803269367299e-4 +5.24013376631556e-4 +5.09056494666997e-4 +4.83572426498987e-4 +4.48399130268426e-4 +4.0453284744819e-4 +3.53183000686343e-4 +2.95634963180971e-4 +2.33335865754758e-4 +1.67733200025968e-4 +1.0033481570486e-4 +3.2648755958072e-5 +-3.38688510549031e-5 +-9.77861652078604e-5 +-1.5784688743622e-4 +-2.12805216855414e-4 +-2.61672595277376e-4 +-3.03528513188856e-4 +-3.37695073721237e-4 +-3.63624442874326e-4 +-3.80996818757606e-4 +-3.89714320620699e-4 +-3.89787045113193e-4 +-3.81480006450086e-4 +-3.6520512783402e-4 +-3.41546210305275e-4 +-3.11248660924794e-4 +-2.75097479638622e-4 +-2.34097670788864e-4 +-1.89235824337239e-4 +-1.41631593345759e-4 +-9.23549576825794e-5 +-4.25222554328811e-5 +6.75449572476166e-6 +5.44472498542575e-5 +9.95536562423676e-5 +1.41212212859299e-4 +1.78588106227681e-4 +2.1102114984442e-4 +2.37953443006062e-4 +2.5895765641908e-4 +2.73776828577359e-4 +2.82264151028901e-4 +2.84407406120996e-4 +2.80406359763515e-4 +2.70467901918912e-4 +2.55025900468172e-4 +2.34566545855999e-4 +2.09683164935054e-4 +1.81062455609401e-4 +1.49425273628651e-4 +1.15541252681312e-4 +8.02019609117841e-5 +4.42652590354071e-5 +8.46197218886673e-6 +-2.64033774281263e-5 +-5.95982432996934e-5 +-9.04917696812033e-5 +-1.18465320314384e-4 +-1.43003280779161e-4 +-1.63698996808348e-4 +-1.80218777351567e-4 +-1.92322259909184e-4 +-1.99940581124459e-4 +-2.02972759290336e-4 +-2.01564656263033e-4 +-1.95867813754568e-4 +-1.86143587824593e-4 +-1.72712890799109e-4 +-1.56012871346288e-4 +-1.3649515371509e-4 +-1.14693160653602e-4 +-9.11217498548619e-5 +-6.63607029679837e-5 +-4.10035600300493e-5 +-1.55984918923049e-5 +9.3129309380048e-6 +3.31799427308997e-5 +5.55488335464633e-5 +7.59553413177967e-5 +9.40746256399753e-5 +1.09537433110581e-4 +1.22120271607441e-4 +1.31649152408872e-4 +1.38042535292926e-4 +1.4121817567785e-4 +1.41266585644598e-4 +1.38242615396576e-4 +1.32393120309911e-4 +1.23877401105374e-4 +1.12981102411937e-4 +1.00039703633977e-4 +8.53884090898411e-5 +6.94390025027894e-5 +5.25300164078023e-5 +3.50927801023099e-5 +1.75262241794632e-5 +1.8211835731409e-7 +-1.65036203311736e-5 +-3.22960637446588e-5 +-4.67784017657438e-5 +-5.97576234894939e-5 +-7.09737795002089e-5 +-8.02605459808726e-5 +-8.74787550676798e-5 +-9.25431334779362e-5 +-9.54489884121157e-5 +-9.61699375283378e-5 +-9.48068546980327e-5 +-9.14514657680923e-5 +-8.6241178990473e-5 +-7.9381160780839e-5 +-7.10668055624751e-5 +-6.15260332171321e-5 +-5.10302848833116e-5 +-3.98156943957032e-5 +-2.8182112834728e-5 +-1.63848253814674e-5 +-4.68762174381739e-6 +6.66515424198749e-6 +1.74547874668573e-5 +2.74298095627849e-5 +3.6439179398353e-5 +4.42950092732983e-5 +5.08935610500647e-5 +5.61760181265976e-5 +5.99917552478514e-5 +6.2383362148182e-5 +6.3320088392269e-5 +6.28816258498489e-5 +6.10944817720679e-5 +5.8058617211836e-5 +5.38887103915501e-5 +4.87313166822799e-5 +4.27456382286692e-5 +3.60545970430637e-5 +2.88933776644191e-5 +2.13787482610813e-5 +1.37140404419924e-5 +6.08602710173464e-6 +-1.37057784993502e-6 +-8.47653619728616e-6 +-1.50963566347366e-5 +-2.11542725315722e-5 +-2.64479100675461e-5 +-3.09755908244563e-5 +-3.46200271022937e-5 +-3.73919246991607e-5 +-3.92125256039437e-5 +-4.01278786536825e-5 +-4.01135752080094e-5 +-3.92567099728606e-5 +-3.75869046571029e-5 +-3.51664827487924e-5 +-3.21077759116387e-5 +-2.8476946106292e-5 +-2.44092890499766e-5 +-1.99867517520571e-5 +-1.53239936200644e-5 +-1.05566723150875e-5 +-5.75008290742105e-6 +-1.07237403409055e-6 +3.44948129599163e-6 +7.67266645113299e-6 +1.15270292808691e-5 +1.49707237863667e-5 +1.79397096215955e-5 +2.03698259249784e-5 +2.22346916834176e-5 +2.35477964026005e-5 +2.42814484952927e-5 +2.44756148778194e-5 +2.41135213673391e-5 +2.3237064442004e-5 +2.19109883335264e-5 +2.0183001663178e-5 +1.80905523657776e-5 +1.57239303578456e-5 +1.31179949559878e-5 +1.03647465427585e-5 +7.49499200727654e-6 +4.65462384661346e-6 +1.83157780808837e-6 +-8.98080427581192e-7 +-3.46810975732889e-6 +-5.82669848029968e-6 +-7.94061043444157e-6 +-9.75795645920384e-6 +-1.12945331543608e-5 +-1.25232516456216e-5 +-1.33693589565357e-5 +-1.39167543346076e-5 +-1.41096581487199e-5 +-1.40143363153509e-5 +-1.35864741790705e-5 +-1.29258356094021e-5 +-1.19812039266178e-5 +-1.08541688245874e-5 +-9.54514698333832e-6 +-8.09156481962559e-6 +-6.55816909846896e-6 +-4.96530162809768e-6 +-3.33935604298266e-6 +-1.73983144001699e-6 +-1.84404808868073e-7 +1.28261796938256e-6 +2.62399132900517e-6 +3.84118987018593e-6 +4.93125339021914e-6 +5.81138982456196e-6 +6.5530535251783e-6 +7.07019338593616e-6 +7.4322223638238e-6 +7.59604323829658e-6 +7.5921592957585e-6 +7.42554420262448e-6 +7.10620984925846e-6 +6.64505288826461e-6 +6.0633779344053e-6 +5.39866854742161e-6 +4.6486553085021e-6 +3.83150595451006e-6 +3.01139455704895e-6 +2.15698996474846e-6 +1.30134942732076e-6 +4.778230486617e-7 +-2.9897580679925e-7 +-1.01450351451109e-6 +-1.66299764538256e-6 +-2.23880629643428e-6 +-2.73085981209485e-6 +-3.10558378787101e-6 +-3.40106555337159e-6 +-3.62820827681515e-6 +-3.73781668478926e-6 +-3.75096178007138e-6 +-3.67684205210421e-6 +-3.54951933335568e-6 +-3.34868062209883e-6 +-3.08872255757467e-6 +-2.77710918199585e-6 +-2.42034886505034e-6 +-2.03191995568737e-6 +-1.6246903514035e-6 +-1.21281774093872e-6 +-8.17500360283736e-7 +-4.3476366150865e-7 +-5.24862218589967e-8 +2.96426729531177e-7 +6.04567255230193e-7 +8.5785768415765e-7 +1.10621331781889e-6 +1.28959869628182e-6 +1.43132387640668e-6 +1.53782569699597e-6 +1.61363975974438e-6 +1.6294811644839e-6 +1.60770440406623e-6 +1.55182559228546e-6 +1.46860535142565e-6 +1.34551951148203e-6 +1.25500772923897e-6 +1.09935217260167e-6 +9.21520058445204e-7 +7.75112423789865e-7 +6.00075575484758e-7 +4.3227430974949e-7 +2.81681324083492e-7 +1.44876241366308e-7 +-5.05264098238236e-9 +-1.54707945258839e-7 +-2.44517851394823e-7 +-3.38624331418706e-7 +-4.53511011468631e-7 +-5.01344341031087e-7 +-5.3712751262779e-7 +-5.61361967225389e-7 +-5.87512127558038e-7 +-5.61504899335206e-7 +-5.58776629837758e-7 +-5.53575138212173e-7 +-5.09702102203457e-7 +-4.87548260748437e-7 +-4.62591739880567e-7 +-4.22986843582035e-7 +-4.2275208095965e-7 +-4.38563052056152e-7 +-5.74349474884059e-7 +6.25765784406859e-7 diff --git a/fceumm/src-fceumm/fir/c96000ntsc.h b/fceumm/src-fceumm/fir/c96000ntsc.h new file mode 100644 index 0000000..e9b003f --- /dev/null +++ b/fceumm/src-fceumm/fir/c96000ntsc.h @@ -0,0 +1,512 @@ +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +0, +0, +0, +0, +0, +0, +-1, +-1, +-2, +-2, +-2, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-3, +-2, +-2, +-1, +-1, +0, +0, +1, +2, +3, +4, +4, +5, +6, +6, +7, +7, +7, +7, +7, +7, +6, +6, +5, +4, +2, +1, +0, +-1, +-3, +-5, +-6, +-8, +-10, +-11, +-12, +-13, +-14, +-14, +-14, +-14, +-14, +-13, +-11, +-10, +-8, +-6, +-3, +0, +1, +4, +7, +10, +13, +16, +18, +21, +22, +24, +25, +25, +25, +24, +23, +21, +18, +15, +12, +8, +3, +-1, +-6, +-11, +-16, +-20, +-25, +-29, +-33, +-36, +-39, +-41, +-42, +-42, +-41, +-39, +-36, +-32, +-27, +-22, +-15, +-8, +-1, +6, +14, +22, +30, +37, +44, +51, +56, +60, +64, +65, +66, +65, +62, +58, +53, +46, +38, +28, +18, +6, +-4, +-17, +-29, +-41, +-53, +-64, +-74, +-83, +-90, +-95, +-99, +-100, +-100, +-97, +-91, +-84, +-74, +-62, +-49, +-33, +-17, +0, +18, +36, +55, +72, +89, +104, +118, +129, +138, +144, +148, +148, +144, +138, +128, +114, +98, +79, +58, +34, +9, +-16, +-42, +-69, +-95, +-120, +-143, +-163, +-181, +-195, +-205, +-211, +-212, +-209, +-201, +-188, +-171, +-149, +-124, +-94, +-62, +-27, +8, +46, +84, +121, +156, +189, +219, +245, +267, +283, +294, +298, +295, +287, +271, +249, +221, +187, +148, +104, +57, +7, +-44, +-96, +-148, +-198, +-245, +-288, +-326, +-358, +-382, +-400, +-408, +-408, +-399, +-381, +-354, +-318, +-274, +-223, +-165, +-102, +-35, +34, +105, +175, +244, +309, +370, +424, +470, +507, +533, +549, +553, +545, +524, +492, +447, +392, +326, +252, +169, +81, +-10, +-105, +-200, +-293, +-383, +-466, +-541, +-606, +-660, +-700, +-726, +-737, +-732, +-710, +-672, +-619, +-550, +-467, +-372, +-266, +-152, +-31, +93, +219, +344, +464, +577, +680, +771, +847, +907, +948, +970, +970, +949, +907, +843, +760, +657, +537, +403, +256, +99, +-62, +-228, +-392, +-552, +-704, +-845, +-970, +-1077, +-1164, +-1226, +-1264, +-1274, +-1257, +-1211, +-1138, +-1038, +-912, +-763, +-593, +-407, +-206, +3, +219, +435, +647, +851, +1040, +1212, +1361, +1484, +1578, +1639, +1666, +1656, +1610, +1528, +1409, +1257, +1073, +860, +623, +367, +95, +-184, +-468, +-749, +-1020, +-1277, +-1512, +-1719, +-1894, +-2033, +-2130, +-2182, +-2188, +-2146, +-2056, +-1918, +-1734, +-1507, +-1240, +-939, +-610, +-257, +109, +484, +859, +1225, +1574, +1898, +2190, +2441, +2646, +2798, +2893, +2926, +2897, +2802, +2643, +2421, +2140, +1803, +1416, +986, +522, +32, +-472, +-983, +-1487, +-1974, +-2433, +-2853, +-3223, +-3534, +-3777, +-3944, +-4030, +-4029, +-3940, +-3760, +-3492, +-3137, +-2701, +-2189, +-1611, +-977, +-298, +411, +1139, +1868, +2584, +3270, +3910, +4489, +4991, +5404, +5713, +5909, +5982, +5926, +5735, +5409, +4948, +4356, +3639, +2808, +1873, +851, +-241, +-1385, +-2559, +-3738, +-4899, +-6016, +-7064, +-8015, +-8845, +-9529, +-10043, +-10366, +-10479, +-10363, +-10006, +-9397, +-8529, +-7398, +-6005, +-4355, +-2456, +-320, +2033, +4587, +7316, +10193, +13188, +16268, +19400, +22548, +25673, +28740, +31710, +34547, +37216, +39683, +41916, +43887, +45570, +46943, +47990, +48695, +49050, diff --git a/fceumm/src-fceumm/fir/c96000ntsc.scm b/fceumm/src-fceumm/fir/c96000ntsc.scm new file mode 100644 index 0000000..9111e96 --- /dev/null +++ b/fceumm/src-fceumm/fir/c96000ntsc.scm @@ -0,0 +1,12 @@ +(title "96000 NTSC") + +(verbose #t) + +(cosine-symmetry) +(filter-length 1024) +(sampling-frequency 1789772.727272727272) +(limit-= (band 0 36850) 1) +(limit-= (band 48000 894886.363636) 0 .5) +(output-file "c96000ntsc.coef") +(plot-file "c96000ntsc.plot") +(go) diff --git a/fceumm/src-fceumm/fir/c96000pal.coef b/fceumm/src-fceumm/fir/c96000pal.coef new file mode 100644 index 0000000..0295f76 --- /dev/null +++ b/fceumm/src-fceumm/fir/c96000pal.coef @@ -0,0 +1,1039 @@ +;; ***** 96000 PAL ***** +;; Filter length: 1024 +;; Symmetry: cosine +;; Sampling frequency: 1662607.125 +;; Grid density: 10257 +;; Deviation parameter: y=-1.67321403971065e-8 +;; +;; Specifications: +;; (limit > 48000 831303.5625 0 0.5) +;; (limit < 48000 831303.5625 0 0.5) +;; (limit > 0 33400 1 1) +;; (limit < 0 33400 1 1) +;; +;; Coefficients: + +1.03151991819582e-8 +8.38300275294078e-9 +1.10906859282933e-8 +1.03271192432242e-8 +1.14333552786323e-8 +1.30077482700426e-8 +1.41716278773579e-8 +1.74208569471553e-8 +2.00800027395966e-8 +2.09724315061768e-8 +2.22929661801192e-8 +1.95132650596489e-8 +1.76960158618376e-8 +1.3068715878392e-8 +1.07557125018314e-8 +6.05954400825878e-9 +1.83985020585335e-9 +-4.35513294668295e-9 +-1.25339352914121e-8 +-2.18251091115114e-8 +-3.19847926493859e-8 +-4.14587362468332e-8 +-5.15215025811016e-8 +-6.3122768061061e-8 +-7.34212411189246e-8 +-8.35519847400028e-8 +-9.19816359673906e-8 +-1.00062504114338e-7 +-1.0581696028102e-7 +-1.09342060902351e-7 +-1.09899151121439e-7 +-1.07199067922224e-7 +-1.01333875812554e-7 +-9.17625273815014e-8 +-7.89956849981134e-8 +-6.14126768147793e-8 +-3.99528124923842e-8 +-1.43267231105268e-8 +1.51839061412207e-8 +4.71079084065085e-8 +8.33872247697555e-8 +1.20450960766471e-7 +1.6066011924682e-7 +1.99015401296622e-7 +2.3707190547137e-7 +2.72939884477538e-7 +3.05703733943038e-7 +3.34271689565622e-7 +3.57246917030831e-7 +3.71753520789388e-7 +3.80032136027046e-7 +3.77007825091848e-7 +3.65236448771379e-7 +3.39343358482371e-7 +3.02990066262988e-7 +2.53431354500078e-7 +1.93531346067046e-7 +1.20312660464537e-7 +3.83506638823491e-8 +-5.50094412531977e-8 +-1.55165787913079e-7 +-2.62247401958816e-7 +-3.72869415873669e-7 +-4.85000602763094e-7 +-5.9487324901853e-7 +-7.00817920677767e-7 +-7.96695832853341e-7 +-8.83009467313344e-7 +-9.516801687493e-7 +-1.00406302340324e-6 +-1.03355489807237e-6 +-1.03946679063045e-6 +-1.01783166180378e-6 +-9.67049604607247e-7 +-8.87746045951503e-7 +-7.77649486859982e-7 +-6.37499558026062e-7 +-4.67089278916325e-7 +-2.69324680211038e-7 +-4.79481886690687e-8 +1.95178720022609e-7 +4.53619817534114e-7 +7.23956612504e-7 +9.97486152500784e-7 +1.26826910787562e-6 +1.53005288621509e-6 +1.77357589639965e-6 +1.99304439308787e-6 +2.17833876701336e-6 +2.32279469282784e-6 +2.41942298528229e-6 +2.46085469574341e-6 +2.44371789997691e-6 +2.36167902121603e-6 +2.21343228064008e-6 +1.99610535588337e-6 +1.71076949967104e-6 +1.35846743996931e-6 +9.44346239710729e-7 +4.73800121500147e-7 +-4.49606767418064e-8 +-6.0197624767097e-7 +-1.18587637892365e-6 +-1.78302023739655e-6 +-2.38006119965271e-6 +-2.96212165638707e-6 +-3.51170040070893e-6 +-4.01344340051503e-6 +-4.44917701834718e-6 +-4.80493586876171e-6 +-5.063623966477e-6 +-5.21373005767686e-6 +-5.24183699733879e-6 +-5.1394946501258e-6 +-4.90048958017337e-6 +-4.52057551249377e-6 +-4.00121137621988e-6 +-3.34381409235837e-6 +-2.55698769776267e-6 +-1.65168508479184e-6 +-6.41630367682649e-7 +4.5272033468355e-7 +1.61065667346661e-6 +2.80519025479194e-6 +4.00982303462755e-6 +5.19442047840389e-6 +6.32696760641722e-6 +7.37667453186873e-6 +8.31026493121452e-6 +9.09759867217571e-6 +9.70730330637792e-6 +1.01139238186566e-5 +1.02939875082689e-5 +1.0228657500937e-5 +9.90357194955147e-6 +9.31094999767115e-6 +8.44836300475225e-6 +7.32184325292062e-6 +5.9411139708878e-6 +4.32718679501898e-6 +2.5045517191364e-6 +5.08537844109541e-7 +-1.62303718375881e-6 +-3.84347493132933e-6 +-6.10417289473804e-6 +-8.34891011005015e-6 +-1.05213195267016e-5 +-1.25625562618188e-5 +-1.44140306102446e-5 +-1.60176157455328e-5 +-1.73187930064226e-5 +-1.82665081367835e-5 +-1.88180884125302e-5 +-1.89349221542663e-5 +-1.85905030202489e-5 +-1.77652468409902e-5 +-1.64542644771625e-5 +-1.46606892008227e-5 +-1.24032950277693e-5 +-9.71123313104019e-6 +-6.62826926323268e-6 +-3.20916832281648e-6 +4.80912959878512e-7 +4.36391659133863e-6 +8.35431095023709e-6 +1.23587745013029e-5 +1.62776057022447e-5 +2.00104633597274e-5 +2.34525897473363e-5 +2.6504113480356e-5 +2.90669843834708e-5 +3.10523292715376e-5 +3.23801498345e-5 +3.29827423119358e-5 +3.28062497909458e-5 +3.18141310912695e-5 +2.99885330657398e-5 +2.73307787009361e-5 +2.3863596601089e-5 +1.9630985529227e-5 +1.46979062042561e-5 +9.15102381017684e-6 +3.09475951446394e-6 +-3.34513850836547e-6 +-1.00309472232173e-5 +-1.68084780282784e-5 +-2.35164419241063e-5 +-2.99843308432599e-5 +-3.60413748500087e-5 +-4.15175966696302e-5 +-4.62496011329744e-5 +-5.00834846280012e-5 +-5.2881756318201e-5 +-5.45231256798723e-5 +-5.49127392818389e-5 +-5.39779986324577e-5 +-5.1680740099127e-5 +-4.80092456996724e-5 +-4.29902880316882e-5 +-3.66811426138427e-5 +-2.91770944785758e-5 +-2.06050398177054e-5 +-1.1125982738189e-5 +-9.29469045115252e-7 +9.76750875584034e-6 +2.07264139138749e-5 +3.16889547008264e-5 +4.23881612033781e-5 +5.25469490585536e-5 +6.18941440803559e-5 +7.01613699670651e-5 +7.70982488738663e-5 +8.24733429562758e-5 +8.60846255633886e-5 +8.77652355990178e-5 +8.73861281253179e-5 +8.48651355449836e-5 +8.01683770409635e-5 +7.33144164498558e-5 +6.43756190395851e-5 +5.347813081375e-5 +4.08032785217656e-5 +2.65822878709086e-5 +1.10959100456974e-5 +-5.33248429467424e-6 +-2.23418652788707e-5 +-3.95425112453473e-5 +-5.65228132450726e-5 +-7.28580214960265e-5 +-8.81236947188922e-5 +-1.01900589865764e-4 +-1.13790446423011e-4 +-1.23423041654638e-4 +-1.30468892775236e-4 +-1.34648743318249e-4 +-1.35739884161422e-4 +-1.33588879261025e-4 +-1.2811333539122e-4 +-1.19309561896777e-4 +-1.0725481963731e-4 +-9.21093274384085e-5 +-7.41158206776385e-5 +-5.35961801579358e-5 +-3.09472952504257e-5 +-6.63430458187306e-6 +1.88188660219006e-5 +4.48385613205947e-5 +7.0815621084536e-5 +9.61160455879359e-5 +1.20099004917142e-4 +1.42129235004429e-4 +1.61594559165767e-4 +1.77921607229302e-4 +1.90590736122456e-4 +1.99151775086795e-4 +2.03236949574574e-4 +2.02573580216899e-4 +1.96994293467081e-4 +1.86445019398819e-4 +1.70990903256481e-4 +1.50819069616185e-4 +1.26238358089726e-4 +9.76776349699245e-5 +6.56776045971978e-5 +3.08848326050668e-5 +-5.96356740813766e-6 +-4.40513605910619e-5 +-8.25032454022742e-5 +-1.20401080500299e-4 +-1.56806879798798e-4 +-1.90783149605849e-4 +-2.21419291675664e-4 +-2.47848788110117e-4 +-2.69279472445284e-4 +-2.85009149126569e-4 +-2.94450224275897e-4 +-2.97145272500789e-4 +-2.9278440100842e-4 +-2.81218526412152e-4 +-2.62467514354949e-4 +-2.36726227379411e-4 +-2.04367498164773e-4 +-1.65935928106054e-4 +-1.22144676611347e-4 +-7.38611116469124e-5 +-2.2092886327107e-5 +3.20332747710491e-5 +8.72935203677178e-5 +1.4239311797007e-4 +1.95996823059339e-4 +2.46758430731207e-4 +2.93354710149485e-4 +3.34516779687324e-4 +3.69063740137675e-4 +3.95935025218761e-4 +4.14218377731336e-4 +4.23179220684935e-4 +4.22282619148847e-4 +4.11214766210894e-4 +3.89896739795703e-4 +3.58494957675319e-4 +3.17425558178502e-4 +2.67352241592445e-4 +2.09178855148142e-4 +1.44035366727157e-4 +7.3257656515258e-5 +-1.63779237740676e-6 +-7.89848893170478e-5 +-1.57002327126315e-4 +-2.33835056002673e-4 +-3.07594047026731e-4 +-3.76404164136881e-4 +-4.38446131068721e-4 +-4.9200703290972e-4 +-5.35520428249821e-4 +-5.67613638239988e-4 +-5.87143099888524e-4 +-5.93232478671107e-4 +-5.85300692351394e-4 +-5.63086337917986e-4 +-5.26663373800026e-4 +-4.76451870743233e-4 +-4.13216007201208e-4 +-3.38060678040117e-4 +-2.52409733078722e-4 +-1.57988085254148e-4 +-5.6784716422895e-5 +4.89841731832692e-5 +1.56922907604873e-4 +2.64508461181843e-4 +3.69146665341244e-4 +4.68233075668834e-4 +5.59215876696991e-4 +6.39657748300381e-4 +7.07299816040927e-4 +7.6012020281837e-4 +7.96391761417496e-4 +8.14730777273661e-4 +8.14142664644267e-4 +7.94056446208742e-4 +7.5435263217961e-4 +6.9537963487656e-4 +6.17959079267155e-4 +5.23381496018073e-4 +4.13387627487922e-4 +2.90142907465985e-4 +1.5619696018914e-4 +1.44330402738205e-5 +-1.31990568245096e-4 +-2.79707337982926e-4 +-4.25218148098678e-4 +-5.6497087428213e-4 +-6.95445072726885e-4 +-8.13236256145513e-4 +-9.15141775653344e-4 +-9.98243562663091e-4 +-0.0010599866628307 +-0.00109825180635536 +-0.00111141913270169 +-0.00109842176590062 +-0.00105878723152578 +-9.92667960092833e-4 +-9.00853865253174e-4 +-7.84775133395688e-4 +-6.46484210138539e-4 +-4.8862706565045e-4 +-3.14396237291812e-4 +-1.27470456729415e-4 +6.80586481779722e-5 +2.67772482152798e-4 +4.67021632594192e-4 +6.61030288225903e-4 +8.45007409820417e-4 +0.00101425950405569 +0.00116430673085702 +0.00129099572518951 +0.0013906093284534 +0.0014599674225506 +0.00149651846177726 +0.00149841919645406 +0.00146459939319946 +0.00139480951060361 +0.00128965157704395 +0.00115058933642334 +9.79937911476128e-4 +7.80834826954757e-4 +5.57187482764196e-4 +3.13605594907024e-4 +5.53078264280656e-5 +-2.1198068576069e-4 +-4.82152145309325e-4 +-7.48849254545155e-4 +-0.0010056096258098 +-0.00124601613279792 +-0.00146385027634117 +-0.00165324714625177 +-0.00180884426159716 +-0.00192592281171168 +-0.00200054079682649 +-0.00202964706581313 +-0.00201118336129597 +-0.00194415758323169 +-0.00182870407402118 +-0.00166611043274461 +-0.0014588228462092 +-0.00121042184021843 +-9.25571871008901e-4 +-6.09943356897427e-4 +-2.70108419498178e-4 +8.65878287229843e-5 +4.52176307534593e-4 +8.18234381982771e-4 +0.00117607035980743 +0.00151692075161767 +0.00183215385494268 +0.00211347938372566 +0.00235315096692847 +0.00254416760290437 +0.00268046014161941 +0.00275706287455375 +0.00277026461769735 +0.00271773284742105 +0.00259861436853517 +0.00241359905001614 +0.00216495311562251 +0.00185651528950842 +0.00149365620556701 +0.0010832027611814 +6.33323430643252e-4 +1.5338150399634e-4 +-3.46245873742672e-4 +-8.54375818614214e-4 +-0.00135925347644246 +-0.00184880903364977 +-0.00231092502530074 +-0.0027337187227384 +-0.00310582337372604 +-0.00341666930468077 +-0.00365675622328083 +-0.00381790643652724 +-0.00389350186222283 +-0.00387868559008699 +-0.00377053814671627 +-0.00356820912785959 +-0.00327301016165189 +-0.0028884598696194 +-0.00242028158028417 +-0.0018763509819845 +-0.00126659496546869 +-6.02837209621259e-4 +1.01397889009688e-4 +8.31132315629842e-4 +0.00157021607771463 +0.00230165125086365 +0.00300793964707363 +0.00367145812920719 +0.00427484711920302 +0.00480141038410035 +0.00523550974836302 +0.00556295588482682 +0.00577137823517525 +0.00585057149230045 +0.0057928072764395 +0.00559310428736023 +0.00524945134321352 +0.00476297411539252 +0.00413804459791576 +0.00338232730758133 +0.00250675668335827 +0.00152545134396061 +4.55555350931454e-4 +-6.82980522572643e-4 +-0.00186768708315042 +-0.00307391993768759 +-0.00427525920508468 +-0.00544395757085389 +-0.00655142415066617 +-0.00756874635507542 +-0.00846722496704464 +-0.00921892960311577 +-0.00979724946072329 +-0.0101774361576858 +-0.0103371277935579 +-0.0102568377148858 +-0.0099204091949967 +-0.00931541332239757 +-0.0084334894941071 +-0.00727062096870851 +-0.0058273332996356 +-0.0041088188533721 +-0.00212497423336652 +1.09643059299226e-4 +0.00257594505916577 +0.0052505266785003 +0.00810596046568048 +0.0111111690166798 +0.0142318659846858 +0.0174310658866196 +0.0206696428324693 +0.0239069404409966 +0.0271014128800568 +0.0302112916385789 +0.0331952625461897 +0.0360131429726491 +0.0386265459586327 +0.0409995195603867 +0.0430991464884573 +0.0448960998991556 +0.0463651374584695 +0.0474855309975742 +0.0482414158697416 +0.0486220638091454 +0.0486220638091454 +0.0482414158697416 +0.0474855309975742 +0.0463651374584695 +0.0448960998991556 +0.0430991464884573 +0.0409995195603867 +0.0386265459586327 +0.0360131429726491 +0.0331952625461897 +0.0302112916385789 +0.0271014128800568 +0.0239069404409966 +0.0206696428324693 +0.0174310658866196 +0.0142318659846858 +0.0111111690166798 +0.00810596046568048 +0.0052505266785003 +0.00257594505916577 +1.09643059299226e-4 +-0.00212497423336652 +-0.0041088188533721 +-0.0058273332996356 +-0.00727062096870851 +-0.0084334894941071 +-0.00931541332239757 +-0.0099204091949967 +-0.0102568377148858 +-0.0103371277935579 +-0.0101774361576858 +-0.00979724946072329 +-0.00921892960311577 +-0.00846722496704464 +-0.00756874635507542 +-0.00655142415066617 +-0.00544395757085389 +-0.00427525920508468 +-0.00307391993768759 +-0.00186768708315042 +-6.82980522572643e-4 +4.55555350931454e-4 +0.00152545134396061 +0.00250675668335827 +0.00338232730758133 +0.00413804459791576 +0.00476297411539252 +0.00524945134321352 +0.00559310428736023 +0.0057928072764395 +0.00585057149230045 +0.00577137823517525 +0.00556295588482682 +0.00523550974836302 +0.00480141038410035 +0.00427484711920302 +0.00367145812920719 +0.00300793964707363 +0.00230165125086365 +0.00157021607771463 +8.31132315629842e-4 +1.01397889009688e-4 +-6.02837209621259e-4 +-0.00126659496546869 +-0.0018763509819845 +-0.00242028158028417 +-0.0028884598696194 +-0.00327301016165189 +-0.00356820912785959 +-0.00377053814671627 +-0.00387868559008699 +-0.00389350186222283 +-0.00381790643652724 +-0.00365675622328083 +-0.00341666930468077 +-0.00310582337372604 +-0.0027337187227384 +-0.00231092502530074 +-0.00184880903364977 +-0.00135925347644246 +-8.54375818614214e-4 +-3.46245873742672e-4 +1.5338150399634e-4 +6.33323430643252e-4 +0.0010832027611814 +0.00149365620556701 +0.00185651528950842 +0.00216495311562251 +0.00241359905001614 +0.00259861436853517 +0.00271773284742105 +0.00277026461769735 +0.00275706287455375 +0.00268046014161941 +0.00254416760290437 +0.00235315096692847 +0.00211347938372566 +0.00183215385494268 +0.00151692075161767 +0.00117607035980743 +8.18234381982771e-4 +4.52176307534593e-4 +8.65878287229843e-5 +-2.70108419498178e-4 +-6.09943356897427e-4 +-9.25571871008901e-4 +-0.00121042184021843 +-0.0014588228462092 +-0.00166611043274461 +-0.00182870407402118 +-0.00194415758323169 +-0.00201118336129597 +-0.00202964706581313 +-0.00200054079682649 +-0.00192592281171168 +-0.00180884426159716 +-0.00165324714625177 +-0.00146385027634117 +-0.00124601613279792 +-0.0010056096258098 +-7.48849254545155e-4 +-4.82152145309325e-4 +-2.1198068576069e-4 +5.53078264280656e-5 +3.13605594907024e-4 +5.57187482764196e-4 +7.80834826954757e-4 +9.79937911476128e-4 +0.00115058933642334 +0.00128965157704395 +0.00139480951060361 +0.00146459939319946 +0.00149841919645406 +0.00149651846177726 +0.0014599674225506 +0.0013906093284534 +0.00129099572518951 +0.00116430673085702 +0.00101425950405569 +8.45007409820417e-4 +6.61030288225903e-4 +4.67021632594192e-4 +2.67772482152798e-4 +6.80586481779722e-5 +-1.27470456729415e-4 +-3.14396237291812e-4 +-4.8862706565045e-4 +-6.46484210138539e-4 +-7.84775133395688e-4 +-9.00853865253174e-4 +-9.92667960092833e-4 +-0.00105878723152578 +-0.00109842176590062 +-0.00111141913270169 +-0.00109825180635536 +-0.0010599866628307 +-9.98243562663091e-4 +-9.15141775653344e-4 +-8.13236256145513e-4 +-6.95445072726885e-4 +-5.6497087428213e-4 +-4.25218148098678e-4 +-2.79707337982926e-4 +-1.31990568245096e-4 +1.44330402738205e-5 +1.5619696018914e-4 +2.90142907465985e-4 +4.13387627487922e-4 +5.23381496018073e-4 +6.17959079267155e-4 +6.9537963487656e-4 +7.5435263217961e-4 +7.94056446208742e-4 +8.14142664644267e-4 +8.14730777273661e-4 +7.96391761417496e-4 +7.6012020281837e-4 +7.07299816040927e-4 +6.39657748300381e-4 +5.59215876696991e-4 +4.68233075668834e-4 +3.69146665341244e-4 +2.64508461181843e-4 +1.56922907604873e-4 +4.89841731832692e-5 +-5.6784716422895e-5 +-1.57988085254148e-4 +-2.52409733078722e-4 +-3.38060678040117e-4 +-4.13216007201208e-4 +-4.76451870743233e-4 +-5.26663373800026e-4 +-5.63086337917986e-4 +-5.85300692351394e-4 +-5.93232478671107e-4 +-5.87143099888524e-4 +-5.67613638239988e-4 +-5.35520428249821e-4 +-4.9200703290972e-4 +-4.38446131068721e-4 +-3.76404164136881e-4 +-3.07594047026731e-4 +-2.33835056002673e-4 +-1.57002327126315e-4 +-7.89848893170478e-5 +-1.63779237740676e-6 +7.3257656515258e-5 +1.44035366727157e-4 +2.09178855148142e-4 +2.67352241592445e-4 +3.17425558178502e-4 +3.58494957675319e-4 +3.89896739795703e-4 +4.11214766210894e-4 +4.22282619148847e-4 +4.23179220684935e-4 +4.14218377731336e-4 +3.95935025218761e-4 +3.69063740137675e-4 +3.34516779687324e-4 +2.93354710149485e-4 +2.46758430731207e-4 +1.95996823059339e-4 +1.4239311797007e-4 +8.72935203677178e-5 +3.20332747710491e-5 +-2.2092886327107e-5 +-7.38611116469124e-5 +-1.22144676611347e-4 +-1.65935928106054e-4 +-2.04367498164773e-4 +-2.36726227379411e-4 +-2.62467514354949e-4 +-2.81218526412152e-4 +-2.9278440100842e-4 +-2.97145272500789e-4 +-2.94450224275897e-4 +-2.85009149126569e-4 +-2.69279472445284e-4 +-2.47848788110117e-4 +-2.21419291675664e-4 +-1.90783149605849e-4 +-1.56806879798798e-4 +-1.20401080500299e-4 +-8.25032454022742e-5 +-4.40513605910619e-5 +-5.96356740813766e-6 +3.08848326050668e-5 +6.56776045971978e-5 +9.76776349699245e-5 +1.26238358089726e-4 +1.50819069616185e-4 +1.70990903256481e-4 +1.86445019398819e-4 +1.96994293467081e-4 +2.02573580216899e-4 +2.03236949574574e-4 +1.99151775086795e-4 +1.90590736122456e-4 +1.77921607229302e-4 +1.61594559165767e-4 +1.42129235004429e-4 +1.20099004917142e-4 +9.61160455879359e-5 +7.0815621084536e-5 +4.48385613205947e-5 +1.88188660219006e-5 +-6.63430458187306e-6 +-3.09472952504257e-5 +-5.35961801579358e-5 +-7.41158206776385e-5 +-9.21093274384085e-5 +-1.0725481963731e-4 +-1.19309561896777e-4 +-1.2811333539122e-4 +-1.33588879261025e-4 +-1.35739884161422e-4 +-1.34648743318249e-4 +-1.30468892775236e-4 +-1.23423041654638e-4 +-1.13790446423011e-4 +-1.01900589865764e-4 +-8.81236947188922e-5 +-7.28580214960265e-5 +-5.65228132450726e-5 +-3.95425112453473e-5 +-2.23418652788707e-5 +-5.33248429467424e-6 +1.10959100456974e-5 +2.65822878709086e-5 +4.08032785217656e-5 +5.347813081375e-5 +6.43756190395851e-5 +7.33144164498558e-5 +8.01683770409635e-5 +8.48651355449836e-5 +8.73861281253179e-5 +8.77652355990178e-5 +8.60846255633886e-5 +8.24733429562758e-5 +7.70982488738663e-5 +7.01613699670651e-5 +6.18941440803559e-5 +5.25469490585536e-5 +4.23881612033781e-5 +3.16889547008264e-5 +2.07264139138749e-5 +9.76750875584034e-6 +-9.29469045115252e-7 +-1.1125982738189e-5 +-2.06050398177054e-5 +-2.91770944785758e-5 +-3.66811426138427e-5 +-4.29902880316882e-5 +-4.80092456996724e-5 +-5.1680740099127e-5 +-5.39779986324577e-5 +-5.49127392818389e-5 +-5.45231256798723e-5 +-5.2881756318201e-5 +-5.00834846280012e-5 +-4.62496011329744e-5 +-4.15175966696302e-5 +-3.60413748500087e-5 +-2.99843308432599e-5 +-2.35164419241063e-5 +-1.68084780282784e-5 +-1.00309472232173e-5 +-3.34513850836547e-6 +3.09475951446394e-6 +9.15102381017684e-6 +1.46979062042561e-5 +1.9630985529227e-5 +2.3863596601089e-5 +2.73307787009361e-5 +2.99885330657398e-5 +3.18141310912695e-5 +3.28062497909458e-5 +3.29827423119358e-5 +3.23801498345e-5 +3.10523292715376e-5 +2.90669843834708e-5 +2.6504113480356e-5 +2.34525897473363e-5 +2.00104633597274e-5 +1.62776057022447e-5 +1.23587745013029e-5 +8.35431095023709e-6 +4.36391659133863e-6 +4.80912959878512e-7 +-3.20916832281648e-6 +-6.62826926323268e-6 +-9.71123313104019e-6 +-1.24032950277693e-5 +-1.46606892008227e-5 +-1.64542644771625e-5 +-1.77652468409902e-5 +-1.85905030202489e-5 +-1.89349221542663e-5 +-1.88180884125302e-5 +-1.82665081367835e-5 +-1.73187930064226e-5 +-1.60176157455328e-5 +-1.44140306102446e-5 +-1.25625562618188e-5 +-1.05213195267016e-5 +-8.34891011005015e-6 +-6.10417289473804e-6 +-3.84347493132933e-6 +-1.62303718375881e-6 +5.08537844109541e-7 +2.5045517191364e-6 +4.32718679501898e-6 +5.9411139708878e-6 +7.32184325292062e-6 +8.44836300475225e-6 +9.31094999767115e-6 +9.90357194955147e-6 +1.0228657500937e-5 +1.02939875082689e-5 +1.01139238186566e-5 +9.70730330637792e-6 +9.09759867217571e-6 +8.31026493121452e-6 +7.37667453186873e-6 +6.32696760641722e-6 +5.19442047840389e-6 +4.00982303462755e-6 +2.80519025479194e-6 +1.61065667346661e-6 +4.5272033468355e-7 +-6.41630367682649e-7 +-1.65168508479184e-6 +-2.55698769776267e-6 +-3.34381409235837e-6 +-4.00121137621988e-6 +-4.52057551249377e-6 +-4.90048958017337e-6 +-5.1394946501258e-6 +-5.24183699733879e-6 +-5.21373005767686e-6 +-5.063623966477e-6 +-4.80493586876171e-6 +-4.44917701834718e-6 +-4.01344340051503e-6 +-3.51170040070893e-6 +-2.96212165638707e-6 +-2.38006119965271e-6 +-1.78302023739655e-6 +-1.18587637892365e-6 +-6.0197624767097e-7 +-4.49606767418064e-8 +4.73800121500147e-7 +9.44346239710729e-7 +1.35846743996931e-6 +1.71076949967104e-6 +1.99610535588337e-6 +2.21343228064008e-6 +2.36167902121603e-6 +2.44371789997691e-6 +2.46085469574341e-6 +2.41942298528229e-6 +2.32279469282784e-6 +2.17833876701336e-6 +1.99304439308787e-6 +1.77357589639965e-6 +1.53005288621509e-6 +1.26826910787562e-6 +9.97486152500784e-7 +7.23956612504e-7 +4.53619817534114e-7 +1.95178720022609e-7 +-4.79481886690687e-8 +-2.69324680211038e-7 +-4.67089278916325e-7 +-6.37499558026062e-7 +-7.77649486859982e-7 +-8.87746045951503e-7 +-9.67049604607247e-7 +-1.01783166180378e-6 +-1.03946679063045e-6 +-1.03355489807237e-6 +-1.00406302340324e-6 +-9.516801687493e-7 +-8.83009467313344e-7 +-7.96695832853341e-7 +-7.00817920677767e-7 +-5.9487324901853e-7 +-4.85000602763094e-7 +-3.72869415873669e-7 +-2.62247401958816e-7 +-1.55165787913079e-7 +-5.50094412531977e-8 +3.83506638823491e-8 +1.20312660464537e-7 +1.93531346067046e-7 +2.53431354500078e-7 +3.02990066262988e-7 +3.39343358482371e-7 +3.65236448771379e-7 +3.77007825091848e-7 +3.80032136027046e-7 +3.71753520789388e-7 +3.57246917030831e-7 +3.34271689565622e-7 +3.05703733943038e-7 +2.72939884477538e-7 +2.3707190547137e-7 +1.99015401296622e-7 +1.6066011924682e-7 +1.20450960766471e-7 +8.33872247697555e-8 +4.71079084065085e-8 +1.51839061412207e-8 +-1.43267231105268e-8 +-3.99528124923842e-8 +-6.14126768147793e-8 +-7.89956849981134e-8 +-9.17625273815014e-8 +-1.01333875812554e-7 +-1.07199067922224e-7 +-1.09899151121439e-7 +-1.09342060902351e-7 +-1.0581696028102e-7 +-1.00062504114338e-7 +-9.19816359673906e-8 +-8.35519847400028e-8 +-7.34212411189246e-8 +-6.3122768061061e-8 +-5.15215025811016e-8 +-4.14587362468332e-8 +-3.19847926493859e-8 +-2.18251091115114e-8 +-1.25339352914121e-8 +-4.35513294668295e-9 +1.83985020585335e-9 +6.05954400825878e-9 +1.07557125018314e-8 +1.3068715878392e-8 +1.76960158618376e-8 +1.95132650596489e-8 +2.22929661801192e-8 +2.09724315061768e-8 +2.00800027395966e-8 +1.74208569471553e-8 +1.41716278773579e-8 +1.30077482700426e-8 +1.14333552786323e-8 +1.03271192432242e-8 +1.10906859282933e-8 +8.38300275294078e-9 +1.03151991819582e-8 diff --git a/fceumm/src-fceumm/fir/c96000pal.h b/fceumm/src-fceumm/fir/c96000pal.h new file mode 100644 index 0000000..dd0f917 --- /dev/null +++ b/fceumm/src-fceumm/fir/c96000pal.h @@ -0,0 +1,512 @@ +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +-1, +-1, +-1, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +1, +1, +1, +1, +2, +2, +2, +2, +2, +2, +2, +2, +2, +1, +1, +0, +0, +0, +0, +-1, +-1, +-2, +-3, +-3, +-4, +-4, +-5, +-5, +-5, +-5, +-5, +-5, +-4, +-4, +-3, +-2, +-1, +0, +0, +1, +2, +4, +5, +6, +7, +8, +9, +10, +10, +10, +10, +10, +9, +8, +7, +6, +4, +2, +0, +-1, +-4, +-6, +-8, +-11, +-13, +-15, +-16, +-18, +-19, +-19, +-19, +-19, +-18, +-17, +-15, +-13, +-10, +-6, +-3, +0, +4, +8, +12, +17, +20, +24, +27, +30, +32, +33, +34, +34, +33, +31, +28, +25, +20, +15, +9, +3, +-3, +-10, +-17, +-24, +-31, +-37, +-43, +-48, +-52, +-55, +-57, +-57, +-56, +-54, +-50, +-45, +-38, +-30, +-21, +-11, +0, +10, +21, +33, +44, +55, +64, +73, +80, +86, +90, +92, +91, +88, +84, +76, +67, +56, +42, +27, +11, +-5, +-23, +-41, +-59, +-76, +-92, +-106, +-119, +-129, +-136, +-141, +-142, +-140, +-134, +-125, +-112, +-96, +-77, +-56, +-32, +-6, +19, +47, +74, +100, +125, +149, +169, +186, +199, +208, +213, +212, +206, +195, +179, +158, +132, +102, +68, +32, +-6, +-46, +-86, +-126, +-164, +-200, +-232, +-259, +-282, +-298, +-308, +-311, +-307, +-294, +-275, +-248, +-214, +-173, +-128, +-77, +-23, +33, +91, +149, +205, +258, +307, +350, +386, +415, +434, +443, +442, +431, +408, +375, +332, +280, +219, +151, +76, +-1, +-82, +-164, +-245, +-322, +-394, +-459, +-515, +-561, +-595, +-615, +-622, +-613, +-590, +-552, +-499, +-433, +-354, +-264, +-165, +-59, +51, +164, +277, +387, +490, +586, +670, +741, +797, +835, +854, +853, +832, +790, +729, +647, +548, +433, +304, +163, +15, +-138, +-293, +-445, +-592, +-729, +-852, +-959, +-1046, +-1111, +-1151, +-1165, +-1151, +-1110, +-1040, +-944, +-822, +-677, +-512, +-329, +-133, +71, +280, +489, +693, +886, +1063, +1220, +1353, +1458, +1530, +1569, +1571, +1535, +1462, +1352, +1206, +1027, +818, +584, +328, +57, +-222, +-505, +-785, +-1054, +-1306, +-1534, +-1733, +-1896, +-2019, +-2097, +-2128, +-2108, +-2038, +-1917, +-1747, +-1529, +-1269, +-970, +-639, +-283, +90, +474, +857, +1233, +1590, +1921, +2216, +2467, +2667, +2810, +2890, +2904, +2849, +2724, +2530, +2270, +1946, +1566, +1135, +664, +160, +-363, +-895, +-1425, +-1938, +-2423, +-2866, +-3256, +-3582, +-3834, +-4003, +-4082, +-4067, +-3953, +-3741, +-3431, +-3028, +-2537, +-1967, +-1328, +-632, +106, +871, +1646, +2413, +3154, +3849, +4482, +5034, +5489, +5833, +6051, +6134, +6074, +5864, +5504, +4994, +4339, +3546, +2628, +1599, +477, +-716, +-1958, +-3223, +-4482, +-5708, +-6869, +-7936, +-8878, +-9666, +-10273, +-10671, +-10839, +-10755, +-10402, +-9767, +-8843, +-7623, +-6110, +-4308, +-2228, +114, +2701, +5505, +8499, +11650, +14923, +18277, +21673, +25068, +28417, +31678, +34807, +37762, +40502, +42991, +45192, +47076, +48617, +49792, +50584, +50983, diff --git a/fceumm/src-fceumm/fir/c96000pal.scm b/fceumm/src-fceumm/fir/c96000pal.scm new file mode 100644 index 0000000..e8901ed --- /dev/null +++ b/fceumm/src-fceumm/fir/c96000pal.scm @@ -0,0 +1,12 @@ +(title "96000 PAL") + +(verbose #t) + +(cosine-symmetry) +(filter-length 1024) +(sampling-frequency 1662607.125) +(limit-= (band 0 33400) 1) +(limit-= (band 48000 831303.5625) 0 .5) +(output-file "c96000pal.coef") +(plot-file "c96000pal.plot") +(go) diff --git a/fceumm/src-fceumm/fir/toh.c b/fceumm/src-fceumm/fir/toh.c new file mode 100644 index 0000000..409eea3 --- /dev/null +++ b/fceumm/src-fceumm/fir/toh.c @@ -0,0 +1,24 @@ +#include + +#define MAX 512 + +main() +{ + char buf[256]; + int count=0; + + while(fgets(buf,256,stdin)>0) + { + double p; + + if(sscanf(buf,"%lf",&p)==1) + { + p*=65536*16; + printf("%ld,\n",(long)p); + count++; + if(count==MAX) break; + } + + } + +} diff --git a/fceumm/src-fceumm/general.c b/fceumm/src-fceumm/general.c new file mode 100644 index 0000000..4995485 --- /dev/null +++ b/fceumm/src-fceumm/general.c @@ -0,0 +1,196 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include + +#include +#include +#ifndef _MSC_VER +#include +#endif + +#include "types.h" +#include "fceu.h" + +#include "general.h" +#include "state.h" + +#include "driver.h" + +#include "md5.h" + +static char BaseDirectory[2048]; +static char FileBase[2048]; +static char FileExt[2048]; /* Includes the . character, as in ".nes" */ + +static char FileBaseDirectory[2048]; + +void FCEUI_SetBaseDirectory(char *dir) +{ + strncpy(BaseDirectory,dir,2047); + BaseDirectory[2047]=0; +} + +static char *odirs[FCEUIOD__COUNT]={0,0,0,0,0,0}; /* odirs, odors. ^_^*/ + +void FCEUI_SetDirOverride(int which, const char *n) +{ + odirs[which] = n; +} + +#ifndef HAVE_ASPRINTF +static int asprintf(char **strp, const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap,fmt); + if(!(*strp=malloc(2048))) + return(0); + ret=vsnprintf(*strp,2048,fmt,ap); + va_end(ap); + return(ret); +} +#endif + +const char * FCEU_MakeFName(int type, int id1, const char *cd1) +{ + char *ret=0; + struct stat tmpstat; + + switch(type) + { + case FCEUMKF_NPTEMP: + asprintf(&ret,"%s"PSS"m590plqd94fo.tmp",BaseDirectory); + break; + case FCEUMKF_STATE: + if(odirs[FCEUIOD_STATE]) + asprintf(&ret,"%s"PSS"%s.fc%d",odirs[FCEUIOD_STATE],FileBase,id1); + else + asprintf(&ret,"%s"PSS"fcs"PSS"%s.fc%d",BaseDirectory,FileBase,id1); + if(stat(ret,&tmpstat)==-1) + { + if(odirs[FCEUIOD_STATE]) + asprintf(&ret,"%s"PSS"%s.fc%d",odirs[FCEUIOD_STATE],FileBase,id1); + else + asprintf(&ret,"%s"PSS"fcs"PSS"%s.fc%d",BaseDirectory,FileBase,id1); + } + break; + case FCEUMKF_FDS: + if(odirs[FCEUIOD_NV]) + asprintf(&ret,"%s"PSS"%s.%s.fds",odirs[FCEUIOD_NV],FileBase,md5_asciistr(FCEUGameInfo->MD5)); + else + asprintf(&ret,"%s"PSS"sav"PSS"%s.%s.fds",BaseDirectory,FileBase,md5_asciistr(FCEUGameInfo->MD5)); + break; + case FCEUMKF_SAV: + if(odirs[FCEUIOD_NV]) + asprintf(&ret,"%s"PSS"%s.%s",odirs[FCEUIOD_NV],FileBase,cd1); + else + asprintf(&ret,"%s"PSS"sav"PSS"%s.%s",BaseDirectory,FileBase,cd1); + if(stat(ret,&tmpstat)==-1) + { + if(odirs[FCEUIOD_NV]) + asprintf(&ret,"%s"PSS"%s.%s.%s",odirs[FCEUIOD_NV],FileBase,md5_asciistr(FCEUGameInfo->MD5),cd1); + else + asprintf(&ret,"%s"PSS"sav"PSS"%s.%s.%s",BaseDirectory,FileBase,md5_asciistr(FCEUGameInfo->MD5),cd1); + } + break; + case FCEUMKF_CHEAT: + if(odirs[FCEUIOD_CHEATS]) + asprintf(&ret,"%s"PSS"%s.cht",odirs[FCEUIOD_CHEATS],FileBase); + else + asprintf(&ret,"%s"PSS"cheats"PSS"%s.cht",BaseDirectory,FileBase); + break; + case FCEUMKF_IPS: + asprintf(&ret,"%s"PSS"%s%s.ips",FileBaseDirectory,FileBase,FileExt); + break; + case FCEUMKF_GGROM: + asprintf(&ret,"%s"PSS"gg.rom",BaseDirectory); + break; + case FCEUMKF_FDSROM: + asprintf(&ret,"%s"PSS"disksys.rom",BaseDirectory); + break; + case FCEUMKF_PALETTE: + if(odirs[FCEUIOD_MISC]) + asprintf(&ret,"%s"PSS"%s.pal",odirs[FCEUIOD_MISC],FileBase); + else + asprintf(&ret,"%s"PSS"gameinfo"PSS"%s.pal",BaseDirectory,FileBase); + break; + } + return(ret); +} + +void GetFileBase(const char *f) +{ + const char *tp1,*tp3; + +#if PSS_STYLE==4 + tp1=((char *)strrchr(f,':')); +#elif PSS_STYLE==1 + tp1=((char *)strrchr(f,'/')); +#else + tp1=((char *)strrchr(f,'\\')); +#if PSS_STYLE!=3 + tp3=((char *)strrchr(f,'/')); + if(tp1tp1)) + { + memcpy(FileBase,tp1,tp3-tp1); + FileBase[tp3-tp1]=0; + strcpy(FileExt,tp3); + } + else + { + strcpy(FileBase,tp1); + FileExt[0]=0; + } +} + +uint32 uppow2(uint32 n) +{ + int x; + + for(x=31;x>=0;x--) + if(n&(1< +#include +#include + +#include "types.h" +#include "x6502.h" +#include "fceu.h" +#include "cart.h" +#include "ppu.h" + +#define INESPRIV +#include "ines.h" +#include "unif.h" +#include "general.h" +#include "state.h" +#include "file.h" +#include "memory.h" +#include "crc32.h" +#include "md5.h" +#include "cheat.h" +#include "vsuni.h" + +extern SFORMAT FCEUVSUNI_STATEINFO[]; + +static uint8 *trainerpoo=0; +static uint8 *ROM=NULL; +static uint8 *VROM=NULL; + +CartInfo iNESCart; + +uint8 iNESMirroring; +uint16 iNESCHRBankList[8]; +int32 iNESIRQLatch,iNESIRQCount; +uint8 iNESIRQa; + +uint32 ROM_size; +uint32 VROM_size; + +static void iNESPower(void); +static int NewiNES_Init(int num); + +void (*MapClose)(void); +void (*MapperReset)(void); + +static int MapperNo; + +static iNES_HEADER head; + +/* MapperReset() is called when the NES is reset(with the reset button). + Mapperxxx_init is called when the NES has been powered on. +*/ + +static DECLFR(TrainerRead) +{ + return(trainerpoo[A&0x1FF]); +} + +static void iNESGI(int h) +{ + switch(h) + { + case GI_RESETM2: + if(MapperReset) + MapperReset(); + if(iNESCart.Reset) + iNESCart.Reset(); + break; + case GI_POWER: + if(iNESCart.Power) + iNESCart.Power(); + if(trainerpoo) + { + int x; + for(x=0;x<512;x++) + { + X6502_DMW(0x7000+x,trainerpoo[x]); + if(X6502_DMR(0x7000+x)!=trainerpoo[x]) + { + SetReadHandler(0x7000,0x71FF,TrainerRead); + break; + } + } + } + break; + case GI_CLOSE: + { + FCEU_SaveGameSave(&iNESCart); + + if(iNESCart.Close) iNESCart.Close(); + if(ROM) {free(ROM);ROM=0;} + if(VROM) {free(VROM);VROM=0;} + if(MapClose) MapClose(); + if(trainerpoo) {free(trainerpoo);trainerpoo=0;} + } + break; + } +} + +uint32 iNESGameCRC32; + +struct CRCMATCH { + uint32 crc; + char *name; +}; + +struct INPSEL { + uint32 crc32; + int input1; + int input2; + int inputfc; +}; + +/* This is mostly for my personal use. So HA. */ +static void SetInput(void) +{ + static struct INPSEL moo[]= + { + {0x3a1694f9,SI_GAMEPAD,SI_GAMEPAD,SIFC_4PLAYER}, /* Nekketsu Kakutou Densetsu */ + + {0xc3c0811d,SI_GAMEPAD,SI_GAMEPAD,SIFC_OEKAKIDS}, /* The two "Oeka Kids" games */ + {0x9d048ea4,SI_GAMEPAD,SI_GAMEPAD,SIFC_OEKAKIDS}, /* */ + + {0xaf4010ea,SI_GAMEPAD,SI_POWERPADB,-1}, /* World Class Track Meet */ + {0xd74b2719,SI_GAMEPAD,SI_POWERPADB,-1}, /* Super Team Games */ + {0x61d86167,SI_GAMEPAD,SI_POWERPADB,-1}, /* Street Cop */ + {0x6435c095,SI_GAMEPAD,SI_POWERPADB,-1}, /* Short Order/Eggsplode */ + + + {0x47232739,SI_GAMEPAD,SI_GAMEPAD,SIFC_TOPRIDER}, /* Top Rider */ + + {0x48ca0ee1,SI_GAMEPAD,SI_GAMEPAD,SIFC_BWORLD}, /* Barcode World */ + {0x9f8f200a,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, /* Super Mogura Tataki!! - Pokkun Moguraa */ + {0x9044550e,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, /* Rairai Kyonshizu */ + {0x2f128512,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, /* Jogging Race */ + {0x60ad090a,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, /* Athletic World */ + + {0x8a12a7d9,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Totsugeki Fuuun Takeshi Jou */ + {0xea90f3e2,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Running Stadium */ + {0x370ceb65,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Meiro Dai Sakusen */ + /* Bad dump? {0x69ffb014,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, Fuun Takeshi Jou 2 */ + {0x6cca1c1f,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Dai Undoukai */ + {0x29de87af,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Aerobics Studio */ + {0xbba58be5,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Family Trainer: Manhattan Police */ + {0xea90f3e2,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Family Trainer: Running Stadium */ + + {0xd9f45be9,SI_GAMEPAD,SI_GAMEPAD,SIFC_QUIZKING}, /* Gimme a Break ... */ + {0x1545bd13,SI_GAMEPAD,SI_GAMEPAD,SIFC_QUIZKING}, /* Gimme a Break ... 2 */ + + {0x7b44fb2a,SI_GAMEPAD,SI_GAMEPAD,SIFC_MAHJONG}, /* Ide Yousuke Meijin no Jissen Mahjong 2 */ + {0x9fae4d46,SI_GAMEPAD,SI_GAMEPAD,SIFC_MAHJONG}, /* Ide Yousuke Meijin no Jissen Mahjong */ + + {0x980be936,SI_GAMEPAD,SI_GAMEPAD,SIFC_HYPERSHOT}, /* Hyper Olympic */ + {0x21f85681,SI_GAMEPAD,SI_GAMEPAD,SIFC_HYPERSHOT}, /* Hyper Olympic (Gentei Ban) */ + {0x915a53a7,SI_GAMEPAD,SI_GAMEPAD,SIFC_HYPERSHOT}, /* Hyper Sports */ + {0xad9c63e2,SI_GAMEPAD,-1,SIFC_SHADOW}, /* Space Shadow */ + + {0x24598791,-1,SI_ZAPPER,0}, /* Duck Hunt */ + {0xff24d794,-1,SI_ZAPPER,0}, /* Hogan's Alley */ + {0xbeb8ab01,-1,SI_ZAPPER,0}, /* Gumshoe */ + {0xde8fd935,-1,SI_ZAPPER,0}, /* To the Earth */ + {0xedc3662b,-1,SI_ZAPPER,0}, /* Operation Wolf */ + {0x2a6559a1,-1,SI_ZAPPER,0}, /* Operation Wolf (J) */ + + {0x23d17f5e,SI_GAMEPAD,SI_ZAPPER,0}, /* The Lone Ranger */ + {0xb8b9aca3,-1,SI_ZAPPER,0}, /* Wild Gunman */ + {0x5112dc21,-1,SI_ZAPPER,0}, /* Wild Gunman */ + {0x4318a2f8,-1,SI_ZAPPER,0}, /* Barker Bill's Trick Shooting */ + {0x5ee6008e,-1,SI_ZAPPER,0}, /* Mechanized Attack */ + {0x3e58a87e,-1,SI_ZAPPER,0}, /* Freedom Force */ + {0x4e959173,-1,SI_ZAPPER,0}, /* Gotcha! - The Sport! */ + + {0xe9a7fe9e,-1,SI_MOUSE,0}, /* Educational Computer 2000 */ + {0x2cf5db05,-1,SI_MOUSE,0}, /* Shu Qi Yu - Zhi Li Xiao Zhuan Yuan (Ch) */ + {0xc043a8df,-1,SI_MOUSE,0}, /* Shu Qi Yu - Shu Xue Xiao Zhuan Yuan (Ch) */ + + {0x851eb9be,SI_GAMEPAD,SI_ZAPPER,0}, /* Shooting Range */ + {0x74bea652,SI_GAMEPAD,SI_ZAPPER,0}, /* Supergun 3-in-1 */ + {0x32fb0583,-1,SI_ARKANOID,0}, /* Arkanoid(NES) */ + {0xd89e5a67,-1,-1,SIFC_ARKANOID}, /* Arkanoid (J) */ + {0x0f141525,-1,-1,SIFC_ARKANOID}, /* Arkanoid 2(J) */ + + {0x912989dc,-1,-1,SIFC_FKB}, /* Playbox BASIC */ + {0xf7606810,-1,-1,SIFC_FKB}, /* Family BASIC 2.0A */ + {0x895037bc,-1,-1,SIFC_FKB}, /* Family BASIC 2.1a */ + {0xb2530afc,-1,-1,SIFC_FKB}, /* Family BASIC 3.0 */ + {0x8587ee00,-1,-1,SIFC_FKB}, /* Keyboard Transformer */ + {0xbb33196f,-1,-1,SIFC_FKB}, /* Keyboard Transformer */ + + {0x8f7b1669,-1,-1,SIFC_SUBORKB}, /* FP BASIC 3.3 by maxzhou88 */ + {0x82f1fb96,-1,-1,SIFC_SUBORKB}, /* Subor 1.0 Russian */ + {0xabb2f974,-1,-1,SIFC_SUBORKB}, /* Study and Game 32-in-1 */ + {0xd5d6eac4,-1,-1,SIFC_SUBORKB}, /* Edu (As) */ + {0x589b6b0d,-1,-1,SIFC_SUBORKB}, /* SuporV20 */ + {0x5e073a1b,-1,-1,SIFC_SUBORKB}, /* Supor English (Chinese) */ + {0x8b265862,-1,-1,SIFC_SUBORKB}, + {0x41401c6d,-1,-1,SIFC_SUBORKB}, /* SuporV40 */ + {0x41ef9ac4,-1,-1,SIFC_SUBORKB}, + {0x368c19a8,-1,-1,SIFC_SUBORKB}, /* LIKO Study Cartridge */ + {0x543ab532,-1,-1,SIFC_SUBORKB}, /* LIKO Color Lines */ + {0,-1,-1,-1} + }; + int x=0; + + while(moo[x].input1>=0 || moo[x].input2>=0 || moo[x].inputfc>=0) + { + if(moo[x].crc32==iNESGameCRC32) + { + FCEUGameInfo->input[0]=moo[x].input1; + FCEUGameInfo->input[1]=moo[x].input2; + FCEUGameInfo->inputfc=moo[x].inputfc; + break; + } + x++; + } +} + +#define INESB_INCOMPLETE 1 +#define INESB_CORRUPT 2 +#define INESB_HACKED 4 + +struct BADINF { + uint64 md5partial; + char *name; + uint32 type; +}; + + +static struct BADINF BadROMImages[]= +{ + #include "ines-bad.h" +}; + +void CheckBad(uint64 md5partial) +{ + int x; + + x=0; + + while(BadROMImages[x].name) + { + if(BadROMImages[x].md5partial == md5partial) + { + FCEU_PrintError("The copy game you have loaded, \"%s\", is bad, and will not work properly on FCE Ultra.", BadROMImages[x].name); + return; + } + x++; + } + +} + + +struct CHINF { + uint32 crc32; + int32 mapper; + int32 mirror; +}; + +static void CheckHInfo(void) +{ + /* ROM images that have the battery-backed bit set in the header that really + don't have battery-backed RAM is not that big of a problem, so I'll + treat this differently by only listing games that should have battery-backed RAM. + + Lower 64 bits of the MD5 hash. + */ + + static uint64 savie[]= + { + 0x498c10dc463cfe95LL, /* Battle Fleet */ + 0x6917ffcaca2d8466LL, /* Famista '90 */ + + 0xd63dcc68c2b20adcLL, /* Final Fantasy J */ + 0x012df596e2b31174LL, /* Final Fantasy 1+2 */ + 0xf6b359a720549ecdLL, /* Final Fantasy 2 */ + 0x5a30da1d9b4af35dLL, /* Final Fantasy 3 */ + + 0x2ee3417ba8b69706LL, /* Hydlide 3*/ + + 0xebbce5a54cf3ecc0LL, /* Justbreed */ + + 0x6a858da551ba239eLL, /* Kaijuu Monogatari */ + 0xa40666740b7d22feLL, /* Mindseeker */ + + 0x77b811b2760104b9LL, /* Mouryou Senki Madara */ + + 0x11b69122efe86e8cLL, /* RPG Jinsei Game */ + + 0xa70b495314f4d075LL, /* Ys 3 */ + + + 0xc04361e499748382LL, /* AD&D Heroes of the Lance */ + 0xb72ee2337ced5792LL, /* AD&D Hillsfar */ + 0x2b7103b7a27bd72fLL, /* AD&D Pool of Radiance */ + + 0x854d7947a3177f57LL, /* Crystalis */ + + 0xb0bcc02c843c1b79LL, /* DW */ + 0x4a1f5336b86851b6LL, /* DW */ + + 0x2dcf3a98c7937c22LL, /* DW 2 */ + 0x733026b6b72f2470LL, /* Dw 3 */ + 0x98e55e09dfcc7533LL, /* DW 4*/ + 0x8da46db592a1fcf4LL, /* Faria */ + 0x91a6846d3202e3d6LL, /* Final Fantasy */ + 0xedba17a2c4608d20LL, /* "" */ + + 0x94b9484862a26cbaLL, /* Legend of Zelda */ + 0x04a31647de80fdabLL, /* "" */ + + 0x9aa1dc16c05e7de5LL, /* Startropics */ + 0x1b084107d0878bd0LL, /* Startropics 2*/ + + 0x836c0ff4f3e06e45LL, /* Zelda 2 */ + + 0x82000965f04a71bbLL, /* Mirai Shinwa Jarvas */ + + 0 /* Abandon all hope if the game has 0 in the lower 64-bits of its MD5 hash */ + }; + + static struct CHINF moo[]= + { +#include "ines-correct.h" + }; + int tofix=0; + int x; + uint64 partialmd5=0; + + for(x=0;x<8;x++) + { + partialmd5 |= (uint64)iNESCart.MD5[15-x] << (x*8); + } + + CheckBad(partialmd5); + + x=0; + + + do + { + if(moo[x].crc32==iNESGameCRC32) + { + if(moo[x].mapper>=0) + { + if(moo[x].mapper&0x800 && VROM_size) + { + VROM_size=0; + free(VROM); + VROM=0; + tofix|=8; + } + if(MapperNo!=(moo[x].mapper&0xFF)) + { + tofix|=1; + MapperNo=moo[x].mapper&0xFF; + } + } + if(moo[x].mirror>=0) + { + if(moo[x].mirror==8) + { + if(Mirroring==2) /* Anything but hard-wired(four screen). */ + { + tofix|=2; + Mirroring=0; + } + } + else if(Mirroring!=moo[x].mirror) + { + if(Mirroring!=(moo[x].mirror&~4)) + if((moo[x].mirror&~4)<=2) /* Don't complain if one-screen mirroring + needs to be set(the iNES header can't + hold this information). + */ + tofix|=2; + Mirroring=moo[x].mirror; + } + } + break; + } + x++; + } while(moo[x].mirror>=0 || moo[x].mapper>=0); + + x=0; + while(savie[x] != 0) + { + if(savie[x] == partialmd5) + { + if(!(head.ROM_type&2)) + { + tofix|=4; + head.ROM_type|=2; + } + } + x++; + } + + /* Games that use these iNES mappers tend to have the four-screen bit set + when it should not be. + */ + if((MapperNo==118 || MapperNo==24 || MapperNo==26) && (Mirroring==2)) + { + Mirroring=0; + tofix|=2; + } + + /* Four-screen mirroring implicitly set. */ + if(MapperNo==99) + Mirroring=2; + +#ifdef FCEU_LOG + if(tofix) + { + char gigastr[768]; + strcpy(gigastr,"The iNES header contains incorrect information. For now, the information will be corrected in RAM. "); + if(tofix&1) + sprintf(gigastr+strlen(gigastr),"The mapper number should be set to %d. ",MapperNo); + if(tofix&2) + { + char *mstr[3]={"Horizontal","Vertical","Four-screen"}; + sprintf(gigastr+strlen(gigastr),"Mirroring should be set to \"%s\". ",mstr[Mirroring&3]); + } + if(tofix&4) + strcat(gigastr,"The battery-backed bit should be set. "); + if(tofix&8) + strcat(gigastr,"This game should not have any CHR ROM. "); + strcat(gigastr,"\n"); + FCEU_printf("%s",gigastr); + } +#endif +} + +typedef struct { + int mapper; + void (*init)(CartInfo *); +} NewMI; + +int iNESLoad(const char *name, FCEUFILE *fp) +{ + struct md5_context md5; + + if(FCEU_fread(&head,1,16,fp)!=16) + return 0; + + if(memcmp(&head,"NES\x1a",4)) + return 0; + + memset(&iNESCart,0,sizeof(iNESCart)); + + if(!memcmp((char *)(&head)+0x7,"DiskDude",8)) + { + memset((char *)(&head)+0x7,0,0x9); + } + + if(!memcmp((char *)(&head)+0x7,"demiforce",9)) + { + memset((char *)(&head)+0x7,0,0x9); + } + + if(!memcmp((char *)(&head)+0xA,"Ni03",4)) + { + if(!memcmp((char *)(&head)+0x7,"Dis",3)) + memset((char *)(&head)+0x7,0,0x9); + else + memset((char *)(&head)+0xA,0,0x6); + } + + /* int ROM_size=0;*/ + if(!head.ROM_size) + { + /* FCEU_PrintError("No PRG ROM!");*/ + /* return(0);*/ + ROM_size=256; + /* head.ROM_size=255;*/ + /*head.ROM_size++;*/ + } + else + ROM_size=head.ROM_size; + + /* ROM_size = head.ROM_size;*/ + VROM_size = head.VROM_size; + + ROM_size=uppow2(ROM_size); + if(VROM_size) + VROM_size=uppow2(VROM_size); + + MapperNo = (head.ROM_type>>4); + MapperNo|=(head.ROM_type2&0xF0); + Mirroring = (head.ROM_type&1); + + if(head.ROM_type&8) Mirroring=2; + + if(!(ROM=(uint8 *)FCEU_malloc(ROM_size<<14))) + return 0; + + if(VROM_size) + if(!(VROM=(uint8 *)FCEU_malloc(VROM_size<<13))) + { + free(ROM); + ROM=0; + return 0; + } + + memset(ROM,0xFF,ROM_size<<14); + if(VROM_size) memset(VROM,0xFF,VROM_size<<13); + if(head.ROM_type&4) /* Trainer */ + { + trainerpoo=(uint8 *)FCEU_gmalloc(512); + FCEU_fread(trainerpoo,512,1,fp); + } + + ResetCartMapping(); + ResetExState(0,0); + + SetupCartPRGMapping(0,ROM,ROM_size*0x4000,0); + /*SetupCartPRGMapping(1,WRAM,8192,1);*/ + + if(head.ROM_size) + FCEU_fread(ROM,0x4000,head.ROM_size,fp); + else + FCEU_fread(ROM,0x4000,ROM_size,fp); + + if(VROM_size) + FCEU_fread(VROM,0x2000,head.VROM_size,fp); + + md5_starts(&md5); + md5_update(&md5,ROM,ROM_size<<14); + + iNESGameCRC32=CalcCRC32(0,ROM,ROM_size<<14); + + if(VROM_size) + { + iNESGameCRC32=CalcCRC32(iNESGameCRC32,VROM,VROM_size<<13); + md5_update(&md5,VROM,VROM_size<<13); + } + md5_finish(&md5,iNESCart.MD5); + memcpy(FCEUGameInfo->MD5,iNESCart.MD5,sizeof(iNESCart.MD5)); + + iNESCart.CRC32=iNESGameCRC32; + +#ifdef FCEU_LOG + FCEU_printf(" PRG ROM: %3d x 16KiB\n",ROM_size); + FCEU_printf(" CHR ROM: %3d x 8KiB\n",head.VROM_size); + FCEU_printf(" ROM CRC32: 0x%08lx\n",iNESGameCRC32); + FCEU_printf(" ROM MD5: 0x%s\n",md5_asciistr(iNESCart.MD5)); + FCEU_printf(" Mapper: %d\n", MapperNo); + FCEU_printf(" Mirroring: %s\n", Mirroring==2?"None(Four-screen)":Mirroring?"Vertical":"Horizontal"); + + if(head.ROM_type&2) FCEU_printf(" Battery-backed.\n"); + if(head.ROM_type&4) FCEU_printf(" Trained.\n"); +#endif + + SetInput(); + CheckHInfo(); + { + int x; + uint64 partialmd5=0; + + for(x=0;x<8;x++) + { + partialmd5 |= (uint64)iNESCart.MD5[7-x] << (x*8); + } + + FCEU_VSUniCheck(partialmd5, &MapperNo, &Mirroring); + } + /* Must remain here because above functions might change value of + VROM_size and free(VROM). + */ + if(VROM_size) + SetupCartCHRMapping(0,VROM,VROM_size*0x2000,0); + + if(Mirroring==2) + SetupCartMirroring(4,1,ExtraNTARAM); + else if(Mirroring>=0x10) + SetupCartMirroring(2+(Mirroring&1),1,0); + else + SetupCartMirroring(Mirroring&1,(Mirroring&4)>>2,0); + + iNESCart.battery=(head.ROM_type&2)?1:0; + iNESCart.mirror=Mirroring; + + /*if(MapperNo != 18) {*/ + /* if(ROM) free(ROM);*/ + /* if(VROM) free(VROM);*/ + /* ROM=VROM=0;*/ + /* return(0);*/ + /* }*/ + + if(NewiNES_Init(MapperNo)) + { + + } + else + { + iNESCart.Power=iNESPower; + if(head.ROM_type&2) + { + iNESCart.SaveGame[0]=WRAM; + iNESCart.SaveGameLen[0]=8192; + } + } + FCEU_LoadGameSave(&iNESCart); + + GameInterface=iNESGI; +#ifdef FCEU_LOG + FCEU_printf("\n"); +#endif + /* since apparently the iNES format doesn't store this information,*/ + /* guess if the settings should be PAL or NTSC from the ROM name*/ + /* TODO: MD5 check against a list of all known PAL games instead?*/ + if(strstr(name,"(E)") || strstr(name,"(e)") + || strstr(name,"(F)") || strstr(name,"(f)") + || strstr(name,"(G)") || strstr(name,"(g)") + || strstr(name,"(I)") || strstr(name,"(i)") + || strstr(name, "(Europe)") || strstr(name, "(Australia)") + || strstr(name, "(France)") || strstr(name, "(Germany)") + || strstr(name, "(Sweden)") || strstr(name, "(En, Fr, De)") + || strstr(name, "(Italy)")) + FCEUI_SetVidSystem(1); + else + FCEUI_SetVidSystem(0); + + return 1; +} + +void VRAM_BANK1(uint32 A, uint8 V) +{ + V&=7; + PPUCHRRAM|=(1<<(A>>10)); + CHRBankList[(A)>>10]=V; + VPage[(A)>>10]=&CHRRAM[V<<10]-(A); +} + +void VRAM_BANK4(uint32 A, uint32 V) +{ + V&=1; + PPUCHRRAM|=(0xF<<(A>>10)); + CHRBankList[(A)>>10]=(V<<2); + CHRBankList[((A)>>10)+1]=(V<<2)+1; + CHRBankList[((A)>>10)+2]=(V<<2)+2; + CHRBankList[((A)>>10)+3]=(V<<2)+3; + VPage[(A)>>10]=&CHRRAM[V<<10]-(A); +} +void VROM_BANK1(uint32 A,uint32 V) +{ + setchr1(A,V); + CHRBankList[(A)>>10]=V; +} + +void VROM_BANK2(uint32 A,uint32 V) +{ + setchr2(A,V); + CHRBankList[(A)>>10]=(V<<1); + CHRBankList[((A)>>10)+1]=(V<<1)+1; +} + +void VROM_BANK4(uint32 A, uint32 V) +{ + setchr4(A,V); + CHRBankList[(A)>>10]=(V<<2); + CHRBankList[((A)>>10)+1]=(V<<2)+1; + CHRBankList[((A)>>10)+2]=(V<<2)+2; + CHRBankList[((A)>>10)+3]=(V<<2)+3; +} + +void VROM_BANK8(uint32 V) +{ + setchr8(V); + CHRBankList[0]=(V<<3); + CHRBankList[1]=(V<<3)+1; + CHRBankList[2]=(V<<3)+2; + CHRBankList[3]=(V<<3)+3; + CHRBankList[4]=(V<<3)+4; + CHRBankList[5]=(V<<3)+5; + CHRBankList[6]=(V<<3)+6; + CHRBankList[7]=(V<<3)+7; +} + +void ROM_BANK8(uint32 A, uint32 V) +{ + setprg8(A,V); + if(A>=0x8000) + PRGBankList[((A-0x8000)>>13)]=V; +} + +void ROM_BANK16(uint32 A, uint32 V) +{ + setprg16(A,V); + if(A>=0x8000) + { + PRGBankList[((A-0x8000)>>13)]=V<<1; + PRGBankList[((A-0x8000)>>13)+1]=(V<<1)+1; + } +} + +void ROM_BANK32(uint32 V) +{ + setprg32(0x8000,V); + PRGBankList[0]=V<<2; + PRGBankList[1]=(V<<2)+1; + PRGBankList[2]=(V<<2)+2; + PRGBankList[3]=(V<<2)+3; +} + +void onemir(uint8 V) +{ + if(Mirroring==2) return; + if(V>1) + V=1; + Mirroring=0x10|V; + setmirror(MI_0+V); +} + +void MIRROR_SET2(uint8 V) +{ + if(Mirroring==2) return; + Mirroring=V; + setmirror(V); +} + +void MIRROR_SET(uint8 V) +{ + if(Mirroring==2) return; + V^=1; + Mirroring=V; + setmirror(V); +} + +static void NONE_init(void) +{ + ROM_BANK16(0x8000,0); + ROM_BANK16(0xC000,~0); + + if(VROM_size) + VROM_BANK8(0); + else + setvram8(CHRRAM); +} + +void (*MapInitTab[256])(void)= +{ + 0, + 0, + 0, /*Mapper2_init,*/ + 0, /*Mapper3_init,*/ + 0, + 0, + Mapper6_init, + 0,/*Mapper7_init,*/ + Mapper8_init, + Mapper9_init, + Mapper10_init, + 0, /*Mapper11_init,*/ + 0, + 0, /*Mapper13_init,*/ + 0, + 0, /*Mapper15_init,*/ + 0, /*Mapper16_init,*/ + Mapper17_init, + Mapper18_init, + 0, + 0, + Mapper21_init, + Mapper22_init, + 0, /*Mapper23_init,*/ + Mapper24_init, + Mapper25_init, + Mapper26_init, + Mapper27_init, + 0, + 0, + 0, + 0, + Mapper32_init, + Mapper33_init, + Mapper34_init, + 0, + 0, + 0, + 0, + 0, + Mapper40_init, + Mapper41_init, + Mapper42_init, + 0, /*Mapper43_init,*/ + 0, + 0, + Mapper46_init, + 0, + Mapper48_init, + 0, + Mapper50_init, + Mapper51_init, + 0, + 0, + 0, + 0, + 0, + 0,/* Mapper57_init,*/ + 0,/* Mapper58_init,*/ + Mapper59_init, + 0,/* Mapper60_init,*/ + Mapper61_init, + Mapper62_init, + 0, + Mapper64_init, + Mapper65_init, + 0,/*Mapper66_init,*/ + Mapper67_init, + 0,/*Mapper68_init,*/ + Mapper69_init, + 0,/*Mapper70_init,*/ + Mapper71_init, + Mapper72_init, + Mapper73_init, + 0, + Mapper75_init, + Mapper76_init, + Mapper77_init, + 0, /*Mapper78_init,*/ + Mapper79_init, + Mapper80_init, + 0, + Mapper82_init, + Mapper83_init, + 0, + Mapper85_init, + Mapper86_init, + 0, /*Mapper87_init,*/ + 0, /*Mapper88_init,*/ + Mapper89_init, + 0, + Mapper91_init, + Mapper92_init, + 0, /*Mapper93_init,*/ + 0, /*Mapper94_init,*/ + 0, + Mapper96_init, + Mapper97_init, + 0, + Mapper99_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /*Mapper107_init,*/ + 0, + 0, + 0, + 0, + 0, + 0, /* Mapper113_init,*/ + 0, + 0, + 0, /*Mapper116_init,*/ + 0, /*Mapper117_init,*/ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /*Mapper140_init,*/ + 0, + 0, + 0, + 0, /*Mapper144_init,*/ + 0, + 0, + 0, + 0, + 0, + 0, + Mapper151_init, + 0, /*Mapper152_init,*/ + 0, /*Mapper153_init,*/ + 0, /*Mapper154_init,*/ + 0, + 0, /*Mapper156_init,*/ + Mapper157_init, + 0, /*Mapper158_init, removed*/ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Mapper166_init, + Mapper167_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /*Mapper180_init,*/ + 0, + 0, + 0, + 0, /*Mapper184_init,*/ + 0, /*Mapper185_init,*/ + 0, + 0, + 0, + 0, /*Mapper189_init,*/ + 0, + 0, /*Mapper191_init,*/ + 0, + 0, /*Mapper193_init,*/ + 0, + 0, + 0, + 0, + 0, + 0, + 0, /*Mapper200_init,*/ + Mapper201_init, + Mapper202_init, + Mapper203_init, + Mapper204_init, + 0, + 0, + Mapper207_init, + 0, + 0, + 0, + 0, /*Mapper211_init,*/ + Mapper212_init, + Mapper213_init, + Mapper214_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /*Mapper225_init,*/ + 0, /*Mapper226_init,*/ + Mapper227_init, + Mapper228_init, + Mapper229_init, + Mapper230_init, + Mapper231_init, + Mapper232_init, + 0, + Mapper234_init, + 0, /*Mapper235_init,*/ + 0, + 0, + 0, + 0, + 0, /*Mapper240_init,*/ + Mapper241_init, + Mapper242_init, + 0, + Mapper244_init, + 0, + Mapper246_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Mapper255_init +}; + +static DECLFW(BWRAM) +{ + WRAM[A-0x6000]=V; +} + +static DECLFR(AWRAM) +{ + return WRAM[A-0x6000]; +} + + +void (*MapStateRestore)(int version); +void iNESStateRestore(int version) +{ + int x; + + if(!MapperNo) return; + + for(x=0;x<4;x++) + setprg8(0x8000+x*8192,PRGBankList[x]); + + if(VROM_size) + for(x=0;x<8;x++) + setchr1(0x400*x,CHRBankList[x]); + +if(0) switch(Mirroring) + { + case 0:setmirror(MI_H);break; + case 1:setmirror(MI_V);break; + case 0x12: + case 0x10:setmirror(MI_0);break; + case 0x13: + case 0x11:setmirror(MI_1);break; + } + if(MapStateRestore) MapStateRestore(version); +} + +static void iNESPower(void) +{ + int x; + int type=MapperNo; + + SetReadHandler(0x8000,0xFFFF,CartBR); + GameStateRestore=iNESStateRestore; + MapClose=0; + MapperReset=0; + MapStateRestore=0; + + setprg8r(1,0x6000,0); + + SetReadHandler(0x6000,0x7FFF,AWRAM); + SetWriteHandler(0x6000,0x7FFF,BWRAM); + FCEU_CheatAddRAM(8,0x6000,WRAM); + + /* This statement represents atrocious code. I need to rewrite + all of the iNES mapper code... */ + IRQCount=IRQLatch=IRQa=0; + if(head.ROM_type&2) + memset(GameMemBlock+8192,0,sizeof(GameMemBlock)-8192); + else + memset(GameMemBlock,0,sizeof(GameMemBlock)); + + NONE_init(); + + ResetExState(0,0); + if(FCEUGameInfo->type == GIT_VSUNI) + AddExState(FCEUVSUNI_STATEINFO, ~0, 0, 0); + + AddExState(WRAM, 8192, 0, "WRAM"); + if(type==19 || type==6 || type==69 || type==85 || type==96) + AddExState(MapperExRAM, 32768, 0, "MEXR"); + if((!VROM_size || type==6 || type==19) && (type!=13 && type!=96)) + AddExState(CHRRAM, 8192 * 4, 0, "CHRR"); + if(head.ROM_type&8) + AddExState(ExtraNTARAM, 2048, 0, "EXNR"); + + /* Exclude some mappers whose emulation code handle save state stuff + themselves. */ + if(type && type!=13 && type!=96) + { + AddExState(mapbyte1, 32, 0, "MPBY"); + AddExState(&Mirroring, 1, 0, "MIRR"); + AddExState(&IRQCount, 4, 1, "IRQC"); + AddExState(&IRQLatch, 4, 1, "IQL1"); + AddExState(&IRQa, 1, 0, "IRQA"); + AddExState(PRGBankList, 4, 0, "PBL"); + for(x=0;x<8;x++) + { + char tak[8]; + sprintf(tak,"CBL%d",x); + AddExState(&CHRBankList[x], 2, 1,tak); + } + } + + if(MapInitTab[type]) MapInitTab[type](); + else if(type) + { + FCEU_PrintError("iNES mapper #%d is not supported at all.",type); + } +} + + +typedef struct { + int number; + void (*init)(CartInfo *); +} BMAPPING; + +static BMAPPING bmap[] = { + {0, NROM_Init}, + {1, Mapper1_Init}, + {2, UNROM_Init}, + {3, CNROM_Init}, + {4, Mapper4_Init}, + {5, Mapper5_Init}, + {7, ANROM_Init}, + {11, Mapper11_Init}, + {12, Mapper12_Init}, + {13, CPROM_Init}, + {15, Mapper15_Init}, + {16, Mapper16_Init}, + {19, Mapper19_Init}, + {23, Mapper23_Init}, + {35, UNLSC127_Init}, /* Wario Land 2*/ + {36, Mapper36_Init}, /* TXC Policeman*/ + {37, Mapper37_Init}, + {38, Mapper38_Init}, /* Bit Corp. Crime Busters*/ + {43, Mapper43_Init}, + {44, Mapper44_Init}, + {45, Mapper45_Init}, + {47, Mapper47_Init}, + {49, Mapper49_Init}, + {52, Mapper52_Init}, + {57, Mapper57_Init}, + {58, BMCGK192_Init}, + {60, BMCD1038_Init}, + {66, MHROM_Init}, + {68, Mapper68_Init}, + {70, Mapper70_Init}, + {74, Mapper74_Init}, + {78, Mapper78_Init}, + {87, Mapper87_Init}, + {88, Mapper88_Init}, + {90, Mapper90_Init}, + {93, SUNSOFT_UNROM_Init}, + {94, Mapper94_Init}, + {95, Mapper95_Init}, + {101, Mapper101_Init}, + {103, Mapper103_Init}, + {105, Mapper105_Init}, + {106, Mapper106_Init}, + {107, Mapper107_Init}, + {108, Mapper108_Init}, + {112, Mapper112_Init}, + {113, Mapper113_Init}, + {114, Mapper114_Init}, + {115, Mapper115_Init}, + {116, UNLSL12_Init}, + {117, Mapper117_Init}, + {118, TKSROM_Init}, + {119, Mapper119_Init}, + {120, Mapper120_Init}, + {121, Mapper121_Init}, + {123, UNLH2288_Init}, + {132, UNL22211_Init}, + {133, SA72008_Init}, + {134, Mapper134_Init}, + {136, TCU02_Init}, + {137, S8259D_Init}, + {138, S8259B_Init}, + {139, S8259C_Init}, + {140, Mapper140_Init}, + {141, S8259A_Init}, + {142, UNLKS7032_Init}, + {143, TCA01_Init}, + {144, Mapper144_Init}, + {145, SA72007_Init}, + {146, SA0161M_Init}, + {147, TCU01_Init}, + {148, SA0037_Init}, + {149, SA0036_Init}, + {150, S74LS374N_Init}, + {152, Mapper152_Init}, + {153, Mapper153_Init}, + {154, Mapper154_Init}, + {155, Mapper155_Init}, + {156, Mapper156_Init}, + {160, SA009_Init}, + {162, UNLFS304_Init}, + {163, Mapper163_Init}, + {164, Mapper164_Init}, + {165, Mapper165_Init}, + {168, Mapper168_Init}, + {170, Mapper170_Init}, + {171, Mapper171_Init}, + {172, Mapper172_Init}, + {173, Mapper173_Init}, + {175, Mapper175_Init}, + {176, BMCFK23C_Init}, + {177, Mapper177_Init}, + {178, Mapper178_Init}, + {180, Mapper180_Init}, + {181, Mapper181_Init}, +/* {182, Mapper114_Init},*/ + {183, Mapper183_Init}, + {184, Mapper184_Init}, + {185, Mapper185_Init}, + {186, Mapper186_Init}, + {187, Mapper187_Init}, + {188, Mapper188_Init}, + {189, Mapper189_Init}, + {191, Mapper191_Init}, + {192, Mapper192_Init}, + {193, Mapper193_Init}, + {194, Mapper194_Init}, + {195, Mapper195_Init}, + {196, Mapper196_Init}, + {197, Mapper197_Init}, + {198, Mapper198_Init}, + {199, Mapper199_Init}, + {200, Mapper200_Init}, + {205, Mapper205_Init}, + {206, DEIROM_Init}, + {208, Mapper208_Init}, + {209, Mapper209_Init}, + {210, Mapper210_Init}, + {211, Mapper211_Init}, + {215, UNL8237_Init}, + {216, Mapper216_Init}, +/* {217, UNL8237A_Init},*/ + {219, UNLA9746_Init}, +/* {220, UNL8237_Init},*/ +/* {220, UNL3DBlock_Init},*/ + {220, BMCFK23CA_Init}, +/* {220, UNLTF1201_Init},*/ +/* {220, UNLSL1632_Init},*/ +/* {220, BMCT2271_Init},*/ +/* {220, UNLPEC586Init},*/ +/* {220, Mapper114_Init},*/ +/* {220, UNLD2000_Init},*/ +/* {220, UNLKOF97_Init},*/ +/* {220, BMC810544CA1_Init},*/ +/* {220, UNLKS7013B_Init},*/ +/* {220, BMCNTD03_Init},*/ +/* {220, UNLOneBus_Init},*/ +/* {220, UNLDANCE_Init},*/ +/* {220, UNL43272_Init},*/ +/* {220, UNLKS7057_Init},*/ + + {221, UNLN625092_Init}, + {222, Mapper222_Init}, + {225, Mapper225_Init}, + {226, Mapper226_Init}, + {235, Mapper235_Init}, + {238, UNL6035052_Init}, + {240, Mapper240_Init}, + {243, S74LS374NA_Init}, + {245, Mapper245_Init}, + {249, Mapper249_Init}, + {250, Mapper250_Init}, + {253, Mapper253_Init}, + {254, Mapper254_Init}, + { 0, 0} +}; + +static int NewiNES_Init(int num) +{ + BMAPPING *tmp=bmap; + + if(FCEUGameInfo->type == GIT_VSUNI) + AddExState(FCEUVSUNI_STATEINFO, ~0, 0, 0); + + while(tmp->init) + { + if(num==tmp->number) + { + UNIFchrrama=0; /* need here for compatibility with UNIF mapper code*/ + if(!VROM_size) + { + int CHRRAMSize; + if(num==13) + CHRRAMSize=16 * 1024; + else if(num==176) + CHRRAMSize=32 * 1024; + else + CHRRAMSize=8 * 1024; + VROM=(uint8 *)malloc(CHRRAMSize); + UNIFchrrama=VROM; + SetupCartCHRMapping(0,VROM,CHRRAMSize,1); + AddExState(VROM,CHRRAMSize, 0, "CHRR"); + } + if(head.ROM_type&8) + AddExState(ExtraNTARAM, 2048, 0, "EXNR"); + tmp->init(&iNESCart); + return(1); + } + tmp++; + } + return(0); +} diff --git a/fceumm/src-fceumm/ines.h b/fceumm/src-fceumm/ines.h new file mode 100644 index 0000000..d3b155b --- /dev/null +++ b/fceumm/src-fceumm/ines.h @@ -0,0 +1,420 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 1998 Bero + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef INESPRIV + +void iNESStateRestore(int version); +extern uint32 iNESGameCRC32; + +extern uint32 VROM_size; +extern uint32 ROM_size; + +extern void (*MapStateRestore)(int version); +extern void (*MapClose)(void); +extern void (*MapperReset)(void); + +/* This order is necessary */ +#define WRAM (GameMemBlock) +#define sizeofWRAM 8192 + +#define MapperExRAM (GameMemBlock+sizeofWRAM) +#define sizeofMapperExRAM 32768 +/* for the MMC5 code to work properly. It might be fixed later... */ + +#define CHRRAM (GameMemBlock+sizeofWRAM+sizeofMapperExRAM) +#define sizeofCHRRAM 8192 + +#define ExtraNTARAM (GameMemBlock+sizeofWRAM+sizeofMapperExRAM+sizeofCHRRAM) +#define sizeofExtraNTARAM 2048 + +#define PRGBankList (ExtraNTARAM+sizeofExtraNTARAM) + +#define mapbyte1 (PRGBankList+4) +#define mapbyte2 (mapbyte1+8) +#define mapbyte3 (mapbyte2+8) +#define mapbyte4 (mapbyte3+8) +extern uint16 iNESCHRBankList[8]; +extern int32 iNESIRQLatch,iNESIRQCount; +extern uint8 iNESMirroring; +extern uint8 iNESIRQa; + +#define IRQa iNESIRQa +#define Mirroring iNESMirroring +#define IRQCount iNESIRQCount +#define IRQLatch iNESIRQLatch +#define CHRBankList iNESCHRBankList +#else +#endif + + typedef struct { + char ID[4]; /*NES^Z*/ + uint8 ROM_size; + uint8 VROM_size; + uint8 ROM_type; + uint8 ROM_type2; + uint8 reserve[8]; + } iNES_HEADER; + +void VRAM_BANK1(uint32 A, uint8 V); +void VRAM_BANK4(uint32 A,uint32 V); + +void VROM_BANK1(uint32 A,uint32 V); +void VROM_BANK2(uint32 A,uint32 V); +void VROM_BANK4(uint32 A, uint32 V); +void VROM_BANK8(uint32 V); +void ROM_BANK8(uint32 A, uint32 V); +void ROM_BANK16(uint32 A, uint32 V); +void ROM_BANK32(uint32 V); + +extern uint8 vmask; +extern uint32 vmask1; +extern uint32 vmask2; +extern uint32 vmask4; +extern uint32 pmask8; +extern uint8 pmask16; +extern uint8 pmask32; + +void onemir(uint8 V); +void MIRROR_SET2(uint8 V); +void MIRROR_SET(uint8 V); + +void Mapper0_init(void); +void Mapper1_init(void); +/*void Mapper2_init(void);*/ +/*void Mapper3_init(void);*/ +void Mapper6_init(void); +/*void Mapper7_init(void);*/ +void Mapper8_init(void); +void Mapper9_init(void); +void Mapper10_init(void); +/*void Mapper11_init(void);*/ +void Mapper12_init(void); +/*void Mapper13_init(void);*/ +void Mapper14_init(void); +/*void Mapper15_init(void);*/ +/*void Mapper16_init(void);*/ +void Mapper17_init(void); +void Mapper18_init(void); +void Mapper19_init(void); +void Mapper20_init(void); +void Mapper21_init(void); +void Mapper22_init(void); +/*void Mapper23_init(void);*/ +void Mapper24_init(void); +void Mapper25_init(void); +void Mapper26_init(void); +void Mapper27_init(void); +void Mapper28_init(void); +void Mapper29_init(void); +void Mapper30_init(void); +void Mapper31_init(void); +void Mapper32_init(void); +void Mapper33_init(void); +void Mapper34_init(void); +void Mapper35_init(void); +void Mapper36_init(void); +/*void Mapper37_init(void);*/ +/*void Mapper38_init(void);*/ +/*void Mapper39_init(void);*/ +void Mapper40_init(void); +void Mapper41_init(void); +void Mapper42_init(void); +/*void Mapper43_init(void);*/ +void Mapper44_init(void); +void Mapper45_init(void); +void Mapper46_init(void); +void Mapper47_init(void); +void Mapper48_init(void); +void Mapper49_init(void); +void Mapper50_init(void); +void Mapper51_init(void); +void Mapper53_init(void); +void Mapper54_init(void); +void Mapper55_init(void); +void Mapper56_init(void); +void Mapper59_init(void); +void Mapper60_init(void); +void Mapper61_init(void); +void Mapper62_init(void); +void Mapper63_init(void); +void Mapper64_init(void); +void Mapper65_init(void); +/*void Mapper66_init(void);*/ +void Mapper67_init(void); +/*void Mapper68_init(void);*/ +void Mapper69_init(void); +/*void Mapper70_init(void);*/ +void Mapper71_init(void); +void Mapper72_init(void); +void Mapper73_init(void); +void Mapper74_init(void); +void Mapper75_init(void); +void Mapper76_init(void); +void Mapper77_init(void); +/*void Mapper78_init(void);*/ +void Mapper79_init(void); +void Mapper80_init(void); +void Mapper81_init(void); +void Mapper82_init(void); +void Mapper83_init(void); +void Mapper84_init(void); +void Mapper85_init(void); +void Mapper86_init(void); +/*void Mapper87_init(void);*/ +void Mapper88_init(void); +void Mapper89_init(void); +void Mapper91_init(void); +void Mapper92_init(void); +/*void Mapper93_init(void);*/ +/*void Mapper94_init(void);*/ +void Mapper96_init(void); +void Mapper97_init(void); +void Mapper98_init(void); +void Mapper99_init(void); +void Mapper100_init(void); +/*void Mapper101_init(void);*/ +/*void Mapper103_init(void);*/ +void Mapper104_init(void); +/*void Mapper106_init(void);*/ +/*void Mapper107_init(void);*/ +/*void Mapper108_init(void);*/ +void Mapper109_init(void); +void Mapper110_init(void); +void Mapper111_init(void); +/*void Mapper113_init(void);*/ +void Mapper115_init(void); +/*void Mapper116_init(void);*/ +/*void Mapper117_init(void);*/ +/*void Mapper120_init(void);*/ +/*void Mapper121_init(void);*/ +void Mapper122_init(void); +void Mapper123_init(void); +void Mapper124_init(void); +void Mapper126_init(void); +void Mapper127_init(void); +void Mapper128_init(void); +void Mapper129_init(void); +void Mapper130_init(void); +void Mapper131_init(void); +void Mapper132_init(void); +/*void Mapper134_init(void);*/ +void Mapper135_init(void); +void Mapper136_init(void); +void Mapper137_init(void); +void Mapper139_init(void); +/*void Mapper140_init(void);*/ +void Mapper141_init(void); +/*void Mapper142_init(void);*/ +void Mapper143_init(void); +/*void Mapper144_init(void);*/ +void Mapper150_init(void); +void Mapper151_init(void); +/*void Mapper152_init(void);*/ +/*void Mapper153_init(void);*/ +void Mapper154_init(void); +/*void Mapper156_init(void);*/ +void Mapper157_init(void); +/*void Mapper158_init(void);*/ +void Mapper159_init(void); +void Mapper160_init(void); +void Mapper161_init(void); +void Mapper162_init(void); +void Mapper166_init(void); +void Mapper167_init(void); +void Mapper168_init(void); +/*void Mapper169_init(void);*/ +void Mapper170_init(void); +/*void Mapper171_init(void);*/ +/*void Mapper172_init(void);*/ +/*void Mapper173_init(void);*/ +void Mapper174_init(void); +void Mapper175_init(void); +void Mapper176_init(void); +/*void Mapper177_init(void);*/ +/*void Mapper178_init(void);*/ +/*void Mapper179_init(void);*/ +/*void Mapper180_init(void);*/ +/*void Mapper181_init(void);*/ +/*void Mapper184_init(void);*/ +/*void Mapper185_init(void);*/ +/*void Mapper189_init(void);*/ +/*void Mapper192_init(void);*/ +/*void Mapper193_init(void);*/ +/*void Mapper194_init(void);*/ +/*void Mapper195_init(void);*/ +/*void Mapper196_init(void);*/ +/*void Mapper197_init(void);*/ +/*void Mapper198_init(void);*/ +void Mapper199_init(void); +/*void Mapper200_init(void);*/ +void Mapper201_init(void); +void Mapper202_init(void); +void Mapper203_init(void); +void Mapper204_init(void); +void Mapper207_init(void); +/*void Mapper211_init(void);*/ +void Mapper212_init(void); +void Mapper213_init(void); +void Mapper214_init(void); +/*void Mapper218_init(void);*/ +void Mapper219_init(void); +/*void Mapper220_init(void);*/ +void Mapper221_init(void); +/*void Mapper222_init(void);*/ +void Mapper223_init(void); +void Mapper224_init(void); +/*void Mapper225_init(void);*/ +/*void Mapper226_init(void);*/ +void Mapper227_init(void); +void Mapper228_init(void); +void Mapper229_init(void); +void Mapper230_init(void); +void Mapper231_init(void); +void Mapper232_init(void); +void Mapper233_init(void); +void Mapper234_init(void); +/*void Mapper235_init(void);*/ +void Mapper236_init(void); +void Mapper237_init(void); +void Mapper238_init(void); +void Mapper239_init(void); +void Mapper240_init(void); +void Mapper241_init(void); +void Mapper242_init(void); +void Mapper244_init(void); +void Mapper245_init(void); +void Mapper246_init(void); +void Mapper247_init(void); +void Mapper249_init(void); +void Mapper251_init(void); +void Mapper252_init(void); +/*void Mapper253_init(void);*/ +void Mapper255_init(void); + +void NSFVRC6_Init(void); +void NSFMMC5_Init(void); +void NSFAY_Init(void); +void NSFN106_Init(void); +void NSFVRC7_Init(void); +void Mapper19_ESI(void); + +void Mapper1_Init(CartInfo *); +void Mapper4_Init(CartInfo *); +void Mapper5_Init(CartInfo *); +void Mapper11_Init(CartInfo *); +void Mapper12_Init(CartInfo *); +void Mapper15_Init(CartInfo *); +void Mapper16_Init(CartInfo *); +void Mapper19_Init(CartInfo *); +void Mapper23_Init(CartInfo *); +void Mapper36_Init(CartInfo *); +void Mapper37_Init(CartInfo *); +void Mapper38_Init(CartInfo *); +void Mapper43_Init(CartInfo *); +void Mapper44_Init(CartInfo *); +void Mapper45_Init(CartInfo *); +void Mapper47_Init(CartInfo *); +void Mapper49_Init(CartInfo *); +void Mapper52_Init(CartInfo *); +void Mapper57_Init(CartInfo *); +/*void Mapper58_Init(CartInfo *);*/ +void Mapper68_Init(CartInfo *); +void Mapper70_Init(CartInfo *); +void Mapper74_Init(CartInfo *); +void Mapper78_Init(CartInfo *); +void Mapper87_Init(CartInfo *); +void Mapper88_Init(CartInfo *); +void Mapper90_Init(CartInfo *); +void Mapper93_Init(CartInfo *); +void Mapper94_Init(CartInfo *); +void Mapper95_Init(CartInfo *); +void Mapper101_Init(CartInfo *); +void Mapper103_Init(CartInfo *); +void Mapper105_Init(CartInfo *); +void Mapper106_Init(CartInfo *); +void Mapper107_Init(CartInfo *); +void Mapper108_Init(CartInfo *); +void Mapper112_Init(CartInfo *); +void Mapper113_Init(CartInfo *); +void Mapper114_Init(CartInfo *); +void Mapper115_Init(CartInfo *); +void Mapper117_Init(CartInfo *); +void Mapper119_Init(CartInfo *); +void Mapper120_Init(CartInfo *); +void Mapper121_Init(CartInfo *); +void Mapper125_Init(CartInfo *); +void Mapper134_Init(CartInfo *); +void Mapper140_Init(CartInfo *); +void Mapper144_Init(CartInfo *); +void Mapper152_Init(CartInfo *); +void Mapper153_Init(CartInfo *); +void Mapper154_Init(CartInfo *); +void Mapper155_Init(CartInfo *); +void Mapper156_Init(CartInfo *); +void Mapper163_Init(CartInfo *); +void Mapper164_Init(CartInfo *); +void Mapper165_Init(CartInfo *); +void Mapper168_Init(CartInfo *); +void Mapper170_Init(CartInfo *); +void Mapper171_Init(CartInfo *); +void Mapper172_Init(CartInfo *); +void Mapper173_Init(CartInfo *); +void Mapper175_Init(CartInfo *); +void Mapper177_Init(CartInfo *); +void Mapper178_Init(CartInfo *); +void Mapper180_Init(CartInfo *); +void Mapper181_Init(CartInfo *); +void Mapper183_Init(CartInfo *); +void Mapper184_Init(CartInfo *); +void Mapper185_Init(CartInfo *); +void Mapper186_Init(CartInfo *); +void Mapper187_Init(CartInfo *); +void Mapper188_Init(CartInfo *); +void Mapper189_Init(CartInfo *); +void Mapper191_Init(CartInfo *); +void Mapper192_Init(CartInfo *); +void Mapper193_Init(CartInfo *); +void Mapper194_Init(CartInfo *); +void Mapper195_Init(CartInfo *); +void Mapper196_Init(CartInfo *); +void Mapper197_Init(CartInfo *); +void Mapper198_Init(CartInfo *); +void Mapper199_Init(CartInfo *); +void Mapper200_Init(CartInfo *); +void Mapper205_Init(CartInfo *); +void Mapper208_Init(CartInfo *); +void Mapper209_Init(CartInfo *); +void Mapper210_Init(CartInfo *); +void Mapper211_Init(CartInfo *); +void Mapper216_Init(CartInfo *); +void Mapper220_Init(CartInfo *); +void Mapper222_Init(CartInfo *); +void Mapper225_Init(CartInfo *); +void Mapper226_Init(CartInfo *); +void Mapper235_Init(CartInfo *); +void Mapper236_Init(CartInfo *); +void Mapper237_Init(CartInfo *); +void Mapper240_Init(CartInfo *); +void Mapper245_Init(CartInfo *); +void Mapper249_Init(CartInfo *); +void Mapper250_Init(CartInfo *); +void Mapper253_Init(CartInfo *); +void Mapper254_Init(CartInfo *); diff --git a/fceumm/src-fceumm/input.c b/fceumm/src-fceumm/input.c new file mode 100644 index 0000000..5c1909b --- /dev/null +++ b/fceumm/src-fceumm/input.c @@ -0,0 +1,429 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 1998 BERO + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include + +#include "types.h" +#include "x6502.h" + +#include "fceu.h" + +#include "input.h" +#include "vsuni.h" +#include "fds.h" + +extern INPUTC *FCEU_InitJoyPad(int w); +extern INPUTC *FCEU_InitZapper(int w); +extern INPUTC *FCEU_InitMouse(int w); +extern INPUTC *FCEU_InitPowerpadA(int w); +extern INPUTC *FCEU_InitPowerpadB(int w); +extern INPUTC *FCEU_InitArkanoid(int w); + +extern INPUTCFC *FCEU_InitFami4(void); +extern INPUTCFC *FCEU_InitArkanoidFC(void); +extern INPUTCFC *FCEU_InitSpaceShadow(void); +extern INPUTCFC *FCEU_InitFKB(void); +extern INPUTCFC *FCEU_InitSuborKB(void); +extern INPUTCFC *FCEU_InitHS(void); +extern INPUTCFC *FCEU_InitMahjong(void); +extern INPUTCFC *FCEU_InitQuizKing(void); +extern INPUTCFC *FCEU_InitFamilyTrainerA(void); +extern INPUTCFC *FCEU_InitFamilyTrainerB(void); +extern INPUTCFC *FCEU_InitOekaKids(void); +extern INPUTCFC *FCEU_InitTopRider(void); +extern INPUTCFC *FCEU_InitBarcodeWorld(void); + +extern uint8 coinon; + +static void *InputDataPtr[2]; +uint8 LastStrobe; + +static int JPAttrib[2]={0,0}; +static int JPType[2]={0,0}; +static INPUTC DummyJPort={0,0,0,0,0}; +static INPUTC *JPorts[2]={&DummyJPort,&DummyJPort}; + +static int JPAttribFC=0; +static int JPTypeFC=0; +static void *InputDataPtrFC; +static INPUTCFC *FCExp=0; + +void (*InputScanlineHook)(uint8 *bg, uint8 *spr, uint32 linets, int final); + +#define DI 01 +#define CLK 02 +#define CS 04 +#define OUT0 01 +#define D3 01 +#define D4 02 + +typedef struct +{ + uint8 state; + uint8 cmd; + uint8 addr; + uint8 iswritable; + uint16 acc; + uint16 data[128]; +} EEPROM; + +EEPROM serialROM[2]; +uint8 oldCLK, bankFlip, DIFlip, OUT0state; + +uint8 serialROMautomat(uint8 chip, uint16 data) +{ + uint8 resp = 1; + chip &= 1; + if(!(data & CS)) + { + if(!(data & CLK)) + { + uint8 state = serialROM[chip].state; + uint8 mask, i; + #ifdef FCEU_LOG + FCEU_printf("> state = %02x\n", serialROM[chip].state); + #endif + switch (serialROM[chip].cmd) + { + case 0x00: + mask = ~(1<<(state&7)); + if(state<8) + { + serialROM[chip].addr &= mask; + serialROM[chip].addr |= ((data&1)<<(state&7)); + #ifdef FCEU_LOG + if(state==7) + FCEU_printf("> addr = %02x\n", serialROM[chip].addr); + #endif + } + else if(state<15) + { + serialROM[chip].acc &= mask; + serialROM[chip].acc |= ((data&1)<<(state&7)); + } + else + { + serialROM[chip].acc &= mask; + serialROM[chip].acc |= ((data&1)<<(state&7)); + serialROM[chip].cmd = serialROM[chip].acc; + #ifdef FCEU_LOG + FCEU_printf("> cmd = %02x\n", serialROM[chip].cmd); + #endif + } + break; + case 0x01: + if(state<30) + resp = (serialROM[chip].data[serialROM[chip].addr]>>(state&15))&1; + else + { + resp = (serialROM[chip].data[serialROM[chip].addr]>>(state&15))&1; + serialROM[chip].cmd = 0; + } + break; + case 0x06: + mask = ~(1<<(state&15)); + if(state<30) + { + serialROM[chip].acc &= mask; + serialROM[chip].acc |= ((data&1)<<(state&15)); + } + else + { + serialROM[chip].acc &= mask; + serialROM[chip].acc |= ((data&1)<<(state&15)); + if(serialROM[chip].iswritable) + serialROM[chip].data[serialROM[chip].addr] = serialROM[chip].acc; + serialROM[chip].cmd = 0; + } + break; + case 0x0C: + for(i=0;i<128;i++) + serialROM[chip].data[i] = 0xFFFF; + serialROM[chip].cmd = 0; + resp = 1; + break; + case 0x0D: + serialROM[chip].cmd = 0; + resp = 1; + break; + case 0x09: + serialROM[chip].cmd = 0; + serialROM[chip].iswritable = 1; + break; + case 0x0B: + serialROM[chip].cmd = 0; + serialROM[chip].iswritable = 0; + break; + default: + serialROM[chip].cmd = 0; + serialROM[chip].state = 0; + break; + } + } + else + { + if(serialROM[chip].cmd == 0) + { + if(serialROM[chip].state>15) + serialROM[chip].state = 0; + } + else + serialROM[chip].state++; + } + } + else + { + serialROM[chip].cmd = 0; + serialROM[chip].state = 0; + } + return resp; +} + +uint8 serialROMstate(uint8 linestate) +{ + uint8 answ = 0, newCLK = linestate & CLK; + if((!oldCLK)&&newCLK) + { + DIFlip^=1; + if(linestate&&OUT0) + { + serialROMautomat(bankFlip, 04+DIFlip); + bankFlip^=1; + serialROMautomat(bankFlip, 02+DIFlip); + } + } + answ = DIFlip^1; + answ |= (serialROMautomat(bankFlip, newCLK+DIFlip)<<1); + oldCLK = newCLK; + return answ << 3; +} + +static DECLFR(JPRead) +{ + uint8 ret=0; + + if(JPorts[A&1]->Read) + ret|=JPorts[A&1]->Read(A&1); + + if(FCExp) + if(FCExp->Read) + ret=FCExp->Read(A&1,ret); + + ret|=X.DB&0xC0; + + return(ret); +} + +static DECLFW(B4016) +{ + if(FCExp) + if(FCExp->Write) + FCExp->Write(V&7); + + if(JPorts[0]->Write) + JPorts[0]->Write(V&1); + if(JPorts[1]->Write) + JPorts[1]->Write(V&1); + + if((LastStrobe&1) && (!(V&1))) + { + if(JPorts[0]->Strobe) + JPorts[0]->Strobe(0); + if(JPorts[1]->Strobe) + JPorts[1]->Strobe(1); + if(FCExp) + if(FCExp->Strobe) + FCExp->Strobe(); + } + LastStrobe=V&0x1; +} + +void FCEU_DrawInput(uint8 *buf) +{ + if(JPorts[0]->Draw) + JPorts[0]->Draw(0,buf,JPAttrib[0]); + + if(JPorts[1]->Draw) + JPorts[1]->Draw(1,buf,JPAttrib[1]); + + if(FCExp) + if(FCExp->Draw) + FCExp->Draw(buf,JPAttribFC); +} + +void FCEU_UpdateInput(void) +{ + if(JPorts[0]->Update) + JPorts[0]->Update(0,InputDataPtr[0],JPAttrib[0]); + + if(JPorts[1]->Update) + JPorts[1]->Update(1,InputDataPtr[1],JPAttrib[1]); + + if(FCExp) + if(FCExp->Update) + FCExp->Update(InputDataPtrFC,JPAttribFC); + + if(FCEUGameInfo->type==GIT_VSUNI) + if(coinon) coinon--; +} + +static DECLFR(VSUNIRead0) +{ + uint8 ret=0; + + if(JPorts[0]->Read) + ret|=(JPorts[0]->Read(0))&1; + + ret|=(vsdip&3)<<3; + if(coinon) + ret|=0x4; + return ret; +} + +static DECLFR(VSUNIRead1) +{ + uint8 ret=0; + + if(JPorts[1]->Read) + ret|=(JPorts[1]->Read(1))&1; + ret|=vsdip&0xFC; + return ret; +} + +static void SLHLHook(uint8 *bg, uint8 *spr, uint32 linets, int final) +{ + if(JPorts[0]->SLHook) + JPorts[0]->SLHook(0,bg,spr,linets,final); + + if(JPorts[1]->SLHook) + JPorts[1]->SLHook(1,bg,spr,linets,final); + + if(FCExp) + if(FCExp->SLHook) + FCExp->SLHook(bg,spr,linets,final); +} + +static void CheckSLHook(void) +{ + InputScanlineHook=0; + if(JPorts[0]->SLHook || JPorts[1]->SLHook) + InputScanlineHook=SLHLHook; + if(FCExp) + if(FCExp->SLHook) + InputScanlineHook=SLHLHook; +} + +static void SetInputStuff(int x) +{ + switch(JPType[x]) + { + case SI_NONE: JPorts[x]=&DummyJPort; break; + case SI_GAMEPAD: JPorts[x]=FCEU_InitJoyPad(x); break; + case SI_ARKANOID: JPorts[x]=FCEU_InitArkanoid(x); break; + case SI_MOUSE: JPorts[x]=FCEU_InitMouse(x); break; + case SI_ZAPPER: JPorts[x]=FCEU_InitZapper(x); break; + case SI_POWERPADA: JPorts[x]=FCEU_InitPowerpadA(x); break; + case SI_POWERPADB: JPorts[x]=FCEU_InitPowerpadB(x); break; + } + CheckSLHook(); +} + +static void SetInputStuffFC(void) +{ + switch(JPTypeFC) + { + case SIFC_NONE: FCExp=0;break; + case SIFC_ARKANOID: FCExp=FCEU_InitArkanoidFC(); break; + case SIFC_SHADOW: FCExp=FCEU_InitSpaceShadow(); break; + case SIFC_OEKAKIDS: FCExp=FCEU_InitOekaKids(); break; + case SIFC_4PLAYER: FCExp=FCEU_InitFami4(); break; + case SIFC_FKB: FCExp=FCEU_InitFKB(); break; + case SIFC_SUBORKB: FCExp=FCEU_InitSuborKB(); break; + case SIFC_HYPERSHOT: FCExp=FCEU_InitHS(); break; + case SIFC_MAHJONG: FCExp=FCEU_InitMahjong(); break; + case SIFC_QUIZKING: FCExp=FCEU_InitQuizKing(); break; + case SIFC_FTRAINERA: FCExp=FCEU_InitFamilyTrainerA(); break; + case SIFC_FTRAINERB: FCExp=FCEU_InitFamilyTrainerB(); break; + case SIFC_BWORLD: FCExp=FCEU_InitBarcodeWorld(); break; + case SIFC_TOPRIDER: FCExp=FCEU_InitTopRider(); break; + } + CheckSLHook(); +} + +void InitializeInput(void) +{ + LastStrobe=0; + if(FCEUGameInfo->type==GIT_VSUNI) + { + SetReadHandler(0x4016,0x4016,VSUNIRead0); + SetReadHandler(0x4017,0x4017,VSUNIRead1); + } + else + SetReadHandler(0x4016,0x4017,JPRead); + + SetWriteHandler(0x4016,0x4016,B4016); + + SetInputStuff(0); + SetInputStuff(1); + SetInputStuffFC(); +} + +void FCEUI_SetInput(int port, int type, void *ptr, int attrib) +{ + JPAttrib[port]=attrib; + JPType[port]=type; + InputDataPtr[port]=ptr; + SetInputStuff(port); +} + +void FCEUI_SetInputFC(int type, void *ptr, int attrib) +{ + JPAttribFC=attrib; + JPTypeFC=type; + InputDataPtrFC=ptr; + SetInputStuffFC(); +} + +void FCEUI_FDSSelect(void) +{ + FCEU_FDSSelect(); +} + +int FCEUI_FDSInsert(int oride) +{ + FCEU_FDSInsert(-1); + return(1); +} + +int FCEUI_FDSEject(void) +{ + FCEU_FDSEject(); + return(1); +} + +void FCEUI_VSUniToggleDIP(int w) +{ + FCEU_VSUniToggleDIP(w); +} + +void FCEUI_VSUniCoin(void) +{ + FCEU_VSUniCoin(); +} diff --git a/fceumm/src-fceumm/input.h b/fceumm/src-fceumm/input.h new file mode 100644 index 0000000..2c9474a --- /dev/null +++ b/fceumm/src-fceumm/input.h @@ -0,0 +1,23 @@ +typedef struct { + uint8 (*Read)(int w); + void (*Write)(uint8 v); + void (*Strobe)(int w); + void (*Update)(int w, void *data, int arg); + void (*SLHook)(int w, uint8 *bg, uint8 *spr, uint32 linets, int final); + void (*Draw)(int w, uint8 *buf, int arg); +} INPUTC; + +typedef struct { + uint8 (*Read)(int w, uint8 ret); + void (*Write)(uint8 v); + void (*Strobe)(void); + void (*Update)(void *data, int arg); + void (*SLHook)(uint8 *bg, uint8 *spr, uint32 linets, int final); + void (*Draw)(uint8 *buf, int arg); +} INPUTCFC; + +void FCEU_DrawInput(uint8 *buf); +void FCEU_UpdateInput(void); +void InitializeInput(void); +extern void (*PStrobe[2])(void); +extern void (*InputScanlineHook)(uint8 *bg, uint8 *spr, uint32 linets, int final); diff --git a/fceumm/src-fceumm/input/arkanoid.c b/fceumm/src-fceumm/input/arkanoid.c new file mode 100644 index 0000000..ed97ae7 --- /dev/null +++ b/fceumm/src-fceumm/input/arkanoid.c @@ -0,0 +1,113 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include "share.h" + +typedef struct { + uint32 mzx,mzb; + uint32 readbit; +} ARK; + +static ARK NESArk[2]; +static ARK FCArk; + +static void StrobeARKFC(void) +{ + FCArk.readbit=0; +} + +static uint8 ReadARKFC(int w,uint8 ret) +{ + ret&=~2; + if(w) + { + if(FCArk.readbit>=8) + ret|=2; + else + { + ret|=((FCArk.mzx>>(7-FCArk.readbit))&1)<<1; + FCArk.readbit++; + } + } + else + ret|=FCArk.mzb<<1; + return(ret); +} + +static uint32 FixX(uint32 x) +{ + x=98+x*144/240; + if(x>242) x=242; + x=~x; + return(x); +} + +static void UpdateARKFC(void *data, int arg) +{ + uint32 *ptr=(uint32*)data; + FCArk.mzx=FixX(ptr[0]); + FCArk.mzb=ptr[2]?1:0; +} + +static INPUTCFC ARKCFC={ReadARKFC,0,StrobeARKFC,UpdateARKFC,0,0}; + +INPUTCFC *FCEU_InitArkanoidFC(void) +{ + FCArk.mzx=98; + FCArk.mzb=0; + return(&ARKCFC); +} + +static uint8 ReadARK(int w) +{ + uint8 ret=0; + if(NESArk[w].readbit>=8) + ret|=1<<4; + else + { + ret|=((NESArk[w].mzx>>(7-NESArk[w].readbit))&1)<<4; + NESArk[w].readbit++; + } + ret|=(NESArk[w].mzb&1)<<3; + return(ret); +} + +static void StrobeARK(int w) +{ + NESArk[w].readbit=0; +} + +static void UpdateARK(int w, void *data, int arg) +{ + uint32 *ptr=(uint32*)data; + NESArk[w].mzx=FixX(ptr[0]); + NESArk[w].mzb=ptr[2]?1:0; +} + +static INPUTC ARKC={ReadARK, 0, StrobeARK, UpdateARK, 0, 0}; + +INPUTC *FCEU_InitArkanoid(int w) +{ + NESArk[w].mzx=98; + NESArk[w].mzb=0; + return(&ARKC); +} diff --git a/fceumm/src-fceumm/input/bbox.c b/fceumm/src-fceumm/input/bbox.c new file mode 100644 index 0000000..5e28e36 --- /dev/null +++ b/fceumm/src-fceumm/input/bbox.c @@ -0,0 +1,194 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +/* +#include +#include +#include "share.h" + +#define DI 01 +#define CLK 02 +#define CS 04 +#define OUT0 01 +#define D3 01 +#define D4 02 + +typedef struct +{ + uint8 state; + uint8 cmd; + uint8 addr; + uint8 iswritable; + uint16 acc; + uint16 data[128]; +} EEPROM; + +EEPROM serialROM[2]; +uint8 oldCLK, bankFlip, DIFlip, OUT0state; + +uint8 serialROMautomat(uint8 chip, uint16 data) +{ + uint8 resp = 1; + chip &= 1; + if(!(data & CS)) + { + if(!(data & CLK)) + { + uint8 state = serialROM[chip].state; + uint8 mask, i; + switch (serialROM[chip].cmd) + { + case 0x00: + mask = ~(1<<(state&7)); + if(state<8) + { + serialROM[chip].addr &= mask; + serialROM[chip].addr |= ((data&1)<<(state&7)); + } + else if(state<15) + { + serialROM[chip].acc &= mask; + serialROM[chip].acc |= ((data&1)<<(state&7)); + } + else + { + serialROM[chip].acc &= mask; + serialROM[chip].acc |= ((data&1)<<(state&7)); + serialROM[chip].cmd = serialROM[chip].acc; + } + break; + case 0x01: + if(state<30) + resp = (serialROM[chip].data[serialROM[chip].addr]>>(state&15))&1; + else + { + resp = (serialROM[chip].data[serialROM[chip].addr]>>(state&15))&1; + serialROM[chip].cmd = 0; + } + break; + case 0x06: + mask = ~(1<<(state&15)); + if(state<30) + { + serialROM[chip].acc &= mask; + serialROM[chip].acc |= ((data&1)<<(state&15)); + } + else + { + serialROM[chip].acc &= mask; + serialROM[chip].acc |= ((data&1)<<(state&15)); + if(serialROM[chip].iswritable) + serialROM[chip].data[serialROM[chip].addr] = serialROM[chip].acc; + serialROM[chip].cmd = 0; + } + break; + case 0x0C: + for(i=0;i<128;i++) + serialROM[chip].data[i] = 0xFFFF; + serialROM[chip].cmd = 0; + resp = 1; + break; + case 0x0D: + serialROM[chip].cmd = 0; + resp = 1; + break; + case 0x09: + serialROM[chip].cmd = 0; + serialROM[chip].iswritable = 1; + break; + case 0x0B: + serialROM[chip].cmd = 0; + serialROM[chip].iswritable = 0; + break; + default: + serialROM[chip].cmd = 0; + serialROM[chip].state = 0; + break; + } + } + else + { + if(serialROM[chip].cmd == 0) + { + if(serialROM[chip].state>15) + serialROM[chip].state = 0; + } + else + serialROM[chip].cmd++; + } + } + else + { + serialROM[chip].cmd = 0; + serialROM[chip].state = 0; + } + return resp; +} + +uint8 serialROMstate(uint8 linestate) +{ + uint8 answ = 0, newCLK = linestate & CLK; + if((!oldCLK)&&newCLK) + { + DIFlip^=1; + if(linestate&&OUT0) + { + serialROMautomat(bankFlip, 04+DIFlip); + bankFlip^=1; + serialROMautomat(bankFlip, 02+DIFlip); + } + } + answ = DIFlip^1; + answ |= (serialROMautomat(bankFlip, newCLK+DIFlip)<<1); + oldCLK = newCLK; + return answ; +} + +static uint8 BBRead(int w, uint8 ret) +{ + if(w) + { + serialROMstate(OUT0); + ret |= serialROMstate(OUT0|CLK); + } + return(ret); +} + +static void BBWrite(uint8 V) +{ + OUT0state = V; + serialROMstate(OUT0state?OUT0:0); +} + +static INPUTCFC BattleBox={BBRead,BBWrite,0,0,0,0}; + +INPUTCFC *FCEU_InitBattleBox(void) +{ + oldCLK = 1; + bankFlip = 0; + DIFlip = 0; + serialROM[0].iswritable = 1; + serialROMautomat(0, 4); + serialROM[1].iswritable = 1; + serialROMautomat(1, 4); + serialROMautomat(bankFlip, 02+DIFlip); + return(&BattleBox); +} + +*/ diff --git a/fceumm/src-fceumm/input/bworld.c b/fceumm/src-fceumm/input/bworld.c new file mode 100644 index 0000000..a34af92 --- /dev/null +++ b/fceumm/src-fceumm/input/bworld.c @@ -0,0 +1,74 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include "share.h" + +static int seq,ptr,bit,cnt,have; +static uint8 bdata[20]; + + +static uint8 Read(int w, uint8 ret) +{ + if(w && have) + { + switch(seq) + { + case 0: seq++; ptr=0; ret|=0x4; break; + case 1: seq++; bit=bdata[ptr]; cnt=0; ret|=0x4; break; + case 2: ret|=((bit&0x01)^0x01)<<2; bit>>=1; if(++cnt > 7) seq++; + break; + case 3: if(++ptr > 19) + { + seq=-1; + have=0; + } + else + seq=1; + default: break; + } + } + return(ret); +} + +static void Write(uint8 V) +{ + /*printf("%02x\n",V);*/ +} + +static void Update(void *data, int arg) +{ + if(*(uint8 *)data) + { + *(uint8 *)data=0; + seq=ptr=0; + have=1; + strcpy(bdata,(uint8 *)data+1); + strcpy(&bdata[13],"SUNSOFT"); + } +} + +static INPUTCFC BarcodeWorld={Read,Write,0,Update,0,0}; + +INPUTCFC *FCEU_InitBarcodeWorld(void) +{ + return(&BarcodeWorld); +} + diff --git a/fceumm/src-fceumm/input/cursor.c b/fceumm/src-fceumm/input/cursor.c new file mode 100644 index 0000000..f7a5b87 --- /dev/null +++ b/fceumm/src-fceumm/input/cursor.c @@ -0,0 +1,86 @@ +#include "share.h" + +static uint8 GunSight[]={ + 0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,0,0,0,0,0,2,0,0,0,0,0,0, + 0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,0,0,0,0,0,2,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,3,0,0,0,0,0,0, + 1,2,1,2,0,3,3,3,0,2,1,2,1, + 0,0,0,0,0,0,3,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,2,0,0,0,0,0,0, + 0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,0,0,0,0,0,2,0,0,0,0,0,0, + 0,0,0,0,0,0,1,0,0,0,0,0,0, +}; +static uint8 FCEUcursor[11*19]= +{ + 1,0,0,0,0,0,0,0,0,0,0, + 1,1,0,0,0,0,0,0,0,0,0, + 1,2,1,0,0,0,0,0,0,0,0, + 1,2,2,1,0,0,0,0,0,0,0, + 1,2,2,2,1,0,0,0,0,0,0, + 1,2,2,2,2,1,0,0,0,0,0, + 1,2,2,2,2,2,1,0,0,0,0, + 1,2,2,2,2,2,2,1,0,0,0, + 1,2,2,2,2,2,2,2,1,0,0, + 1,2,2,2,2,2,2,2,2,1,0, + 1,2,2,2,2,2,1,1,1,1,1, + 1,2,2,1,2,2,1,0,0,0,0, + 1,2,1,0,1,2,2,1,0,0,0, + 1,1,0,0,1,2,2,1,0,0,0, + 1,0,0,0,0,1,2,2,1,0,0, + 0,0,0,0,0,1,2,2,1,0,0, + 0,0,0,0,0,0,1,2,2,1,0, + 0,0,0,0,0,0,1,2,2,1,0, + 0,0,0,0,0,0,0,1,1,0,0, +}; + +void FCEU_DrawGunSight(uint8 *buf, int xc, int yc) +{ + int x,y; + int c,d; + + for(y=0;y<13;y++) + for(x=0;x<13;x++) + { + uint8 a; + a=GunSight[y*13+x]; + if(a) + { + c=(yc+y-7); + d=(xc+x-7); + if(c>=0 && d>=0 && d<256 && c<240) + { + if(a==3) + buf[c*256+d]=0xBF-(buf[c*256+d]&0x3F); + else + buf[c*256+d]=a-1; + } + } + } +} + + +void FCEU_DrawCursor(uint8 *buf, int xc, int yc) +{ + int x,y; + int c,d; + + if(xc<256 && yc<240) + for(y=0;y<19;y++) + for(x=0;x<11;x++) + { + uint8 a; + a=FCEUcursor[y*11+x]; + if(a) + { + c=(yc+y); + d=(xc+x); + if(d<256 && c<240) + buf[c*256+d]=a+127; + } + } +} diff --git a/fceumm/src-fceumm/input/fkb.c b/fceumm/src-fceumm/input/fkb.c new file mode 100644 index 0000000..ba0a816 --- /dev/null +++ b/fceumm/src-fceumm/input/fkb.c @@ -0,0 +1,98 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include "share.h" +#include "fkb.h" +#define AK2(x,y) ( (FKB_##x) | (FKB_##y <<8) ) +#define AK(x) FKB_##x + +static uint8 bufit[0x49]; +static uint8 ksmode; +static uint8 ksindex; + + +static uint16 matrix[9][2][4]= +{ +{{AK(F8),AK(RETURN),AK(BRACKETLEFT),AK(BRACKETRIGHT)}, + {AK(KANA),AK(RIGHTSHIFT),AK(BACKSLASH),AK(STOP)}}, +{{AK(F7),AK(AT),AK(COLON),AK(SEMICOLON)}, + {AK(UNDERSCORE),AK(SLASH),AK(MINUS),AK(CARET)}}, +{{AK(F6),AK(O),AK(L),AK(K)}, + {AK(PERIOD),AK(COMMA),AK(P),AK(0)}}, +{{AK(F5),AK(I),AK(U),AK(J)}, + {AK(M),AK(N),AK(9),AK(8)}}, +{{AK(F4),AK(Y),AK(G),AK(H)}, + {AK(B),AK(V),AK(7),AK(6)}}, +{{AK(F3),AK(T),AK(R),AK(D)}, + {AK(F),AK(C),AK(5),AK(4)}}, +{{AK(F2),AK(W),AK(S),AK(A)}, + {AK(X),AK(Z),AK(E),AK(3)}}, +{{AK(F1),AK(ESCAPE),AK(Q),AK(CONTROL)}, + {AK(LEFTSHIFT),AK(GRAPH),AK(1),AK(2)}}, +{{AK(CLEAR),AK(UP),AK(RIGHT),AK(LEFT)}, + {AK(DOWN),AK(SPACE),AK(DELETE),AK(INSERT)}}, +}; + +static void FKB_Write(uint8 v) +{ + v>>=1; + if(v&2) + { + if((ksmode&1) && !(v&1)) + ksindex=(ksindex+1)%9; + } + ksmode=v; +} + +static uint8 FKB_Read(int w, uint8 ret) +{ + if(w) + { + int x; + + ret&=~0x1E; + for(x=0;x<4;x++) + if(bufit[ matrix[ksindex][ksmode&1][x]&0xFF ] || bufit[ matrix[ksindex][ksmode&1][x]>>8]) + ret|=1<<(x+1); + ret^=0x1E; + } + return(ret); +} + +static void FKB_Strobe(void) +{ + ksmode=0; + ksindex=0; +} + +static void FKB_Update(void *data, int arg) +{ + memcpy(bufit+1,data,0x48); +} + +static INPUTCFC FKB={FKB_Read,FKB_Write,FKB_Strobe,FKB_Update,0,0}; + +INPUTCFC *FCEU_InitFKB(void) +{ + memset(bufit,0,sizeof(bufit)); + ksmode=ksindex=0; + return(&FKB); +} diff --git a/fceumm/src-fceumm/input/fkb.h b/fceumm/src-fceumm/input/fkb.h new file mode 100644 index 0000000..8a7331a --- /dev/null +++ b/fceumm/src-fceumm/input/fkb.h @@ -0,0 +1,72 @@ +#define FKB_F1 0x01 +#define FKB_F2 0x02 +#define FKB_F3 0x03 +#define FKB_F4 0x04 +#define FKB_F5 0x05 +#define FKB_F6 0x06 +#define FKB_F7 0x07 +#define FKB_F8 0x08 +#define FKB_1 0x09 +#define FKB_2 0x0A +#define FKB_3 0x0B +#define FKB_4 0x0C +#define FKB_5 0x0D +#define FKB_6 0x0E +#define FKB_7 0x0F +#define FKB_8 0x10 +#define FKB_9 0x11 +#define FKB_0 0x12 +#define FKB_MINUS 0x13 +#define FKB_CARET 0x14 +#define FKB_BACKSLASH 0x15 +#define FKB_STOP 0x16 +#define FKB_ESCAPE 0x17 +#define FKB_Q 0x18 +#define FKB_W 0x19 +#define FKB_E 0x1A +#define FKB_R 0x1B +#define FKB_T 0x1C +#define FKB_Y 0x1D +#define FKB_U 0x1E +#define FKB_I 0x1F +#define FKB_O 0x20 +#define FKB_P 0x21 +#define FKB_AT 0x22 +#define FKB_BRACKETLEFT 0x23 +#define FKB_RETURN 0x24 +#define FKB_CONTROL 0x25 +#define FKB_A 0x26 +#define FKB_S 0x27 +#define FKB_D 0x28 +#define FKB_F 0x29 +#define FKB_G 0x2A +#define FKB_H 0x2B +#define FKB_J 0x2C +#define FKB_K 0x2D +#define FKB_L 0x2E +#define FKB_SEMICOLON 0x2F +#define FKB_COLON 0x30 +#define FKB_BRACKETRIGHT 0x31 +#define FKB_KANA 0x32 +#define FKB_LEFTSHIFT 0x33 +#define FKB_Z 0x34 +#define FKB_X 0x35 +#define FKB_C 0x36 +#define FKB_V 0x37 +#define FKB_B 0x38 +#define FKB_N 0x39 +#define FKB_M 0x3A +#define FKB_COMMA 0x3B +#define FKB_PERIOD 0x3C +#define FKB_SLASH 0x3D +#define FKB_UNDERSCORE 0x3E +#define FKB_RIGHTSHIFT 0x3F +#define FKB_GRAPH 0x40 +#define FKB_SPACE 0x41 +#define FKB_CLEAR 0x42 +#define FKB_INSERT 0x43 +#define FKB_DELETE 0x44 +#define FKB_UP 0x45 +#define FKB_LEFT 0x46 +#define FKB_RIGHT 0x47 +#define FKB_DOWN 0x48 diff --git a/fceumm/src-fceumm/input/ftrainer.c b/fceumm/src-fceumm/input/ftrainer.c new file mode 100644 index 0000000..a996875 --- /dev/null +++ b/fceumm/src-fceumm/input/ftrainer.c @@ -0,0 +1,75 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include "share.h" + +static uint32 FTVal,FTValR; +static char side; + +static uint8 FT_Read(int w, uint8 ret) +{ + if(w) + { + ret|=FTValR; + } + return(ret); +} + +static void FT_Write(uint8 V) +{ + FTValR=0; + + /*printf("%08x\n",FTVal);*/ + if(!(V&0x1)) + FTValR=(FTVal>>8); + else if(!(V&0x2)) + FTValR=(FTVal>>4); + else if(!(V&0x4)) + FTValR=FTVal; + + FTValR=(~FTValR)&0xF; + if(side=='B') + FTValR=((FTValR&0x8)>>3) | ((FTValR&0x4)>>1) | ((FTValR&0x2)<<1) | ((FTValR&0x1)<<3); + FTValR<<=1; +} + +static void FT_Update(void *data, int arg) +{ + FTVal=*(uint32 *)data; +} + +static INPUTCFC FamilyTrainer={FT_Read,FT_Write,0,FT_Update,0,0}; + +INPUTCFC *FCEU_InitFamilyTrainerA(void) +{ + side='A'; + FTVal=FTValR=0; + return(&FamilyTrainer); +} + +INPUTCFC *FCEU_InitFamilyTrainerB(void) +{ + side='B'; + FTVal=FTValR=0; + return(&FamilyTrainer); +} + diff --git a/fceumm/src-fceumm/input/hypershot.c b/fceumm/src-fceumm/input/hypershot.c new file mode 100644 index 0000000..02195d4 --- /dev/null +++ b/fceumm/src-fceumm/input/hypershot.c @@ -0,0 +1,51 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include "share.h" + +static uint8 HSVal,HSValR; + + +static uint8 HS_Read(int w, uint8 ret) +{ + if(w) + ret|=HSValR; + + return(ret); +} + +static void HS_Strobe(void) +{ + HSValR=HSVal<<1; +} + +static void HS_Update(void *data, int arg) +{ + HSVal=*(uint8*)data; +} + +static INPUTCFC HyperShot={HS_Read,0,HS_Strobe,HS_Update,0,0}; + +INPUTCFC *FCEU_InitHS(void) +{ + HSVal=HSValR=0; + return(&HyperShot); +} diff --git a/fceumm/src-fceumm/input/mahjong.c b/fceumm/src-fceumm/input/mahjong.c new file mode 100644 index 0000000..0990ae6 --- /dev/null +++ b/fceumm/src-fceumm/input/mahjong.c @@ -0,0 +1,78 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include "share.h" + +static uint32 MReal,MRet; + +static uint8 MJ_Read(int w, uint8 ret) +{ + if(w) + { + /* ret|=(MRet&1)<<1;*/ + ret|=((MRet&0x80)>>6)&2; + /* MRet>>=1;*/ + MRet<<=1; + } + return(ret); +} + +static void MJ_Write(uint8 v) +{ + /* 1: I-D7, J-D6, K-D5, L-D4, M-D3, Big Red-D2 + 2: A-D7, B-D6, C-D5, D-D4, E-D3, F-D2, G-D1, H-D0 + 3: Sel-D6, Start-D7, D5, D4, D3, D2, D1 + */ + MRet=0; + + v>>=1; + v&=3; + + if(v==3) + { + MRet=(MReal>>14)&0x7F; + /*MRet=((MRet&0x1F) |((MRet&0x40)>>1)|((MRet&0x20)<<1)) <<1; //(MReal>>13)&0x7F;*/ + } + else if(v==2) + { + MRet=MReal&0xFF; + } + else if(v==1) + { + MRet=(MReal>>8)&0x3F; + } +/* HSValR=HSVal<<1;*/ +} + +static void MJ_Update(void *data, int arg) +{ + MReal=*(uint32*)data; + /*printf("%08x\n",MReal>>13);*/ + /*HSVal=*(uint8*)data;*/ +} + +static INPUTCFC Mahjong={MJ_Read,MJ_Write,0,MJ_Update,0,0}; + +INPUTCFC *FCEU_InitMahjong(void) +{ + MReal=MRet=0; + return(&Mahjong); +} diff --git a/fceumm/src-fceumm/input/mouse.c b/fceumm/src-fceumm/input/mouse.c new file mode 100644 index 0000000..f2af66f --- /dev/null +++ b/fceumm/src-fceumm/input/mouse.c @@ -0,0 +1,88 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include "share.h" + +typedef struct { + int32 mzx, mzy, mzxold, mzyold; + uint32 readbit; + uint32 data; +} MOUSE; + +static MOUSE Mouse; + +static void StrobeMOUSE(int w) +{ + Mouse.readbit=0; + if((Mouse.mzxold-Mouse.mzx)>0) + Mouse.data|=0x0C; + else if((Mouse.mzxold-Mouse.mzx)<0) + Mouse.data|=0x04; + if((Mouse.mzyold-Mouse.mzy)>0) + Mouse.data|=0x30; + else if((Mouse.mzyold-Mouse.mzy)<0) + Mouse.data|=0x10; +} + +static uint8 ReadMOUSE(int w) +{ + uint8 ret=0; + if(Mouse.readbit>=8) + ret|=1; + else + { + ret|=(Mouse.data>>Mouse.readbit)&1; + Mouse.readbit++; + } + return(ret); +} + +static void UpdateMOUSE(int w, void *data, int arg) +{ + uint32 *ptr=(uint32*)data; + Mouse.data=0; + Mouse.mzxold=Mouse.mzx; + Mouse.mzyold=Mouse.mzy; + Mouse.mzx=ptr[0]; + Mouse.mzy=ptr[1]; + Mouse.data|=ptr[2]; + if((Mouse.mzxold-Mouse.mzx)>0) + Mouse.data|=0x0C; + else if((Mouse.mzxold-Mouse.mzx)<0) + Mouse.data|=0x04; + if((Mouse.mzyold-Mouse.mzy)>0) + Mouse.data|=0x30; + else if((Mouse.mzyold-Mouse.mzy)<0) + Mouse.data|=0x10; +} + +static INPUTC MOUSEC={ReadMOUSE,0,StrobeMOUSE,UpdateMOUSE,0,0}; + +INPUTC *FCEU_InitMouse(int w) +{ + Mouse.mzx=0; + Mouse.mzy=0; + Mouse.mzxold=0; + Mouse.mzyold=0; + Mouse.data=0; + return(&MOUSEC); +} diff --git a/fceumm/src-fceumm/input/oekakids.c b/fceumm/src-fceumm/input/oekakids.c new file mode 100644 index 0000000..b2d89ef --- /dev/null +++ b/fceumm/src-fceumm/input/oekakids.c @@ -0,0 +1,93 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include "share.h" + +static uint8 OKValR,LastWR; +static uint32 OKData; +static uint32 OKX,OKY,OKB; + +static uint8 OK_Read(int w, uint8 ret) +{ + if(w) + ret|=OKValR; + return(ret); +} + +static void OK_Write(uint8 V) +{ + if(!(V&0x1)) + { + int32 vx,vy; + + /*puts("Redo");*/ + OKValR=OKData=0; + + if(OKB) OKData|=1; + + if(OKY >= 48) + OKData|=2; + else if(OKB) OKData|=3; + + vx=OKX*240/256+8; + vy=OKY*256/240-12; + if(vy<0) vy=0; + if(vy>255) vy=255; + if(vx<0) vx=0; + if(vx>255) vx=255; + OKData |= (vx<<10) | (vy<<2); + } + else + { + if((~LastWR)&V&0x02) + OKData<<=1; + + if(!(V&0x2)) OKValR=0x4; + else + { + if(OKData&0x40000) OKValR=0; + else OKValR=0x8; + } + } + LastWR=V; +} + +static void OK_Update(void *data, int arg) +{ + /*puts("Sync");*/ + OKX=((uint32*)data)[0]; + OKY=((uint32*)data)[1]; + OKB=((uint32*)data)[2]; +} + +static void DrawOeka(uint8 *buf, int arg) +{ + if(arg && OKY<44) + FCEU_DrawCursor(buf, OKX, OKY); +} + +static INPUTCFC OekaKids={OK_Read,OK_Write,0,OK_Update,0,DrawOeka}; + +INPUTCFC *FCEU_InitOekaKids(void) +{ + OKValR=0; + return(&OekaKids); +} diff --git a/fceumm/src-fceumm/input/pads.c b/fceumm/src-fceumm/input/pads.c new file mode 100644 index 0000000..229c37a --- /dev/null +++ b/fceumm/src-fceumm/input/pads.c @@ -0,0 +1,142 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include "share.h" +#include "../vsuni.h" + +static uint8 joy_readbit[2]; +static uint8 joy[4]={0,0,0,0}; + +static int FSDisable=0; /* Set to 1 if NES-style four-player adapter is disabled. */ +void FCEUI_DisableFourScore(int s) +{ + FSDisable=s; +} + +extern uint8 LastStrobe; + +SFORMAT FCEUCTRL_STATEINFO[]={ + { joy_readbit, 2, "JYRB"}, + { joy, 4, "JOYS"}, + { &LastStrobe, 1, "LSTS"}, + { 0 } + }; + +/* This function is a quick hack to get the NSF player to use emulated gamepad + input. +*/ +uint8 FCEU_GetJoyJoy(void) +{ + return(joy[0]|joy[1]|joy[2]|joy[3]); +} + +static void StrobeGP(int w) +{ + joy_readbit[w]=0; +} + +static uint8 ReadGPVS(int w) +{ + uint8 ret=0; + if(joy_readbit[w]>=8) + ret=1; + else + { + ret = ((joy[w]>>(joy_readbit[w]))&1); + joy_readbit[w]++; + } + return ret; +} + +static uint8 ReadGP(int w) +{ + uint8 ret; + if(joy_readbit[w]>=8) + ret = ((joy[2+w]>>(joy_readbit[w]&7))&1); + else + ret = ((joy[w]>>(joy_readbit[w]))&1); + if(joy_readbit[w]>=16) ret=0; + if(FSDisable) + { + if(joy_readbit[w]>=8) + ret|=1; + } + else + { + if(joy_readbit[w]==19-w) + ret|=1; + } + joy_readbit[w]++; + return ret; +} + +static void UpdateGP(int w, void *data, int arg) +{ + uint32 *ptr=(uint32*)data; + if(!w) + { + joy[0]=*(uint32*)ptr; + joy[2]=*(uint32*)ptr>>16; + } + else + { + joy[1]=*(uint32*)ptr>>8; + joy[3]=*(uint32*)ptr>>24; + } + if(FCEUGameInfo->type==GIT_VSUNI) + FCEU_VSUniSwap(&joy[0],&joy[1]); +} + +static INPUTC GPC={ReadGP,0,StrobeGP,UpdateGP,0,0}; +static INPUTC GPCVS={ReadGPVS,0,StrobeGP,UpdateGP,0,0}; + +INPUTC *FCEU_InitJoyPad(int w) +{ + joy_readbit[w]=0; + joy[w]=0; + joy[w+2]=0; + if(FCEUGameInfo->type==GIT_VSUNI) + return(&GPCVS); + else + return(&GPC); +} + +static uint8 F4ReadBit[2]; +static void StrobeFami4(void) +{ + F4ReadBit[0]=F4ReadBit[1]=0; +} + +static uint8 ReadFami4(int w, uint8 ret) +{ + ret&=1; + ret|=((joy[2+w]>>(F4ReadBit[w]))&1)<<1; + if(F4ReadBit[w]>=8) ret|=2; + else F4ReadBit[w]++; + return(ret); +} + +static INPUTCFC FAMI4C={ReadFami4,0,StrobeFami4,0,0,0}; +INPUTCFC *FCEU_InitFami4(int w) +{ + memset(&F4ReadBit,0,sizeof(F4ReadBit)); + return(&FAMI4C); +} diff --git a/fceumm/src-fceumm/input/pec586kb.c b/fceumm/src-fceumm/input/pec586kb.c new file mode 100644 index 0000000..43dba7b --- /dev/null +++ b/fceumm/src-fceumm/input/pec586kb.c @@ -0,0 +1,69 @@ +#include +#include "share.h" +/*#include "Pec586kb.h"*/ +/*#define AK2(x,y) ( (FKB_##x) | (FKB_##y <<8) )*/ +/*#define AK(x) FKB_##x*/ +/* +static uint8 bufit[0x61]; +static uint8 ksmode; +static uint8 ksindex; + + +static uint16 matrix[13][8]= +{ + {AK(4), AK(G), AK(F), AK(C), AK(F2), AK(E), AK(5), AK(V) }, + {AK(2), AK(D), AK(S), AK(END), AK(F1), AK(W), AK(3), AK(X) }, + {AK(INSERT), AK(BACK), AK(NEXT), AK(RIGHT), AK(F8), AK(PRIOR), AK(DELETE), AK(HOME) }, + {AK(9), AK(I), AK(L), AK(COMMA), AK(F5), AK(O), AK(0), AK(PERIOD)}, + {AK(RBRACKET), AK(RETURN), AK(UP), AK(LEFT), AK(F7), AK(LBRACKET), AK(BACKSLASH), AK(DOWN) }, + {AK(Q), AK(CAPITAL), AK(Z), AK(TAB), AK(ESCAPE), AK(A), AK(1), AK(LCONTROL)}, + {AK(7), AK(Y), AK(K), AK(M), AK(F4), AK(U), AK(8), AK(J)}, + {AK(MINUS), AK(SEMICOLON),AK(APOSTROPHE), AK(SLASH), AK(F6), AK(P), AK(EQUALS), AK(LSHIFT)}, + {AK(T), AK(H), AK(N), AK(SPACE), AK(F3), AK(R), AK(6), AK(B)}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {AK(LMENU), AK(NUMPAD4), AK(NUMPAD7), AK(F11), AK(F12), AK(NUMPAD1), AK(NUMPAD2), AK(NUMPAD8)}, + {AK(SUBTRACT), AK(ADD), AK(MULTIPLY), AK(NUMPAD9), AK(F10), AK(NUMPAD5), AK(DIVIDE), AK(NUMLOCK)}, + {AK(GRAVE), AK(NUMPAD6), AK(PAUSE), AK(SPACE), AK(F9), AK(NUMPAD3), AK(DECIMAL), AK(NUMPAD0)}, +}; + +static void Pec586KB_Write(uint8 v) +{ + if((ksmode&2) && !(v&2)) + ksindex=(ksindex+1)%13; + ksmode=v; +} + +static uint8 Pec586KB_Read(int w, uint8 ret) +{ + if(w) + { + int x; + + ret&=~2; + if(bufit[matrix[ksindex][ksmode&1][x]&0xFF]||bufit[matrix[ksindex][ksmode&1][x]>>8]) + ret|=1<<(x+1); + ret^=0x1E; + } + return(ret); +} + +static void Pec586KB_Strobe(void) +{ + ksmode=0; + ksindex=0; +} + +static void Pec586KB_Update(void *data, int arg) +{ + memcpy(bufit+1,data,0x60); +} + +static INPUTCFC Pec586KB={Pec586KB_Read,Pec586KB_Write,Pec586KB_Strobe,Pec586KB_Update,0,0}; + +INPUTCFC *FCEU_InitPec586KB(void) +{ + memset(bufit,0,sizeof(bufit)); + ksmode=ksindex=0; + return(&Pec586KB); +} +*/ diff --git a/fceumm/src-fceumm/input/powerpad.c b/fceumm/src-fceumm/input/powerpad.c new file mode 100644 index 0000000..914ba0d --- /dev/null +++ b/fceumm/src-fceumm/input/powerpad.c @@ -0,0 +1,84 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include "share.h" + + +static char side; +static uint32 pprsb[2]; +static uint32 pprdata[2]; + +static uint8 ReadPP(int w) +{ + uint8 ret=0; + ret|=((pprdata[w]>>pprsb[w])&1)<<3; + ret|=((pprdata[w]>>(pprsb[w]+8))&1)<<4; + if(pprsb[w]>=4) + { + ret|=0x10; + if(pprsb[w]>=8) + ret|=0x08; + } + pprsb[w]++; + return ret; +} + +static void StrobePP(int w) +{ + pprsb[w]=0; +} + +void UpdatePP(int w, void *data, int arg) +{ + static const char shifttableA[12]={8,9,0,1,11,7,4,2,10,6,5,3}; + static const char shifttableB[12]={1,0,9,8,2,4,7,11,3,5,6,10}; + int x; + + pprdata[w]=0; + + if(side=='A') + for(x=0;x<12;x++) + pprdata[w]|=(((*(uint32 *)data)>>x)&1)<>x)&1)< +#include "share.h" + +static uint8 QZVal,QZValR; +static uint8 FunkyMode; + +static uint8 QZ_Read(int w, uint8 ret) +{ + if(w) + { + /*if(X.PC==0xdc7d) return(0xFF);*/ + /*printf("Blah: %04x\n",X.PC);*/ + /*FCEUI_DumpMem("dmp2",0xc000,0xffff);*/ + + ret|=(QZValR&0x7)<<2; + QZValR=QZValR>>3; + + if(FunkyMode) + { + /*ret=0x14;*/ + /*puts("Funky");*/ + QZValR|=0x28; + } + else + { + QZValR|=0x38; + } + } + return(ret); +} + +static void QZ_Strobe(void) +{ + QZValR=QZVal; + /*puts("Strobe");*/ +} + +static void QZ_Write(uint8 V) +{ + /*printf("Wr: %02x\n",V);*/ + FunkyMode=V&4; +} + +static void QZ_Update(void *data, int arg) +{ + QZVal=*(uint8 *)data; +} + +static INPUTCFC QuizKing={QZ_Read,QZ_Write,QZ_Strobe,QZ_Update,0,0}; + +INPUTCFC *FCEU_InitQuizKing(void) +{ + QZVal=QZValR=0; + return(&QuizKing); +} diff --git a/fceumm/src-fceumm/input/shadow.c b/fceumm/src-fceumm/input/shadow.c new file mode 100644 index 0000000..6bb4e30 --- /dev/null +++ b/fceumm/src-fceumm/input/shadow.c @@ -0,0 +1,153 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include + +#include "share.h" + +typedef struct { + uint32 mzx,mzy,mzb; + int zap_readbit; + int bogo; + int zappo; + uint64 zaphit; +} ZAPPER; + +static ZAPPER ZD; + +static void ZapperFrapper(uint8 *bg, uint8 *spr, uint32 linets, int final) +{ + int xs,xe; + int zx,zy; + + if(!bg) /* New line, so reset stuff.*/ + { + ZD.zappo=0; + return; + } + xs=ZD.zappo; + xe=final; + + zx=ZD.mzx; + zy=ZD.mzy; + + if(xe>256) xe=256; + + if(scanline>=(zy-4) && scanline<=(zy+4)) + { + while(xs=(zx-4)) + { + a1=bg[xs]; + if(spr) + { + a2=spr[xs]; + + if(!(a2&0x80)) + if(!(a2&0x40) || (a1&64)) + a1=a2; + } + a1&=63; + + sum=palo[a1].r+palo[a1].g+palo[a1].b; + if(sum>=100*3) + { + ZD.zaphit=((uint64)linets+(xs+16)*(PAL?15:16))/48+timestampbase; + goto endo; + } + } + xs++; + } + } +endo: + ZD.zappo=final; +} + +static INLINE int CheckColor(void) +{ + FCEUPPU_LineUpdate(); + + if((ZD.zaphit+10)>=(timestampbase+timestamp)) return(0); + + return(1); +} + + +static uint8 ReadZapper(int w, uint8 ret) +{ + if(w) + { + ret&=~0x18; + if(ZD.bogo) + ret|=0x10; + if(CheckColor()) + ret|=0x8; + } + else + { + if(ZD.zap_readbit==1) + { + ret&=~2; + ret|=ZD.mzb&2; + } + ret|=(ret&1)<<1; + ZD.zap_readbit++; + } + return ret; +} + +static void DrawZapper(uint8 *buf, int arg) +{ + if(arg) + FCEU_DrawGunSight(buf, ZD.mzx,ZD.mzy); +} + +static void UpdateZapper(void *data, int arg) +{ + uint32 *ptr=(uint32*)data; + + if(ZD.bogo) + ZD.bogo--; + if(ptr[2]&1 && (!(ZD.mzb&1))) + ZD.bogo=5; + + ZD.mzx=ptr[0]; + ZD.mzy=ptr[1]; + ZD.mzb=ptr[2]; +} + +static void StrobeShadow(void) +{ + ZD.zap_readbit=0; +} + +static INPUTCFC SHADOWC={ReadZapper,0,StrobeShadow,UpdateZapper,ZapperFrapper,DrawZapper}; + +INPUTCFC *FCEU_InitSpaceShadow(void) +{ + memset(&ZD,0,sizeof(ZAPPER)); + return(&SHADOWC); +} + + diff --git a/fceumm/src-fceumm/input/share.h b/fceumm/src-fceumm/input/share.h new file mode 100644 index 0000000..5a3d169 --- /dev/null +++ b/fceumm/src-fceumm/input/share.h @@ -0,0 +1,10 @@ +#include "../types.h" +#include "../input.h" +#include "../fceu.h" +#include "../ppu.h" +#include "../x6502.h" +#include "../palette.h" +#include "../state.h" + +void FCEU_DrawCursor(uint8 *buf, int xc, int yc); +void FCEU_DrawGunSight(uint8 *buf, int xc, int yc); diff --git a/fceumm/src-fceumm/input/suborkb.c b/fceumm/src-fceumm/input/suborkb.c new file mode 100644 index 0000000..48f4ea6 --- /dev/null +++ b/fceumm/src-fceumm/input/suborkb.c @@ -0,0 +1,86 @@ +#include +#include "share.h" +#include "suborkb.h" +#define AK2(x,y) ( (FKB_##x) | (FKB_##y <<8) ) +#define AK(x) FKB_##x + +static uint8 bufit[0x61]; +static uint8 ksmode; +static uint8 ksindex; + + +static uint16 matrix[13][2][4]= +{ + {{AK(4), AK(G), AK(F), AK(C) }, + {AK(F2), AK(E), AK(5), AK(V) }}, + {{AK(2), AK(D), AK(S), AK(END) }, + {AK(F1), AK(W), AK(3), AK(X) }}, + {{AK(INSERT), AK(BACK), AK(NEXT), AK(RIGHT) }, + {AK(F8), AK(PRIOR), AK(DELETE), AK(HOME) }}, + {{AK(9), AK(I), AK(L), AK(COMMA) }, + {AK(F5), AK(O), AK(0), AK(PERIOD) }}, + {{AK(RBRACKET),AK(RETURN), AK(UP), AK(LEFT) }, + {AK(F7), AK(LBRACKET), AK(BACKSLASH), AK(DOWN) }}, + {{AK(Q), AK(CAPITAL), AK(Z), AK(TAB) }, + {AK(ESCAPE), AK(A), AK(1), AK(LCONTROL)}}, + {{AK(7), AK(Y), AK(K), AK(M) }, + {AK(F4), AK(U), AK(8), AK(J) }}, + {{AK(MINUS), AK(SEMICOLON),AK(APOSTROPHE),AK(SLASH) }, + {AK(F6), AK(P), AK(EQUALS), AK(LSHIFT) }}, + {{AK(T), AK(H), AK(N), AK(SPACE) }, + {AK(F3), AK(R), AK(6), AK(B) }}, + {{0, 0, 0, 0 }, + {0, 0, 0, 0 }}, + {{AK(LMENU), AK(NUMPAD4), AK(NUMPAD7), AK(F11) }, + {AK(F12), AK(NUMPAD1), AK(NUMPAD2), AK(NUMPAD8) }}, + {{AK(SUBTRACT),AK(ADD), AK(MULTIPLY), AK(NUMPAD9) }, + {AK(F10), AK(NUMPAD5), AK(DIVIDE), AK(NUMLOCK) }}, + {{AK(GRAVE), AK(NUMPAD6), AK(PAUSE), AK(SPACE) }, + {AK(F9), AK(NUMPAD3), AK(DECIMAL), AK(NUMPAD0) }}, +}; + +static void SuborKB_Write(uint8 v) +{ + v>>=1; + if(v&2) + { + if((ksmode&1) && !(v&1)) + ksindex=(ksindex+1)%13; + } + ksmode=v; +} + +static uint8 SuborKB_Read(int w, uint8 ret) +{ + if(w) + { + int x; + + ret&=~0x1E; + for(x=0;x<4;x++) + if(bufit[matrix[ksindex][ksmode&1][x]&0xFF]||bufit[matrix[ksindex][ksmode&1][x]>>8]) + ret|=1<<(x+1); + ret^=0x1E; + } + return(ret); +} + +static void SuborKB_Strobe(void) +{ + ksmode=0; + ksindex=0; +} + +static void SuborKB_Update(void *data, int arg) +{ + memcpy(bufit+1,data,0x60); +} + +static INPUTCFC SuborKB={SuborKB_Read,SuborKB_Write,SuborKB_Strobe,SuborKB_Update,0,0}; + +INPUTCFC *FCEU_InitSuborKB(void) +{ + memset(bufit,0,sizeof(bufit)); + ksmode=ksindex=0; + return(&SuborKB); +} diff --git a/fceumm/src-fceumm/input/suborkb.h b/fceumm/src-fceumm/input/suborkb.h new file mode 100644 index 0000000..ee56315 --- /dev/null +++ b/fceumm/src-fceumm/input/suborkb.h @@ -0,0 +1,96 @@ +#define FKB_ESCAPE 0x01 +#define FKB_F1 0x02 +#define FKB_F2 0x03 +#define FKB_F3 0x04 +#define FKB_F4 0x05 +#define FKB_F5 0x06 +#define FKB_F6 0x07 +#define FKB_F7 0x08 +#define FKB_F8 0x09 +#define FKB_F9 0x0A +#define FKB_F10 0x0B +#define FKB_F11 0x0C +#define FKB_F12 0x0D +#define FKB_PAUSE 0x0E +#define FKB_GRAVE 0x0F +#define FKB_1 0x10 +#define FKB_2 0x11 +#define FKB_3 0x12 +#define FKB_4 0x13 +#define FKB_5 0x14 +#define FKB_6 0x15 +#define FKB_7 0x16 +#define FKB_8 0x17 +#define FKB_9 0x18 +#define FKB_0 0x19 +#define FKB_MINUS 0x1A +#define FKB_EQUALS 0x1B +#define FKB_BACK 0x1C +#define FKB_INSERT 0x1D +#define FKB_HOME 0x1E +#define FKB_PRIOR 0x1F +#define FKB_NUMLOCK 0x20 +#define FKB_DIVIDE 0x21 +#define FKB_MULTIPLY 0x22 +#define FKB_SUBTRACT 0x23 +#define FKB_TAB 0x24 +#define FKB_Q 0x25 +#define FKB_W 0x26 +#define FKB_E 0x27 +#define FKB_R 0x28 +#define FKB_T 0x29 +#define FKB_Y 0x2A +#define FKB_U 0x2B +#define FKB_I 0x2C +#define FKB_O 0x2D +#define FKB_P 0x2E +#define FKB_LBRACKET 0x2F +#define FKB_RBRACKET 0x30 +#define FKB_RETURN 0x31 +#define FKB_DELETE 0x32 +#define FKB_END 0x33 +#define FKB_NEXT 0x34 +#define FKB_NUMPAD7 0x35 +#define FKB_NUMPAD8 0x36 +#define FKB_NUMPAD9 0x37 +#define FKB_ADD 0x38 +#define FKB_CAPITAL 0x39 +#define FKB_A 0x3A +#define FKB_S 0x3B +#define FKB_D 0x3C +#define FKB_F 0x3D +#define FKB_G 0x3E +#define FKB_H 0x3F +#define FKB_J 0x40 +#define FKB_K 0x41 +#define FKB_L 0x42 +#define FKB_SEMICOLON 0x43 +#define FKB_APOSTROPHE 0x44 +#define FKB_NUMPAD4 0x45 +#define FKB_NUMPAD5 0x46 +#define FKB_NUMPAD6 0x47 +#define FKB_LSHIFT 0x48 +#define FKB_Z 0x49 +#define FKB_X 0x4A +#define FKB_C 0x4B +#define FKB_V 0x4C +#define FKB_B 0x4D +#define FKB_N 0x4E +#define FKB_M 0x4F +#define FKB_COMMA 0x50 +#define FKB_PERIOD 0x51 +#define FKB_SLASH 0x52 +#define FKB_BACKSLASH 0x53 +#define FKB_UP 0x54 +#define FKB_NUMPAD1 0x55 +#define FKB_NUMPAD2 0x56 +#define FKB_NUMPAD3 0x57 +#define FKB_LCONTROL 0x58 +#define FKB_LMENU 0x59 +#define FKB_SPACE 0x5A +#define FKB_LEFT 0x5B +#define FKB_DOWN 0x5C +#define FKB_RIGHT 0x5D +#define FKB_NUMPAD0 0x5E +#define FKB_DECIMAL 0x5F + diff --git a/fceumm/src-fceumm/input/toprider.c b/fceumm/src-fceumm/input/toprider.c new file mode 100644 index 0000000..b5eaca7 --- /dev/null +++ b/fceumm/src-fceumm/input/toprider.c @@ -0,0 +1,57 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include "share.h" + +static uint32 bs,bss; +static uint32 boop; + +static uint8 Read(int w, uint8 ret) +{ + if(w) + { + ret|=(bs&1)<<3; + ret|=(boop&1)<<4; + bs>>=1; + boop>>=1; + } + return(ret); +} + +static void Write(uint8 V) +{ + bs=bss; +} + +static void Update(void *data, int arg) +{ + bss=*(uint8*)data; + bss|=bss<<8; + bss|=bss<<8; +} + +static INPUTCFC TopRider={Read,Write,0,Update,0,0}; + +INPUTCFC *FCEU_InitTopRider(void) +{ + return(&TopRider); +} + diff --git a/fceumm/src-fceumm/input/zapper.c b/fceumm/src-fceumm/input/zapper.c new file mode 100644 index 0000000..06a16fd --- /dev/null +++ b/fceumm/src-fceumm/input/zapper.c @@ -0,0 +1,165 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include + +#include "share.h" + +typedef struct { + uint32 mzx,mzy,mzb; + int zap_readbit; + int bogo; + int zappo; + uint64 zaphit; +} ZAPPER; + +static ZAPPER ZD[2]; + +static void ZapperFrapper(int w, uint8 *bg, uint8 *spr, uint32 linets, int final) +{ + int xs,xe; + int zx,zy; + + if(!bg) /* New line, so reset stuff.*/ + { + ZD[w].zappo=0; + return; + } + xs=ZD[w].zappo; + xe=final; + + zx=ZD[w].mzx; + zy=ZD[w].mzy; + + if(xe>256) xe=256; + + if(scanline>=(zy-4) && scanline<=(zy+4)) + { + while(xs=(zx-4)) + { + a1=bg[xs]; + if(spr) + { + a2=spr[xs]; + + if(!(a2&0x80)) + if(!(a2&0x40) || (a1&64)) + a1=a2; + } + a1&=63; + + sum=palo[a1].r+palo[a1].g+palo[a1].b; + if(sum>=100*3) + { + ZD[w].zaphit=((uint64)linets+(xs+16)*(PAL?15:16))/48+timestampbase; + goto endo; + } + } + xs++; + } + } + endo: + ZD[w].zappo=final; +} + +static INLINE int CheckColor(int w) +{ + FCEUPPU_LineUpdate(); + + if((ZD[w].zaphit+100)>=(timestampbase+timestamp) + && !(ZD[w].mzb&2)) return(0); + + return(1); +} + +static uint8 ReadZapperVS(int w) +{ + uint8 ret=0; + + if(ZD[w].zap_readbit==4) ret=1; + + if(ZD[w].zap_readbit==7) + { + if(ZD[w].bogo) + ret|=0x1; + } + if(ZD[w].zap_readbit==6) + { + if(!CheckColor(w)) + ret|=0x1; + } + ZD[w].zap_readbit++; + return ret; +} + +static void StrobeZapperVS(int w) +{ + ZD[w].zap_readbit=0; +} + +static uint8 ReadZapper(int w) +{ + uint8 ret=0; + if(ZD[w].bogo) + ret|=0x10; + if(CheckColor(w)) + ret|=0x8; + return ret; +} + +static void DrawZapper(int w, uint8 *buf, int arg) +{ + if(arg) + FCEU_DrawGunSight(buf, ZD[w].mzx,ZD[w].mzy); +} + +static void UpdateZapper(int w, void *data, int arg) +{ + uint32 *ptr=(uint32 *)data; + + /*FCEU_DispMessage("%3d:%3d",ZD[w].mzx,ZD[w].mzy);*/ + if(ZD[w].bogo) + ZD[w].bogo--; + if(ptr[2]&3 && (!(ZD[w].mzb&3))) + ZD[w].bogo=5; + + ZD[w].mzx=ptr[0]; + ZD[w].mzy=ptr[1]; + ZD[w].mzb=ptr[2]; +} + +static INPUTC ZAPC={ReadZapper,0,0,UpdateZapper,ZapperFrapper,DrawZapper}; +static INPUTC ZAPVSC={ReadZapperVS,0,StrobeZapperVS,UpdateZapper,ZapperFrapper,DrawZapper}; + +INPUTC *FCEU_InitZapper(int w) +{ + memset(&ZD[w],0,sizeof(ZAPPER)); + if(FCEUGameInfo->type == GIT_VSUNI) + return(&ZAPVSC); + else + return(&ZAPC); +} + + diff --git a/fceumm/src-fceumm/mappers/151.c b/fceumm/src-fceumm/mappers/151.c new file mode 100644 index 0000000..5d2cb28 --- /dev/null +++ b/fceumm/src-fceumm/mappers/151.c @@ -0,0 +1,41 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + + + +DECLFW(Mapper151_write) +{ + switch(A&0xF000) + { + case 0x8000:ROM_BANK8(0x8000,V);break; + case 0xA000:ROM_BANK8(0xA000,V);break; + case 0xC000:ROM_BANK8(0xC000,V);break; + case 0xe000:VROM_BANK4(0x0000,V);break; + case 0xf000:VROM_BANK4(0x1000,V);break; + } +} + +void Mapper151_init(void) +{ + SetWriteHandler(0x8000,0xffff,Mapper151_write); +} + diff --git a/fceumm/src-fceumm/mappers/157.c b/fceumm/src-fceumm/mappers/157.c new file mode 100644 index 0000000..5ad7607 --- /dev/null +++ b/fceumm/src-fceumm/mappers/157.c @@ -0,0 +1,240 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 1998 BERO + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static void BandaiIRQHook(int a) +{ + if(IRQa) + { + IRQCount-=a; + if(IRQCount<0) + { + X6502_IRQBegin(FCEU_IQEXT); +/* FCEU_printf("IRQ: %d, %d\n",scanline,timestamp);*/ + IRQa=0; + IRQCount=0xFFFF; + } + } +} + +static DECLFW(Mapper16_write) +{ + A&=0xF; + + if(A<=0x7) + VROM_BANK1(A<<10,V); + else if(A==0x8) + ROM_BANK16(0x8000,V); + else switch(A) { + case 0x9: switch(V&3) { + case 0x00:MIRROR_SET2(1);break; + case 0x01:MIRROR_SET2(0);break; + case 0x02:onemir(0);break; + case 0x03:onemir(1);break; + } + break; + case 0xA:X6502_IRQEnd(FCEU_IQEXT); + IRQa=V&1; + IRQCount=IRQLatch; + break; + case 0xB:IRQLatch&=0xFF00; IRQLatch|=V; + break; + case 0xC:IRQLatch&=0xFF; IRQLatch|=V<<8; + break; + case 0xD: break;/* Serial EEPROM control port */ + } +} + +static uint8 BarcodeData[256]; +static int BarcodeReadPos; +static int BarcodeCycleCount; +static uint32 BarcodeOut; + +int FCEUI_DatachSet(const uint8 *rcode) +{ + int prefix_parity_type[10][6] = { + {0,0,0,0,0,0}, {0,0,1,0,1,1}, {0,0,1,1,0,1}, {0,0,1,1,1,0}, + {0,1,0,0,1,1}, {0,1,1,0,0,1}, {0,1,1,1,0,0}, {0,1,0,1,0,1}, + {0,1,0,1,1,0}, {0,1,1,0,1,0} + }; + int data_left_odd[10][7] = { + {0,0,0,1,1,0,1}, {0,0,1,1,0,0,1}, {0,0,1,0,0,1,1}, {0,1,1,1,1,0,1}, + {0,1,0,0,0,1,1}, {0,1,1,0,0,0,1}, {0,1,0,1,1,1,1}, {0,1,1,1,0,1,1}, + {0,1,1,0,1,1,1}, {0,0,0,1,0,1,1} + }; + int data_left_even[10][7] = { + {0,1,0,0,1,1,1}, {0,1,1,0,0,1,1}, {0,0,1,1,0,1,1}, {0,1,0,0,0,0,1}, + {0,0,1,1,1,0,1}, {0,1,1,1,0,0,1}, {0,0,0,0,1,0,1}, {0,0,1,0,0,0,1}, + {0,0,0,1,0,0,1}, {0,0,1,0,1,1,1} + }; + int data_right[10][7] = { + {1,1,1,0,0,1,0}, {1,1,0,0,1,1,0}, {1,1,0,1,1,0,0}, {1,0,0,0,0,1,0}, + {1,0,1,1,1,0,0}, {1,0,0,1,1,1,0}, {1,0,1,0,0,0,0}, {1,0,0,0,1,0,0}, + {1,0,0,1,0,0,0}, {1,1,1,0,1,0,0} + }; + uint8 code[13+1]; + uint32 tmp_p=0; + int i, j; + int len; + + for(i=len=0;i<13;i++) + { + if(!rcode[i]) break; + + if((code[i]=rcode[i]-'0') > 9) + return(0); + len++; + } + if(len!=13 && len!=12 && len!=8 && len!=7) return(0); + + #define BS(x) BarcodeData[tmp_p]=x;tmp_p++ + + for(j=0;j<32;j++) + { + BS(0x00); + } + + /* Left guard bars */ + BS(1); BS(0); BS(1); + + if(len==13 || len==12) + { + uint32 csum; + + for(i=0;i<6;i++) + if(prefix_parity_type[code[0]][i]) + { + for(j=0;j<7;j++) + { + BS(data_left_even[code[i+1]][j]); + } + } + else + for(j=0;j<7;j++) + { + BS(data_left_odd[code[i+1]][j]); + } + + /* Center guard bars */ + BS(0); BS(1); BS(0); BS(1); BS(0); + + for(i=7;i<12;i++) + for(j=0;j<7;j++) + { + BS(data_right[code[i]][j]); + } + csum=0; + for(i=0;i<12;i++) csum+=code[i]*((i&1)?3:1); + csum=(10-(csum%10))%10; + /*printf("%d\n",csum);*/ + for(j=0;j<7;j++) + { + BS(data_right[csum][j]); + } + + } + else if(len==8 || len==7) + { + uint32 csum=0; + + for(i=0;i<7;i++) csum+=(i&1)?code[i]:(code[i]*3); + + csum=(10-(csum%10))%10; + + for(i=0;i<4;i++) + for(j=0;j<7;j++) + { + BS(data_left_odd[code[i]][j]); + } + + + /* Center guard bars */ + BS(0); BS(1); BS(0); BS(1); BS(0); + + for(i=4;i<7;i++) + for(j=0;j<7;j++) + { + BS(data_right[code[i]][j]); + } + + for(j=0;j<7;j++) + { BS(data_right[csum][j]);} + + } + + /* Right guard bars */ + BS(1); BS(0); BS(1); + + for(j=0;j<32;j++) + { + BS(0x00); + } + + BS(0xFF); + #undef BS + BarcodeReadPos=0; + BarcodeOut=0x8; + BarcodeCycleCount=0; + return(1); +} + +static void BarcodeIRQHook(int a) +{ + BandaiIRQHook(a); + + BarcodeCycleCount+=a; + + if(BarcodeCycleCount >= 1000) + { + BarcodeCycleCount -= 1000; + if(BarcodeData[BarcodeReadPos]==0xFF) + { + BarcodeOut=0; + } + else + { + BarcodeOut=(BarcodeData[BarcodeReadPos]^1)<<3; + BarcodeReadPos++; + } + } +} + +static DECLFR(Mapper157_read) +{ + uint8 ret; + + ret=BarcodeOut; + return(ret); +} + +void Mapper157_init(void) +{ + FCEUGameInfo->cspecial = SIS_DATACH; + MapIRQHook=BarcodeIRQHook; + SetWriteHandler(0x6000,0xFFFF,Mapper16_write); + SetReadHandler(0x6000,0x7FFF,Mapper157_read); + + BarcodeData[0]=0xFF; + BarcodeReadPos=0; + BarcodeOut=0; + BarcodeCycleCount=0; +} diff --git a/fceumm/src-fceumm/mappers/17.c b/fceumm/src-fceumm/mappers/17.c new file mode 100644 index 0000000..7cc9e7e --- /dev/null +++ b/fceumm/src-fceumm/mappers/17.c @@ -0,0 +1,73 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + + + +static void FFEIRQHook(int a) +{ + if(IRQa) + { + IRQCount+=a; + if(IRQCount>=0x10000) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + IRQCount=0; + } + } +} + + +DECLFW(Mapper17_write) +{ + switch(A){ + default: + break; + case 0x42FE: + onemir((V>>4)&1); + break; + case 0x42FF: + MIRROR_SET((V>>4)&1); + break; + case 0x4501:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break; + case 0x4502:IRQCount&=0xFF00;IRQCount|=V;break; + case 0x4503:IRQCount&=0x00FF;IRQCount|=V<<8;IRQa=1;break; + case 0x4504: ROM_BANK8(0x8000,V);break; + case 0x4505: ROM_BANK8(0xA000,V);break; + case 0x4506: ROM_BANK8(0xC000,V);break; + case 0x4507: ROM_BANK8(0xE000,V);break; + case 0x4510: VROM_BANK1(0x0000,V);break; + case 0x4511: VROM_BANK1(0x0400,V);break; + case 0x4512: VROM_BANK1(0x0800,V);break; + case 0x4513: VROM_BANK1(0x0C00,V);break; + case 0x4514: VROM_BANK1(0x1000,V);break; + case 0x4515: VROM_BANK1(0x1400,V);break; + case 0x4516: VROM_BANK1(0x1800,V);break; + case 0x4517: VROM_BANK1(0x1C00,V);break; + } +} + +void Mapper17_init(void) +{ +MapIRQHook=FFEIRQHook; +SetWriteHandler(0x4020,0x5fff,Mapper17_write); +} diff --git a/fceumm/src-fceumm/mappers/18.c b/fceumm/src-fceumm/mappers/18.c new file mode 100644 index 0000000..6791f05 --- /dev/null +++ b/fceumm/src-fceumm/mappers/18.c @@ -0,0 +1,80 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +#define K4buf mapbyte2 +#define K4buf2 mapbyte3 + +void JalecoIRQHook(int a) +{ + if(IRQa && IRQCount) + { + IRQCount-=a; + if(IRQCount<=0) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount=0; + IRQa=0; + } + } +} + +DECLFW(Mapper18_write) +{ + A&=0xF003; + if(A>=0x8000 && A<=0x9001) + { + int x=((A>>1)&1)|((A-0x8000)>>11); + + K4buf2[x]&=(0xF0)>>((A&1)<<2); + K4buf2[x]|=(V&0xF)<<((A&1)<<2); + ROM_BANK8(0x8000+(x<<13),K4buf2[x]); + } + else if(A>=0xa000 && A<=0xd003) + { + int x=((A>>1)&1)|((A-0xA000)>>11); + + K4buf[x]&=(0xF0)>>((A&1)<<2); + K4buf[x]|=(V&0xF)<<((A&1)<<2); + VROM_BANK1(x<<10,K4buf[x]); + } + else switch(A) + { + case 0xe000:IRQLatch&=0xFFF0;IRQLatch|=(V&0x0f);break; + case 0xe001:IRQLatch&=0xFF0F;IRQLatch|=(V&0x0f)<<4;break; + case 0xe002:IRQLatch&=0xF0FF;IRQLatch|=(V&0x0f)<<8;break; + case 0xe003:IRQLatch&=0x0FFF;IRQLatch|=(V&0x0f)<<12;break; + case 0xf000:IRQCount=IRQLatch; + break; + case 0xf001:IRQa=V&1; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xf002:MIRROR_SET2(V&1); + if(V&2) onemir(0); + break; + } +} + +void Mapper18_init(void) +{ + SetWriteHandler(0x8000,0xffff,Mapper18_write); + MapIRQHook=JalecoIRQHook; +} diff --git a/fceumm/src-fceumm/mappers/201.c b/fceumm/src-fceumm/mappers/201.c new file mode 100644 index 0000000..069f6d5 --- /dev/null +++ b/fceumm/src-fceumm/mappers/201.c @@ -0,0 +1,44 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static DECLFW(Mapper201_write) +{ +/* FCEU_printf("%04x, %02x\n",A,V);*/ + if(A&0x08) + { + ROM_BANK32(A&0x03); + VROM_BANK8(A&0x03); + } + else + { + ROM_BANK32(0); + VROM_BANK8(0); + } +} + +void Mapper201_init(void) +{ + ROM_BANK32(~0); + VROM_BANK8(~0); + SetWriteHandler(0x8000,0xffff,Mapper201_write); +} + diff --git a/fceumm/src-fceumm/mappers/202.c b/fceumm/src-fceumm/mappers/202.c new file mode 100644 index 0000000..cac2a88 --- /dev/null +++ b/fceumm/src-fceumm/mappers/202.c @@ -0,0 +1,39 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static DECLFW(Mapper202_write) +{ + int tmp=(A>>1)&0x7; + + MIRROR_SET(A&1); + ROM_BANK16(0x8000,tmp); + ROM_BANK16(0xc000,tmp+(((tmp&0x6)==0x6)?1:0)); + VROM_BANK8(tmp); +} + +void Mapper202_init(void) +{ + ROM_BANK16(0x8000,0); + ROM_BANK16(0xc000,0); + VROM_BANK8(0); + SetWriteHandler(0x8000,0xFFFF,Mapper202_write); +} diff --git a/fceumm/src-fceumm/mappers/203.c b/fceumm/src-fceumm/mappers/203.c new file mode 100644 index 0000000..6ab5d52 --- /dev/null +++ b/fceumm/src-fceumm/mappers/203.c @@ -0,0 +1,36 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static DECLFW(Mapper203_write) +{ + ROM_BANK16(0x8000,(V>>2)&3); + ROM_BANK16(0xc000,(V>>2)&3); + VROM_BANK8(V&3); +} + +void Mapper203_init(void) +{ + ROM_BANK16(0x8000,0); + ROM_BANK16(0xc000,0); + VROM_BANK8(0); + SetWriteHandler(0x8000,0xFFFF,Mapper203_write); +} diff --git a/fceumm/src-fceumm/mappers/204.c b/fceumm/src-fceumm/mappers/204.c new file mode 100644 index 0000000..3d79918 --- /dev/null +++ b/fceumm/src-fceumm/mappers/204.c @@ -0,0 +1,38 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static DECLFW(Mapper204_write) +{ + int tmp2=A&0x6; + int tmp1=tmp2+((tmp2==0x6)?0:(A&1)); + MIRROR_SET((A>>4)&1); + ROM_BANK16(0x8000,tmp1); + ROM_BANK16(0xc000,tmp2+((tmp2==0x6)?1:(A&1))); + VROM_BANK8(tmp1); +} + +void Mapper204_init(void) +{ + ROM_BANK32(~0); + VROM_BANK8(~0); + SetWriteHandler(0x8000,0xFFFF,Mapper204_write); +} diff --git a/fceumm/src-fceumm/mappers/21.c b/fceumm/src-fceumm/mappers/21.c new file mode 100644 index 0000000..80e2173 --- /dev/null +++ b/fceumm/src-fceumm/mappers/21.c @@ -0,0 +1,106 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +#define K4buf mapbyte2 +#define K4IRQ mapbyte1[1] +#define K4sel mapbyte1[0] + +static int acount=0; + +DECLFW(Mapper21_write) +{ + A|=((A>>5)&0xF); + + if((A&0xF000)==0xA000) + ROM_BANK8(0xA000,V); + else if((A&0xF000)==0x8000) + { + if(K4sel&2) + ROM_BANK8(0xC000,V); + else + ROM_BANK8(0x8000,V); + } + else if(A>=0xb000 && A<=0xefff) + { + A&=0xF006; + { + int x=((A>>2)&1)|((A-0xB000)>>11); + + K4buf[x]&=(0xF0)>>((A&2)<<1); + K4buf[x]|=(V&0xF)<<((A&2)<<1); + VROM_BANK1(x<<10,K4buf[x]); + } + + } + else switch(A&0xF006) + { + case 0x9000: + switch(V&0x3) + { + case 0:MIRROR_SET(0);break; + case 1:MIRROR_SET(1);break; + case 2:onemir(0);break; + case 3:onemir(1);break; + } + break; + case 0x9006: + case 0x9004: + case 0x9002:if((K4sel&2)!=(V&2)) + { + uint8 swa; + swa=PRGBankList[0]; + ROM_BANK8(0x8000,PRGBankList[2]); + ROM_BANK8(0xc000,swa); + } + K4sel=V; + break; + case 0xf000:IRQLatch&=0xF0;IRQLatch|=V&0xF;break; + case 0xf002:IRQLatch&=0x0F;IRQLatch|=V<<4;break; + case 0xf004:IRQCount=IRQLatch;acount=0; + IRQa=V&2;K4IRQ=V&1; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xf006:IRQa=K4IRQ;X6502_IRQEnd(FCEU_IQEXT);break; + } +} +static void KonamiIRQHook(int a) +{ + #define LCYCS ((227*2)+1) + /*#define LCYCS 341*/ + if(IRQa) + { +/* acount+=a*3;*/ + acount+=a*4; + if(acount>=LCYCS) + { + doagainbub:acount-=LCYCS;IRQCount++; + if(IRQCount&0x100) {X6502_IRQBegin(FCEU_IQEXT);IRQCount=IRQLatch;} + if(acount>=LCYCS) goto doagainbub; + } + } +} + +void Mapper21_init(void) +{ + SetWriteHandler(0x8000,0xffff,Mapper21_write); + MapIRQHook=KonamiIRQHook; +} diff --git a/fceumm/src-fceumm/mappers/212.c b/fceumm/src-fceumm/mappers/212.c new file mode 100644 index 0000000..b069fc3 --- /dev/null +++ b/fceumm/src-fceumm/mappers/212.c @@ -0,0 +1,23 @@ +#include "mapinc.h" + +static DECLFW(Mapper212_write) +{ + if((A&0x4000)==0x4000) + { + ROM_BANK32((A&6)>>1); + } + else + { + ROM_BANK16(0x8000,A&7); + ROM_BANK16(0xc000,A&7); + } + VROM_BANK8(A&7); + MIRROR_SET((A>>3)&1); +} + +void Mapper212_init(void) +{ + ROM_BANK32(~0); + VROM_BANK8(~0); + SetWriteHandler(0x8000,0xFFFF,Mapper212_write); +} diff --git a/fceumm/src-fceumm/mappers/213.c b/fceumm/src-fceumm/mappers/213.c new file mode 100644 index 0000000..e0b8d82 --- /dev/null +++ b/fceumm/src-fceumm/mappers/213.c @@ -0,0 +1,14 @@ +#include "mapinc.h" + +static DECLFW(Mapper213_write) +{ + ROM_BANK32((A>>1)&3); + VROM_BANK8((A>>3)&7); +} + +void Mapper213_init(void) +{ + ROM_BANK32(0); + VROM_BANK8(0); + SetWriteHandler(0x8000,0xFFFF,Mapper213_write); +} diff --git a/fceumm/src-fceumm/mappers/214.c b/fceumm/src-fceumm/mappers/214.c new file mode 100644 index 0000000..c22d170 --- /dev/null +++ b/fceumm/src-fceumm/mappers/214.c @@ -0,0 +1,17 @@ +#include "mapinc.h" + +static DECLFW(Mapper214_write) +{ +/* FCEU_printf("%02x:%02x\n",A,V);*/ + ROM_BANK16(0x8000,(A>>2)&3); + ROM_BANK16(0xC000,(A>>2)&3); + VROM_BANK8(A&3); +} + +void Mapper214_init(void) +{ + ROM_BANK16(0x8000,0); + ROM_BANK16(0xC000,0); + VROM_BANK8(0); + SetWriteHandler(0x8000,0xFFFF,Mapper214_write); +} diff --git a/fceumm/src-fceumm/mappers/215.c b/fceumm/src-fceumm/mappers/215.c new file mode 100644 index 0000000..772691c --- /dev/null +++ b/fceumm/src-fceumm/mappers/215.c @@ -0,0 +1,96 @@ +/* +#include "mapinc.h" + +static uint8 cmdin; +static uint8 cmd; +static uint8 regs[8]; +static uint8 master,chrm; + +static void DoPRG215(void) +{ + if(master&0x80) + { + setprg16(0x8000,master&0x1F); + setprg16(0xc000,master&0x1F); + } + else + { + setprg8(0x8000,regs[4]); 6 + setprg8(0xA000,regs[6]); 7 0, 2, 5, 3, 6, 1, 7, 4 + setprg8(0xC000,~1); + setprg8(0xE000,~0); + } + +} + +static void DoCHR215(void) +{ + uint32 base=(cmd&0x80)<<5; + int orie=(chrm&0x4)<<6; + + setchr2(0x0000^base,(orie|regs[0])>>1); 0 + setchr2(0x0800^base,(orie|regs[5])>>1); 1 + + setchr1(0x1000,orie|regs[1]); 2 + setchr1(0x1400,orie|regs[3]); 3 + setchr1(0x1800,orie|regs[7]); 4 + setchr1(0x1c00,orie|regs[2]); 5 +} + +static DECLFW(Write215_write) +{ + switch(A&0xF001) + { + case 0xF001:IRQCount=V+2;break; + case 0xF000:X6502_IRQEnd(FCEU_IQEXT);break; + } + if(A==0x5000) + { + master=V; + DoPRG215(); +// DoCHR215(); + } + else if(A==0x5001) + { + chrm=V; + DoCHR215(); + } + else + switch(A&0xE001) + { + case 0xC000:setmirror(((V|(V>>7))&1)^1);break; + case 0xa000:cmd=V;cmdin=1;DoCHR215();break; + case 0x8001:if(!cmdin) break; + regs[cmd&7]=V; + DoPRG215(); + DoCHR215(); + cmdin=0; + break; + } +} + +static void hooko215(void) +{ + if(IRQCount) + { + IRQCount--; + if(!IRQCount) + { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +void Mapper215_init(void) +{ + int x; + for(x=0;x<8;x++) regs[x]=0; + master=chrm=cmd=cmdin=IRQCount=0; + GameHBIRQHook=hooko215; + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x5000,0xFFFF,Write215_write); + DoPRG215(); + DoCHR215(); +} + +*/ diff --git a/fceumm/src-fceumm/mappers/217.c b/fceumm/src-fceumm/mappers/217.c new file mode 100644 index 0000000..6f7a251 --- /dev/null +++ b/fceumm/src-fceumm/mappers/217.c @@ -0,0 +1,96 @@ +/* +#include "mapinc.h" + +static uint8 cmdin; +static uint8 cmd; +static uint8 regs[8]; +static uint8 master,chrm; + +static void DoPRG217(void) +{ + if(master&0x80) + { + setprg16(0x8000,master&0x1F); + setprg16(0xc000,master&0x1F); + } + else + { + setprg8(0x8000,regs[1]); + setprg8(0xA000,regs[3]); + setprg8(0xC000,~1); + setprg8(0xE000,~0); + } +} + +static void DoCHR217(void) +{ + uint32 base=(cmd&0x80)<<5; + int orie=(chrm&0x4)<<6; + + setchr2(0x0000^base,(orie|regs[0])>>1); + setchr2(0x0800^base,(orie|regs[7])>>1); + + setchr1(0x1000,orie|regs[5]); + setchr1(0x1400,orie|regs[2]); + setchr1(0x1800,orie|regs[6]); + setchr1(0x1c00,orie|regs[4]); +} + +static DECLFW(Write217_write) +{ +// if(A==0x5000) +// { +// master=V; +// DoPRG217(); +// } +// else if(A==0x5001) +// { +// chrm=V; +// DoCHR217(); +// } +// else if(A==0x5007) +// { +// } + + switch(A&0xE001) + { + case 0x4000:master=V;DoPRG217();break; + case 0x8000:IRQCount=V;break; + case 0xc001:break; + case 0xe000:X6502_IRQEnd(FCEU_IQEXT);break; + case 0xe001:break; + case 0xa001:setmirror((V&1)^1);break; + case 0x8001:cmd=V;cmdin=1;DoPRG217();DoCHR217();break; + case 0xa000:if(!cmdin) break; + regs[cmd&7]=V; + DoPRG217(); + DoCHR217(); + cmdin=0; + break; + } +} + +static void hooko217(void) +{ + if(IRQCount) + { + IRQCount--; + if(!IRQCount) + { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +void Mapper217_init(void) +{ + int x; + for(x=0;x<8;x++) regs[x]=0; + master=chrm=cmd=cmdin=IRQCount=0; + GameHBIRQHook=hooko217; + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x5000,0xFFFF,Write217_write); + DoPRG217(); + DoCHR217(); +} +*/ \ No newline at end of file diff --git a/fceumm/src-fceumm/mappers/22.c b/fceumm/src-fceumm/mappers/22.c new file mode 100644 index 0000000..9335106 --- /dev/null +++ b/fceumm/src-fceumm/mappers/22.c @@ -0,0 +1,64 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * (VRC4 mapper) + */ + +#include "mapinc.h" + +#define K4buf mapbyte2 + + + +DECLFW(Mapper22_write) +{ + if(A<=0xAFFF) + { + switch(A&0xF000) + { + case 0x8000:ROM_BANK8(0x8000,V);break; + case 0xa000:ROM_BANK8(0xA000,V);break; + case 0x9000:switch(V&3) + { + case 0x00:MIRROR_SET2(1);break; + case 0x01:MIRROR_SET2(0);break; + case 0x02:onemir(0);break; + case 0x03:onemir(1);break; + } + break; + } + } + else + { + A&=0xF003; + if(A>=0xb000 && A<=0xe003) + { + int x=(A&1)|((A-0xB000)>>11); + + K4buf[x]&=(0xF0)>>((A&2)<<1); + K4buf[x]|=(V&0xF)<<((A&2)<<1); + VROM_BANK1(x<<10,K4buf[x]>>1); + } + } +} + + +void Mapper22_init(void) +{ + SetWriteHandler(0x8000,0xffff,Mapper22_write); +} diff --git a/fceumm/src-fceumm/mappers/227.c b/fceumm/src-fceumm/mappers/227.c new file mode 100644 index 0000000..51c49e4 --- /dev/null +++ b/fceumm/src-fceumm/mappers/227.c @@ -0,0 +1,79 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +#define rg mapbyte1 + +static void DoSync(uint32 A) +{ + int32 p=((A>>3)&0xF) | ((A>>4)&0x10); + + rg[0]=A; + rg[1]=A>>8; + + MIRROR_SET((A>>1)&1); + if(A&1) /*32 KB*/ + { + ROM_BANK32(p); + } + else /*16 KB*/ + { + ROM_BANK16(0x8000,(p<<1)|((A&4)>>2)); + ROM_BANK16(0xc000,(p<<1)|((A&4)>>2)); + } + if(A&0x80) + { + PPUCHRRAM=0; + } + else + { + PPUCHRRAM=0xFF; + if(A&0x200) + ROM_BANK16(0xC000,(p<<1)|7); + else + ROM_BANK16(0xC000,(p<<1)&(~7)); + } +} + +static DECLFW(Mapper227_write) +{ + rg[A&1]=V; + DoSync(A); +} + +static void M227Reset(void) +{ + rg[0]=rg[1]=0; + DoSync(0); +} + +static void M227Restore(int version) +{ + DoSync(rg[0]|(rg[1]<<8)); +} + +void Mapper227_init(void) +{ + SetWriteHandler(0x6000,0xffff,Mapper227_write); + MapperReset=M227Reset; + GameStateRestore=M227Restore; + M227Reset(); +} diff --git a/fceumm/src-fceumm/mappers/228.c b/fceumm/src-fceumm/mappers/228.c new file mode 100644 index 0000000..bafa41b --- /dev/null +++ b/fceumm/src-fceumm/mappers/228.c @@ -0,0 +1,76 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +/*16 bits of ram in total*/ +/*only use bottom 4 bits as ram though*/ +static uint8 mapper228_ram[4]; + +static SFORMAT StateRegs[]= +{ + { mapper228_ram, 4, "MAPPER_RAM" }, + { 0 } +}; + +static DECLFR(Mapper228_read) +{ + return mapper228_ram[A & 3] & 0xF; +} + +static DECLFW(Mapper228_write) +{ + uint32 page,pagel,pageh; + + /*write to ram*/ + if (A < 0x6000) + { + mapper228_ram[A & 3] = V; + return; + } + MIRROR_SET((A>>13)&1); + page=(A>>7)&0x3F; + + if((page&0x30)==0x30) + page-=0x10; + + pagel=pageh=(page<<1) + (((A>>6)&1)&((A>>5)&1)); + pageh+=((A>>5)&1)^1; + + ROM_BANK16(0x8000,pagel); + ROM_BANK16(0xC000,pageh); + VROM_BANK8( (V&0x3) | ((A&0xF)<<2) ); +} + +static void A52Reset(void) +{ + Mapper228_write(0x8000, 0); +} + +void Mapper228_init(void) +{ + MapperReset=A52Reset; + A52Reset(); + SetWriteHandler(0x8000, 0xFFFF, Mapper228_write); + SetWriteHandler(0x4020, 0x5FFF, Mapper228_write); + SetReadHandler (0x4020, 0x5FFF, Mapper228_read); + AddExState(StateRegs, ~0, 0, 0); +} + diff --git a/fceumm/src-fceumm/mappers/229.c b/fceumm/src-fceumm/mappers/229.c new file mode 100644 index 0000000..a78dd73 --- /dev/null +++ b/fceumm/src-fceumm/mappers/229.c @@ -0,0 +1,48 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + + + +DECLFW(Mapper229_write) +{ +if(A>=0x8000) +{ +MIRROR_SET((A>>5)&1); +if(!(A&0x1e)) + { + ROM_BANK32(0); + } +else + { + ROM_BANK16(0x8000,A&0x1f); + ROM_BANK16(0xC000,A&0x1f); + } + VROM_BANK8(A); +} + +} + +void Mapper229_init(void) +{ + SetWriteHandler(0x8000,0xffff,Mapper229_write); +} + diff --git a/fceumm/src-fceumm/mappers/230.c b/fceumm/src-fceumm/mappers/230.c new file mode 100644 index 0000000..b71c8c5 --- /dev/null +++ b/fceumm/src-fceumm/mappers/230.c @@ -0,0 +1,62 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +#define rom_sw mapbyte1[0] + +void Mapper230_Reset(void) +{ + rom_sw ^= 1; /*1 - rom_sw;*/ + + if( rom_sw ) { + ROM_BANK16(0x8000,0); + ROM_BANK16(0xc000,7); + } else { + ROM_BANK16(0x8000,8); + ROM_BANK16(0xc000,39); + } + MIRROR_SET2(1); +} + +static DECLFW(Mapper230_write) +{ + if( rom_sw ) { + ROM_BANK16( 0x8000, V&0x07 ); + } else { + if( V & 0x20 ) { + ROM_BANK16( 0x8000, (V&0x1F)+8 ); + ROM_BANK16( 0xc000, (V&0x1F)+8 ); + } else { + ROM_BANK32( ((V&0x1E) >> 1) + 4 ); + } + MIRROR_SET2( ((V & 0x40) >> 6) ); + } +} + +void Mapper230_init(void) +{ + ROM_BANK16(0x8000,0); + ROM_BANK16(0xc000,7); + SetWriteHandler(0x8000, 0xffff, Mapper230_write); + MapperReset = Mapper230_Reset; + rom_sw = 1; +} + diff --git a/fceumm/src-fceumm/mappers/231.c b/fceumm/src-fceumm/mappers/231.c new file mode 100644 index 0000000..9b8d1fc --- /dev/null +++ b/fceumm/src-fceumm/mappers/231.c @@ -0,0 +1,41 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static DECLFW(Mapper231_write) +{ + if(A&0x20) + ROM_BANK32((A>>1)&0xF); + else + { + ROM_BANK16(0x8000,(A&0x1E)); + ROM_BANK16(0xc000,(A&0x1E)); + } + MIRROR_SET((A>>7)&1); +} + +void Mapper231_init(void) +{ + ROM_BANK16(0x8000,0); + ROM_BANK16(0xc000,0); + SetWriteHandler(0x8000,0xffff,Mapper231_write); +} + diff --git a/fceumm/src-fceumm/mappers/232.c b/fceumm/src-fceumm/mappers/232.c new file mode 100644 index 0000000..548db8c --- /dev/null +++ b/fceumm/src-fceumm/mappers/232.c @@ -0,0 +1,50 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static void DoIt(void) +{ + ROM_BANK16(0x8000,(mapbyte1[1]&3) | ((mapbyte1[0]&0x18)>>1)); + ROM_BANK16(0xc000,3|(((mapbyte1[0])&0x18)>>1)); +} + +DECLFW(Mapper232_write) +{ + if(A<=0x9FFF) + mapbyte1[0]=V; + else + mapbyte1[1]=V; + DoIt(); +} + +static void QuattroReset(void) +{ + mapbyte1[0]=0x18; + DoIt(); +} + +void Mapper232_init(void) +{ + SetWriteHandler(0x6000,0xffff,Mapper232_write); + MapperReset=QuattroReset; + QuattroReset(); +} + diff --git a/fceumm/src-fceumm/mappers/234.c b/fceumm/src-fceumm/mappers/234.c new file mode 100644 index 0000000..d8ca53f --- /dev/null +++ b/fceumm/src-fceumm/mappers/234.c @@ -0,0 +1,107 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +#define r1 mapbyte1[0] +#define r2 mapbyte1[1] + +static void DoBS(void) +{ + if(r1&0x40) + { + ROM_BANK32((r1&0xE)|(r2&1)); + VROM_BANK8( ((r1&0xE)<<2) | ((r2>>4)&7) ); + } + else + { + ROM_BANK32(r1&0xF); + VROM_BANK8( ((r1&0xF)<<2) | ((r2>>4)&3) ); + } +} + +static void R1Set(uint8 V) +{ + if(r1) return; + r1=V; + MIRROR_SET(V>>7); + DoBS(); +} + +static void R2Set(uint8 V) +{ + r2=V; + DoBS(); +} + +DECLFW(R1W) +{ + R1Set(V); +} + +DECLFR(R1R) +{ + uint8 r=CartBR(A); + R1Set(r); + return r; +} + +DECLFW(R2W) +{ + R2Set(V); +} + +DECLFR(R2R) +{ + uint8 r=CartBR(A); + R2Set(r); + return r; +} + +static void M15Restore(int version) +{ + DoBS(); + MIRROR_SET(r1>>7); +} + +static void M15Reset(void) +{ + r1=r2=0; + DoBS(); + MIRROR_SET(0); +} + +void Mapper234_init(void) +{ + SetWriteHandler(0xff80,0xff9f,R1W); + SetReadHandler(0xff80,0xff9f,R1R); + + SetWriteHandler(0xffe8,0xfff7,R2W); + SetReadHandler(0xffe8,0xfff7,R2R); + + SetReadHandler(0x6000,0x7FFF,0); + SetWriteHandler(0x6000,0x7FFF,0); + + M15Reset(); + + GameStateRestore=M15Restore; + MapperReset=M15Reset; +} + diff --git a/fceumm/src-fceumm/mappers/241.c b/fceumm/src-fceumm/mappers/241.c new file mode 100644 index 0000000..6ae49d3 --- /dev/null +++ b/fceumm/src-fceumm/mappers/241.c @@ -0,0 +1,27 @@ +#include "mapinc.h" + +static DECLFW(M241wr) +{ +/* FCEU_printf("Wr: $%04x:$%02x, $%04x\n",A,V,X.PC);*/ + if(A<0x8000) + { +/* printf("$%04x:$%02x, $%04x\n",A,V,X.PC);*/ + } + else + ROM_BANK32(V); +} + +static DECLFR(M241rd) +{ + /*DumpMem("out",0x8000,0xffff);*/ + /*printf("Rd: $%04x, $%04x\n",A,X.PC);*/ + return(0x50); +} + +void Mapper241_init(void) +{ + ROM_BANK32(0); + SetWriteHandler(0x5000,0x5fff,M241wr); + SetWriteHandler(0x8000,0xFFFF,M241wr); + SetReadHandler(0x4020,0x5fff,M241rd); +} diff --git a/fceumm/src-fceumm/mappers/242.c b/fceumm/src-fceumm/mappers/242.c new file mode 100644 index 0000000..2fa4171 --- /dev/null +++ b/fceumm/src-fceumm/mappers/242.c @@ -0,0 +1,41 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + + +DECLFW(Mapper242_write) +{ + ROM_BANK32((A>>3)&0xF); + switch(V&3) + { + case 0:MIRROR_SET(0);break; + case 1:MIRROR_SET(1);break; + case 2:onemir(0);break; + case 3:onemir(1);break; + } +} + +void Mapper242_init(void) +{ + ROM_BANK32(0); + SetWriteHandler(0x8000,0xffff,Mapper242_write); +} + diff --git a/fceumm/src-fceumm/mappers/244.c b/fceumm/src-fceumm/mappers/244.c new file mode 100644 index 0000000..889f13b --- /dev/null +++ b/fceumm/src-fceumm/mappers/244.c @@ -0,0 +1,53 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 prg_perm[4][4] = { + {0, 1, 2, 3,}, + {3, 2, 1, 0,}, + {0, 2, 1, 3,}, + {3, 1, 2, 0,}, +}; + +static uint8 chr_perm[8][8] = { + {0, 1, 2, 3, 4, 5, 6, 7,}, + {0, 2, 1, 3, 4, 6, 5, 7,}, + {0, 1, 4, 5, 2, 3, 6, 7,}, + {0, 4, 1, 5, 2, 6, 3, 7,}, + {0, 4, 2, 6, 1, 5, 3, 7,}, + {0, 2, 4, 6, 1, 3, 5, 7,}, + {7, 6, 5, 4, 3, 2, 1, 0,}, + {7, 6, 5, 4, 3, 2, 1, 0,}, +}; + +static DECLFW(Mapper244_write) +{ + if(V&8) + VROM_BANK8(chr_perm[(V>>4)&7][V&7]); + else + ROM_BANK32(prg_perm[(V>>4)&3][V&3]); +} + +void Mapper244_init(void) +{ + ROM_BANK32(0); + SetWriteHandler(0x8000,0xffff,Mapper244_write); +} diff --git a/fceumm/src-fceumm/mappers/246.c b/fceumm/src-fceumm/mappers/246.c new file mode 100644 index 0000000..8623233 --- /dev/null +++ b/fceumm/src-fceumm/mappers/246.c @@ -0,0 +1,44 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + + +DECLFW(Mapper246_write) +{ + switch(A&0xF007) + { + case 0x6000:ROM_BANK8(0x8000,V);break; + case 0x6001:ROM_BANK8(0xA000,V);break; + case 0x6002:ROM_BANK8(0xC000,V);break; + case 0x6003:ROM_BANK8(0xE000,V);break; + case 0x6004:VROM_BANK2(0x0000,V);break; + case 0x6005:VROM_BANK2(0x0800,V);break; + case 0x6006:VROM_BANK2(0x1000,V);break; + case 0x6007:VROM_BANK2(0x1800,V);break; + } +} + +void Mapper246_init(void) +{ + SetWriteHandler(0x4020,0x67ff,Mapper246_write); + SetWriteHandler(0x8000,0xffff,Mapper246_write); +} + diff --git a/fceumm/src-fceumm/mappers/24and26.c b/fceumm/src-fceumm/mappers/24and26.c new file mode 100644 index 0000000..2eb425d --- /dev/null +++ b/fceumm/src-fceumm/mappers/24and26.c @@ -0,0 +1,366 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static void (*sfun[3])(void); + +#define vrctemp mapbyte1[0] +#define VPSG2 mapbyte3 +#define VPSG mapbyte2 + +static void DoSQV1(void); +static void DoSQV2(void); +static void DoSawV(void); + +static int swaparoo; + +static int acount=0; + +static void KonamiIRQHook(int a) +{ + #define LCYCS 341 +/* #define LCYCS ((227*2)+1)*/ + if(IRQa) + { + acount+=a*3; + if(acount>=LCYCS) + { + doagainbub:acount-=LCYCS;IRQCount++; + if(IRQCount==0x100) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount=IRQLatch; + } + if(acount>=LCYCS) goto doagainbub; + } + } +} + +static DECLFW(VRC6SW) +{ + A&=0xF003; + if(A>=0x9000 && A<=0x9002) + { + VPSG[A&3]=V; + if(sfun[0]) sfun[0](); + } + else if(A>=0xa000 && A<=0xa002) + { + VPSG[4|(A&3)]=V; + if(sfun[1]) sfun[1](); + } + else if(A>=0xb000 && A<=0xb002) + { + VPSG2[A&3]=V; + if(sfun[2]) sfun[2](); + } + +} + +static DECLFW(Mapper24_write) +{ + if(swaparoo) + A=(A&0xFFFC)|((A>>1)&1)|((A<<1)&2); + if(A>=0x9000 && A<=0xb002) + { + VRC6SW(A,V); + return; + } + A&=0xF003; +/* if(A>=0xF000) printf("%d, %d, $%04x:$%02x\n",scanline,timestamp,A,V);*/ + switch(A&0xF003) + { + case 0x8000:ROM_BANK16(0x8000,V);break; + case 0xB003: + switch(V&0xF) + { + case 0x0:MIRROR_SET2(1);break; + case 0x4:MIRROR_SET2(0);break; + case 0x8:onemir(0);break; + case 0xC:onemir(1);break; + } + break; + case 0xC000:ROM_BANK8(0xC000,V);break; + case 0xD000:VROM_BANK1(0x0000,V);break; + case 0xD001:VROM_BANK1(0x0400,V);break; + case 0xD002:VROM_BANK1(0x0800,V);break; + case 0xD003:VROM_BANK1(0x0c00,V);break; + case 0xE000:VROM_BANK1(0x1000,V);break; + case 0xE001:VROM_BANK1(0x1400,V);break; + case 0xE002:VROM_BANK1(0x1800,V);break; + case 0xE003:VROM_BANK1(0x1c00,V);break; + case 0xF000:IRQLatch=V; + /*acount=0;*/ + break; + case 0xF001:IRQa=V&2; + vrctemp=V&1; + if(V&2) + { + IRQCount=IRQLatch; + acount=0; + } + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xf002:IRQa=vrctemp; + X6502_IRQEnd(FCEU_IQEXT);break; + case 0xF003:break; + } +} + +static int32 CVBC[3]; +static int32 vcount[3]; +static int32 dcount[2]; + +static INLINE void DoSQV(int x) +{ + int32 V; + int32 amp=(((VPSG[x<<2]&15)<<8)*6/8)>>4; + int32 start,end; + + start=CVBC[x]; + end=(SOUNDTS<<16)/soundtsinc; + if(end<=start) return; + CVBC[x]=end; + + if(VPSG[(x<<2)|0x2]&0x80) + { + if(VPSG[x<<2]&0x80) + { + for(V=start;V>4]+=amp; + } + else + { + int32 thresh=(VPSG[x<<2]>>4)&7; + int32 freq=((VPSG[(x<<2)|0x1]|((VPSG[(x<<2)|0x2]&15)<<8))+1)<<17; + for(V=start;Vthresh) /* Greater than, not >=. Important. */ + Wave[V>>4]+=amp; + vcount[x]-=nesincsize; + while(vcount[x]<=0) /* Should only be <0 in a few circumstances. */ + { + vcount[x]+=freq; + dcount[x]=(dcount[x]+1)&15; + } + } + } + } +} + +static void DoSQV1(void) +{ + DoSQV(0); +} + +static void DoSQV2(void) +{ + DoSQV(1); +} + +static void DoSawV(void) +{ + int V; + int32 start,end; + + start=CVBC[2]; + end=(SOUNDTS<<16)/soundtsinc; + if(end<=start) return; + CVBC[2]=end; + + if(VPSG2[2]&0x80) + { + static int32 saw1phaseacc=0; + uint32 freq3; + static uint8 b3=0; + static int32 phaseacc=0; + static uint32 duff=0; + + freq3=(VPSG2[1]+((VPSG2[2]&15)<<8)+1); + + for(V=start;V>3)&0x1f)<<4)*6/8; + } + Wave[V>>4]+=duff; + } + } +} + +static INLINE void DoSQVHQ(int x) +{ + int32 V; + int32 amp=((VPSG[x<<2]&15)<<8)*6/8; + + if(VPSG[(x<<2)|0x2]&0x80) + { + if(VPSG[x<<2]&0x80) + { + for(V=CVBC[x];V>4)&7; + for(V=CVBC[x];Vthresh) /* Greater than, not >=. Important. */ + WaveHi[V]+=amp; + vcount[x]--; + if(vcount[x]<=0) /* Should only be <0 in a few circumstances. */ + { + vcount[x]=(VPSG[(x<<2)|0x1]|((VPSG[(x<<2)|0x2]&15)<<8))+1; + dcount[x]=(dcount[x]+1)&15; + } + } + } + } + CVBC[x]=SOUNDTS; +} + +static void DoSQV1HQ(void) +{ + DoSQVHQ(0); +} + +static void DoSQV2HQ(void) +{ + DoSQVHQ(1); +} + +static void DoSawVHQ(void) +{ + static uint8 b3=0; + static int32 phaseacc=0; + int32 V; + + if(VPSG2[2]&0x80) + { + for(V=CVBC[2];V>3)&0x1f)<<8)*6/8; + vcount[2]--; + if(vcount[2]<=0) + { + vcount[2]=(VPSG2[1]+((VPSG2[2]&15)<<8)+1)<<1; + phaseacc+=VPSG2[0]&0x3f; + b3++; + if(b3==7) + { + b3=0; + phaseacc=0; + } + + } + } + } + CVBC[2]=SOUNDTS; +} + + +void VRC6Sound(int Count) +{ + int x; + + DoSQV1(); + DoSQV2(); + DoSawV(); + for(x=0;x<3;x++) + CVBC[x]=Count; +} + +void VRC6SoundHQ(void) +{ + DoSQV1HQ(); + DoSQV2HQ(); + DoSawVHQ(); +} + +void VRC6SyncHQ(int32 ts) +{ + int x; + for(x=0;x<3;x++) CVBC[x]=ts; +} + +static void VRC6_ESI(void) +{ + GameExpSound.RChange=VRC6_ESI; + GameExpSound.Fill=VRC6Sound; + GameExpSound.HiFill=VRC6SoundHQ; + GameExpSound.HiSync=VRC6SyncHQ; + + memset(CVBC,0,sizeof(CVBC)); + memset(vcount,0,sizeof(vcount)); + memset(dcount,0,sizeof(dcount)); + if(FSettings.SndRate) + { +#if SOUND_QUALITY == 1 + sfun[0]=DoSQV1HQ; + sfun[1]=DoSQV2HQ; + sfun[2]=DoSawVHQ; +#else + sfun[0]=DoSQV1; + sfun[1]=DoSQV2; + sfun[2]=DoSawV; +#endif + } + else + memset(sfun,0,sizeof(sfun)); +} + +void Mapper24_init(void) +{ + SetWriteHandler(0x8000,0xffff,Mapper24_write); + VRC6_ESI(); + MapIRQHook=KonamiIRQHook; + swaparoo=0; +} + +void Mapper26_init(void) +{ + SetWriteHandler(0x8000,0xffff,Mapper24_write); + VRC6_ESI(); + MapIRQHook=KonamiIRQHook; + swaparoo=1; +} + +void NSFVRC6_Init(void) +{ + VRC6_ESI(); + SetWriteHandler(0x8000,0xbfff,VRC6SW); +} diff --git a/fceumm/src-fceumm/mappers/25.c b/fceumm/src-fceumm/mappers/25.c new file mode 100644 index 0000000..784f4b8 --- /dev/null +++ b/fceumm/src-fceumm/mappers/25.c @@ -0,0 +1,115 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * (VRC4 mapper) + */ + +#include "mapinc.h" + +#define K4buf mapbyte2 +#define K4IRQ mapbyte1[1] +#define K4sel mapbyte1[0] + +static int acount=0; +static int weirdo=0; +static DECLFW(Mapper25_write) +{ + if(A==0xC007) + { + weirdo=8; /* Ganbare Goemon Gaiden does strange things!!! at the end credits*/ + /* quick dirty hack, seems there is no other games with such PCB, so*/ + /* we never know if it will not work for something else lol*/ + VROM_BANK1(0x0000,0xFC); + VROM_BANK1(0x0400,0xFD); + VROM_BANK1(0x0800,0xFF); + } + + A=(A&0xF003)|((A&0xC)>>2); + + if((A&0xF000)==0xA000) + ROM_BANK8(0xA000,V); + else if(A>=0xB000 && A<=0xEFFF) + { + int x=(A&1)|((A-0xB000)>>11); + + K4buf[x]&=(0xF0)>>((A&2)<<1); + K4buf[x]|=(V&0xF)<<((A&2)<<1); + if(weirdo) + weirdo--; + else + VROM_BANK1(x<<10,K4buf[x]); + } + else if((A&0xF000)==0x8000) + { + if(K4sel&2) + ROM_BANK8(0xC000,V); + else + ROM_BANK8(0x8000,V); + } + else switch(A) + { + case 0x9000:switch(V&0x3) + { + case 0:MIRROR_SET(0);break; + case 1:MIRROR_SET(1);break; + case 2:onemir(0);break; + case 3:onemir(1);break; + } + break; + case 0x9001:if((K4sel&2)!=(V&2)) + { + uint8 swa; + swa=PRGBankList[0]; + ROM_BANK8(0x8000,PRGBankList[2]); + ROM_BANK8(0xc000,swa); + } + K4sel=V; + break; + case 0xf000:IRQLatch&=0xF0;IRQLatch|=V&0xF;break; + case 0xf002:IRQLatch&=0x0F;IRQLatch|=V<<4;break; + case 0xf001:IRQCount=IRQLatch;IRQa=V&2;K4IRQ=V&1;acount=0;X6502_IRQEnd(FCEU_IQEXT);break; + case 0xf003:IRQa=K4IRQ;X6502_IRQEnd(FCEU_IQEXT);break; + } +} + +static void KonamiIRQHook(int a) +{ + /* #define LCYCS ((227*2))*/ +#define LCYCS 341 + if(IRQa) + { + acount+=a*3; + /* acount+=a*4;*/ + if(acount>=LCYCS) + { +doagainbub:acount-=LCYCS;IRQCount++; + if(IRQCount&0x100) + {/*acount=0;*/ + X6502_IRQBegin(FCEU_IQEXT);IRQCount=IRQLatch; + } + if(acount>=LCYCS) goto doagainbub; + } + } +} + +void Mapper25_init(void) +{ + SetWriteHandler(0x8000,0xffff,Mapper25_write); + MapIRQHook=KonamiIRQHook; +} + diff --git a/fceumm/src-fceumm/mappers/255.c b/fceumm/src-fceumm/mappers/255.c new file mode 100644 index 0000000..90cf887 --- /dev/null +++ b/fceumm/src-fceumm/mappers/255.c @@ -0,0 +1,67 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + + + +static DECLFW(Mapper255_write) +{ + uint32 pbank=(A>>7)&0x1F; + uint32 cbank=A&0x3F; + uint32 rbank=(A>>14)&1; + +/* printf("$%04x:$%02x\n",A,V);*/ +/* printf("%2x:%2x:%2x,%2x\n",pbank,cbank,rbank,(A&0x40)>>6);*/ + + if(A&0x1000) + { + ROM_BANK16(0x8000,((pbank|(rbank<<5))<<1)|((A&0x40)>>6)); + ROM_BANK16(0xc000,((pbank|(rbank<<5))<<1)|((A&0x40)>>6)); + } + else + { + ROM_BANK32(pbank|(rbank<<5)); + } + MIRROR_SET((A>>13)&1); + VROM_BANK8((rbank<<6)|cbank); +} + +static DECLFW(Mapper255_wl) +{ +/* printf("Wr: $%04x:$%02x\n",A,V);*/ + mapbyte1[A&3]=V&0xF; +} + +static DECLFR(Mapper255_read) +{ + /*printf("Rd: $%04x\n",A);*/ + return(mapbyte1[A&3]); /*|(X.DB&0xF0));*/ +} + +void Mapper255_init(void) +{ + mapbyte1[0]=mapbyte1[1]=0xF; + ROM_BANK32(0); + VROM_BANK8(0); + SetWriteHandler(0x5800,0x5FF0,Mapper255_wl); + SetWriteHandler(0x8000,0xffff,Mapper255_write); + SetReadHandler(0x5800,0x5FFF,Mapper255_read); +} diff --git a/fceumm/src-fceumm/mappers/27.c b/fceumm/src-fceumm/mappers/27.c new file mode 100644 index 0000000..13ae78a --- /dev/null +++ b/fceumm/src-fceumm/mappers/27.c @@ -0,0 +1,69 @@ +#include "mapinc.h" + +static uint32 regchr[9]; + +static DECLFW(Mapper27_write) +{ + int regnum; + A&=0xF00F; + if((A>=0xB000) && (A<=0xE003)) { + regnum=((((A>>12)+1)&0x03)<<1)|((A&0x02)>>1); + if(A&1) + regchr[regnum]=(regchr[regnum]&0x00F)|(V<<4); + else + regchr[regnum]=(regchr[regnum]&0x1F0)|(V&0xF); + VROM_BANK1(regnum<<10,regchr[regnum]); + } + switch(A) + { + case 0x8000: ROM_BANK8(0x8000|((regchr[8]&2)<<13),V); break; + case 0xA000: ROM_BANK8(0xa000,V); break; + case 0x9000: switch(V&3){ + case 0:setmirror(MI_V);break; + case 1:setmirror(MI_H);break; + case 2:setmirror(MI_0);break; + case 3:setmirror(MI_1);break; + } + case 0x9002: regchr[8]=V; break; + case 0xF000: /*X6502_IRQEnd(FCEU_IQEXT);*/ + IRQLatch=(IRQLatch&0xF0)|(V&0x0F); + break; + case 0xF001: /*X6502_IRQEnd(FCEU_IQEXT);*/ + IRQLatch=(IRQLatch&0x0F)|((V&0xF)<<4); + break; + case 0xF003: IRQa=((IRQa&0x1)<<1)|(IRQa&0x1); + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xF002: IRQa=V&3; + if(IRQa&0x02) IRQCount=IRQLatch-1; +/* X6502_IRQEnd(FCEU_IQEXT);*/ + break; + } +/* if((A&0xF000)==0xF000) FCEU_printf("$%04x:$%02x, %d\n",A,V, scanline);*/ +} + +static void Mapper27_hb(void) +{ +/* FCEU_printf("%02x-%d,%d,%d\n",scanline,IRQa,IRQCount,IRQLatch);*/ + if(IRQa&0x2){ + if(IRQCount==0xFF){ + X6502_IRQBegin(FCEU_IQEXT); + IRQCount=IRQLatch+1; + } else { + IRQCount++; + } + } +} + +void Mapper27_init(void) +{ + int i; + for (i=0; i<9; i++) { + regchr[i]=0; + } + IRQa=0; + IRQCount=IRQLatch=0; + SetWriteHandler(0x8000,0xffff,Mapper27_write); + GameHBIRQHook=Mapper27_hb; +} + diff --git a/fceumm/src-fceumm/mappers/32.c b/fceumm/src-fceumm/mappers/32.c new file mode 100644 index 0000000..13e4bba --- /dev/null +++ b/fceumm/src-fceumm/mappers/32.c @@ -0,0 +1,53 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + + +#define IREMCon mapbyte1[0] + +static DECLFW(Mapper32_write) +{ + switch(A>>12) + { + case 0x8: + mapbyte1[1]=V; + if(IREMCon) {ROM_BANK8(0xc000,V);ROM_BANK8(0x8000,~1);} + else {ROM_BANK8(0x8000,V);ROM_BANK8(0xc000,~1);} + break; + case 0x9:IREMCon=(V>>1)&1; + if(IREMCon) {ROM_BANK8(0xc000,mapbyte1[1]);ROM_BANK8(0x8000,~1);} + else {ROM_BANK8(0x8000,mapbyte1[1]); ROM_BANK8(0xc000,~1);} + MIRROR_SET(V&1); + break; + case 0xa:ROM_BANK8(0xA000,V); + break; + } + + if((A&0xF000)==0xb000) + VROM_BANK1((A&0x7)<<10,V); +} + +void Mapper32_init(void) +{ + ROM_BANK16(0x8000,0); + ROM_BANK16(0xc000,~0); + SetWriteHandler(0x8000,0xffff,Mapper32_write); +} diff --git a/fceumm/src-fceumm/mappers/33.c b/fceumm/src-fceumm/mappers/33.c new file mode 100644 index 0000000..429fee8 --- /dev/null +++ b/fceumm/src-fceumm/mappers/33.c @@ -0,0 +1,81 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static int is48; + +static DECLFW(Mapper33_write) +{ + /*printf("%04x:%02x, %d\n",A,V,scanline);*/ + + A&=0xF003; + if(A>=0xA000 && A<=0xA003) + VROM_BANK1(0x1000+((A&3)<<10),V); + else switch(A) + { + case 0x8000:if(!is48) MIRROR_SET((V>>6)&1); + ROM_BANK8(0x8000,V); + break; + case 0x8001:ROM_BANK8(0xA000,V); break; + case 0x8002:VROM_BANK2(0x0000,V);break; + case 0x8003:VROM_BANK2(0x0800,V);break; + case 0xe000:MIRROR_SET((V>>6)&1);break; + } +} + +static DECLFW(Mapper48_HiWrite) +{ + switch(A&0xF003) + { + case 0xc000:IRQLatch=V;break; + case 0xc001:IRQCount=IRQLatch;break; + case 0xc003:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break; + case 0xc002:IRQa=1;break; + case 0xe000:MIRROR_SET((V>>6)&1);break; + } +} + +static void heho(void) +{ + if(IRQa) + { + IRQCount++; + if(IRQCount==0x100) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + } + } +} + +void Mapper33_init(void) +{ + SetWriteHandler(0x8000,0xffff,Mapper33_write); + is48=0; +} + +void Mapper48_init(void) +{ + SetWriteHandler(0x8000,0xbfff,Mapper33_write); + SetWriteHandler(0xc000,0xffff,Mapper48_HiWrite); + GameHBIRQHook=heho; + is48=1; +} diff --git a/fceumm/src-fceumm/mappers/40.c b/fceumm/src-fceumm/mappers/40.c new file mode 100644 index 0000000..df6de99 --- /dev/null +++ b/fceumm/src-fceumm/mappers/40.c @@ -0,0 +1,61 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * + */ + +#include "mapinc.h" + + +static DECLFW(Mapper40_write) +{ + switch(A&0xe000) + { + case 0x8000:IRQa=0;IRQCount=0;X6502_IRQEnd(FCEU_IQEXT);break; + case 0xa000:IRQa=1;break; + case 0xe000:ROM_BANK8(0xc000,V&7);break; + } +} + +static void Mapper40IRQ(int a) +{ + if(IRQa) + { + if(IRQCount<4096) + IRQCount+=a; + else + { + IRQa=0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +void Mapper40_init(void) +{ + ROM_BANK8(0x6000,(~0)-1); + ROM_BANK8(0x8000,(~0)-3); + ROM_BANK8(0xa000,(~0)-2); + SetWriteHandler(0x8000,0xffff,Mapper40_write); + SetReadHandler(0x6000,0x7fff,CartBR); + MapIRQHook=Mapper40IRQ; +} + + diff --git a/fceumm/src-fceumm/mappers/41.c b/fceumm/src-fceumm/mappers/41.c new file mode 100644 index 0000000..dfb6908 --- /dev/null +++ b/fceumm/src-fceumm/mappers/41.c @@ -0,0 +1,57 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + + +#define calreg mapbyte1[0] +#define calchr mapbyte1[1] + +DECLFW(Mapper41_write) +{ + if(A<0x8000) + { + ROM_BANK32(A&7); + MIRROR_SET((A>>5)&1); + calreg=A; + calchr&=0x3; + calchr|=(A>>1)&0xC; + VROM_BANK8(calchr); + } + else if(calreg&0x4) + { + calchr&=0xC; + calchr|=A&3; + VROM_BANK8(calchr); + } +} + +static void M41Reset(void) +{ + calreg=calchr=0; +} + +void Mapper41_init(void) +{ + MapperReset=M41Reset; + ROM_BANK32(0); + SetWriteHandler(0x8000,0xffff,Mapper41_write); + SetWriteHandler(0x6000,0x67ff,Mapper41_write); +} diff --git a/fceumm/src-fceumm/mappers/42.c b/fceumm/src-fceumm/mappers/42.c new file mode 100644 index 0000000..49bbc09 --- /dev/null +++ b/fceumm/src-fceumm/mappers/42.c @@ -0,0 +1,71 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * + */ + +#include "mapinc.h" + + +static DECLFW(Mapper42_write) +{ +/* FCEU_printf("%04x:%04x\n",A,V);*/ + switch(A&0xe003) + { + case 0x8000:VROM_BANK8(V);break; + case 0xe000:mapbyte1[0]=V;ROM_BANK8(0x6000,V&0xF);break; + case 0xe001:MIRROR_SET((V>>3)&1);break; + case 0xe002:IRQa=V&2;if(!IRQa) IRQCount=0;X6502_IRQEnd(FCEU_IQEXT);break; + } +} + +static void Mapper42IRQ(int a) +{ + if(IRQa) + { + IRQCount+=a; + if(IRQCount>=32768) IRQCount-=32768; + if(IRQCount>=24576) + { + X6502_IRQBegin(FCEU_IQEXT); + } + else + { + X6502_IRQEnd(FCEU_IQEXT); + } + } +} + +static void Mapper42_StateRestore(int version) +{ + ROM_BANK8(0x6000,mapbyte1[0]&0xF); +} + + +void Mapper42_init(void) +{ + ROM_BANK8(0x6000,0); + ROM_BANK32(~0); + SetWriteHandler(0x6000,0xffff,Mapper42_write); + SetReadHandler(0x6000,0x7fff,CartBR); + MapStateRestore=Mapper42_StateRestore; + MapIRQHook=Mapper42IRQ; +} + diff --git a/fceumm/src-fceumm/mappers/46.c b/fceumm/src-fceumm/mappers/46.c new file mode 100644 index 0000000..8c4ef6d --- /dev/null +++ b/fceumm/src-fceumm/mappers/46.c @@ -0,0 +1,48 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + + + +#define A64reg mapbyte1[0] +#define A64wr mapbyte1[1] + +DECLFW(Mapper46_writel) +{ + A64reg=V; + ROM_BANK32((A64wr&1)+((A64reg&0xF)<<1)); + VROM_BANK8(((A64wr>>4)&7)+((A64reg&0xF0)>>1)); +} + +DECLFW(Mapper46_write) +{ + A64wr=V; + ROM_BANK32((V&1)+((A64reg&0xF)<<1)); + VROM_BANK8(((V>>4)&7)+((A64reg&0xF0)>>1)); +} + +void Mapper46_init(void) +{ + MIRROR_SET(0); + ROM_BANK32(0); + SetWriteHandler(0x8000,0xffff,Mapper46_write); + SetWriteHandler(0x6000,0x7fff,Mapper46_writel); +} diff --git a/fceumm/src-fceumm/mappers/50.c b/fceumm/src-fceumm/mappers/50.c new file mode 100644 index 0000000..a8ea424 --- /dev/null +++ b/fceumm/src-fceumm/mappers/50.c @@ -0,0 +1,78 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * + */ + +#include "mapinc.h" + + +static void Mapper50IRQ(int a) +{ + if(IRQa) + { + if(IRQCount<4096) + IRQCount+=a; + else + { + IRQa=0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void M50Restore(int version) +{ + setprg8(0xc000,mapbyte1[0]); +} + +static DECLFW(M50W) +{ + if((A&0xD060)==0x4020) + { + if(A&0x100) + { + IRQa=V&1; + if(!IRQa) IRQCount=0; + X6502_IRQEnd(FCEU_IQEXT); + } + else + { + V=((V&1)<<2)|((V&2)>>1)|((V&4)>>1)|(V&8); + mapbyte1[0]=V; + setprg8(0xc000,V); + } + } +} + +void Mapper50_init(void) +{ + SetWriteHandler(0x4020,0x5fff,M50W); + SetReadHandler(0x6000,0xffff,CartBR); + MapStateRestore=M50Restore; + MapIRQHook=Mapper50IRQ; + + setprg8(0x6000,0xF); + setprg8(0x8000,0x8); + setprg8(0xa000,0x9); + setprg8(0xc000,0x0); + setprg8(0xe000,0xB); +} + diff --git a/fceumm/src-fceumm/mappers/51.c b/fceumm/src-fceumm/mappers/51.c new file mode 100644 index 0000000..cc1fbbd --- /dev/null +++ b/fceumm/src-fceumm/mappers/51.c @@ -0,0 +1,66 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +#define mode mapbyte1[0] +#define page mapbyte1[1] + +static uint32 Get8K(uint32 A) +{ + uint32 bank; + + bank=(page<<2)|((A>>13)&1); + + if(A&0x4000 && !(mode&1)) bank|=0xC; + if(!(A&0x8000)) bank|=0x20; + if(mode==2) bank|=2; + else bank|=(A>>13)&2; + return(bank); +} + +static void Synco(void) +{ + uint32 x; + if(mapbyte1[0]<=2) + MIRROR_SET2(1); + else + MIRROR_SET2(0); + for(x=0x6000;x<0x10000;x+=8192) + ROM_BANK8(x,Get8K(x)); +} + +static DECLFW(Write) +{ + if(A&0x8000) mapbyte1[1]=V&0xF; + else mapbyte1[0]=(mapbyte1[0]&2)|((V>>1)&1); + + if(A&0x4000) mapbyte1[0]=(mapbyte1[0]&1)|((V>>3)&2); + Synco(); +} + +void Mapper51_init(void) +{ + SetWriteHandler(0x6000,0xFFFF,Write); + SetReadHandler(0x6000,0xFFFF,CartBR); + mapbyte1[0]=1; + mapbyte1[1]=0; + Synco(); +} diff --git a/fceumm/src-fceumm/mappers/59.c b/fceumm/src-fceumm/mappers/59.c new file mode 100644 index 0000000..0887dfa --- /dev/null +++ b/fceumm/src-fceumm/mappers/59.c @@ -0,0 +1,47 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static int ay; +static DECLFW(Mapper59_write) +{ + /*printf("$%04x:$%02x\n",A,V);*/ + setprg32(0x8000,(A&0x70)>>4); + setchr8(A&0x7); + /*if(A&0x100)*/ + /* setprg32r(0x10,0x8000,0);*/ + ay=A; + MIRROR_SET2((A&0x8)>>3); +} + +static DECLFR(m59rd) +{ + if(ay&0x100) return(0); + else + return(CartBR(A)); +} + +void Mapper59_init(void) +{ + setprg32(0x8000,0); + SetReadHandler(0x8000,0xffff,m59rd); + SetWriteHandler(0x8000,0xffff,Mapper59_write); +} diff --git a/fceumm/src-fceumm/mappers/6.c b/fceumm/src-fceumm/mappers/6.c new file mode 100644 index 0000000..2fa44ec --- /dev/null +++ b/fceumm/src-fceumm/mappers/6.c @@ -0,0 +1,80 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 FFEmode; + +#define FVRAM_BANK8(A,V) {VPage[0]=VPage[1]=VPage[2]=VPage[3]=VPage[4]=VPage[5]=VPage[6]=VPage[7]=V?&MapperExRAM[(V)<<13]-(A):&CHRRAM[(V)<<13]-(A);CHRBankList[0]=((V)<<3);CHRBankList[1]=((V)<<3)+1;CHRBankList[2]=((V)<<3)+2;CHRBankList[3]=((V)<<3)+3;CHRBankList[4]=((V)<<3)+4;CHRBankList[5]=((V)<<3)+5;CHRBankList[6]=((V)<<3)+6;CHRBankList[7]=((V)<<3)+7;PPUCHRRAM=0xFF;} + +static void FFEIRQHook(int a) +{ + if(IRQa) + { + IRQCount+=a; + if(IRQCount>=0x10000) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + IRQCount=0; + } + } +} + +DECLFW(Mapper6_write) +{ + if(A<0x8000) + { + switch(A){ + case 0x42FF:MIRROR_SET((V>>4)&1);break; + case 0x42FE:onemir((V>>3)&2); FFEmode=V&0x80;break; + case 0x4501:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break; + case 0x4502:IRQCount&=0xFF00;IRQCount|=V;break; + case 0x4503:IRQCount&=0xFF;IRQCount|=V<<8;IRQa=1;break; + } + } else { + switch (FFEmode) + { + case 0x80: setchr8(V); break; + default: ROM_BANK16(0x8000,V>>2); + FVRAM_BANK8(0x0000,V&3); + } + } +} +void Mapper6_StateRestore(int version) +{ + int x; + for(x=0;x<8;x++) + if(PPUCHRRAM&(1<7) + VPage[x]=&MapperExRAM[(CHRBankList[x]&31)*0x400]-(x*0x400); + else VPage[x]=&CHRRAM[(CHRBankList[x]&7)*0x400]-(x*0x400); + } +} +void Mapper6_init(void) +{ +MapIRQHook=FFEIRQHook; +ROM_BANK16(0xc000,7); + +SetWriteHandler(0x4020,0x5fff,Mapper6_write); +SetWriteHandler(0x8000,0xffff,Mapper6_write); +MapStateRestore=Mapper6_StateRestore; +} diff --git a/fceumm/src-fceumm/mappers/61.c b/fceumm/src-fceumm/mappers/61.c new file mode 100644 index 0000000..54e68ba --- /dev/null +++ b/fceumm/src-fceumm/mappers/61.c @@ -0,0 +1,54 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + + +static DECLFW(Mapper61_write) +{ +/* printf("$%04x:$%02x\n",A,V);*/ + switch(A&0x30) + { + case 0x00: + case 0x30: + ROM_BANK32(A&0xF); + break; + case 0x20: + case 0x10: + ROM_BANK16(0x8000,((A&0xF)<<1)| (((A&0x20)>>4)) ); + ROM_BANK16(0xC000,((A&0xF)<<1)| (((A&0x20)>>4)) ); + break; + } + #ifdef moo + if(!(A&0x10)) + ROM_BANK32(A&0xF); + else + { + ROM_BANK16(0x8000,((A&0xF)<<1)| (((A&0x10)>>4)^1) ); + ROM_BANK16(0xC000,((A&0xF)<<1)| (((A&0x10)>>4)^1) ); + } + #endif + MIRROR_SET((A&0x80)>>7); +} + +void Mapper61_init(void) +{ + SetWriteHandler(0x8000,0xffff,Mapper61_write); +} diff --git a/fceumm/src-fceumm/mappers/62.c b/fceumm/src-fceumm/mappers/62.c new file mode 100644 index 0000000..4d03c88 --- /dev/null +++ b/fceumm/src-fceumm/mappers/62.c @@ -0,0 +1,41 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 CaH4e3 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static DECLFW(Mapper62_write) +{ + VROM_BANK8(((A&0x1F)<<2)|(V&0x03)); + if(A&0x20) { + ROM_BANK16(0x8000,(A&0x40)|((A>>8)&0x3F)); + ROM_BANK16(0xc000,(A&0x40)|((A>>8)&0x3F)); + } + else + ROM_BANK32(((A&0x40)|((A>>8)&0x3F))>>1); + MIRROR_SET((A&0x80)>>7); +} + +void Mapper62_init(void) +{ + SetWriteHandler(0x8000,0xffff, Mapper62_write); + ROM_BANK32(0); +} + + diff --git a/fceumm/src-fceumm/mappers/65.c b/fceumm/src-fceumm/mappers/65.c new file mode 100644 index 0000000..0474566 --- /dev/null +++ b/fceumm/src-fceumm/mappers/65.c @@ -0,0 +1,74 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + + +void IREMIRQHook(int a) +{ + if(IRQa) + { + IRQCount-=a; + if(IRQCount<-4) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + IRQCount=0xFFFF; + } + } +} + +static DECLFW(Mapper65_write) +{ + /*if(A>=0x9000 && A<=0x9006)*/ + /* printf("$%04x:$%02x, %d\n",A,V,scanline);*/ + switch(A) + { + /*default: printf("$%04x:$%02x\n",A,V);*/ + /* break;*/ + case 0x8000:ROM_BANK8(0x8000,V);break; + /* case 0x9000:printf("$%04x:$%02x\n",A,V);MIRROR_SET2((V>>6)&1);break;*/ + case 0x9001:MIRROR_SET(V>>7);break; + case 0x9003:IRQa=V&0x80;X6502_IRQEnd(FCEU_IQEXT);break; + case 0x9004:IRQCount=IRQLatch;break; + case 0x9005: IRQLatch&=0x00FF; + IRQLatch|=V<<8; + break; + case 0x9006: IRQLatch&=0xFF00;IRQLatch|=V; + break; + case 0xB000:VROM_BANK1(0x0000,V);break; + case 0xB001:VROM_BANK1(0x0400,V);break; + case 0xB002:VROM_BANK1(0x0800,V);break; + case 0xB003:VROM_BANK1(0x0C00,V);break; + case 0xB004:VROM_BANK1(0x1000,V);break; + case 0xB005:VROM_BANK1(0x1400,V);break; + case 0xB006:VROM_BANK1(0x1800,V);break; + case 0xB007:VROM_BANK1(0x1C00,V);break; + case 0xa000:ROM_BANK8(0xA000,V);break; + case 0xC000:ROM_BANK8(0xC000,V);break; + } + /*MIRROR_SET2(1);*/ +} + +void Mapper65_init(void) +{ + MapIRQHook=IREMIRQHook; + SetWriteHandler(0x8000,0xffff,Mapper65_write); +} diff --git a/fceumm/src-fceumm/mappers/67.c b/fceumm/src-fceumm/mappers/67.c new file mode 100644 index 0000000..face316 --- /dev/null +++ b/fceumm/src-fceumm/mappers/67.c @@ -0,0 +1,78 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + + +#define suntoggle mapbyte1[0] + +static DECLFW(Mapper67_write) +{ + A&=0xF800; + if((A&0x800) && A<=0xb800) + { + VROM_BANK2((A-0x8800)>>1,V); + } + else switch(A) + { + case 0xc800: + case 0xc000:if(!suntoggle) + { + IRQCount&=0xFF; + IRQCount|=V<<8; + } + else + { + IRQCount&=0xFF00; + IRQCount|=V; + } + suntoggle^=1; + break; + case 0xd800:suntoggle=0;IRQa=V&0x10;X6502_IRQEnd(FCEU_IQEXT);break; + + case 0xe800:switch(V&3) + { + case 0:MIRROR_SET2(1);break; + case 1:MIRROR_SET2(0);break; + case 2:onemir(0);break; + case 3:onemir(1);break; + } + break; + case 0xf800:ROM_BANK16(0x8000,V);break; + } +} +static void SunIRQHook(int a) +{ + if(IRQa) + { + IRQCount-=a; + if(IRQCount<=0) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + IRQCount=0xFFFF; + } + } +} +void Mapper67_init(void) +{ +SetWriteHandler(0x8000,0xffff,Mapper67_write); +MapIRQHook=SunIRQHook; +} diff --git a/fceumm/src-fceumm/mappers/69.c b/fceumm/src-fceumm/mappers/69.c new file mode 100644 index 0000000..8de6781 --- /dev/null +++ b/fceumm/src-fceumm/mappers/69.c @@ -0,0 +1,274 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static void AYSound(int Count); +static void AYSoundHQ(void); +static void DoAYSQ(int x); +static void DoAYSQHQ(int x); + +#define sunselect mapbyte1[0] +#define sungah mapbyte1[1] +static uint8 sunindex; + +static DECLFW(SUN5BWRAM) +{ + if((sungah&0xC0)==0xC0) + (WRAM-0x6000)[A]=V; +} + +static DECLFR(SUN5AWRAM) +{ + if((sungah&0xC0)==0x40) + return X.DB; + return CartBROB(A); +} + +static DECLFW(Mapper69_SWL) +{ + sunindex=V%14; +} + +static DECLFW(Mapper69_SWH) +{ + int x; + GameExpSound.Fill=AYSound; + GameExpSound.HiFill=AYSoundHQ; + if(FSettings.SndRate); + switch(sunindex) + { + case 0: + case 1: + case 8: +#if SOUND_QUALITY == 1 + DoAYSQHQ(0); +#else + DoAYSQ(0); +#endif + break; + case 2: + case 3: + case 9: +#if SOUND_QUALITY == 1 + DoAYSQHQ(1); +#else + DoAYSQ(1); +#endif + break; + case 4: + case 5: + case 10: +#if SOUND_QUALITY == 1 + DoAYSQHQ(2); +#else + DoAYSQ(2); +#endif + break; + case 7: + for(x=0;x<2;x++) +#if SOUND_QUALITY == 1 + DoAYSQHQ(x); +#else + DoAYSQ(x); +#endif + break; + } + MapperExRAM[sunindex]=V; +} + +static DECLFW(Mapper69_write) +{ + switch(A&0xE000) + { + case 0x8000:sunselect=V;break; + case 0xa000: + sunselect&=0xF; + if(sunselect<=7) + VROM_BANK1(sunselect<<10,V); + else + switch(sunselect&0x0f) + { + case 8: + sungah=V; + if(V&0x40) + { + if(V&0x80) /* Select WRAM*/ + setprg8r(0x10,0x6000,0); + } + else + setprg8(0x6000,V); + break; + case 9:ROM_BANK8(0x8000,V);break; + case 0xa:ROM_BANK8(0xa000,V);break; + case 0xb:ROM_BANK8(0xc000,V);break; + case 0xc: + switch(V&3) + { + case 0:MIRROR_SET2(1);break; + case 1:MIRROR_SET2(0);break; + case 2:onemir(0);break; + case 3:onemir(1);break; + } + break; + case 0xd:IRQa=V;X6502_IRQEnd(FCEU_IQEXT);break; + case 0xe:IRQCount&=0xFF00;IRQCount|=V;X6502_IRQEnd(FCEU_IQEXT);break; + case 0xf:IRQCount&=0x00FF;IRQCount|=V<<8;X6502_IRQEnd(FCEU_IQEXT);break; + } + break; + } +} + +static int32 vcount[3]; +static int32 dcount[3]; +static int CAYBC[3]; + +static void DoAYSQ(int x) +{ + int32 freq=((MapperExRAM[x<<1]|((MapperExRAM[(x<<1)+1]&15)<<8))+1)<<(4+17); + int32 amp=(MapperExRAM[0x8+x]&15)<<2; + int32 start,end; + int V; + + amp+=amp>>1; + + start=CAYBC[x]; + end=(SOUNDTS<<16)/soundtsinc; + if(end<=start) return; + CAYBC[x]=end; + + if(amp) + for(V=start;V>4]+=amp; + vcount[x]-=nesincsize; + while(vcount[x]<=0) + { + dcount[x]^=1; + vcount[x]+=freq; + } + } +} + +static void DoAYSQHQ(int x) +{ + int32 V; + int32 freq=((MapperExRAM[x<<1]|((MapperExRAM[(x<<1)+1]&15)<<8))+1)<<4; + int32 amp=(MapperExRAM[0x8+x]&15)<<6; + + amp+=amp>>1; + + if(!(MapperExRAM[0x7]&(1<>3)&2);break; + } +} + +void Mapper71_init(void) +{ +SetWriteHandler(0x4020,0xffff,Mapper71_write); +} + diff --git a/fceumm/src-fceumm/mappers/72.c b/fceumm/src-fceumm/mappers/72.c new file mode 100644 index 0000000..480a035 --- /dev/null +++ b/fceumm/src-fceumm/mappers/72.c @@ -0,0 +1,37 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + + +DECLFW(Mapper72_write) +{ + mapbyte1[0]=V; + if(V&0x80) + ROM_BANK16(0x8000,V&0xF); + if(V&0x40) + VROM_BANK8(V&0xF); +} + +void Mapper72_init(void) +{ + SetWriteHandler(0x6000,0xffff,Mapper72_write); +} + diff --git a/fceumm/src-fceumm/mappers/73.c b/fceumm/src-fceumm/mappers/73.c new file mode 100644 index 0000000..f0ffb45 --- /dev/null +++ b/fceumm/src-fceumm/mappers/73.c @@ -0,0 +1,60 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + + + +static DECLFW(Mapper73_write) +{ + /*if(A>=0xd000 && A<=0xdfff)*/ + X6502_IRQEnd(FCEU_IQEXT); /* How are IRQs acknowledged on this chip? */ + switch(A&0xF000) + { + /*default: printf("$%04x:$%02x\n",A,V);break;*/ + case 0x8000:IRQCount&=0xFFF0;IRQCount|=(V&0xF);break; + case 0x9000:IRQCount&=0xFF0F;IRQCount|=(V&0xF)<<4;break; + case 0xa000:IRQCount&=0xF0FF;IRQCount|=(V&0xF)<<8;break; + case 0xb000:IRQCount&=0x0FFF;IRQCount|=(V&0xF)<<12;break; + case 0xc000:IRQa=V&2;break; + case 0xf000:ROM_BANK16(0x8000,V);break; + } +} + +static void Mapper73IRQHook(int a) +{ + if(IRQa) + { + IRQCount+=a; + if(IRQCount>=0xFFFF) + { + IRQCount&=0xFFFF; + IRQa=0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +void Mapper73_init(void) +{ + SetWriteHandler(0x8000,0xffff,Mapper73_write); + MapIRQHook=Mapper73IRQHook; +} + diff --git a/fceumm/src-fceumm/mappers/75.c b/fceumm/src-fceumm/mappers/75.c new file mode 100644 index 0000000..f2b00bd --- /dev/null +++ b/fceumm/src-fceumm/mappers/75.c @@ -0,0 +1,47 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + + +#define map75sel mapbyte1[0] +#define map75ar mapbyte2 + +DECLFW(Mapper75_write) +{ +switch(A&0xF000) + { + case 0x8000:ROM_BANK8(0x8000,V);break; + case 0x9000: + VROM_BANK4(0x0000,map75ar[0]|((V&2)<<3)); + VROM_BANK4(0x1000,map75ar[1]|((V&4)<<2)); + map75sel=V;MIRROR_SET(V&1);break; + case 0xa000:ROM_BANK8(0xa000,V);break; + case 0xc000:ROM_BANK8(0xc000,V);break; + case 0xe000:V&=0xF;map75ar[0]=V;V|=(map75sel&2)<<3;VROM_BANK4(0x0000,V);break; + case 0xf000:V&=0xF;map75ar[1]=V;V|=(map75sel&4)<<2;VROM_BANK4(0x1000,V);break; + } +} + +void Mapper75_init(void) +{ +SetWriteHandler(0x8000,0xffff,Mapper75_write); +} + diff --git a/fceumm/src-fceumm/mappers/76.c b/fceumm/src-fceumm/mappers/76.c new file mode 100644 index 0000000..a59ef1e --- /dev/null +++ b/fceumm/src-fceumm/mappers/76.c @@ -0,0 +1,54 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" +static uint8 MMC3_cmd; + +static DECLFW(Mapper76_write) +{ + switch(A&0xE001){ + case 0x8000: + MMC3_cmd = V; + break; + case 0x8001: + switch(MMC3_cmd&0x07){ + case 2: VROM_BANK2(0x000,V);break; + case 3: VROM_BANK2(0x800,V);break; + case 4: VROM_BANK2(0x1000,V);break; + case 5: VROM_BANK2(0x1800,V);break; + case 6: + if(MMC3_cmd&0x40) ROM_BANK8(0xC000,V); + else ROM_BANK8(0x8000,V); + break; + case 7: ROM_BANK8(0xA000,V); + break; + } + break; + case 0xA000: + MIRROR_SET(V&1); + break; + } +} + +void Mapper76_init(void) +{ +SetWriteHandler(0x8000,0xffff,Mapper76_write); +} + diff --git a/fceumm/src-fceumm/mappers/77.c b/fceumm/src-fceumm/mappers/77.c new file mode 100644 index 0000000..06f15cc --- /dev/null +++ b/fceumm/src-fceumm/mappers/77.c @@ -0,0 +1,54 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +/* Original code provided by LULU */ + +static DECLFW(Mapper77_write) +{ + mapbyte1[0]=V; + ROM_BANK32(V&0x7); + VROM_BANK2(0x0000, (V&0xf0)>>4); +} + +static void Mapper77_StateRestore(int version) +{ + int x; + + if(version>=7200) + { + ROM_BANK32(mapbyte1[0]&0x7); + VROM_BANK2(0x0000, (mapbyte1[0]&0xf0)>>4); + } + for(x=2;x<8;x++) + VRAM_BANK1(x*0x400,x); +} + +void Mapper77_init(void) +{ + int x; + + ROM_BANK32(0); + for(x=2;x<8;x++) + VRAM_BANK1(x*0x400,x); + SetWriteHandler(0x6000,0xffff,Mapper77_write); + MapStateRestore=Mapper77_StateRestore; +} diff --git a/fceumm/src-fceumm/mappers/79.c b/fceumm/src-fceumm/mappers/79.c new file mode 100644 index 0000000..094592a --- /dev/null +++ b/fceumm/src-fceumm/mappers/79.c @@ -0,0 +1,41 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * TXC mapper variation, F-15 City War + */ + +#include "mapinc.h" + + + +DECLFW(Mapper79_write) +{ + if(A<0x8000 && ((A^0x4100)==0)) + { + ROM_BANK32((V>>3)&1); + } + VROM_BANK8(V); +} + +void Mapper79_init(void) +{ + ROM_BANK32(~0); + SetWriteHandler(0x8000,0xffff,Mapper79_write); + SetWriteHandler(0x4020,0x5fff,Mapper79_write); +} + diff --git a/fceumm/src-fceumm/mappers/8.c b/fceumm/src-fceumm/mappers/8.c new file mode 100644 index 0000000..53c91a2 --- /dev/null +++ b/fceumm/src-fceumm/mappers/8.c @@ -0,0 +1,34 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static DECLFW(Mapper8_write) +{ + ROM_BANK16(0x8000,V>>3); + VROM_BANK8(V&7); +} + +void Mapper8_init(void) +{ + ROM_BANK32(0); + SetWriteHandler(0x8000,0xFFFF,Mapper8_write); +} + diff --git a/fceumm/src-fceumm/mappers/80.c b/fceumm/src-fceumm/mappers/80.c new file mode 100644 index 0000000..948faec --- /dev/null +++ b/fceumm/src-fceumm/mappers/80.c @@ -0,0 +1,101 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint32 lastA; +static int isfu; +static uint8 CCache[8]; + +static void Fudou_PPU(uint32 A) +{ + static int last=-1; + static uint8 z; + + if(A>=0x2000) return; + + A>>=10; + lastA=A; + + z=CCache[A]; + if(z!=last) + { + onemir(z); + last=z; + } +} + +static void mira() +{ + if(isfu) + { + int x; + CCache[0]=CCache[1]=mapbyte2[0]>>7; + CCache[2]=CCache[3]=mapbyte2[1]>>7; + + for(x=0;x<4;x++) + CCache[4+x]=mapbyte2[2+x]>>7; + + onemir(CCache[lastA]); + } + else + MIRROR_SET2(mapbyte1[0]&1); +} + +static DECLFW(Mapper80_write) +{ + switch(A) + { + case 0x7ef0: mapbyte2[0]=V;VROM_BANK2(0x0000,(V>>1)&0x3F);mira();break; + case 0x7ef1: mapbyte2[1]=V;VROM_BANK2(0x0800,(V>>1)&0x3f);mira();break; + + case 0x7ef2: mapbyte2[2]=V;VROM_BANK1(0x1000,V);mira();break; + case 0x7ef3: mapbyte2[3]=V;VROM_BANK1(0x1400,V);mira();break; + case 0x7ef4: mapbyte2[4]=V;VROM_BANK1(0x1800,V);mira();break; + case 0x7ef5: mapbyte2[5]=V;VROM_BANK1(0x1c00,V);mira();break; + case 0x7ef6: mapbyte1[0]=V;mira();break; + case 0x7efa: + case 0x7efb: ROM_BANK8(0x8000,V);break; + case 0x7efd: + case 0x7efc: ROM_BANK8(0xA000,V);break; + case 0x7efe: + case 0x7eff: ROM_BANK8(0xC000,V);break; + } +} + +static void booga(int version) +{ + mira(); +} + +void Mapper80_init(void) +{ + SetWriteHandler(0x4020,0x7eff,Mapper80_write);/* 7f00-7fff battery backed ram inside mapper chip,*/ + /* controlled by 7ef8 register, A8 - enable, FF - disable (?)*/ + MapStateRestore=booga; + isfu=0; +} + +void Mapper207_init(void) +{ + Mapper80_init(); + isfu=1; + PPU_hook=Fudou_PPU; +} diff --git a/fceumm/src-fceumm/mappers/82.c b/fceumm/src-fceumm/mappers/82.c new file mode 100644 index 0000000..b4288b1 --- /dev/null +++ b/fceumm/src-fceumm/mappers/82.c @@ -0,0 +1,62 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +#define ctrl mapbyte1[6] + +static void DoCHR(void) +{ + int x; + + for(x=0;x<2;x++) + VROM_BANK2((x<<11)|((ctrl&2)<<11),mapbyte1[x]>>1); + for(x=0;x<4;x++) + VROM_BANK1((x<<10) | (((ctrl&2)^2)<<11),mapbyte1[2+x]); +} + +static DECLFW(Mapper82_write) +{ + if(A<=0x7EF5) + { + mapbyte1[A&7]=V; + DoCHR(); + } + else + switch(A) + { + case 0x7ef6:ctrl=V&3; + MIRROR_SET2(V&1); + DoCHR(); + break; + case 0x7efa:V>>=2;mapbyte2[0]=V;ROM_BANK8(0x8000,V);break; + case 0x7efb:V>>=2;mapbyte2[1]=V;ROM_BANK8(0xa000,V);break; + case 0x7efc:V>>=2;mapbyte2[2]=V;ROM_BANK8(0xc000,V);break; + } +} + +void Mapper82_init(void) +{ + ROM_BANK8(0xE000,~0); + + /* external WRAM might end at $73FF */ + SetWriteHandler(0x7ef0,0x7efc,Mapper82_write); +} + diff --git a/fceumm/src-fceumm/mappers/83.c b/fceumm/src-fceumm/mappers/83.c new file mode 100644 index 0000000..e8bc93c --- /dev/null +++ b/fceumm/src-fceumm/mappers/83.c @@ -0,0 +1,150 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * YOKO mapper, almost the same as UNLYOKO_Init, TODO: merge + * + */ + +#include "mapinc.h" + +static uint8 is2kbank, isnot2kbank, dipreg; + +/*void Mapper83_init(void) +{ + +} +*/ +static void m83IRQHook(int a) +{ + if(IRQa) + { + IRQCount-=a; + if(IRQCount<0) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + IRQCount=0xFFFF; + } + } +} + +static DECLFW(wrlow) +{ + mapbyte4[A&3]=V; +} + +static DECLFR(rdlow) +{ + return mapbyte4[A&3]; +} + +static DECLFR(rd5000) +{ + return dipreg; +} + +static void m83prg(void) +{ + ROM_BANK16(0x8000,(mapbyte1[0]&0x3F)); + ROM_BANK16(0xC000,(mapbyte1[0]&0x30)|0xF); +} + +static void m83chr(void) +{ + if(is2kbank&&!isnot2kbank) + { + VROM_BANK2(0x0000,mapbyte2[0]); + VROM_BANK2(0x0800,mapbyte2[1]); + VROM_BANK2(0x1000,mapbyte2[6]); + VROM_BANK2(0x1800,mapbyte2[7]); + } + else + { + int x; + for(x=0;x<8;x++) + VROM_BANK1(x*0x400,mapbyte2[x]|((mapbyte1[0]&0x30)<<4)); + } +} + +static DECLFW(Mapper83_write) +{ + /*printf("$%04x:$%02x\n",A,V);*/ + switch(A) + { + case 0x8000: is2kbank = 1; + case 0xB000: + case 0xB0FF: + case 0xB1FF: + { + mapbyte1[0]=V; + m83prg(); + m83chr(); + } + break; + case 0x8100: + mapbyte3[0]=V&0x80; + switch(V&0x3) + { + case 0x00:MIRROR_SET2(1);break; + case 0x01:MIRROR_SET2(0);break; + case 0x02:onemir(0);break; + case 0x03:onemir(1);break; + } + break; + case 0x8200:IRQCount&=0xFF00;IRQCount|=V;X6502_IRQEnd(FCEU_IQEXT);break; + case 0x8201:IRQa=mapbyte3[0];IRQCount&=0xFF;IRQCount|=V<<8;break; + case 0x8300:ROM_BANK8(0x8000,V);break; + case 0x8301:ROM_BANK8(0xA000,V);break; + case 0x8302:ROM_BANK8(0xC000,V);break; + case 0x8310:mapbyte2[0]=V;m83chr();break; + case 0x8311:mapbyte2[1]=V;m83chr();break; + case 0x8312:mapbyte2[2]=V;isnot2kbank = 1;m83chr();break; /* 2 mappers in one :)*/ + case 0x8313:mapbyte2[3]=V;isnot2kbank = 1;m83chr();break; + case 0x8314:mapbyte2[4]=V;isnot2kbank = 1;m83chr();break; + case 0x8315:mapbyte2[5]=V;isnot2kbank = 1;m83chr();break; + case 0x8316:mapbyte2[6]=V;m83chr();break; + case 0x8317:mapbyte2[7]=V;m83chr();break; + case 0x8318:mapbyte1[1]=V;m83prg();break; + } +/* printf("$%04x:$%02x, $%04x\n",A,V,X.PC.W);*/ + +} + +static void m83Reset(void) +{ + dipreg^=1; +} + +void Mapper83_init(void) +{ + is2kbank = 0; + isnot2kbank = 0; + dipreg = 0; + ROM_BANK8(0xc000,0x1e); + ROM_BANK8(0xe000,0x1f); + + MapIRQHook=m83IRQHook; + MapperReset=m83Reset; + + SetReadHandler(0x5000,0x5000,rd5000); /* title scren dip switch*/ + SetReadHandler(0x5100,0x5103,rdlow); + SetWriteHandler(0x5100,0x5103,wrlow); + SetWriteHandler(0x8000,0xffff,Mapper83_write); + mapbyte1[1]=0xF; +} diff --git a/fceumm/src-fceumm/mappers/85.c b/fceumm/src-fceumm/mappers/85.c new file mode 100644 index 0000000..cd888ee --- /dev/null +++ b/fceumm/src-fceumm/mappers/85.c @@ -0,0 +1,196 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +#define vrctemp mapbyte1[0] +static uint8 indox; + +#include "emu2413.h" + +static int acount=0; + +static OPLL *VRC7Sound=NULL; +static int dwave=0; + +void DoVRC7Sound(void) +{ +#if SOUND_QUALITY == 0 + int32 z,a; + + z=((SOUNDTS<<16)/soundtsinc)>>4; + a=z-dwave; + + moocow(VRC7Sound, &Wave[dwave], a, 1); + + dwave+=a; +#endif +} + +void UpdateOPLNEO(int32 *Wave, int Count) +{ + moocow(VRC7Sound, Wave, Count, 4); +} + +void UpdateOPL(int Count) +{ + int32 z,a; + + z=((SOUNDTS<<16)/soundtsinc)>>4; + a=z-dwave; + + if(VRC7Sound && a) + moocow(VRC7Sound, &Wave[dwave], a, 1); + + dwave=0; +} + +static INLINE void DaMirror(int V) +{ + int salpo[4]={MI_V,MI_H,MI_0,MI_1}; + setmirror(salpo[V&3]); +} + +DECLFW(Mapper85_write) +{ + A|=(A&8)<<1; + + if(A>=0xa000 && A<=0xDFFF) + { + /* printf("$%04x, $%04x\n",X.PC,A);*/ + A&=0xF010; + { + int x=((A>>4)&1)|((A-0xA000)>>11); + mapbyte3[x]=V; + setchr1(x<<10,V); + } + } + else if(A==0x9030) + { + if(FSettings.SndRate) + { + OPLL_writeReg(VRC7Sound, indox, V); + GameExpSound.Fill=UpdateOPL; + GameExpSound.NeoFill=UpdateOPLNEO; + } + } + else switch(A&0xF010) + { + case 0x8000:mapbyte2[0]=V;setprg8(0x8000,V);break; + case 0x8010:mapbyte2[1]=V;setprg8(0xa000,V);break; + case 0x9000:mapbyte2[2]=V;setprg8(0xc000,V);break; + case 0x9010:indox=V;break; + case 0xe000:mapbyte2[3]=V;DaMirror(V);break; + case 0xE010:IRQLatch=V; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xF000:IRQa=V&2; + vrctemp=V&1; + if(V&2) {IRQCount=IRQLatch;} + acount=0; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xf010:if(vrctemp) IRQa=1; + else IRQa=0; + X6502_IRQEnd(FCEU_IQEXT); + break; + } +} + +static void KonamiIRQHook(int a) +{ + #define ACBOO 341 +/* #define ACBOO ((227*2)+1)*/ + if(IRQa) + { + acount+=a*3; + + if(acount>=ACBOO) + { + doagainbub:acount-=ACBOO; + IRQCount++; + if(IRQCount&0x100) {X6502_IRQBegin(FCEU_IQEXT);IRQCount=IRQLatch;} + if(acount>=ACBOO) goto doagainbub; + } + } +} + +void Mapper85_StateRestore(int version) +{ + int x; + + if(version<7200) + { + for(x=0;x<8;x++) + mapbyte3[x]=CHRBankList[x]; + for(x=0;x<3;x++) + mapbyte2[x]=PRGBankList[x]; + mapbyte2[3]=(Mirroring<0x10)?Mirroring:Mirroring-0xE; + } + + for(x=0;x<8;x++) + setchr1(x*0x400,mapbyte3[x]); + for(x=0;x<3;x++) + setprg8(0x8000+x*8192,mapbyte2[x]); + DaMirror(mapbyte2[3]); + /*LoadOPL();*/ +} + +static void M85SC(void) +{ + if(VRC7Sound) + OPLL_set_rate(VRC7Sound, FSettings.SndRate); +} + +static void M85SKill(void) +{ + if(VRC7Sound) + OPLL_delete(VRC7Sound); + VRC7Sound=NULL; +} + +static void VRC7SI(void) +{ + GameExpSound.RChange=M85SC; + GameExpSound.Kill=M85SKill; + + VRC7Sound=OPLL_new(3579545, FSettings.SndRate?FSettings.SndRate:44100); + OPLL_reset(VRC7Sound); + OPLL_reset(VRC7Sound); +} + +void NSFVRC7_Init(void) +{ + SetWriteHandler(0x9010,0x901F,Mapper85_write); + SetWriteHandler(0x9030,0x903F,Mapper85_write); + VRC7SI(); +} + +void Mapper85_init(void) +{ + MapIRQHook=KonamiIRQHook; + SetWriteHandler(0x8000,0xffff,Mapper85_write); + GameStateRestore=Mapper85_StateRestore; + if(!VROM_size) + SetupCartCHRMapping(0, CHRRAM, 8192, 1); + /*AddExState(VRC7Instrument, 16, 0, "VC7I");*/ + /*AddExState(VRC7Chan, sizeof(VRC7Chan), 0, "V7CH");*/ + VRC7SI(); +} diff --git a/fceumm/src-fceumm/mappers/86.c b/fceumm/src-fceumm/mappers/86.c new file mode 100644 index 0000000..0791677 --- /dev/null +++ b/fceumm/src-fceumm/mappers/86.c @@ -0,0 +1,39 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +DECLFW(Mapper86_write) +{ + if(A>=0x6000 && A<=0x6fFF) + { + VROM_BANK8((V&3)|((V>>4)&4)); + ROM_BANK32((V>>4)&3); + } + /*else*/ + /*if(A!=0x6000)*/ + /* printf("$%04x:$%02x\n",A,V);*/ +} + +void Mapper86_init(void) +{ + SetWriteHandler(0x6000,0x6fff,Mapper86_write); + SetWriteHandler(0x4020,0xffff,Mapper86_write); +} diff --git a/fceumm/src-fceumm/mappers/89.c b/fceumm/src-fceumm/mappers/89.c new file mode 100644 index 0000000..a3a6f09 --- /dev/null +++ b/fceumm/src-fceumm/mappers/89.c @@ -0,0 +1,34 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +DECLFW(Mapper89_write) +{ + VROM_BANK8((V&7)|((V>>4)&8)); + ROM_BANK16(0x8000,(V>>4)&7); + onemir((V>>3)&1); +} + +void Mapper89_init(void) +{ + Mirroring=0; + SetWriteHandler(0x8000,0xffff,Mapper89_write); +} diff --git a/fceumm/src-fceumm/mappers/91.c b/fceumm/src-fceumm/mappers/91.c new file mode 100644 index 0000000..27de497 --- /dev/null +++ b/fceumm/src-fceumm/mappers/91.c @@ -0,0 +1,59 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static DECLFW(Mapper91_write) +{ +/*if(A>=0x7001)*/ +/*printf("$%04x:$%02x, %d\n",A,V,scanline);*/ + A&=0xF007; + + if(A>=0x6000 && A<=0x6003) VROM_BANK2((A&3)*2048,V); + else switch(A&0xF003) + { + case 0x7000: + case 0x7001:ROM_BANK8(0x8000+(A&1)*8192,V);break; + case 0x7002:IRQa=IRQCount=0;X6502_IRQEnd(FCEU_IQEXT);break; + case 0x7003:IRQa=1;X6502_IRQEnd(FCEU_IQEXT);break; +/* default: printf("Iyee: $%04x:$%02x\n",A,V);break;*/ + } + /*if(A>=0x7000)*/ + /* printf("$%04x:$%02x, %d\n",A,V,scanline);*/ +} + +static void Mapper91_hb(void) +{ + if(IRQCount<8 && IRQa) + { + IRQCount++; + if(IRQCount>=8) + { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +void Mapper91_init(void) +{ + SetWriteHandler(0x4020,0xFFFF,Mapper91_write); + GameHBIRQHook=Mapper91_hb; +} + diff --git a/fceumm/src-fceumm/mappers/92.c b/fceumm/src-fceumm/mappers/92.c new file mode 100644 index 0000000..e2ad374 --- /dev/null +++ b/fceumm/src-fceumm/mappers/92.c @@ -0,0 +1,45 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +/* Original code provided by LULU */ + +static DECLFW(Mapper92_write) +{ + uint8 reg=(A&0xF0)>>4; + uint8 bank=A&0xF; + + if(A>=0x9000) + { + if(reg==0xD) ROM_BANK16(0xc000,bank); + else if(reg==0xE) VROM_BANK8(bank); + } + else + { + if(reg==0xB) ROM_BANK16(0xc000,bank); + else if(reg==0x7) VROM_BANK8(bank); + } +} + +void Mapper92_init(void) +{ + SetWriteHandler(0x8000,0xFFFF,Mapper92_write); +} diff --git a/fceumm/src-fceumm/mappers/97.c b/fceumm/src-fceumm/mappers/97.c new file mode 100644 index 0000000..2990c0e --- /dev/null +++ b/fceumm/src-fceumm/mappers/97.c @@ -0,0 +1,42 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + + + +DECLFW(Mapper97_write) +{ +ROM_BANK16(0xC000,V&15); +switch(V>>6) + { + case 0:break; + case 1:MIRROR_SET2(0);break; + case 2:MIRROR_SET2(1);break; + case 3:break; + } +} + +void Mapper97_init(void) +{ + ROM_BANK16(0x8000,~0); + SetWriteHandler(0x8000,0xffff,Mapper97_write); +} + diff --git a/fceumm/src-fceumm/mappers/99.c b/fceumm/src-fceumm/mappers/99.c new file mode 100644 index 0000000..7a55536 --- /dev/null +++ b/fceumm/src-fceumm/mappers/99.c @@ -0,0 +1,37 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static writefunc oldmorko; + +static DECLFW(morko) +{ + VROM_BANK8((V>>2)&1); + oldmorko(A,V); + setprg8(0x8000,V&0x4); /* Special for VS Gumshoe */ +} + +void Mapper99_init(void) +{ + ROM_BANK32(0); + oldmorko=GetWriteHandler(0x4016); + SetWriteHandler(0x4016,0x4016,morko); +} diff --git a/fceumm/src-fceumm/mappers/emu2413.c b/fceumm/src-fceumm/mappers/emu2413.c new file mode 100644 index 0000000..a1d1fed --- /dev/null +++ b/fceumm/src-fceumm/mappers/emu2413.c @@ -0,0 +1,1300 @@ +/*********************************************************************************** + + emu2413.c -- YM2413 emulator written by Mitsutaka Okazaki 2001 + + 2001 01-08 : Version 0.10 -- 1st version. + 2001 01-15 : Version 0.20 -- semi-public version. + 2001 01-16 : Version 0.30 -- 1st public version. + 2001 01-17 : Version 0.31 -- Fixed bassdrum problem. + : Version 0.32 -- LPF implemented. + 2001 01-18 : Version 0.33 -- Fixed the drum problem, refine the mix-down method. + -- Fixed the LFO bug. + 2001 01-24 : Version 0.35 -- Fixed the drum problem, + support undocumented EG behavior. + 2001 02-02 : Version 0.38 -- Improved the performance. + Fixed the hi-hat and cymbal model. + Fixed the default percussive datas. + Noise reduction. + Fixed the feedback problem. + 2001 03-03 : Version 0.39 -- Fixed some drum bugs. + Improved the performance. + 2001 03-04 : Version 0.40 -- Improved the feedback. + Change the default table size. + Clock and Rate can be changed during play. + 2001 06-24 : Version 0.50 -- Improved the hi-hat and the cymbal tone. + Added VRC7 patch (OPLL_reset_patch is changed). + Fixed OPLL_reset() bug. + Added OPLL_setMask, OPLL_getMask and OPLL_toggleMask. + Added OPLL_writeIO. + 2001 09-28 : Version 0.51 -- Removed the noise table. + 2002 01-28 : Version 0.52 -- Added Stereo mode. + 2002 02-07 : Version 0.53 -- Fixed some drum bugs. + 2002 02-20 : Version 0.54 -- Added the best quality mode. + 2002 03-02 : Version 0.55 -- Removed OPLL_init & OPLL_close. + 2002 05-30 : Version 0.60 -- Fixed HH&CYM generator and all voice datas. + + 2004 01-24 : Modified by xodnizel to remove code not needed for the VRC7, among other things. + + References: + fmopl.c -- 1999,2000 written by Tatsuyuki Satoh (MAME development). + fmopl.c(fixed) -- (C) 2002 Jarek Burczynski. + s_opl.c -- 2001 written by Mamiya (NEZplug development). + fmgen.cpp -- 1999,2000 written by cisc. + fmpac.ill -- 2000 created by NARUTO. + MSX-Datapack + YMU757 data sheet + YM2143 data sheet + +**************************************************************************************/ +#include +#include +#include +#include +#include "emu2413.h" + +static const unsigned char default_inst[15][8] = { + #include "vrc7tone.h" +}; + +/* Size of Sintable ( 8 -- 18 can be used. 9 recommended.)*/ +#define PG_BITS 9 +#define PG_WIDTH (1<>(b)) + +/* Leave the lower b bit(s). */ +#define LOWBITS(c,b) ((c)&((1<<(b))-1)) + +/* Expand x which is s bits to d bits. */ +#define EXPAND_BITS(x,s,d) ((x)<<((d)-(s))) + +/* Expand x which is s bits to d bits and fill expanded bits '1' */ +#define EXPAND_BITS_X(x,s,d) (((x)<<((d)-(s)))|((1<<((d)-(s)))-1)) + +/* Adjust envelope speed which depends on sampling rate. */ +#define rate_adjust(x) (rate==49716?x:(e_uint32)((double)(x)*clk/72/rate + 0.5)) /* added 0.5 to round the value*/ + +#define MOD(o,x) (&(o)->slot[(x)<<1]) +#define CAR(o,x) (&(o)->slot[((x)<<1)|1]) + +#define BIT(s,b) (((s)>>(b))&1) + +/* Input clock */ +static e_uint32 clk = 844451141; +/* Sampling rate */ +static e_uint32 rate = 3354932; + +/* WaveTable for each envelope amp */ +static e_uint16 fullsintable[PG_WIDTH]; +static e_uint16 halfsintable[PG_WIDTH]; + +static e_uint16 *waveform[2] = { fullsintable, halfsintable }; + +/* LFO Table */ +static e_int32 pmtable[PM_PG_WIDTH]; +static e_int32 amtable[AM_PG_WIDTH]; + +/* Phase delta for LFO */ +static e_uint32 pm_dphase; +static e_uint32 am_dphase; + +/* dB to Liner table */ +static e_int16 DB2LIN_TABLE[(DB_MUTE + DB_MUTE) * 2]; + +/* Liner to Log curve conversion table (for Attack rate). */ +static e_uint16 AR_ADJUST_TABLE[1 << EG_BITS]; + +/* Definition of envelope mode */ +enum +{ SETTLE, ATTACK, DECAY, SUSHOLD, SUSTINE, RELEASE, FINISH }; + +/* Phase incr table for Attack */ +static e_uint32 dphaseARTable[16][16]; +/* Phase incr table for Decay and Release */ +static e_uint32 dphaseDRTable[16][16]; + +/* KSL + TL Table */ +static e_uint32 tllTable[16][8][1 << TL_BITS][4]; +static e_int32 rksTable[2][8][2]; + +/* Phase incr table for PG */ +static e_uint32 dphaseTable[512][8][16]; + +/*************************************************** + + Create tables + +****************************************************/ +INLINE static e_int32 +Min (e_int32 i, e_int32 j) +{ + if(i < j) + return i; + else + return j; +} + +/* Table for AR to LogCurve. */ +static void +makeAdjustTable (void) +{ + e_int32 i; + + AR_ADJUST_TABLE[0] = (1 << EG_BITS); + for (i = 1; i < 128; i++) + AR_ADJUST_TABLE[i] = (e_uint16) ((double) (1 << EG_BITS) - 1 - (1 << EG_BITS) * log (i) / log (128)); +} + + +/* Table for dB(0 -- (1<= DB_MUTE) DB2LIN_TABLE[i] = 0; + DB2LIN_TABLE[i + DB_MUTE + DB_MUTE] = (e_int16) (-DB2LIN_TABLE[i]); + } +} + +/* Liner(+0.0 - +1.0) to dB((1<> (20 - DP_BITS)); +} + +static void +makeTllTable (void) +{ +#define dB2(x) ((x)*2) + + static double kltable[16] = { + dB2 (0.000), dB2 (9.000), dB2 (12.000), dB2 (13.875), dB2 (15.000), dB2 (16.125), dB2 (16.875), dB2 (17.625), + dB2 (18.000), dB2 (18.750), dB2 (19.125), dB2 (19.500), dB2 (19.875), dB2 (20.250), dB2 (20.625), dB2 (21.000) + }; + + e_int32 tmp; + e_int32 fnum, block, TL, KL; + + for (fnum = 0; fnum < 16; fnum++) + for (block = 0; block < 8; block++) + for (TL = 0; TL < 64; TL++) + for (KL = 0; KL < 4; KL++) + { + if(KL == 0) + { + tllTable[fnum][block][TL][KL] = TL2EG (TL); + } + else + { + tmp = (e_int32) (kltable[fnum] - dB2 (3.000) * (7 - block)); + if(tmp <= 0) + tllTable[fnum][block][TL][KL] = TL2EG (TL); + else + tllTable[fnum][block][TL][KL] = (e_uint32) ((tmp >> (3 - KL)) / EG_STEP) + TL2EG (TL); + } + } +} + +#ifdef USE_SPEC_ENV_SPEED +static double attacktime[16][4] = { + {0, 0, 0, 0}, + {1730.15, 1400.60, 1153.43, 988.66}, + {865.08, 700.30, 576.72, 494.33}, + {432.54, 350.15, 288.36, 247.16}, + {216.27, 175.07, 144.18, 123.58}, + {108.13, 87.54, 72.09, 61.79}, + {54.07, 43.77, 36.04, 30.90}, + {27.03, 21.88, 18.02, 15.45}, + {13.52, 10.94, 9.01, 7.72}, + {6.76, 5.47, 4.51, 3.86}, + {3.38, 2.74, 2.25, 1.93}, + {1.69, 1.37, 1.13, 0.97}, + {0.84, 0.70, 0.60, 0.54}, + {0.50, 0.42, 0.34, 0.30}, + {0.28, 0.22, 0.18, 0.14}, + {0.00, 0.00, 0.00, 0.00} +}; + +static double decaytime[16][4] = { + {0, 0, 0, 0}, + {20926.60, 16807.20, 14006.00, 12028.60}, + {10463.30, 8403.58, 7002.98, 6014.32}, + {5231.64, 4201.79, 3501.49, 3007.16}, + {2615.82, 2100.89, 1750.75, 1503.58}, + {1307.91, 1050.45, 875.37, 751.79}, + {653.95, 525.22, 437.69, 375.90}, + {326.98, 262.61, 218.84, 187.95}, + {163.49, 131.31, 109.42, 93.97}, + {81.74, 65.65, 54.71, 46.99}, + {40.87, 32.83, 27.36, 23.49}, + {20.44, 16.41, 13.68, 11.75}, + {10.22, 8.21, 6.84, 5.87}, + {5.11, 4.10, 3.42, 2.94}, + {2.55, 2.05, 1.71, 1.47}, + {1.27, 1.27, 1.27, 1.27} +}; +#endif + +/* Rate Table for Attack */ +static void +makeDphaseARTable (void) +{ + e_int32 AR, Rks, RM, RL; +#ifdef USE_SPEC_ENV_SPEED + e_uint32 attacktable[16][4]; + + for (RM = 0; RM < 16; RM++) + for (RL = 0; RL < 4; RL++) + { + if(RM == 0) + attacktable[RM][RL] = 0; + else if(RM == 15) + attacktable[RM][RL] = EG_DP_WIDTH; + else + attacktable[RM][RL] = (e_uint32) ((double) (1 << EG_DP_BITS) / (attacktime[RM][RL] * 3579545 / 72000)); + + } +#endif + + for (AR = 0; AR < 16; AR++) + for (Rks = 0; Rks < 16; Rks++) + { + RM = AR + (Rks >> 2); + RL = Rks & 3; + if(RM > 15) + RM = 15; + switch (AR) + { + case 0: + dphaseARTable[AR][Rks] = 0; + break; + case 15: + dphaseARTable[AR][Rks] = 0;/*EG_DP_WIDTH;*/ + break; + default: +#ifdef USE_SPEC_ENV_SPEED + dphaseARTable[AR][Rks] = rate_adjust (attacktable[RM][RL]); +#else + dphaseARTable[AR][Rks] = rate_adjust ((3 * (RL + 4) << (RM + 1))); +#endif + break; + } + } +} + +/* Rate Table for Decay and Release */ +static void +makeDphaseDRTable (void) +{ + e_int32 DR, Rks, RM, RL; + +#ifdef USE_SPEC_ENV_SPEED + e_uint32 decaytable[16][4]; + + for (RM = 0; RM < 16; RM++) + for (RL = 0; RL < 4; RL++) + if(RM == 0) + decaytable[RM][RL] = 0; + else + decaytable[RM][RL] = (e_uint32) ((double) (1 << EG_DP_BITS) / (decaytime[RM][RL] * 3579545 / 72000)); +#endif + + for (DR = 0; DR < 16; DR++) + for (Rks = 0; Rks < 16; Rks++) + { + RM = DR + (Rks >> 2); + RL = Rks & 3; + if(RM > 15) + RM = 15; + switch (DR) + { + case 0: + dphaseDRTable[DR][Rks] = 0; + break; + default: +#ifdef USE_SPEC_ENV_SPEED + dphaseDRTable[DR][Rks] = rate_adjust (decaytable[RM][RL]); +#else + dphaseDRTable[DR][Rks] = rate_adjust ((RL + 4) << (RM - 1)); +#endif + break; + } + } +} + +static void +makeRksTable (void) +{ + + e_int32 fnum8, block, KR; + + for (fnum8 = 0; fnum8 < 2; fnum8++) + for (block = 0; block < 8; block++) + for (KR = 0; KR < 2; KR++) + { + if(KR != 0) + rksTable[fnum8][block][KR] = (block << 1) + fnum8; + else + rksTable[fnum8][block][KR] = block >> 1; + } +} + +/************************************************************ + + Calc Parameters + +************************************************************/ + +INLINE static e_uint32 +calc_eg_dphase (OPLL_SLOT * slot) +{ + + switch (slot->eg_mode) + { + case ATTACK: + return dphaseARTable[slot->patch.AR][slot->rks]; + + case DECAY: + return dphaseDRTable[slot->patch.DR][slot->rks]; + + case SUSHOLD: + return 0; + + case SUSTINE: + return dphaseDRTable[slot->patch.RR][slot->rks]; + + case RELEASE: + if(slot->sustine) + return dphaseDRTable[5][slot->rks]; + else if(slot->patch.EG) + return dphaseDRTable[slot->patch.RR][slot->rks]; + else + return dphaseDRTable[7][slot->rks]; + + case FINISH: + return 0; + + default: + return 0; + } +} + +/************************************************************* + + OPLL internal interfaces + +*************************************************************/ + +#define UPDATE_PG(S) (S)->dphase = dphaseTable[(S)->fnum][(S)->block][(S)->patch.ML] +#define UPDATE_TLL(S)\ +(((S)->type==0)?\ +((S)->tll = tllTable[((S)->fnum)>>5][(S)->block][(S)->patch.TL][(S)->patch.KL]):\ +((S)->tll = tllTable[((S)->fnum)>>5][(S)->block][(S)->volume][(S)->patch.KL])) +#define UPDATE_RKS(S) (S)->rks = rksTable[((S)->fnum)>>8][(S)->block][(S)->patch.KR] +#define UPDATE_WF(S) (S)->sintbl = waveform[(S)->patch.WF] +#define UPDATE_EG(S) (S)->eg_dphase = calc_eg_dphase(S) +#define UPDATE_ALL(S)\ + UPDATE_PG(S);\ + UPDATE_TLL(S);\ + UPDATE_RKS(S);\ + UPDATE_WF(S); \ + UPDATE_EG(S) /* EG should be updated last. */ + + +/* Slot key on */ +INLINE static void +slotOn (OPLL_SLOT * slot) +{ + slot->eg_mode = ATTACK; + slot->eg_phase = 0; + slot->phase = 0; +} + +/* Slot key on without reseting the phase */ +INLINE static void +slotOn2 (OPLL_SLOT * slot) +{ + slot->eg_mode = ATTACK; + slot->eg_phase = 0; +} + +/* Slot key off */ +INLINE static void +slotOff (OPLL_SLOT * slot) +{ + if(slot->eg_mode == ATTACK) + slot->eg_phase = EXPAND_BITS (AR_ADJUST_TABLE[HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS)], EG_BITS, EG_DP_BITS); + slot->eg_mode = RELEASE; +} + +/* Channel key on */ +INLINE static void +keyOn (OPLL * opll, e_int32 i) +{ + if(!opll->slot_on_flag[i * 2]) + slotOn (MOD(opll,i)); + if(!opll->slot_on_flag[i * 2 + 1]) + slotOn (CAR(opll,i)); + opll->key_status[i] = 1; +} + +/* Channel key off */ +INLINE static void +keyOff (OPLL * opll, e_int32 i) +{ + if(opll->slot_on_flag[i * 2 + 1]) + slotOff (CAR(opll,i)); + opll->key_status[i] = 0; +} + +/* Set sustine parameter */ +INLINE static void +setSustine (OPLL * opll, e_int32 c, e_int32 sustine) +{ + CAR(opll,c)->sustine = sustine; + if(MOD(opll,c)->type) + MOD(opll,c)->sustine = sustine; +} + +/* Volume : 6bit ( Volume register << 2 ) */ +INLINE static void +setVolume (OPLL * opll, e_int32 c, e_int32 volume) +{ + CAR(opll,c)->volume = volume; +} + +INLINE static void +setSlotVolume (OPLL_SLOT * slot, e_int32 volume) +{ + slot->volume = volume; +} + +/* Set F-Number ( fnum : 9bit ) */ +INLINE static void +setFnumber (OPLL * opll, e_int32 c, e_int32 fnum) +{ + CAR(opll,c)->fnum = fnum; + MOD(opll,c)->fnum = fnum; +} + +/* Set Block data (block : 3bit ) */ +INLINE static void +setBlock (OPLL * opll, e_int32 c, e_int32 block) +{ + CAR(opll,c)->block = block; + MOD(opll,c)->block = block; +} + +INLINE static void update_key_status (OPLL * opll) +{ + int ch; + + for (ch = 0; ch < 6; ch++) + opll->slot_on_flag[ch * 2] = opll->slot_on_flag[ch * 2 + 1] = (opll->HiFreq[ch]) & 0x10; +} + +/*********************************************************** + + Initializing + +***********************************************************/ + +static void +OPLL_SLOT_reset (OPLL_SLOT * slot, int type) +{ + slot->type = type; + slot->sintbl = waveform[0]; + slot->phase = 0; + slot->dphase = 0; + slot->output[0] = 0; + slot->output[1] = 0; + slot->feedback = 0; + slot->eg_mode = SETTLE; + slot->eg_phase = EG_DP_WIDTH; + slot->eg_dphase = 0; + slot->rks = 0; + slot->tll = 0; + slot->sustine = 0; + slot->fnum = 0; + slot->block = 0; + slot->volume = 0; + slot->pgout = 0; + slot->egout = 0; +} + +static void +internal_refresh (void) +{ + makeDphaseTable (); + makeDphaseARTable (); + makeDphaseDRTable (); + pm_dphase = (e_uint32) rate_adjust (PM_SPEED * PM_DP_WIDTH / (clk / 72)); + am_dphase = (e_uint32) rate_adjust (AM_SPEED * AM_DP_WIDTH / (clk / 72)); +} + +static void +maketables (e_uint32 c, e_uint32 r) +{ + if(c != clk) + { + clk = c; + makePmTable (); + makeAmTable (); + makeDB2LinTable (); + makeAdjustTable (); + makeTllTable (); + makeRksTable (); + makeSinTable (); + /*makeDefaultPatch ();*/ + } + + if(r != rate) + { + rate = r; + internal_refresh (); + } +} + +OPLL *OPLL_new (e_uint32 clk, e_uint32 rate) +{ + OPLL *opll; + + maketables (clk, rate); + + opll = (OPLL *) calloc (sizeof (OPLL), 1); + if(opll == NULL) + return NULL; + + opll->mask = 0; + + OPLL_reset (opll); + + return opll; +} + + +void +OPLL_delete (OPLL * opll) +{ + free (opll); +} + +/* Reset whole of OPLL except patch datas. */ +void +OPLL_reset (OPLL * opll) +{ + e_int32 i; + + if(!opll) + return; + + opll->adr = 0; + opll->out = 0; + + opll->pm_phase = 0; + opll->am_phase = 0; + + opll->mask = 0; + + for (i = 0; i < 12; i++) + OPLL_SLOT_reset(&opll->slot[i], i%2); + + for (i = 0; i < 6; i++) + { + opll->key_status[i] = 0; + /*setPatch (opll, i, 0);*/ + } + + for (i = 0; i < 0x40; i++) + OPLL_writeReg (opll, i, 0); + +#ifndef EMU2413_COMPACTION + opll->realstep = (e_uint32) ((1 << 31) / rate); + opll->opllstep = (e_uint32) ((1 << 31) / (clk / 72)); + opll->oplltime = 0; +#endif +} + +/* Force Refresh (When external program changes some parameters). */ +void +OPLL_forceRefresh (OPLL * opll) +{ + e_int32 i; + + if(opll == NULL) + return; + + for (i = 0; i < 12; i++) + { + UPDATE_PG (&opll->slot[i]); + UPDATE_RKS (&opll->slot[i]); + UPDATE_TLL (&opll->slot[i]); + UPDATE_WF (&opll->slot[i]); + UPDATE_EG (&opll->slot[i]); + } +} + +void +OPLL_set_rate (OPLL * opll, e_uint32 r) +{ + if(opll->quality) + rate = 49716; + else + rate = r; + internal_refresh (); + rate = r; +} + +void +OPLL_set_quality (OPLL * opll, e_uint32 q) +{ + opll->quality = q; + OPLL_set_rate (opll, rate); +} + +/********************************************************* + + Generate wave data + +*********************************************************/ +/* Convert Amp(0 to EG_HEIGHT) to Phase(0 to 2PI). */ +#if( SLOT_AMP_BITS - PG_BITS ) > 0 +#define wave2_2pi(e) ( (e) >> ( SLOT_AMP_BITS - PG_BITS )) +#else +#define wave2_2pi(e) ( (e) << ( PG_BITS - SLOT_AMP_BITS )) +#endif + +/* Convert Amp(0 to EG_HEIGHT) to Phase(0 to 4PI). */ +#if( SLOT_AMP_BITS - PG_BITS - 1 ) == 0 +#define wave2_4pi(e) (e) +#elif( SLOT_AMP_BITS - PG_BITS - 1 ) > 0 +#define wave2_4pi(e) ( (e) >> ( SLOT_AMP_BITS - PG_BITS - 1 )) +#else +#define wave2_4pi(e) ( (e) << ( 1 + PG_BITS - SLOT_AMP_BITS )) +#endif + +/* Convert Amp(0 to EG_HEIGHT) to Phase(0 to 8PI). */ +#if( SLOT_AMP_BITS - PG_BITS - 2 ) == 0 +#define wave2_8pi(e) (e) +#elif( SLOT_AMP_BITS - PG_BITS - 2 ) > 0 +#define wave2_8pi(e) ( (e) >> ( SLOT_AMP_BITS - PG_BITS - 2 )) +#else +#define wave2_8pi(e) ( (e) << ( 2 + PG_BITS - SLOT_AMP_BITS )) +#endif + + + +/* Update AM, PM unit */ +static void +update_ampm (OPLL * opll) +{ + opll->pm_phase = (opll->pm_phase + pm_dphase) & (PM_DP_WIDTH - 1); + opll->am_phase = (opll->am_phase + am_dphase) & (AM_DP_WIDTH - 1); + opll->lfo_am = amtable[HIGHBITS (opll->am_phase, AM_DP_BITS - AM_PG_BITS)]; + opll->lfo_pm = pmtable[HIGHBITS (opll->pm_phase, PM_DP_BITS - PM_PG_BITS)]; +} + +/* PG */ +INLINE static void +calc_phase (OPLL_SLOT * slot, e_int32 lfo) +{ + if(slot->patch.PM) + slot->phase += (slot->dphase * lfo) >> PM_AMP_BITS; + else + slot->phase += slot->dphase; + + slot->phase &= (DP_WIDTH - 1); + + slot->pgout = HIGHBITS (slot->phase, DP_BASE_BITS); +} + +/* EG */ +static void +calc_envelope (OPLL_SLOT * slot, e_int32 lfo) +{ +#define S2E(x) (SL2EG((e_int32)(x/SL_STEP))<<(EG_DP_BITS-EG_BITS)) + + static e_uint32 SL[16] = { + S2E (0.0), S2E (3.0), S2E (6.0), S2E (9.0), S2E (12.0), S2E (15.0), S2E (18.0), S2E (21.0), + S2E (24.0), S2E (27.0), S2E (30.0), S2E (33.0), S2E (36.0), S2E (39.0), S2E (42.0), S2E (48.0) + }; + + e_uint32 egout; + + switch (slot->eg_mode) + { + + case ATTACK: + egout = AR_ADJUST_TABLE[HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS)]; + slot->eg_phase += slot->eg_dphase; + if((EG_DP_WIDTH & slot->eg_phase)||(slot->patch.AR==15)) + { + egout = 0; + slot->eg_phase = 0; + slot->eg_mode = DECAY; + UPDATE_EG (slot); + } + break; + + case DECAY: + egout = HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS); + slot->eg_phase += slot->eg_dphase; + if(slot->eg_phase >= SL[slot->patch.SL]) + { + if(slot->patch.EG) + { + slot->eg_phase = SL[slot->patch.SL]; + slot->eg_mode = SUSHOLD; + UPDATE_EG (slot); + } + else + { + slot->eg_phase = SL[slot->patch.SL]; + slot->eg_mode = SUSTINE; + UPDATE_EG (slot); + } + } + break; + + case SUSHOLD: + egout = HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS); + if(slot->patch.EG == 0) + { + slot->eg_mode = SUSTINE; + UPDATE_EG (slot); + } + break; + + case SUSTINE: + case RELEASE: + egout = HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS); + slot->eg_phase += slot->eg_dphase; + if(egout >= (1 << EG_BITS)) + { + slot->eg_mode = FINISH; + egout = (1 << EG_BITS) - 1; + } + break; + + case FINISH: + egout = (1 << EG_BITS) - 1; + break; + + default: + egout = (1 << EG_BITS) - 1; + break; + } + + if(slot->patch.AM) + egout = EG2DB (egout + slot->tll) + lfo; + else + egout = EG2DB (egout + slot->tll); + + if(egout >= DB_MUTE) + egout = DB_MUTE - 1; + + slot->egout = egout; +} + +/* CARRIOR */ +INLINE static e_int32 +calc_slot_car (OPLL_SLOT * slot, e_int32 fm) +{ + slot->output[1] = slot->output[0]; + + if(slot->egout >= (DB_MUTE - 1)) + { + slot->output[0] = 0; + } + else + { + slot->output[0] = DB2LIN_TABLE[slot->sintbl[(slot->pgout+wave2_8pi(fm))&(PG_WIDTH-1)] + slot->egout]; + } + + return (slot->output[1] + slot->output[0]) >> 1; +} + +/* MODULATOR */ +INLINE static e_int32 +calc_slot_mod (OPLL_SLOT * slot) +{ + e_int32 fm; + + slot->output[1] = slot->output[0]; + + if(slot->egout >= (DB_MUTE - 1)) + { + slot->output[0] = 0; + } + else if(slot->patch.FB != 0) + { + fm = wave2_4pi (slot->feedback) >> (7 - slot->patch.FB); + slot->output[0] = DB2LIN_TABLE[slot->sintbl[(slot->pgout + fm)&(PG_WIDTH-1)] + slot->egout]; + } + else + { + slot->output[0] = DB2LIN_TABLE[slot->sintbl[slot->pgout] + slot->egout]; + } + + slot->feedback = (slot->output[1] + slot->output[0]) >> 1; + + return slot->feedback; + +} + +static INLINE e_int16 calc (OPLL * opll) +{ + e_int32 inst = 0, out = 0; + e_int32 i; + + update_ampm (opll); + + for (i = 0; i < 12; i++) + { + calc_phase(&opll->slot[i],opll->lfo_pm); + calc_envelope(&opll->slot[i],opll->lfo_am); + } + + for (i = 0; i < 6; i++) + if(!(opll->mask & OPLL_MASK_CH (i)) && (CAR(opll,i)->eg_mode != FINISH)) + inst += calc_slot_car (CAR(opll,i), calc_slot_mod(MOD(opll,i))); + + out = inst; + return (e_int16) out; +} + +void moocow(OPLL* opll, e_int32 *buf, e_int32 len, int shift) +{ + while(len > 0) + { + *buf+=(calc(opll)+32768)<quality) + return calc (opll); + + while (opll->realstep > opll->oplltime) + { + opll->oplltime += opll->opllstep; + opll->prev = opll->next; + opll->next = calc (opll); + } + + opll->oplltime -= opll->realstep; + opll->out = (e_int16) (((double) opll->next * (opll->opllstep - opll->oplltime) + + (double) opll->prev * opll->oplltime) / opll->opllstep); + + return (e_int16) opll->out; +} +#endif + +e_uint32 +OPLL_setMask (OPLL * opll, e_uint32 mask) +{ + e_uint32 ret; + + if(opll) + { + ret = opll->mask; + opll->mask = mask; + return ret; + } + else + return 0; +} + +e_uint32 +OPLL_toggleMask (OPLL * opll, e_uint32 mask) +{ + e_uint32 ret; + + if(opll) + { + ret = opll->mask; + opll->mask ^= mask; + return ret; + } + else + return 0; +} + +/**************************************************** + + I/O Ctrl + +*****************************************************/ + +static void setInstrument(OPLL * opll, e_uint i, e_uint inst) +{ + const e_uint8 *src; + OPLL_PATCH *modp, *carp; + + opll->patch_number[i]=inst; + + if(inst) + src=default_inst[inst-1]; + else + src=opll->CustInst; + + modp=&MOD(opll,i)->patch; + carp=&CAR(opll,i)->patch; + + modp->AM=(src[0]>>7)&1; + modp->PM=(src[0]>>6)&1; + modp->EG=(src[0]>>5)&1; + modp->KR=(src[0]>>4)&1; + modp->ML=(src[0]&0xF); + + carp->AM=(src[1]>>7)&1; + carp->PM=(src[1]>>6)&1; + carp->EG=(src[1]>>5)&1; + carp->KR=(src[1]>>4)&1; + carp->ML=(src[1]&0xF); + + modp->KL=(src[2]>>6)&3; + modp->TL=(src[2]&0x3F); + + carp->KL = (src[3] >> 6) & 3; + carp->WF = (src[3] >> 4) & 1; + + modp->WF = (src[3] >> 3) & 1; + + modp->FB = (src[3]) & 7; + + modp->AR = (src[4]>>4)&0xF; + modp->DR = (src[4]&0xF); + + carp->AR = (src[5]>>4)&0xF; + carp->DR = (src[5]&0xF); + + modp->SL = (src[6]>>4)&0xF; + modp->RR = (src[6]&0xF); + + carp->SL = (src[7]>>4)&0xF; + carp->RR = (src[7]&0xF); +} + + +void +OPLL_writeReg (OPLL * opll, e_uint32 reg, e_uint32 data) +{ + + e_int32 i, v, ch; + + data = data & 0xff; + reg = reg & 0x3f; + + switch (reg) + { + case 0x00: + opll->CustInst[0]=data; + for (i = 0; i < 6; i++) + { + if(opll->patch_number[i] == 0) + { + setInstrument(opll, i, 0); + UPDATE_PG (MOD(opll,i)); + UPDATE_RKS (MOD(opll,i)); + UPDATE_EG (MOD(opll,i)); + } + } + break; + + case 0x01: + opll->CustInst[1]=data; + for (i = 0; i < 6; i++) + { + if(opll->patch_number[i] == 0) + { + setInstrument(opll, i, 0); + UPDATE_PG (CAR(opll,i)); + UPDATE_RKS (CAR(opll,i)); + UPDATE_EG (CAR(opll,i)); + } + } + break; + + case 0x02: + opll->CustInst[2]=data; + for (i = 0; i < 6; i++) + { + if(opll->patch_number[i] == 0) + { + setInstrument(opll, i, 0); + UPDATE_TLL(MOD(opll,i)); + } + } + break; + + case 0x03: + opll->CustInst[3]=data; + for (i = 0; i < 6; i++) + { + if(opll->patch_number[i] == 0) + { + setInstrument(opll, i, 0); + UPDATE_WF(MOD(opll,i)); + UPDATE_WF(CAR(opll,i)); + } + } + break; + + case 0x04: + opll->CustInst[4]=data; + for (i = 0; i < 6; i++) + { + if(opll->patch_number[i] == 0) + { + setInstrument(opll, i, 0); + UPDATE_EG (MOD(opll,i)); + } + } + break; + + case 0x05: + opll->CustInst[5]=data; + for (i = 0; i < 6; i++) + { + if(opll->patch_number[i] == 0) + { + setInstrument(opll, i, 0); + UPDATE_EG(CAR(opll,i)); + } + } + break; + + case 0x06: + opll->CustInst[6]=data; + for (i = 0; i < 6; i++) + { + if(opll->patch_number[i] == 0) + { + setInstrument(opll, i, 0); + UPDATE_EG (MOD(opll,i)); + } + } + break; + + case 0x07: + opll->CustInst[7]=data; + for (i = 0; i < 6; i++) + { + if(opll->patch_number[i] == 0) + { + setInstrument(opll, i, 0); + UPDATE_EG (CAR(opll,i)); + } + } + break; + + case 0x10: + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + ch = reg - 0x10; + opll->LowFreq[ch]=data; + setFnumber (opll, ch, data + ((opll->HiFreq[ch] & 1) << 8)); + UPDATE_ALL (MOD(opll,ch)); + UPDATE_ALL (CAR(opll,ch)); + break; + + case 0x20: + case 0x21: + case 0x22: + case 0x23: + case 0x24: + case 0x25: + ch = reg - 0x20; + opll->HiFreq[ch]=data; + + setFnumber (opll, ch, ((data & 1) << 8) + opll->LowFreq[ch]); + setBlock (opll, ch, (data >> 1) & 7); + setSustine (opll, ch, (data >> 5) & 1); + if(data & 0x10) + keyOn (opll, ch); + else + keyOff (opll, ch); + UPDATE_ALL (MOD(opll,ch)); + UPDATE_ALL (CAR(opll,ch)); + update_key_status (opll); + break; + + case 0x30: + case 0x31: + case 0x32: + case 0x33: + case 0x34: + case 0x35: + opll->InstVol[reg-0x30]=data; + i = (data >> 4) & 15; + v = data & 15; + setInstrument(opll, reg-0x30, i); + setVolume (opll, reg - 0x30, v << 2); + UPDATE_ALL (MOD(opll,reg - 0x30)); + UPDATE_ALL (CAR(opll,reg - 0x30)); + break; + + default: + break; + + } +} + +void +OPLL_writeIO (OPLL * opll, e_uint32 adr, e_uint32 val) +{ + if(adr & 1) + OPLL_writeReg (opll, opll->adr, val); + else + opll->adr = val; +} + diff --git a/fceumm/src-fceumm/mappers/emu2413.h b/fceumm/src-fceumm/mappers/emu2413.h new file mode 100644 index 0000000..906b4c5 --- /dev/null +++ b/fceumm/src-fceumm/mappers/emu2413.h @@ -0,0 +1,134 @@ +#ifndef _EMU2413_H_ +#define _EMU2413_H_ + +#include "emutypes.h" + +#ifdef EMU2413_DLL_EXPORTS + #define EMU2413_API __declspec(dllexport) +#elif defined(EMU2413_DLL_IMPORTS) + #define EMU2413_API __declspec(dllimport) +#else + #define EMU2413_API +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#define PI 3.14159265358979323846 + +enum {OPLL_VRC7_TONE=0} ; + +/* voice data */ +typedef struct { + e_uint32 TL,FB,EG,ML,AR,DR,SL,RR,KR,KL,AM,PM,WF ; +} OPLL_PATCH ; + +/* slot */ +typedef struct { + + OPLL_PATCH patch; + + e_int32 type ; /* 0 : modulator 1 : carrier */ + + /* OUTPUT */ + e_int32 feedback ; + e_int32 output[2] ; /* Output value of slot */ + + /* for Phase Generator (PG) */ + e_uint16 *sintbl ; /* Wavetable */ + e_uint32 phase ; /* Phase */ + e_uint32 dphase ; /* Phase increment amount */ + e_uint32 pgout ; /* output */ + + /* for Envelope Generator (EG) */ + e_int32 fnum ; /* F-Number */ + e_int32 block ; /* Block */ + e_int32 volume ; /* Current volume */ + e_int32 sustine ; /* Sustine 1 = ON, 0 = OFF */ + e_uint32 tll ; /* Total Level + Key scale level*/ + e_uint32 rks ; /* Key scale offset (Rks) */ + e_int32 eg_mode ; /* Current state */ + e_uint32 eg_phase ; /* Phase */ + e_uint32 eg_dphase ; /* Phase increment amount */ + e_uint32 egout ; /* output */ + +} OPLL_SLOT ; + +/* Mask */ +#define OPLL_MASK_CH(x) (1<<(x)) + +/* opll */ +typedef struct { + + e_uint32 adr ; + e_int32 out ; + +#ifndef EMU2413_COMPACTION + e_uint32 realstep ; + e_uint32 oplltime ; + e_uint32 opllstep ; + e_int32 prev, next ; +#endif + + /* Register */ + e_uint8 LowFreq[6]; + e_uint8 HiFreq[6]; + e_uint8 InstVol[6]; + + e_uint8 CustInst[8]; + + e_int32 slot_on_flag[6 * 2] ; + + /* Pitch Modulator */ + e_uint32 pm_phase ; + e_int32 lfo_pm ; + + /* Amp Modulator */ + e_int32 am_phase ; + e_int32 lfo_am ; + + e_uint32 quality; + + /* Channel Data */ + e_int32 patch_number[6]; + e_int32 key_status[6] ; + + /* Slot */ + OPLL_SLOT slot[6 * 2] ; + + e_uint32 mask ; + +} OPLL ; + +/* Create Object */ +EMU2413_API OPLL *OPLL_new(e_uint32 clk, e_uint32 rate) ; +EMU2413_API void OPLL_delete(OPLL *) ; + +/* Setup */ +EMU2413_API void OPLL_reset(OPLL *) ; +EMU2413_API void OPLL_set_rate(OPLL *opll, e_uint32 r) ; +EMU2413_API void OPLL_set_quality(OPLL *opll, e_uint32 q) ; + +/* Port/Register access */ +EMU2413_API void OPLL_writeIO(OPLL *, e_uint32 reg, e_uint32 val) ; +EMU2413_API void OPLL_writeReg(OPLL *, e_uint32 reg, e_uint32 val) ; + +/* Synthsize */ +EMU2413_API e_int16 OPLL_calc(OPLL *) ; + +/* Misc */ +EMU2413_API void OPLL_forceRefresh(OPLL *) ; + +/* Channel Mask */ +EMU2413_API e_uint32 OPLL_setMask(OPLL *, e_uint32 mask) ; +EMU2413_API e_uint32 OPLL_toggleMask(OPLL *, e_uint32 mask) ; + + +void moocow(OPLL* opll, e_int32 *buf, e_int32 len, int shift); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/fceumm/src-fceumm/mappers/emutypes.h b/fceumm/src-fceumm/mappers/emutypes.h new file mode 100644 index 0000000..fdef420 --- /dev/null +++ b/fceumm/src-fceumm/mappers/emutypes.h @@ -0,0 +1,44 @@ +#ifndef _EMUTYPES_H_ +#define _EMUTYPES_H_ + +#ifndef INLINE + +#if defined(_MSC_VER) +#define INLINE __forceinline +#elif defined(__GNUC__) +#define INLINE __inline__ +#elif defined(_MWERKS_) +#define INLINE inline +#else +#define INLINE +#endif +#endif + +#if defined(EMU_DLL_IMPORTS) +#define EMU2149_DLL_IMPORTS +#define EMU2212_DLL_IMPORTS +#define EMU2413_DLL_IMPORTS +#define EMU8950_DLL_IMPORTS +#define EMU76489_DLL_IMPORTS +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef unsigned int e_uint; +typedef signed int e_int; + +typedef unsigned char e_uint8 ; +typedef signed char e_int8 ; + +typedef unsigned short e_uint16 ; +typedef signed short e_int16 ; + +typedef unsigned int e_uint32 ; +typedef signed int e_int32 ; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/fceumm/src-fceumm/mappers/mapinc.h b/fceumm/src-fceumm/mappers/mapinc.h new file mode 100644 index 0000000..694a7c9 --- /dev/null +++ b/fceumm/src-fceumm/mappers/mapinc.h @@ -0,0 +1,11 @@ +#include "../types.h" +#include "../x6502.h" +#include "../fceu.h" +#include "../ppu.h" +#define INESPRIV +#include "../cart.h" +#include "../ines.h" +#include "../memory.h" +#include "../sound.h" +#include "../state.h" +#include diff --git a/fceumm/src-fceumm/mappers/mmc2and4.c b/fceumm/src-fceumm/mappers/mmc2and4.c new file mode 100644 index 0000000..6033e88 --- /dev/null +++ b/fceumm/src-fceumm/mappers/mmc2and4.c @@ -0,0 +1,121 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +#define MMC4reg mapbyte1 +#define latcha1 mapbyte2[0] +#define latcha2 mapbyte2[1] + + +static void latchcheck(uint32 VAddr) +{ + uint8 l,h; + + h=VAddr>>8; + + if(h>=0x20 || ((h&0xF)!=0xF)) + return; + + l=VAddr&0xF0; + + if(h<0x10) + { + if(l==0xD0) + { + VROM_BANK4(0x0000,MMC4reg[0]); + latcha1=0xFD; + } + else if(l==0xE0) + { + VROM_BANK4(0x0000,MMC4reg[1]); + latcha1=0xFE; + } + } + else + { + if(l==0xD0) + { + VROM_BANK4(0x1000,MMC4reg[2]); + latcha2=0xFD; + } + else if(l==0xE0) + { + VROM_BANK4(0x1000,MMC4reg[3]); + latcha2=0xFE; + } + } +} + +DECLFW(Mapper9_write) /* $Axxx*/ +{ + ROM_BANK8(0x8000,V); +} + +DECLFW(Mapper10_write) +{ + ROM_BANK16(0x8000,V); +} + +DECLFW(Mapper9and10_write) +{ + switch(A&0xF000) + { + case 0xB000: + if(latcha1==0xFD) { VROM_BANK4(0x0000,V);} + MMC4reg[0]=V; + break; + case 0xC000: + if(latcha1==0xFE) {VROM_BANK4(0x0000,V);} + MMC4reg[1]=V; + break; + case 0xD000: + if(latcha2==0xFD) {VROM_BANK4(0x1000,V);} + MMC4reg[2]=V; + break; + case 0xE000: + if(latcha2==0xFE) {VROM_BANK4(0x1000,V);} + MMC4reg[3]=V; + break; + case 0xF000: + MIRROR_SET(V&1); + break; + } +} + +void Mapper9_init(void) +{ + latcha1=0xFE; + latcha2=0xFE; + ROM_BANK8(0xA000,~2); + ROM_BANK8(0x8000,0); + SetWriteHandler(0xA000,0xAFFF,Mapper9_write); + SetWriteHandler(0xB000,0xFFFF,Mapper9and10_write); + PPU_hook=latchcheck; +} + +void Mapper10_init(void) +{ + latcha1=latcha2=0xFE; + SetWriteHandler(0xA000,0xAFFF,Mapper10_write); + SetWriteHandler(0xB000,0xFFFF,Mapper9and10_write); + PPU_hook=latchcheck; +} + diff --git a/fceumm/src-fceumm/mappers/simple.c b/fceumm/src-fceumm/mappers/simple.c new file mode 100644 index 0000000..82442cb --- /dev/null +++ b/fceumm/src-fceumm/mappers/simple.c @@ -0,0 +1,84 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 1998 BERO + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 latche; + +static DECLFW(Mapper34_write) +{ + switch(A) + { + case 0x7FFD:ROM_BANK32(V);break; + case 0x7FFE:VROM_BANK4(0x0000,V);break; + case 0x7fff:VROM_BANK4(0x1000,V);break; + } + if(A>=0x8000) + ROM_BANK32(V); +} + +void Mapper34_init(void) +{ + ROM_BANK32(0); + SetWriteHandler(0x7ffd,0xffff,Mapper34_write); +} + +/* I might want to add some code to the mapper 96 PPU hook function + to not change CHR banks if the attribute table is being accessed, + if I make emulation a little more accurate in the future. +*/ + +static uint8 M96LA; +static DECLFW(Mapper96_write) +{ + latche=V; + setprg32(0x8000,V&3); + setchr4r(0x10,0x0000,(latche&4)|M96LA); + setchr4r(0x10,0x1000,(latche&4)|3); +} + +static void M96Hook(uint32 A) +{ + if((A&0x3000)!=0x2000) return; + /*if((A&0x3ff)>=0x3c0) return;*/ + M96LA=(A>>8)&3; + setchr4r(0x10,0x0000,(latche&4)|M96LA); +} + +static void M96Sync(int v) +{ + setprg32(0x8000,latche&3); + setchr4r(0x10,0x0000,(latche&4)|M96LA); + setchr4r(0x10,0x1000,(latche&4)|3); +} + +void Mapper96_init(void) +{ + SetWriteHandler(0x8000,0xffff,Mapper96_write); + PPU_hook=M96Hook; + AddExState(&latche, 1, 0, "LATC"); + AddExState(&M96LA, 1, 0, "LAVA"); + SetupCartCHRMapping(0x10, MapperExRAM, 32768, 1); + latche=M96LA=0; + M96Sync(0); + setmirror(MI_0); + GameStateRestore=M96Sync; +} diff --git a/fceumm/src-fceumm/mappers/vrc7tone.h b/fceumm/src-fceumm/mappers/vrc7tone.h new file mode 100644 index 0000000..d136307 --- /dev/null +++ b/fceumm/src-fceumm/mappers/vrc7tone.h @@ -0,0 +1,17 @@ +/* VRC7 instruments, January 17, 2004 update -Xodnizel */ + {0x03, 0x21, 0x04, 0x06, 0x8D, 0xF2, 0x42, 0x17}, + {0x13, 0x41, 0x05, 0x0E, 0x99, 0x96, 0x63, 0x12}, + {0x31, 0x11, 0x10, 0x0A, 0xF0, 0x9C, 0x32, 0x02}, + {0x21, 0x61, 0x1D, 0x07, 0x9F, 0x64, 0x20, 0x27}, + {0x22, 0x21, 0x1E, 0x06, 0xF0, 0x76, 0x08, 0x28}, + {0x02, 0x01, 0x06, 0x00, 0xF0, 0xF2, 0x03, 0x95}, + {0x21, 0x61, 0x1C, 0x07, 0x82, 0x81, 0x16, 0x07}, + {0x23, 0x21, 0x1A, 0x17, 0xEF, 0x82, 0x25, 0x15}, + {0x25, 0x11, 0x1F, 0x00, 0x86, 0x41, 0x20, 0x11}, + {0x85, 0x01, 0x1F, 0x0F, 0xE4, 0xA2, 0x11, 0x12}, + {0x07, 0xC1, 0x2B, 0x45, 0xB4, 0xF1, 0x24, 0xF4}, + {0x61, 0x23, 0x11, 0x06, 0x96, 0x96, 0x13, 0x16}, + {0x01, 0x02, 0xD3, 0x05, 0x82, 0xA2, 0x31, 0x51}, + {0x61, 0x22, 0x0D, 0x02, 0xC3, 0x7F, 0x24, 0x05}, + {0x21, 0x62, 0x0E, 0x00, 0xA1, 0xA0, 0x44, 0x17}, + diff --git a/fceumm/src-fceumm/md5.c b/fceumm/src-fceumm/md5.c new file mode 100644 index 0000000..bb18600 --- /dev/null +++ b/fceumm/src-fceumm/md5.c @@ -0,0 +1,246 @@ +/* + * RFC 1321 compliant MD5 implementation, + * by Christophe Devine ; + * this program is licensed under the GPL. + */ + +/* Modified October 3, 2003, to remove testing code, and add + include of "types.h". + + Added simple MD5 to ASCII string conversion function. + -Xodnizel +*/ + +#include +#include "types.h" +#include "md5.h" + +#define GET_UINT32(n,b,i) \ +{ \ + (n) = ( (uint32) (b)[(i) + 3] << 24 ) \ + | ( (uint32) (b)[(i) + 2] << 16 ) \ + | ( (uint32) (b)[(i) + 1] << 8 ) \ + | ( (uint32) (b)[(i) ] ); \ +} + +#define PUT_UINT32(n,b,i) \ +{ \ + (b)[(i) ] = (uint8) ( (n) ); \ + (b)[(i) + 1] = (uint8) ( (n) >> 8 ); \ + (b)[(i) + 2] = (uint8) ( (n) >> 16 ); \ + (b)[(i) + 3] = (uint8) ( (n) >> 24 ); \ +} + +void md5_starts( struct md5_context *ctx ) +{ + ctx->total[0] = 0; + ctx->total[1] = 0; + ctx->state[0] = 0x67452301; + ctx->state[1] = 0xEFCDAB89; + ctx->state[2] = 0x98BADCFE; + ctx->state[3] = 0x10325476; +} + +static void md5_process( struct md5_context *ctx, uint8 data[64] ) +{ + uint32 A, B, C, D, X[16]; + + GET_UINT32( X[0], data, 0 ); + GET_UINT32( X[1], data, 4 ); + GET_UINT32( X[2], data, 8 ); + GET_UINT32( X[3], data, 12 ); + GET_UINT32( X[4], data, 16 ); + GET_UINT32( X[5], data, 20 ); + GET_UINT32( X[6], data, 24 ); + GET_UINT32( X[7], data, 28 ); + GET_UINT32( X[8], data, 32 ); + GET_UINT32( X[9], data, 36 ); + GET_UINT32( X[10], data, 40 ); + GET_UINT32( X[11], data, 44 ); + GET_UINT32( X[12], data, 48 ); + GET_UINT32( X[13], data, 52 ); + GET_UINT32( X[14], data, 56 ); + GET_UINT32( X[15], data, 60 ); + +#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) + +#define P(a,b,c,d,k,s,t) \ +{ \ + a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \ +} + + A = ctx->state[0]; + B = ctx->state[1]; + C = ctx->state[2]; + D = ctx->state[3]; + +#define F(x,y,z) (z ^ (x & (y ^ z))) + + P( A, B, C, D, 0, 7, 0xD76AA478 ); + P( D, A, B, C, 1, 12, 0xE8C7B756 ); + P( C, D, A, B, 2, 17, 0x242070DB ); + P( B, C, D, A, 3, 22, 0xC1BDCEEE ); + P( A, B, C, D, 4, 7, 0xF57C0FAF ); + P( D, A, B, C, 5, 12, 0x4787C62A ); + P( C, D, A, B, 6, 17, 0xA8304613 ); + P( B, C, D, A, 7, 22, 0xFD469501 ); + P( A, B, C, D, 8, 7, 0x698098D8 ); + P( D, A, B, C, 9, 12, 0x8B44F7AF ); + P( C, D, A, B, 10, 17, 0xFFFF5BB1 ); + P( B, C, D, A, 11, 22, 0x895CD7BE ); + P( A, B, C, D, 12, 7, 0x6B901122 ); + P( D, A, B, C, 13, 12, 0xFD987193 ); + P( C, D, A, B, 14, 17, 0xA679438E ); + P( B, C, D, A, 15, 22, 0x49B40821 ); + +#undef F + +#define F(x,y,z) (y ^ (z & (x ^ y))) + + P( A, B, C, D, 1, 5, 0xF61E2562 ); + P( D, A, B, C, 6, 9, 0xC040B340 ); + P( C, D, A, B, 11, 14, 0x265E5A51 ); + P( B, C, D, A, 0, 20, 0xE9B6C7AA ); + P( A, B, C, D, 5, 5, 0xD62F105D ); + P( D, A, B, C, 10, 9, 0x02441453 ); + P( C, D, A, B, 15, 14, 0xD8A1E681 ); + P( B, C, D, A, 4, 20, 0xE7D3FBC8 ); + P( A, B, C, D, 9, 5, 0x21E1CDE6 ); + P( D, A, B, C, 14, 9, 0xC33707D6 ); + P( C, D, A, B, 3, 14, 0xF4D50D87 ); + P( B, C, D, A, 8, 20, 0x455A14ED ); + P( A, B, C, D, 13, 5, 0xA9E3E905 ); + P( D, A, B, C, 2, 9, 0xFCEFA3F8 ); + P( C, D, A, B, 7, 14, 0x676F02D9 ); + P( B, C, D, A, 12, 20, 0x8D2A4C8A ); + +#undef F + +#define F(x,y,z) (x ^ y ^ z) + + P( A, B, C, D, 5, 4, 0xFFFA3942 ); + P( D, A, B, C, 8, 11, 0x8771F681 ); + P( C, D, A, B, 11, 16, 0x6D9D6122 ); + P( B, C, D, A, 14, 23, 0xFDE5380C ); + P( A, B, C, D, 1, 4, 0xA4BEEA44 ); + P( D, A, B, C, 4, 11, 0x4BDECFA9 ); + P( C, D, A, B, 7, 16, 0xF6BB4B60 ); + P( B, C, D, A, 10, 23, 0xBEBFBC70 ); + P( A, B, C, D, 13, 4, 0x289B7EC6 ); + P( D, A, B, C, 0, 11, 0xEAA127FA ); + P( C, D, A, B, 3, 16, 0xD4EF3085 ); + P( B, C, D, A, 6, 23, 0x04881D05 ); + P( A, B, C, D, 9, 4, 0xD9D4D039 ); + P( D, A, B, C, 12, 11, 0xE6DB99E5 ); + P( C, D, A, B, 15, 16, 0x1FA27CF8 ); + P( B, C, D, A, 2, 23, 0xC4AC5665 ); + +#undef F + +#define F(x,y,z) (y ^ (x | ~z)) + + P( A, B, C, D, 0, 6, 0xF4292244 ); + P( D, A, B, C, 7, 10, 0x432AFF97 ); + P( C, D, A, B, 14, 15, 0xAB9423A7 ); + P( B, C, D, A, 5, 21, 0xFC93A039 ); + P( A, B, C, D, 12, 6, 0x655B59C3 ); + P( D, A, B, C, 3, 10, 0x8F0CCC92 ); + P( C, D, A, B, 10, 15, 0xFFEFF47D ); + P( B, C, D, A, 1, 21, 0x85845DD1 ); + P( A, B, C, D, 8, 6, 0x6FA87E4F ); + P( D, A, B, C, 15, 10, 0xFE2CE6E0 ); + P( C, D, A, B, 6, 15, 0xA3014314 ); + P( B, C, D, A, 13, 21, 0x4E0811A1 ); + P( A, B, C, D, 4, 6, 0xF7537E82 ); + P( D, A, B, C, 11, 10, 0xBD3AF235 ); + P( C, D, A, B, 2, 15, 0x2AD7D2BB ); + P( B, C, D, A, 9, 21, 0xEB86D391 ); + +#undef F + + ctx->state[0] += A; + ctx->state[1] += B; + ctx->state[2] += C; + ctx->state[3] += D; +} + +void md5_update( struct md5_context *ctx, uint8 *input, uint32 length ) +{ + uint32 left, fill; + + if( ! length ) return; + + left = ( ctx->total[0] >> 3 ) & 0x3F; + fill = 64 - left; + + ctx->total[0] += length << 3; + ctx->total[1] += length >> 29; + + ctx->total[0] &= 0xFFFFFFFF; + ctx->total[1] += ctx->total[0] < ( length << 3 ); + + if( left && length >= fill ) + { + memcpy( (void *) (ctx->buffer + left), (void *) input, fill ); + md5_process( ctx, ctx->buffer ); + length -= fill; + input += fill; + left = 0; + } + + while( length >= 64 ) + { + md5_process( ctx, input ); + length -= 64; + input += 64; + } + + if( length ) + { + memcpy( (void *) (ctx->buffer + left), (void *) input, length ); + } +} + +static uint8 md5_padding[64] = +{ + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +void md5_finish( struct md5_context *ctx, uint8 digest[16] ) +{ + uint32 last, padn; + uint8 msglen[8]; + + PUT_UINT32( ctx->total[0], msglen, 0 ); + PUT_UINT32( ctx->total[1], msglen, 4 ); + + last = ( ctx->total[0] >> 3 ) & 0x3F; + padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last ); + + md5_update( ctx, md5_padding, padn ); + md5_update( ctx, msglen, 8 ); + + PUT_UINT32( ctx->state[0], digest, 0 ); + PUT_UINT32( ctx->state[1], digest, 4 ); + PUT_UINT32( ctx->state[2], digest, 8 ); + PUT_UINT32( ctx->state[3], digest, 12 ); +} + + +/* Uses a static buffer, so beware of how it's used. */ +char *md5_asciistr(uint8 digest[16]) +{ + static char str[33]; + static char trans[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; + int x; + + for(x=0;x<16;x++) + { + str[x*2]=trans[digest[x]>>4]; + str[x*2+1]=trans[digest[x]&0x0F]; + } + return(str); +} diff --git a/fceumm/src-fceumm/md5.h b/fceumm/src-fceumm/md5.h new file mode 100644 index 0000000..c5c8ddf --- /dev/null +++ b/fceumm/src-fceumm/md5.h @@ -0,0 +1,18 @@ +#ifndef _MD5_H +#define _MD5_H + +struct md5_context +{ + uint32 total[2]; + uint32 state[4]; + uint8 buffer[64]; +}; + +void md5_starts( struct md5_context *ctx ); +void md5_update( struct md5_context *ctx, uint8 *input, uint32 length ); +void md5_finish( struct md5_context *ctx, uint8 digest[16] ); + +/* Uses a static buffer, so beware of how it's used. */ +char *md5_asciistr(uint8 digest[16]); + +#endif /* md5.h */ diff --git a/fceumm/src-fceumm/memory.c b/fceumm/src-fceumm/memory.c new file mode 100644 index 0000000..7470c83 --- /dev/null +++ b/fceumm/src-fceumm/memory.c @@ -0,0 +1,50 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "types.h" +#include "fceu.h" +#include "memory.h" +#include "general.h" + +void *FCEU_gmalloc(uint32 size) +{ + void *ret; + ret=malloc(size); + if(!ret) + { + /*FCEU_PrintError("Error allocating memory! Doing a hard exit.");*/ + exit(1); + } + return ret; +} + +void *FCEU_malloc(uint32 size) +{ + void *ret; + ret=malloc(size); + if(!ret) + { + /*FCEU_PrintError("Error allocating memory!");*/ + return(0); + } + return ret; +} diff --git a/fceumm/src-fceumm/memory.h b/fceumm/src-fceumm/memory.h new file mode 100644 index 0000000..157cb09 --- /dev/null +++ b/fceumm/src-fceumm/memory.h @@ -0,0 +1,28 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* Various macros for faster memory stuff + (at least that's the idea) +*/ + +#define FCEU_dwmemset(d,c,n) {int _x; for(_x=n-4;_x>=0;_x-=4) *(uint32 *)&(d)[_x]=c;} + +void *FCEU_malloc(uint32 size); +void *FCEU_gmalloc(uint32 size); diff --git a/fceumm/src-fceumm/mycrc32.c b/fceumm/src-fceumm/mycrc32.c new file mode 100644 index 0000000..8378ed4 --- /dev/null +++ b/fceumm/src-fceumm/mycrc32.c @@ -0,0 +1,33 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "types.h" +#include "crc32.h" + +#include +uint32 CalcCRC32(uint32 crc, uint8 *buf, uint32 len) +{ + return(crc32(crc,buf,len)); +} + +uint32 FCEUI_CRC32(uint32 crc, uint8 *buf, uint32 len) +{ + return(CalcCRC32(crc,buf,len)); +} diff --git a/fceumm/src-fceumm/myendian.c b/fceumm/src-fceumm/myendian.c new file mode 100644 index 0000000..81d8d60 --- /dev/null +++ b/fceumm/src-fceumm/myendian.c @@ -0,0 +1,137 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* Contains file I/O functions that write/read data */ +/* LSB first. */ + +#include +#include "types.h" +#include "myendian.h" + +#ifdef __SNC__ +#include +#endif + +void FlipByteOrder(uint8 *src, uint32 count) +{ + uint8 *start=src; + uint8 *end=src+count-1; + + if((count&1) || !count) return; /* This shouldn't happen. */ + + while(count--) + { + uint8 tmp; + + tmp=*end; + *end=*start; + *start=tmp; + end--; + start++; + } +} + +/*/writes a little endian 16bit value to the specified file*/ +int write16le(uint16 b, FILE *fp) +{ + uint8 s[2]; + s[0]=(uint8)b; + s[1]=(uint8)(b>>8); + return((fwrite(s,1,2,fp)<2)?0:2); +} + +/*/writes a little endian 32bit value to the specified file*/ +int write32le(uint32 b, FILE *fp) +{ + uint8 s[4]; + s[0]=b; + s[1]=b>>8; + s[2]=b>>16; + s[3]=b>>24; + return((fwrite(s,1,4,fp)<4)?0:4); +} + +int read32le(uint32 *Bufo, FILE *fp) +{ + uint32 buf; + if(fread(&buf,1,4,fp)<4) + return 0; +#ifdef LSB_FIRST + *(uint32*)Bufo=buf; +#elif __SNC__ + *(uint32*)Bufo = __builtin_lwbrx(&buf, 0); +#else + *(uint32*)Bufo=((buf&0xFF)<<24)|((buf&0xFF00)<<8)|((buf&0xFF0000)>>8)|((buf&0xFF000000)>>24); +#endif + return 1; +} + +#ifdef __LIBSNES__ +int write32le_mem(uint32 b, memstream_t *mem) +{ + uint8 s[4]; + s[0]=b; + s[1]=b>>8; + s[2]=b>>16; + s[3]=b>>24; + return((memstream_write(mem, s, 4)<4)?0:4); +} + +int read32le_mem(uint32 *Bufo, memstream_t *mem) +{ + uint32 buf; + if(memstream_read(mem, &buf, 4)<4) + return 0; + #ifdef LSB_FIRST + *(uint32*)Bufo=buf; + #else + *(uint32*)Bufo=((buf&0xFF)<<24)|((buf&0xFF00)<<8)|((buf&0xFF0000)>>8)|((buf&0xFF000000)>>24); + #endif + return 1; +} +#endif + + +int read16le(char *d, FILE *fp) +{ +#ifdef LSB_FIRST + return((fread(d,1,2,fp)<2)?0:2); +#else + int ret; + ret=fread(d+1,1,1,fp); + ret+=fread(d,1,1,fp); + return ret<2?0:2; +#endif +} + +void FCEU_en32lsb(uint8 *buf, uint32 morp) +{ + buf[0]=morp; + buf[1]=morp>>8; + buf[2]=morp>>16; + buf[3]=morp>>24; +} + +/*/unpacks a 32bit little endian value from the provided byte array into host byte order*/ +uint32 FCEU_de32lsb(uint8 *morp) +{ + return(morp[0]|(morp[1]<<8)|(morp[2]<<16)|(morp[3]<<24)); +} + diff --git a/fceumm/src-fceumm/myendian.h b/fceumm/src-fceumm/myendian.h new file mode 100644 index 0000000..040b1b4 --- /dev/null +++ b/fceumm/src-fceumm/myendian.h @@ -0,0 +1,21 @@ +#ifndef FCEU_ENDIAN_H +#define FCEU_ENDIAN_H + +#include "types.h" + +int write16le(uint16 b, FILE *fp); +int write32le(uint32 b, FILE *fp); + +#ifdef __LIBSNES__ +#include "../libsnes-fceumm/memstream.h" +int write32le_mem(uint32 b, memstream_t *mem); +int read32le_mem(uint32 *Bufo, memstream_t *mem); +#endif + +int read32le(uint32 *Bufo, FILE *fp); +void FlipByteOrder(uint8 *src, uint32 count); + +void FCEU_en32lsb(uint8 *, uint32); +uint32 FCEU_de32lsb(uint8 *); + +#endif diff --git a/fceumm/src-fceumm/ops.h b/fceumm/src-fceumm/ops.h new file mode 100644 index 0000000..0c6405d --- /dev/null +++ b/fceumm/src-fceumm/ops.h @@ -0,0 +1,485 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +case 0x00: /* BRK */ + _PC++; + PUSH(_PC>>8); + PUSH(_PC); + PUSH(_P|U_FLAG|B_FLAG); + _P|=I_FLAG; + _PI|=I_FLAG; + _PC=RdMem(0xFFFE); + _PC|=RdMem(0xFFFF)<<8; + break; + +case 0x40: /* RTI */ + _P=POP(); + /* _PI=_P; This is probably incorrect, so it's commented out. */ + _PI = _P; + _PC=POP(); + _PC|=POP()<<8; + break; + +case 0x60: /* RTS */ + _PC=POP(); + _PC|=POP()<<8; + _PC++; + break; + +case 0x48: /* PHA */ + PUSH(_A); + break; +case 0x08: /* PHP */ + PUSH(_P|U_FLAG|B_FLAG); + break; +case 0x68: /* PLA */ + _A=POP(); + X_ZN(_A); + break; +case 0x28: /* PLP */ + _P=POP(); + break; +case 0x4C: + { + uint16 ptmp=_PC; + unsigned int npc; + + npc=RdMem(ptmp); + ptmp++; + npc|=RdMem(ptmp)<<8; + _PC=npc; + } + break; /* JMP ABSOLUTE */ +case 0x6C: + { + uint32 tmp; + GetAB(tmp); + _PC=RdMem(tmp); + _PC|=RdMem( ((tmp+1)&0x00FF) | (tmp&0xFF00))<<8; + } + break; +case 0x20: /* JSR */ + { + uint8 npc; + npc=RdMem(_PC); + _PC++; + PUSH(_PC>>8); + PUSH(_PC); + _PC=RdMem(_PC)<<8; + _PC|=npc; + } + break; + +case 0xAA: /* TAX */ + _X=_A; + X_ZN(_A); + break; + +case 0x8A: /* TXA */ + _A=_X; + X_ZN(_A); + break; + +case 0xA8: /* TAY */ + _Y=_A; + X_ZN(_A); + break; +case 0x98: /* TYA */ + _A=_Y; + X_ZN(_A); + break; + +case 0xBA: /* TSX */ + _X=_S; + X_ZN(_X); + break; +case 0x9A: /* TXS */ + _S=_X; + break; + +case 0xCA: /* DEX */ + _X--; + X_ZN(_X); + break; +case 0x88: /* DEY */ + _Y--; + X_ZN(_Y); + break; + +case 0xE8: /* INX */ + _X++; + X_ZN(_X); + break; +case 0xC8: /* INY */ + _Y++; + X_ZN(_Y); + break; + +case 0x18: /* CLC */ + _P&=~C_FLAG; + break; +case 0xD8: /* CLD */ + _P&=~D_FLAG; + break; +case 0x58: /* CLI */ + _P&=~I_FLAG; + break; +case 0xB8: /* CLV */ + _P&=~V_FLAG; + break; + +case 0x38: /* SEC */ + _P|=C_FLAG; + break; +case 0xF8: /* SED */ + _P|=D_FLAG; + break; +case 0x78: /* SEI */ + _P|=I_FLAG; + break; + +case 0xEA: /* NOP */ + break; + +case 0x0A: RMW_A(ASL); +case 0x06: RMW_ZP(ASL); +case 0x16: RMW_ZPX(ASL); +case 0x0E: RMW_AB(ASL); +case 0x1E: RMW_ABX(ASL); + +case 0xC6: RMW_ZP(DEC); +case 0xD6: RMW_ZPX(DEC); +case 0xCE: RMW_AB(DEC); +case 0xDE: RMW_ABX(DEC); + +case 0xE6: RMW_ZP(INC); +case 0xF6: RMW_ZPX(INC); +case 0xEE: RMW_AB(INC); +case 0xFE: RMW_ABX(INC); + +case 0x4A: RMW_A(LSR); +case 0x46: RMW_ZP(LSR); +case 0x56: RMW_ZPX(LSR); +case 0x4E: RMW_AB(LSR); +case 0x5E: RMW_ABX(LSR); + +case 0x2A: RMW_A(ROL); +case 0x26: RMW_ZP(ROL); +case 0x36: RMW_ZPX(ROL); +case 0x2E: RMW_AB(ROL); +case 0x3E: RMW_ABX(ROL); + +case 0x6A: RMW_A(ROR); +case 0x66: RMW_ZP(ROR); +case 0x76: RMW_ZPX(ROR); +case 0x6E: RMW_AB(ROR); +case 0x7E: RMW_ABX(ROR); + +case 0x69: LD_IM(ADC); +case 0x65: LD_ZP(ADC); +case 0x75: LD_ZPX(ADC); +case 0x6D: LD_AB(ADC); +case 0x7D: LD_ABX(ADC); +case 0x79: LD_ABY(ADC); +case 0x61: LD_IX(ADC); +case 0x71: LD_IY(ADC); + +case 0x29: LD_IM(AND); +case 0x25: LD_ZP(AND); +case 0x35: LD_ZPX(AND); +case 0x2D: LD_AB(AND); +case 0x3D: LD_ABX(AND); +case 0x39: LD_ABY(AND); +case 0x21: LD_IX(AND); +case 0x31: LD_IY(AND); + +case 0x24: LD_ZP(BIT); +case 0x2C: LD_AB(BIT); + +case 0xC9: LD_IM(CMP); +case 0xC5: LD_ZP(CMP); +case 0xD5: LD_ZPX(CMP); +case 0xCD: LD_AB(CMP); +case 0xDD: LD_ABX(CMP); +case 0xD9: LD_ABY(CMP); +case 0xC1: LD_IX(CMP); +case 0xD1: LD_IY(CMP); + +case 0xE0: LD_IM(CPX); +case 0xE4: LD_ZP(CPX); +case 0xEC: LD_AB(CPX); + +case 0xC0: LD_IM(CPY); +case 0xC4: LD_ZP(CPY); +case 0xCC: LD_AB(CPY); + +case 0x49: LD_IM(EOR); +case 0x45: LD_ZP(EOR); +case 0x55: LD_ZPX(EOR); +case 0x4D: LD_AB(EOR); +case 0x5D: LD_ABX(EOR); +case 0x59: LD_ABY(EOR); +case 0x41: LD_IX(EOR); +case 0x51: LD_IY(EOR); + +case 0xA9: LD_IM(LDA); +case 0xA5: LD_ZP(LDA); +case 0xB5: LD_ZPX(LDA); +case 0xAD: LD_AB(LDA); +case 0xBD: LD_ABX(LDA); +case 0xB9: LD_ABY(LDA); +case 0xA1: LD_IX(LDA); +case 0xB1: LD_IY(LDA); + +case 0xA2: LD_IM(LDX); +case 0xA6: LD_ZP(LDX); +case 0xB6: LD_ZPY(LDX); +case 0xAE: LD_AB(LDX); +case 0xBE: LD_ABY(LDX); + +case 0xA0: LD_IM(LDY); +case 0xA4: LD_ZP(LDY); +case 0xB4: LD_ZPX(LDY); +case 0xAC: LD_AB(LDY); +case 0xBC: LD_ABX(LDY); + +case 0x09: LD_IM(ORA); +case 0x05: LD_ZP(ORA); +case 0x15: LD_ZPX(ORA); +case 0x0D: LD_AB(ORA); +case 0x1D: LD_ABX(ORA); +case 0x19: LD_ABY(ORA); +case 0x01: LD_IX(ORA); +case 0x11: LD_IY(ORA); + +case 0xEB: /* (undocumented) */ +case 0xE9: LD_IM(SBC); +case 0xE5: LD_ZP(SBC); +case 0xF5: LD_ZPX(SBC); +case 0xED: LD_AB(SBC); +case 0xFD: LD_ABX(SBC); +case 0xF9: LD_ABY(SBC); +case 0xE1: LD_IX(SBC); +case 0xF1: LD_IY(SBC); + +case 0x85: ST_ZP(_A); +case 0x95: ST_ZPX(_A); +case 0x8D: ST_AB(_A); +case 0x9D: ST_ABX(_A); +case 0x99: ST_ABY(_A); +case 0x81: ST_IX(_A); +case 0x91: ST_IY(_A); + +case 0x86: ST_ZP(_X); +case 0x96: ST_ZPY(_X); +case 0x8E: ST_AB(_X); + +case 0x84: ST_ZP(_Y); +case 0x94: ST_ZPX(_Y); +case 0x8C: ST_AB(_Y); + +/* BCC */ +case 0x90: JR(!(_P&C_FLAG)); break; + +/* BCS */ +case 0xB0: JR(_P&C_FLAG); break; + +/* BEQ */ +case 0xF0: JR(_P&Z_FLAG); break; + +/* BNE */ +case 0xD0: JR(!(_P&Z_FLAG)); break; + +/* BMI */ +case 0x30: JR(_P&N_FLAG); break; + +/* BPL */ +case 0x10: JR(!(_P&N_FLAG)); break; + +/* BVC */ +case 0x50: JR(!(_P&V_FLAG)); break; + +/* BVS */ +case 0x70: JR(_P&V_FLAG); break; + +/*default: printf("Bad %02x at $%04x\n",b1,X.PC);break;*/ +/*ifdef moo*/ +/* Here comes the undocumented instructions block. Note that this implementation + may be "wrong". If so, please tell me. +*/ + +/* AAC */ +case 0x2B: +case 0x0B: LD_IM(AND;_P&=~C_FLAG;_P|=_A>>7); + +/* AAX */ +case 0x87: ST_ZP(_A&_X); +case 0x97: ST_ZPY(_A&_X); +case 0x8F: ST_AB(_A&_X); +case 0x83: ST_IX(_A&_X); + +/* ARR - ARGH, MATEY! */ +case 0x6B: { + uint8 arrtmp; + LD_IM(AND;_P&=~V_FLAG;_P|=(_A^(_A>>1))&0x40;arrtmp=_A>>7;_A>>=1;_A|=(_P&C_FLAG)<<7;_P&=~C_FLAG;_P|=arrtmp;X_ZN(_A)); + } +/* ASR */ +case 0x4B: LD_IM(AND;LSRA); + +/* ATX(OAL) Is this(OR with $EE) correct? */ +case 0xAB: LD_IM(_A|=0xEE;AND;_X=_A); + +/* AXS */ +case 0xCB: LD_IM(AXS); + +/* DCP */ +case 0xC7: RMW_ZP(DEC;CMP); +case 0xD7: RMW_ZPX(DEC;CMP); +case 0xCF: RMW_AB(DEC;CMP); +case 0xDF: RMW_ABX(DEC;CMP); +case 0xDB: RMW_ABY(DEC;CMP); +case 0xC3: RMW_IX(DEC;CMP); +case 0xD3: RMW_IY(DEC;CMP); + +/* ISB */ +case 0xE7: RMW_ZP(INC;SBC); +case 0xF7: RMW_ZPX(INC;SBC); +case 0xEF: RMW_AB(INC;SBC); +case 0xFF: RMW_ABX(INC;SBC); +case 0xFB: RMW_ABY(INC;SBC); +case 0xE3: RMW_IX(INC;SBC); +case 0xF3: RMW_IY(INC;SBC); + +/* DOP */ + +case 0x04: _PC++;break; +case 0x14: _PC++;break; +case 0x34: _PC++;break; +case 0x44: _PC++;break; +case 0x54: _PC++;break; +case 0x64: _PC++;break; +case 0x74: _PC++;break; + +case 0x80: _PC++;break; +case 0x82: _PC++;break; +case 0x89: _PC++;break; +case 0xC2: _PC++;break; +case 0xD4: _PC++;break; +case 0xE2: _PC++;break; +case 0xF4: _PC++;break; + +/* KIL */ + +case 0x02: +case 0x12: +case 0x22: +case 0x32: +case 0x42: +case 0x52: +case 0x62: +case 0x72: +case 0x92: +case 0xB2: +case 0xD2: +case 0xF2:ADDCYC(0xFF); + _jammed=1; + _PC--; + break; + +/* LAR */ +case 0xBB: RMW_ABY(_S&=x;_A=_X=_S;X_ZN(_X)); + +/* LAX */ +case 0xA7: LD_ZP(LDA;LDX); +case 0xB7: LD_ZPY(LDA;LDX); +case 0xAF: LD_AB(LDA;LDX); +case 0xBF: LD_ABY(LDA;LDX); +case 0xA3: LD_IX(LDA;LDX); +case 0xB3: LD_IY(LDA;LDX); + +/* NOP */ +case 0x1A: +case 0x3A: +case 0x5A: +case 0x7A: +case 0xDA: +case 0xFA: break; + +/* RLA */ +case 0x27: RMW_ZP(ROL;AND); +case 0x37: RMW_ZPX(ROL;AND); +case 0x2F: RMW_AB(ROL;AND); +case 0x3F: RMW_ABX(ROL;AND); +case 0x3B: RMW_ABY(ROL;AND); +case 0x23: RMW_IX(ROL;AND); +case 0x33: RMW_IY(ROL;AND); + +/* RRA */ +case 0x67: RMW_ZP(ROR;ADC); +case 0x77: RMW_ZPX(ROR;ADC); +case 0x6F: RMW_AB(ROR;ADC); +case 0x7F: RMW_ABX(ROR;ADC); +case 0x7B: RMW_ABY(ROR;ADC); +case 0x63: RMW_IX(ROR;ADC); +case 0x73: RMW_IY(ROR;ADC); + +/* SLO */ +case 0x07: RMW_ZP(ASL;ORA); +case 0x17: RMW_ZPX(ASL;ORA); +case 0x0F: RMW_AB(ASL;ORA); +case 0x1F: RMW_ABX(ASL;ORA); +case 0x1B: RMW_ABY(ASL;ORA); +case 0x03: RMW_IX(ASL;ORA); +case 0x13: RMW_IY(ASL;ORA); + +/* SRE */ +case 0x47: RMW_ZP(LSR;EOR); +case 0x57: RMW_ZPX(LSR;EOR); +case 0x4F: RMW_AB(LSR;EOR); +case 0x5F: RMW_ABX(LSR;EOR); +case 0x5B: RMW_ABY(LSR;EOR); +case 0x43: RMW_IX(LSR;EOR); +case 0x53: RMW_IY(LSR;EOR); + +/* AXA - SHA */ +case 0x93: ST_IY(_A&_X&(((A-_Y)>>8)+1)); +case 0x9F: ST_ABY(_A&_X&(((A-_Y)>>8)+1)); + +/* SYA */ +case 0x9C: ST_ABX(_Y&(((A-_X)>>8)+1)); + +/* SXA */ +case 0x9E: ST_ABY(_X&(((A-_Y)>>8)+1)); + +/* XAS */ +case 0x9B: _S=_A&_X;ST_ABY(_S& (((A-_Y)>>8)+1) ); + +/* TOP */ +case 0x0C: LD_AB(;); +case 0x1C: +case 0x3C: +case 0x5C: +case 0x7C: +case 0xDC: +case 0xFC: LD_ABX(;); + +/* XAA - BIG QUESTION MARK HERE */ +case 0x8B: _A|=0xEE; _A&=_X; LD_IM(AND); +/*endif*/ diff --git a/fceumm/src-fceumm/palette.c b/fceumm/src-fceumm/palette.c new file mode 100644 index 0000000..46ba7df --- /dev/null +++ b/fceumm/src-fceumm/palette.c @@ -0,0 +1,329 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002,2003 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +#include "types.h" +#include "fceu.h" +#include "general.h" +#include "driver.h" + +#include "palette.h" +#include "palettes/palettes.h" + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +static int ntsccol=0; +static int ntsctint=46+10; +static int ntschue=72; + +/* These are dynamically filled/generated palettes: */ +pal palettei[64]; /* Custom palette for an individual game.*/ +pal palettec[64]; /* Custom "global" palette.*/ +pal paletten[64]; /* Mathematically generated palette.*/ + +uint8 pale=0; + +pal *palo; +static pal *palpoint[8]= +{ + palette, + rp2c04001, + rp2c04002, + rp2c04003, + rp2c05004, +}; + + +void FCEUI_SetPaletteArray(uint8 *pal) +{ + if(!pal) + palpoint[0]=palette; + else + { + int x; + + palpoint[0]=palettec; + for(x=0;x<64;x++) + { + palpoint[0][x].r=*((uint8 *)pal+x+x+x); + palpoint[0][x].g=*((uint8 *)pal+x+x+x+1); + palpoint[0][x].b=*((uint8 *)pal+x+x+x+2); + } + } + FCEU_ResetPalette(); +} + + +void FCEUI_SetNTSCTH(int n, int tint, int hue) +{ + ntsctint=tint; + ntschue=hue; + ntsccol=n; + FCEU_ResetPalette(); +} + + +static uint8 lastd=0; +void SetNESDeemph(uint8 d, int force) +{ + static uint16 rtmul[7]={32768*1.239,32768*.794,32768*1.019,32768*.905,32768*1.023,32768*.741,32768*.75}; + static uint16 gtmul[7]={32768*.915,32768*1.086,32768*.98,32768*1.026,32768*.908,32768*.987,32768*.75}; + static uint16 btmul[7]={32768*.743,32768*.882,32768*.653,32768*1.277,32768*.979,32768*.101,32768*.75}; + uint32 r,g,b; + int x; + + /* If it's not forced(only forced when the palette changes), + don't waste cpu time if the same deemphasis bits are set as the last call. + */ + if(!force) + { + if(d==lastd) + return; + } + else /* Only set this when palette has changed. */ + { + r=rtmul[6]; + g=rtmul[6]; + b=rtmul[6]; + + for(x=0;x<0x40;x++) + { + uint32 m,n,o; + m=palo[x].r; + n=palo[x].g; + o=palo[x].b; + m=(m*r)>>15; + n=(n*g)>>15; + o=(o*b)>>15; + if(m>0xff) m=0xff; + if(n>0xff) n=0xff; + if(o>0xff) o=0xff; + FCEUD_SetPalette(x|0xC0,m,n,o); + } + } + if(!d) return; /* No deemphasis, so return. */ + + r=rtmul[d-1]; + g=gtmul[d-1]; + b=btmul[d-1]; + + for(x=0;x<0x40;x++) + { + uint32 m,n,o; + + m=palo[x].r; + n=palo[x].g; + o=palo[x].b; + m=(m*r)>>15; + n=(n*g)>>15; + o=(o*b)>>15; + if(m>0xff) m=0xff; + if(n>0xff) n=0xff; + if(o>0xff) o=0xff; + + FCEUD_SetPalette(x|0x40,m,n,o); + } + + lastd=d; +} + +void WritePalette(void) +{ + int x; + + for(x=0;x<7;x++) + FCEUD_SetPalette(x,unvpalette[x].r,unvpalette[x].g,unvpalette[x].b); + for(x=0;x<64;x++) + FCEUD_SetPalette(128+x,palo[x].r,palo[x].g,palo[x].b); + SetNESDeemph(lastd,1); +} + + +/* Converted from Kevin Horton's qbasic palette generator. */ +static void CalculatePalette(void) +{ + int x,z; + int r,g,b; + double s,luma,theta; + static uint8 cols[16]={0,24,21,18,15,12,9,6,3,0,33,30,27,0,0,0}; + static uint8 br1[4]={6,9,12,12}; + static double br2[4]={.29,.45,.73,.9}; + static double br3[4]={0,.24,.47,.77}; + + for(x=0;x<=3;x++) + for(z=0;z<16;z++) + { + s=(double)ntsctint/128; + luma=br2[x]; + if(z==0) {s=0;luma=((double)br1[x])/12;} + + if(z>=13) + { + s=luma=0; + if(z==13) + luma=br3[x]; + } + + theta=(double)M_PI*(double)(((double)cols[z]*10+ (((double)ntschue/2)+300) )/(double)180); + r=(int)((luma+s*sin(theta))*256); + g=(int)((luma-(double)27/53*s*sin(theta)+(double)10/53*s*cos(theta))*256); + b=(int)((luma-s*cos(theta))*256); + + + if(r>255) r=255; + if(g>255) g=255; + if(b>255) b=255; + if(r<0) r=0; + if(g<0) g=0; + if(b<0) b=0; + + paletten[(x<<4)+z].r=r; + paletten[(x<<4)+z].g=g; + paletten[(x<<4)+z].b=b; + } + WritePalette(); +} + +static int ipalette=0; + +void FCEU_LoadGamePalette(void) +{ + uint8 ptmp[192]; + FILE *fp; + char * fn; + + ipalette=0; + + fn=FCEU_MakeFName(FCEUMKF_PALETTE,0,0); + + if((fp=fopen(fn,"rb"))) + { + int x; + fread(ptmp,1,192,fp); + fclose(fp); + for(x=0;x<64;x++) + { + palettei[x].r=ptmp[x+x+x]; + palettei[x].g=ptmp[x+x+x+1]; + palettei[x].b=ptmp[x+x+x+2]; + } + ipalette=1; + } + free(fn); +} + +static void ChoosePalette(void) +{ + if(ipalette) + palo=palettei; + else if(ntsccol && !PAL && FCEUGameInfo->type!=GIT_VSUNI) + { + palo=paletten; + CalculatePalette(); + } + else + palo=palpoint[pale]; +} + +void FCEU_ResetPalette(void) +{ + if(FCEUGameInfo) + { + ChoosePalette(); + WritePalette(); + } +} + +void FCEUI_GetNTSCTH(int *tint, int *hue) +{ + *tint=ntsctint; + *hue=ntschue; +} + +static int controlselect=0; +static int controllength=0; + +void FCEUI_NTSCDEC(void) +{ + if(ntsccol && FCEUGameInfo->type!=GIT_VSUNI &&!PAL) + { + int which; + if(controlselect) + { + if(controllength) + { + which=controlselect==1?ntschue:ntsctint; + which--; + if(which<0) which=0; + if(controlselect==1) + ntschue=which; + else ntsctint=which; + CalculatePalette(); + } + controllength=360; + } + } +} + +void FCEUI_NTSCINC(void) +{ + if(ntsccol && FCEUGameInfo->type!=GIT_VSUNI && !PAL) + if(controlselect) + { + if(controllength) + { + switch(controlselect) + { + case 1:ntschue++; + if(ntschue>128) ntschue=128; + CalculatePalette(); + break; + case 2:ntsctint++; + if(ntsctint>128) ntsctint=128; + CalculatePalette(); + break; + } + } + controllength=360; + } +} + +void FCEUI_NTSCSELHUE(void) +{ + if(ntsccol && FCEUGameInfo->type!=GIT_VSUNI && !PAL) + { + controlselect = 1; + controllength = 360; + } +} + +void FCEUI_NTSCSELTINT(void) +{ + if(ntsccol && FCEUGameInfo->type!=GIT_VSUNI && !PAL) + { + controlselect=2; + controllength=360; + } +} diff --git a/fceumm/src-fceumm/palette.h b/fceumm/src-fceumm/palette.h new file mode 100644 index 0000000..894d73f --- /dev/null +++ b/fceumm/src-fceumm/palette.h @@ -0,0 +1,23 @@ +#ifndef _FCEU_PALETTE_H +#define _FCEU_PALETTE_H + +#include "types.h" + +typedef struct { + uint8 r,g,b; +} pal; + +extern pal *palo; + +#ifdef __cplusplus +extern "C" { +#endif + +void FCEU_ResetPalette(void); +void FCEU_LoadGamePalette(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/fceumm/src-fceumm/palettes/conv.c b/fceumm/src-fceumm/palettes/conv.c new file mode 100644 index 0000000..ba97698 --- /dev/null +++ b/fceumm/src-fceumm/palettes/conv.c @@ -0,0 +1,74 @@ +/* Quick conversion stuff for MAME->FCE Ultra */ + +#include +#include "../types.h" +#include "../palette.h" +#include "palettes.h" + +/* check 0x08 */ +static uint8 rp2c04001_colortable[] = +{ + 0x35, 0x23, 0x16, 0x22, 0x1c, 0x09, 0xff, 0x15, /* 0x00 - 0x07 */ + 0x20, 0x00, 0x27, 0x05, 0x04, 0x27, 0x08, 0x30, /* 0x08 - 0x0f */ + 0x21, 0xff, 0xff, 0x29, 0x3c, 0x32, 0x36, 0x12, /* 0x10 - 0x17 */ + 0xff, 0x2b, 0x0f, 0xff, 0x20, 0x10, 0x24, 0x01, /* 0x18 - 0x1f */ + 0xff, 0x31, 0xff, 0x2a, 0x2c, 0x0c, 0xff, 0xff, /* 0x20 - 0x27 */ + 0xff, 0x07, 0x34, 0x06, 0x13, 0x02, 0x26, 0x0f, /* 0x28 - 0x2f */ + 0xff, 0x19, 0x10, 0x0a, 0x39, 0xff, 0x37, 0x17, /* 0x30 - 0x37 */ + 0xff, 0x11, 0x09, 0xff, 0x39, 0x25, 0x18, 0xff /* 0x38 - 0x3f */ +}; + +/* RP2C04-002 */ +static uint8 rp2c04002_colortable[] = +{ + 0x0f, 0x27, 0x18, 0xff, 0x3a, 0x25, 0xff, 0x31, /* 0x00 - 0x07 */ + 0x16, 0x13, 0x38, 0x34, 0x20, 0x23, 0xff, 0x0b, /* 0x08 - 0x0f */ + 0xff, 0x21, 0x06, 0xff, 0x1b, 0x29, 0xff, 0x22, /* 0x10 - 0x17 */ + 0xff, 0x24, 0xff, 0x2b, 0xff, 0x08, 0xff, 0x03, /* 0x18 - 0x1f */ + 0xff, 0x36, 0x26, 0x33, 0x11, 0xff, 0x10, 0x02, /* 0x20 - 0x27 */ + 0x14, 0xff, 0x00, 0x09, 0x12, 0x0f, 0x37, 0x30, /* 0x28 - 0x2f */ + 0xff, 0xff, 0x2a, 0x17, 0x0c, 0x01, 0x15, 0x19, /* 0x30 - 0x37 */ + 0xff, 0x2c, 0x07, 0x37, 0xff, 0x05, 0x0a, 0x00 /* 0x38 - 0x3f */ +}; + +/* RP2C04-003 */ +/* Check 0x00. Used in Dr Mario. */ +static uint8 rp2c04003_colortable[] = +{ + 0x03, 0xff, 0xff, 0x00, 0x1a, 0x30, 0x31, 0x09, /* 0x00 - 0x07 */ + 0x01, 0x0f, 0x36, 0x08, 0x15, 0xff, 0xff, 0x30, /* 0x08 - 0x0f */ + 0x22, 0x1c, 0xff, 0x12, 0x19, 0x18, 0x17, 0x1b, /* 0x10 - 0x17 */ + 0x00, 0xff, 0xff, 0x02, 0x16, 0x06, 0xff, 0x35, /* 0x18 - 0x1f */ + 0x23, 0xff, 0x0f, 0x37, 0xff, 0x27, 0x26, 0x30, /* 0x20 - 0x27 */ + 0x29, 0xff, 0x21, 0x24, 0x11, 0xff, 0x0f, 0xff, /* 0x28 - 0x2f */ + 0x2c, 0xff, 0xff, 0xff, 0x07, 0x2a, 0x28, 0xff, /* 0x30 - 0x37 */ + 0x0a, 0xff, 0x32, 0x37, 0x13, 0xff, 0xff, 0x0c /* 0x38 - 0x3f */ +}; + +/* RP2C05-004 */ +/* check 0x1d, 0x38 */ +static uint8 rp2c05004_colortable[] = +{ + 0x18, 0xff, 0x1c, 0x28, 0xff, 0xff, 0x01, 0x17, /* 0x00 - 0x07 */ + 0x10, 0x0f, 0x2a, 0x0f, 0x36, 0x37, 0x1a, 0xff, /* 0x08 - 0x0f */ + 0x25, 0xff, 0x12, 0xff, 0x0f, 0xff, 0xff, 0x26, /* 0x10 - 0x17 */ + 0xff, 0xff, 0x22, 0x19, 0xff, 0x0f, 0x3a, 0x21, /* 0x18 - 0x1f */ + 0x05, 0x0a, 0x07, 0x01, 0x13, 0xff, 0x00, 0x15, /* 0x20 - 0x27 */ + 0x0c, 0xff, 0x11, 0xff, 0xff, 0x38, 0xff, 0xff, /* 0x28 - 0x2f */ + 0xff, 0xff, 0x08, 0x16, 0xff, 0xff, 0x30, 0x3c, /* 0x30 - 0x37 */ + 0x0f, 0x27, 0xff, 0x31, 0x29, 0xff, 0x30, 0x09 /* 0x38 - 0x3f */ +}; + + +main() +{ + int x; + for(x=0;x<64;x++) + { + // if(x <= 0x20) +// if(rp2c04002_colortable[x] == 0xFF) rp2c04002_colortable[x]= 0x30; + printf("{0x%02x, 0x%02x, 0x%02x},\n",palette[rp2c04001_colortable[x]&0x3F].r, + palette[rp2c04001_colortable[x]&0x3F].g, + palette[rp2c04001_colortable[x]&0x3F].b); + } +} diff --git a/fceumm/src-fceumm/palettes/palettes.h b/fceumm/src-fceumm/palettes/palettes.h new file mode 100644 index 0000000..9d01d0a --- /dev/null +++ b/fceumm/src-fceumm/palettes/palettes.h @@ -0,0 +1,95 @@ +pal rp2c04001[64] = { + #include "rp2c04001.h" +}; + +pal rp2c04002[64] = { + #include "rp2c04002.h" +}; + +pal rp2c04003[64] = { + #include "rp2c04003.h" +}; +pal rp2c05004[64] = { + #include "rp2c05004.h" +}; + +pal unvpalette[7] = +{ + { 0x00<<2,0x00<<2,0x00<<2}, /* Black*/ + { 0x3F<<2,0x3F<<2,0x34<<2}, /* White*/ + { 0x00<<2,0x00<<2,0x00<<2}, /* Black*/ + { 0x1d<<2,0x1d<<2,0x24<<2}, /* Greyish*/ + { 190,0,0 }, /* Redish*/ + { 51,255,51}, /* Bright green*/ + { 49,14,200}, +}; + + +/* Default palette */ +pal palette[64] = { + + { 0x1D<<2, 0x1D<<2, 0x1D<<2 }, /* Value 0 */ + { 0x09<<2, 0x06<<2, 0x23<<2 }, /* Value 1 */ + { 0x00<<2, 0x00<<2, 0x2A<<2 }, /* Value 2 */ + { 0x11<<2, 0x00<<2, 0x27<<2 }, /* Value 3 */ + { 0x23<<2, 0x00<<2, 0x1D<<2 }, /* Value 4 */ + { 0x2A<<2, 0x00<<2, 0x04<<2 }, /* Value 5 */ + { 0x29<<2, 0x00<<2, 0x00<<2 }, /* Value 6 */ + { 0x1F<<2, 0x02<<2, 0x00<<2 }, /* Value 7 */ + { 0x10<<2, 0x0B<<2, 0x00<<2 }, /* Value 8 */ + { 0x00<<2, 0x11<<2, 0x00<<2 }, /* Value 9 */ + { 0x00<<2, 0x14<<2, 0x00<<2 }, /* Value 10 */ + { 0x00<<2, 0x0F<<2, 0x05<<2 }, /* Value 11 */ + { 0x06<<2, 0x0F<<2, 0x17<<2 }, /* Value 12 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 13 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 14 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 15 */ + { 0x2F<<2, 0x2F<<2, 0x2F<<2 }, /* Value 16 */ + { 0x00<<2, 0x1C<<2, 0x3B<<2 }, /* Value 17 */ + { 0x08<<2, 0x0E<<2, 0x3B<<2 }, /* Value 18 */ + { 0x20<<2, 0x00<<2, 0x3C<<2 }, /* Value 19 */ + { 0x2F<<2, 0x00<<2, 0x2F<<2 }, /* Value 20 */ + { 0x39<<2, 0x00<<2, 0x16<<2 }, /* Value 21 */ + { 0x36<<2, 0x0A<<2, 0x00<<2 }, /* Value 22 */ + { 0x32<<2, 0x13<<2, 0x03<<2 }, /* Value 23 */ + { 0x22<<2, 0x1C<<2, 0x00<<2 }, /* Value 24 */ + { 0x00<<2, 0x25<<2, 0x00<<2 }, /* Value 25 */ + { 0x00<<2, 0x2A<<2, 0x00<<2 }, /* Value 26 */ + { 0x00<<2, 0x24<<2, 0x0E<<2 }, /* Value 27 */ + { 0x00<<2, 0x20<<2, 0x22<<2 }, /* Value 28 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 29 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 30 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 31 */ + { 0x3F<<2, 0x3F<<2, 0x3F<<2 }, /* Value 32 */ + { 0x0F<<2, 0x2F<<2, 0x3F<<2 }, /* Value 33 */ + { 0x17<<2, 0x25<<2, 0x3F<<2 }, /* Value 34 */ + { 0x33<<2, 0x22<<2, 0x3F<<2 }, /* Value 35 */ + { 0x3D<<2, 0x1E<<2, 0x3F<<2 }, /* Value 36 */ + { 0x3F<<2, 0x1D<<2, 0x2D<<2 }, /* Value 37 */ + { 0x3F<<2, 0x1D<<2, 0x18<<2 }, /* Value 38 */ + { 0x3F<<2, 0x26<<2, 0x0E<<2 }, /* Value 39 */ + { 0x3C<<2, 0x2F<<2, 0x0F<<2 }, /* Value 40 */ + { 0x20<<2, 0x34<<2, 0x04<<2 }, /* Value 41 */ + { 0x13<<2, 0x37<<2, 0x12<<2 }, /* Value 42 */ + { 0x16<<2, 0x3E<<2, 0x26<<2 }, /* Value 43 */ + { 0x00<<2, 0x3A<<2, 0x36<<2 }, /* Value 44 */ + { 0x1E<<2, 0x1E<<2, 0x1E<<2 }, /* Value 45 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 46 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 47 */ + { 0x3F<<2, 0x3F<<2, 0x3F<<2 }, /* Value 48 */ + { 0x2A<<2, 0x39<<2, 0x3F<<2 }, /* Value 49 */ + { 0x31<<2, 0x35<<2, 0x3F<<2 }, /* Value 50 */ + { 0x35<<2, 0x32<<2, 0x3F<<2 }, /* Value 51 */ + { 0x3F<<2, 0x31<<2, 0x3F<<2 }, /* Value 52 */ + { 0x3F<<2, 0x31<<2, 0x36<<2 }, /* Value 53 */ + { 0x3F<<2, 0x2F<<2, 0x2C<<2 }, /* Value 54 */ + { 0x3F<<2, 0x36<<2, 0x2A<<2 }, /* Value 55 */ + { 0x3F<<2, 0x39<<2, 0x28<<2 }, /* Value 56 */ + { 0x38<<2, 0x3F<<2, 0x28<<2 }, /* Value 57 */ + { 0x2A<<2, 0x3C<<2, 0x2F<<2 }, /* Value 58 */ + { 0x2C<<2, 0x3F<<2, 0x33<<2 }, /* Value 59 */ + { 0x27<<2, 0x3F<<2, 0x3C<<2 }, /* Value 60 */ + { 0x31<<2, 0x31<<2, 0x31<<2 }, /* Value 61 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 62 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 63 */ +}; diff --git a/fceumm/src-fceumm/palettes/rp2c04001.h b/fceumm/src-fceumm/palettes/rp2c04001.h new file mode 100644 index 0000000..8752b2e --- /dev/null +++ b/fceumm/src-fceumm/palettes/rp2c04001.h @@ -0,0 +1,64 @@ +{0xfc, 0xc4, 0xd8}, +{0x40, 0x88, 0xfc}, +{0xd8, 0x28, 0x00}, +{0x5c, 0x94, 0xfc}, +{0x00, 0x80, 0x88}, +{0x00, 0x44, 0x00}, +{0x00, 0x00, 0x00}, +{0xe4, 0x00, 0x58}, +{0xfc, 0xfc, 0xfc}, +{0x74, 0x74, 0x74}, +{0xfc, 0x98, 0x38}, +{0xa8, 0x00, 0x10}, +{0x8c, 0x00, 0x74}, +{0xfc, 0x98, 0x38}, +{0x40, 0x2c, 0x00}, +{0xfc, 0xfc, 0xfc}, +{0x3c, 0xbc, 0xfc}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x80, 0xd0, 0x10}, +{0x9c, 0xfc, 0xf0}, +{0xc4, 0xd4, 0xfc}, +{0xfc, 0xbc, 0xb0}, +{0x20, 0x38, 0xec}, +{0x00, 0x00, 0x00}, +{0x58, 0xf8, 0x98}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0xfc, 0xfc, 0xfc}, +{0xbc, 0xbc, 0xbc}, +{0xf4, 0x78, 0xfc}, +{0x24, 0x18, 0x8c}, +{0x00, 0x00, 0x00}, +{0xa8, 0xe4, 0xfc}, +{0x00, 0x00, 0x00}, +{0x4c, 0xdc, 0x48}, +{0x00, 0xe8, 0xd8}, +{0x18, 0x3c, 0x5c}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x7c, 0x08, 0x00}, +{0xfc, 0xc4, 0xfc}, +{0xa4, 0x00, 0x00}, +{0x80, 0x00, 0xf0}, +{0x00, 0x00, 0xa8}, +{0xfc, 0x74, 0x60}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x94, 0x00}, +{0xbc, 0xbc, 0xbc}, +{0x00, 0x50, 0x00}, +{0xe0, 0xfc, 0xa0}, +{0x00, 0x00, 0x00}, +{0xfc, 0xd8, 0xa8}, +{0xc8, 0x4c, 0x0c}, +{0x00, 0x00, 0x00}, +{0x00, 0x70, 0xec}, +{0x00, 0x44, 0x00}, +{0x00, 0x00, 0x00}, +{0xe0, 0xfc, 0xa0}, +{0xfc, 0x74, 0xb4}, +{0x88, 0x70, 0x00}, +{0x00, 0x00, 0x00}, diff --git a/fceumm/src-fceumm/palettes/rp2c04002.h b/fceumm/src-fceumm/palettes/rp2c04002.h new file mode 100644 index 0000000..d0f46b9 --- /dev/null +++ b/fceumm/src-fceumm/palettes/rp2c04002.h @@ -0,0 +1,64 @@ +{0x00, 0x00, 0x00}, +{0xfc, 0x98, 0x38}, +{0x88, 0x70, 0x00}, +{0x00, 0x00, 0x00}, +{0xa8, 0xf0, 0xbc}, +{0xfc, 0x74, 0xb4}, +{0x00, 0x00, 0x00}, +{0xa8, 0xe4, 0xfc}, +{0xd8, 0x28, 0x00}, +{0x80, 0x00, 0xf0}, +{0xfc, 0xe4, 0xa0}, +{0xfc, 0xc4, 0xfc}, +{0xfc, 0xfc, 0xfc}, +{0x40, 0x88, 0xfc}, +{0x00, 0x00, 0x00}, +{0x00, 0x3c, 0x14}, +{0x00, 0x00, 0x00}, +{0x3c, 0xbc, 0xfc}, +{0xa4, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x90, 0x38}, +{0x80, 0xd0, 0x10}, +{0x00, 0x00, 0x00}, +{0x5c, 0x94, 0xfc}, +{0x00, 0x00, 0x00}, +{0xf4, 0x78, 0xfc}, +{0x00, 0x00, 0x00}, +{0x58, 0xf8, 0x98}, +{0x00, 0x00, 0x00}, +{0x40, 0x2c, 0x00}, +{0x00, 0x00, 0x00}, +{0x44, 0x00, 0x9c}, +{0x00, 0x00, 0x00}, +{0xfc, 0xbc, 0xb0}, +{0xfc, 0x74, 0x60}, +{0xd4, 0xc8, 0xfc}, +{0x00, 0x70, 0xec}, +{0x00, 0x00, 0x00}, +{0xbc, 0xbc, 0xbc}, +{0x00, 0x00, 0xa8}, +{0xbc, 0x00, 0xbc}, +{0x00, 0x00, 0x00}, +{0x74, 0x74, 0x74}, +{0x00, 0x44, 0x00}, +{0x20, 0x38, 0xec}, +{0x00, 0x00, 0x00}, +{0xfc, 0xd8, 0xa8}, +{0xfc, 0xfc, 0xfc}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x4c, 0xdc, 0x48}, +{0xc8, 0x4c, 0x0c}, +{0x18, 0x3c, 0x5c}, +{0x24, 0x18, 0x8c}, +{0xe4, 0x00, 0x58}, +{0x00, 0x94, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0xe8, 0xd8}, +{0x7c, 0x08, 0x00}, +{0xfc, 0xd8, 0xa8}, +{0x00, 0x00, 0x00}, +{0xa8, 0x00, 0x10}, +{0x00, 0x50, 0x00}, +{0x74, 0x74, 0x74}, diff --git a/fceumm/src-fceumm/palettes/rp2c04003.h b/fceumm/src-fceumm/palettes/rp2c04003.h new file mode 100644 index 0000000..9a4717c --- /dev/null +++ b/fceumm/src-fceumm/palettes/rp2c04003.h @@ -0,0 +1,64 @@ +{0x44, 0x00, 0x9c}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x74, 0x74, 0x74}, +{0x00, 0xa8, 0x00}, +{0xfc, 0xfc, 0xfc}, +{0xa8, 0xe4, 0xfc}, +{0x00, 0x44, 0x00}, +{0x24, 0x18, 0x8c}, +{0x00, 0x00, 0x00}, +{0xfc, 0xbc, 0xb0}, +{0x40, 0x2c, 0x00}, +{0xe4, 0x00, 0x58}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0xfc, 0xfc, 0xfc}, +{0x5c, 0x94, 0xfc}, +{0x00, 0x80, 0x88}, +{0x00, 0x00, 0x00}, +{0x20, 0x38, 0xec}, +{0x00, 0x94, 0x00}, +{0x88, 0x70, 0x00}, +{0xc8, 0x4c, 0x0c}, +{0x00, 0x90, 0x38}, +{0x74, 0x74, 0x74}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0xa8}, +{0xd8, 0x28, 0x00}, +{0xa4, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0xfc, 0xc4, 0xd8}, +{0x40, 0x88, 0xfc}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0xfc, 0xd8, 0xa8}, +{0x00, 0x00, 0x00}, +{0xfc, 0x98, 0x38}, +{0xfc, 0x74, 0x60}, +{0xfc, 0xfc, 0xfc}, +{0x80, 0xd0, 0x10}, +{0x00, 0x00, 0x00}, +{0x3c, 0xbc, 0xfc}, +{0xf4, 0x78, 0xfc}, +{0x00, 0x70, 0xec}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0xe8, 0xd8}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x7c, 0x08, 0x00}, +{0x4c, 0xdc, 0x48}, +{0xf0, 0xbc, 0x3c}, +{0x00, 0x00, 0x00}, +{0x00, 0x50, 0x00}, +{0x00, 0x00, 0x00}, +{0xc4, 0xd4, 0xfc}, +{0xfc, 0xd8, 0xa8}, +{0x80, 0x00, 0xf0}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x18, 0x3c, 0x5c}, diff --git a/fceumm/src-fceumm/palettes/rp2c05004.h b/fceumm/src-fceumm/palettes/rp2c05004.h new file mode 100644 index 0000000..dc0a90a --- /dev/null +++ b/fceumm/src-fceumm/palettes/rp2c05004.h @@ -0,0 +1,64 @@ +{0x88, 0x70, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x80, 0x88}, +{0xf0, 0xbc, 0x3c}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x24, 0x18, 0x8c}, +{0xc8, 0x4c, 0x0c}, +{0xbc, 0xbc, 0xbc}, +{0x00, 0x00, 0x00}, +{0x4c, 0xdc, 0x48}, +{0x00, 0x00, 0x00}, +{0xfc, 0xbc, 0xb0}, +{0xfc, 0xd8, 0xa8}, +{0x00, 0xa8, 0x00}, +{0x00, 0x00, 0x00}, +{0xfc, 0x74, 0xb4}, +{0x00, 0x00, 0x00}, +{0x20, 0x38, 0xec}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0xfc, 0x74, 0x60}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x5c, 0x94, 0xfc}, +{0x00, 0x94, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0xa8, 0xf0, 0xbc}, +{0x3c, 0xbc, 0xfc}, +{0xa8, 0x00, 0x10}, +{0x00, 0x50, 0x00}, +{0x7c, 0x08, 0x00}, +{0x00, 0x00, 0xa8}, +{0x80, 0x00, 0xf0}, +{0x00, 0x00, 0x00}, +{0x74, 0x74, 0x74}, +{0xe4, 0x00, 0x58}, +{0x18, 0x3c, 0x5c}, +{0x00, 0x00, 0x00}, +{0x00, 0x70, 0xec}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0xfc, 0xe4, 0xa0}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x40, 0x2c, 0x00}, +{0xd8, 0x28, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0xfc, 0xfc, 0xfc}, +{0x9c, 0xfc, 0xf0}, +{0x00, 0x00, 0x00}, +{0xfc, 0x98, 0x38}, +{0x00, 0x00, 0x00}, +{0xa8, 0xe4, 0xfc}, +{0x80, 0xd0, 0x10}, +{0x00, 0x00, 0x00}, +{0xfc, 0xfc, 0xfc}, +{0x00, 0x44, 0x00}, diff --git a/fceumm/src-fceumm/ppu.c b/fceumm/src-fceumm/ppu.c new file mode 100644 index 0000000..9567a0b --- /dev/null +++ b/fceumm/src-fceumm/ppu.c @@ -0,0 +1,1317 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 1998 BERO + * Copyright (C) 2003 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +#include "types.h" +#include "x6502.h" +#include "fceu.h" +#include "ppu.h" +#include "sound.h" +#include "general.h" +#include "myendian.h" +#include "memory.h" +#include "ppuview.h" + +#include "cart.h" +#include "palette.h" +#include "state.h" +#include "input.h" + +#define VBlankON (PPU[0]&0x80) /* Generate VBlank NMI */ +#define Sprite16 (PPU[0]&0x20) /* Sprites 8x16/8x8 */ +#define BGAdrHI (PPU[0]&0x10) /* BG pattern adr $0000/$1000 */ +#define SpAdrHI (PPU[0]&0x08) /* Sprite pattern adr $0000/$1000 */ +#define INC32 (PPU[0]&0x04) /* auto increment 1/32 */ + +#define SpriteON (PPU[1]&0x10) /* Show Sprite */ +#define ScreenON (PPU[1]&0x08) /* Show screen */ + +#define PPU_status (PPU[2]) + +#define Pal (PALRAM) + +uint8 *XBuf=NULL; + +int FCEU_InitVirtualVideo(void) +{ + if(!XBuf) /* Some driver code may allocate XBuf externally. */ + /* 256 bytes per scanline, * 240 scanline maximum, +8 for alignment, + */ + if(!(XBuf= (uint8*) (FCEU_malloc(256 * 256 + 8)))) + return 0; + + if(sizeof(uint8*)==4) + { + uintptr_t m; + m=(uintptr_t)XBuf; + m=(4-m)&3; + XBuf+=m; + } + memset(XBuf,128,256*256); /**240);*/ + return 1; +} + +static void FetchSpriteData(void); +static void RefreshLine(int lastpixel); +static void RefreshSprites(void); +static void CopySprites(uint8 *target); + +static void Fixit1(void); +static uint32 ppulut1[256]; +static uint32 ppulut2[256]; +static uint32 ppulut3[128]; + +static int ppudead=1; +static int kook = 0; + +int MMC5Hack; +uint32 MMC5HackVROMMask; +uint8 *MMC5HackExNTARAMPtr; +uint8 *MMC5HackVROMPTR; +uint8 MMC5HackCHRMode=0; +uint8 MMC5HackSPMode; +uint8 MMC5HackSPScroll; +uint8 MMC5HackSPPage; + + +uint8 VRAMBuffer,PPUGenLatch; +uint8 *vnapage[4]; +uint8 PPUNTARAM; +uint8 PPUCHRRAM; + +/* Color deemphasis emulation. Joy... */ +static uint8 deemp=0; +static int deempcnt[8]; + +void (*GameHBIRQHook)(void), (*GameHBIRQHook2)(void); +void (*PPU_hook)(uint32 A); + +uint8 vtoggle=0; +uint8 XOffset=0; + +uint32 TempAddr,RefreshAddr; + +static int maxsprites=8; + +/* scanline is equal to the current visible scanline we're on. */ + +int scanline; +static uint32 scanlines_per_frame; + +uint8 PPU[4]; +uint8 PPUSPL; +uint8 NTARAM[0x800],PALRAM[0x20],SPRAM[0x100],SPRBUF[0x100]; + + +#define MMC5SPRVRAMADR(V) &MMC5SPRVPage[(V)>>10][(V)] +#define MMC5BGVRAMADR(V) &MMC5BGVPage[(V)>>10][(V)] +#define VRAMADR(V) &VPage[(V)>>10][(V)] + +static DECLFR(A2002) +{ + uint8 ret; + + FCEUPPU_LineUpdate(); + ret = PPU_status; + ret|=PPUGenLatch&0x1F; + + vtoggle=0; + PPU_status&=0x7F; + PPUGenLatch=ret; + return ret; +} + +static DECLFR(A200x) /* Not correct for $2004 reads. */ +{ + FCEUPPU_LineUpdate(); + return PPUGenLatch; +} + +static DECLFR(A2007) +{ + uint8 ret; + uint32 tmp; + + tmp=RefreshAddr&0x3FFF; + + FCEUPPU_LineUpdate(); + + ret=VRAMBuffer; + + if(PPU_hook) PPU_hook(tmp); + PPUGenLatch=VRAMBuffer; + if(tmp<0x2000) + VRAMBuffer=VPage[tmp>>10][tmp]; + else + VRAMBuffer=vnapage[(tmp>>10)&0x3][tmp&0x3FF]; + if((ScreenON || SpriteON) && (scanline < 240)) + { + uint32 rad=RefreshAddr; + if((rad&0x7000)==0x7000) + { + rad^=0x7000; + if((rad&0x3E0)==0x3A0) + rad^=0xBA0; + else if((rad&0x3E0)==0x3e0) + rad^=0x3e0; + else + rad+=0x20; + } + else + rad+=0x1000; + RefreshAddr=rad; + } + else + { + if (INC32) + RefreshAddr+=32; + else + RefreshAddr++; + } + if(PPU_hook) PPU_hook(RefreshAddr&0x3fff); + return ret; +} + +static DECLFW(B2000) +{ + /*printf("%04x:$%02x, %d\n",A,V&0x38,scanline);*/ + + FCEUPPU_LineUpdate(); + PPUGenLatch=V; + if(!(PPU[0]&0x80) && (V&0x80) && (PPU_status&0x80)) + { + /*printf("Trigger NMI, %d, %d\n",timestamp,ppudead);*/ + TriggerNMI2(); + } + PPU[0]=V; + TempAddr&=0xF3FF; + TempAddr|=(V&3)<<10; +} + +static DECLFW(B2001) +{ + /*printf("%04x:$%02x, %d\n",A,V,scanline);*/ + FCEUPPU_LineUpdate(); + PPUGenLatch=V; + PPU[1]=V; + if(V&0xE0) + deemp=V>>5; +} + +static DECLFW(B2002) +{ + PPUGenLatch=V; +} + +static DECLFW(B2003) +{ + /*printf("$%04x:$%02x, %d, %d\n",A,V,timestamp,scanline);*/ + PPUGenLatch=V; + PPU[3]=V; + PPUSPL=V&0x7; +} + +static DECLFW(B2004) +{ + /*printf("Wr: %04x:$%02x\n",A,V);*/ + + PPUGenLatch=V; + if(PPUSPL>=8) + { + if(PPU[3]>=8) + SPRAM[PPU[3]]=V; + } + else + { + /*printf("$%02x:$%02x\n",PPUSPL,V);*/ + SPRAM[PPUSPL]=V; + } + PPU[3]++; + PPUSPL++; + +} + +static DECLFW(B2005) +{ + uint32 tmp; + + tmp=TempAddr; + FCEUPPU_LineUpdate(); + PPUGenLatch=V; + if (!vtoggle) + { + tmp&=0xFFE0; + tmp|=V>>3; + XOffset=V&7; + } + else + { + tmp&=0x8C1F; + tmp|=((V&~0x7)<<2); + tmp|=(V&7)<<12; + } + TempAddr=tmp; + vtoggle^=1; +} + + +static DECLFW(B2006) +{ + FCEUPPU_LineUpdate(); + + PPUGenLatch=V; + if(!vtoggle) + { + TempAddr&=0x00FF; + TempAddr|=(V&0x3f)<<8; + } + else + { + TempAddr&=0xFF00; + TempAddr|=V; + + RefreshAddr=TempAddr; + if(PPU_hook) + PPU_hook(RefreshAddr); + /*printf("%d, %04x\n",scanline,RefreshAddr);*/ + } + vtoggle^=1; +} + +static DECLFW(B2007) +{ + uint32 tmp; + + tmp=RefreshAddr&0x3FFF; + PPUGenLatch=V; + if(tmp>=0x3F00) + { + /* hmmm....*/ + if(!(tmp&0xf)) + PALRAM[0x00]=PALRAM[0x04]=PALRAM[0x08]=PALRAM[0x0C]=V&0x3F; + else if(tmp&3) PALRAM[(tmp&0x1f)]=V&0x3f; + } + else if(tmp<0x2000) + { + if(PPUCHRRAM&(1<<(tmp>>10))) + VPage[tmp>>10][tmp]=V; + } + else + { + if(PPUNTARAM&(1<<((tmp&0xF00)>>10))) + vnapage[((tmp&0xF00)>>10)][tmp&0x3FF]=V; + } + if (INC32) RefreshAddr+=32; + else RefreshAddr++; + if(PPU_hook) PPU_hook(RefreshAddr&0x3fff); +} + +static DECLFW(B4014) +{ + uint32 t; + int x; + + t= V << 8; + + for(x=0;x<256;x++) + X6502_DMW(0x2004,X6502_DMR(t+x)); + +#define ADDCYC(x) \ + { \ + int __x=x; \ + X.tcount+=__x; \ + X.count-=__x*48; \ + timestamp+=__x; \ + } + ADDCYC(1); +#undef ADDCYC +} + +#define PAL(c) ((c)+cc) + +#define GETLASTPIXEL (PAL?((timestamp*48-linestartts)/15) : ((timestamp*48-linestartts)>>4) ) + +static uint8 *Pline,*Plinef; +static int firsttile; +static int linestartts; +static int tofix=0; + +static void ResetRL(uint8 *target) +{ + memset(target,0xFF,256); + if(InputScanlineHook) + InputScanlineHook(0,0,0,0); + Plinef=target; + Pline=target; + firsttile=0; + linestartts=timestamp*48+X.count; + tofix=0; + FCEUPPU_LineUpdate(); + tofix=1; +} +static uint8 sprlinebuf[256+8]; + +void FCEUPPU_LineUpdate(void) +{ + if(Pline) + { + int l=GETLASTPIXEL; + RefreshLine(l); + } +} + +static void CheckSpriteHit(int p); + +static void EndRL(void) +{ + RefreshLine(272); + if(tofix) + Fixit1(); + CheckSpriteHit(272); + Pline=0; +} + +static int32 sphitx; +static uint8 sphitdata; + +static void CheckSpriteHit(int p) +{ + int l=p-16; + int x; + + if(sphitx==0x100) return; + + for(x=sphitx;x<(sphitx+8) && x>(x-sphitx))) && !(Plinef[x]&64))*/ + if((sphitdata&(0x80>>(x-sphitx))) && !(Plinef[x]&64) && x < 255) + { + PPU_status|=0x40; + /*printf("Ha: %d, %d, Hita: %d, %d, %d, %d, %d\n",p,p&~7,scanline,GETLASTPIXEL-16,&Plinef[x],Pline,Pline-Plinef);*/ + /*printf("%d\n",GETLASTPIXEL-16);*/ + /*if(Plinef[x] == 0xFF)*/ + /*printf("PL: %d, %02x\n",scanline, Plinef[x]);*/ + sphitx=0x100; + break; + } + } +} +static int spork=0; /* spork the world. Any sprites on this line? + Then this will be set to 1. Needed for zapper + emulation and *gasp* sprite emulation. + */ + +/* lasttile is really "second to last tile."*/ +static void RefreshLine(int lastpixel) +{ + static uint32 pshift[2]; + static uint32 atlatch; + uint32 smorkus=RefreshAddr; + +#define RefreshAddr smorkus + uint32 vofs; + int X1; + + register uint8 *P=Pline; + int lasttile=lastpixel>>3; + int numtiles; + static int norecurse=0; /* Yeah, recursion would be bad. + PPU_hook() functions can call + mirroring/chr bank switching functions, + which call FCEUPPU_LineUpdate, which call this + function. */ + if(norecurse) return; + + if(sphitx != 0x100 && !(PPU_status&0x40)) + { + if((sphitx < (lastpixel-16)) && !(sphitx < ((lasttile - 2)*8))) + { + /*printf("OK: %d\n",scanline);*/ + lasttile++; + } + + } + + if(lasttile>34) lasttile=34; + numtiles=lasttile-firsttile; + + if(numtiles<=0) return; + + P=Pline; + + vofs=0; + + vofs=((PPU[0]&0x10)<<8) | ((RefreshAddr>>12)&7); + + if(!ScreenON && !SpriteON) + { + uint32 tem; + tem=Pal[0]|(Pal[0]<<8)|(Pal[0]<<16)|(Pal[0]<<24); + tem|=0x40404040; + FCEU_dwmemset(Pline,tem,numtiles*8); + P+=numtiles*8; + Pline=P; + + firsttile=lasttile; + +#define TOFIXNUM (272-0x4) + if(lastpixel>=TOFIXNUM && tofix) + { + Fixit1(); + tofix=0; + } + + if(InputScanlineHook && (lastpixel-16)>=0) + { + InputScanlineHook(Plinef,spork?sprlinebuf:0,linestartts,lasttile*8-16); + } + return; + } + + /* Priority bits, needed for sprite emulation. */ + Pal[0]|=64; + Pal[4]|=64; + Pal[8]|=64; + Pal[0xC]|=64; + + /* This high-level graphics MMC5 emulation code was written + for MMC5 carts in "CL" mode. It's probably not totally + correct for carts in "SL" mode. + */ + +#define PPUT_MMC5 + if(MMC5Hack && geniestage!=1) + { + if(MMC5HackCHRMode==0 && (MMC5HackSPMode&0x80)) + { + int tochange=MMC5HackSPMode&0x1F; + tochange-=firsttile; + for(X1=firsttile;X10 && !(MMC5HackSPMode&0x40))) + { +#define PPUT_MMC5SP +#include "pputile.h" +#undef PPUT_MMC5SP + } + else + { +#include "pputile.h" + } + tochange--; + } + } + else if(MMC5HackCHRMode==1 && (MMC5HackSPMode&0x80)) + { + int tochange=MMC5HackSPMode&0x1F; + tochange-=firsttile; + +#define PPUT_MMC5SP +#define PPUT_MMC5CHR1 + for(X1=firsttile;X10) + FCEU_dwmemset(Plinef+tstart*8,tem,tcount*8); + } + + if(lastpixel>=TOFIXNUM && tofix) + { + /*puts("Fixed");*/ + Fixit1(); + tofix=0; + } + + /*CheckSpriteHit(lasttile*8); //lasttile*8); //lastpixel);*/ + + CheckSpriteHit(lastpixel); /* This only works right because + of a hack earlier in this function. + */ + if(InputScanlineHook && (lastpixel-16)>=0) + { + InputScanlineHook(Plinef,spork?sprlinebuf:0,linestartts,lasttile*8-16); + } + Pline=P; + firsttile=lasttile; +} + +static INLINE void Fixit2(void) +{ + if(ScreenON || SpriteON) + { + uint32 rad=RefreshAddr; + rad&=0xFBE0; + rad|=TempAddr&0x041f; + RefreshAddr=rad; + /*PPU_hook(RefreshAddr);*/ + /*PPU_hook(RefreshAddr,-1);*/ + } +} + +static void Fixit1(void) +{ + if(ScreenON || SpriteON) + { + uint32 rad=RefreshAddr; + + if((rad&0x7000)==0x7000) + { + rad^=0x7000; + if((rad&0x3E0)==0x3A0) + rad^=0xBA0; + else if((rad&0x3E0)==0x3e0) + rad^=0x3e0; + else + rad+=0x20; + } + else + rad+=0x1000; + RefreshAddr=rad; + /*PPU_hook(RefreshAddr); //,-1);*/ + } +} + +void MMC5_hb(int); /* Ugh ugh ugh. */ +static void DoLine(void) +{ + int x; + uint8 *target; + + target= XBuf + (scanline << 8); + + if(MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline); + + X6502_Run(256); + EndRL(); + + if(SpriteON) + CopySprites(target); + + if(ScreenON || SpriteON) /* Yes, very el-cheapo.*/ + { + if(PPU[1]&0x01) + { + for(x=63;x>=0;x--) + *(uint32 *)&target[x<<2]=(*(uint32*)&target[x<<2])&0x30303030; + } + } + if((PPU[1]>>5)==0x7) + { + for(x=63;x>=0;x--) + *(uint32 *)&target[x<<2]=((*(uint32*)&target[x<<2])&0x3f3f3f3f)|0xc0c0c0c0; + } + else if(PPU[1]&0xE0) + for(x=63;x>=0;x--) + *(uint32 *)&target[x<<2]=(*(uint32*)&target[x<<2])|0x40404040; + else + for(x=63;x>=0;x--) + *(uint32 *)&target[x<<2]=((*(uint32*)&target[x<<2])&0x3f3f3f3f)|0x80808080; + + sphitx=0x100; + + if(ScreenON || SpriteON) + FetchSpriteData(); + + X6502_Run(6); /* Tried 65, caused problems with Slalom(maybe others)*/ + Fixit2(); + if(GameHBIRQHook && (ScreenON || SpriteON) && ((PPU[0]&0x38)!=0x18)) + { + X6502_Run(4); + GameHBIRQHook(); + X6502_Run(85-16-10); + } + else + { + X6502_Run(85-6-16); + + /* A semi-hack for Star Trek: 25th Anniversary*/ + if(GameHBIRQHook && (ScreenON || SpriteON) && ((PPU[0]&0x38)!=0x18)) + GameHBIRQHook(); + } + + if(SpriteON) + RefreshSprites(); + if(GameHBIRQHook2 && (ScreenON || SpriteON)) + GameHBIRQHook2(); + scanline++; + if(scanline<240) + { + ResetRL(XBuf+(scanline<<8)); + } + X6502_Run(16); +} + +#define V_FLIP 0x80 +#define H_FLIP 0x40 +#define SP_BACK 0x20 + +typedef struct { + uint8 y,no,atr,x; +} SPR; + +typedef struct { + uint8 ca[2],atr,x; +} SPRB; + +void FCEUI_DisableSpriteLimitation(int a) +{ + maxsprites= a ? 64 : 8; +} + +static uint8 numsprites,SpriteBlurp; + +static void FetchSpriteData(void) +{ + uint8 ns,sb; + SPR *spr; + uint8 H; + int n; + int vofs; + uint8 P0=PPU[0]; + + spr=(SPR *)SPRAM; + H=8; + + ns=sb=0; + + vofs=(unsigned int)(P0&0x8&(((P0&0x20)^0x20)>>2))<<9; + H+=(P0&0x20)>>2; + + if(!PPU_hook) + for(n=63;n>=0;n--,spr++) + { + if((unsigned int)(scanline-spr->y)>=H) continue; + /*printf("%d, %u\n",scanline,(unsigned int)(scanline-spr->y));*/ + if(nsy); + + if (Sprite16) + vadr = ((spr->no&1)<<12) + ((spr->no&0xFE)<<4); + else + vadr = (spr->no<<4)+vofs; + + if (spr->atr&V_FLIP) + { + vadr+=7; + vadr-=t; + vadr+=(P0&0x20)>>1; + vadr-=t&8; + } + else + { + vadr+=t; + vadr+=t&8; + } + + /* Fix this geniestage hack */ + if(MMC5Hack && geniestage!=1) C = MMC5SPRVRAMADR(vadr); + else C = VRAMADR(vadr); + + + dst.ca[0]=C[0]; + dst.ca[1]=C[8]; + dst.x=spr->x; + dst.atr=spr->atr; + + *(uint32 *)&SPRBUF[ns<<2]=*(uint32 *)&dst; + } + + ns++; + } + else + { + PPU_status|=0x20; + break; + } + } + else + for(n=63;n>=0;n--,spr++) + { + if((unsigned int)(scanline-spr->y)>=H) continue; + + if(nsy); + + if (Sprite16) + vadr = ((spr->no&1)<<12) + ((spr->no&0xFE)<<4); + else + vadr = (spr->no<<4)+vofs; + + if (spr->atr&V_FLIP) + { + vadr+=7; + vadr-=t; + vadr+=(P0&0x20)>>1; + vadr-=t&8; + } + else + { + vadr+=t; + vadr+=t&8; + } + + if(MMC5Hack) C = MMC5SPRVRAMADR(vadr); + else C = VRAMADR(vadr); + dst.ca[0]=C[0]; + if(ns<8) + { + PPU_hook(0x2000); + PPU_hook(vadr); + } + dst.ca[1]=C[8]; + dst.x=spr->x; + dst.atr=spr->atr; + + + *(uint32 *)&SPRBUF[ns<<2]=*(uint32 *)&dst; + } + + ns++; + } + else + { + PPU_status|=0x20; + break; + } + } + /*if(ns>=7)*/ + /*printf("%d %d\n",scanline,ns);*/ + if(ns>8) PPU_status|=0x20; /* Handle case when >8 sprites per + scanline option is enabled. */ + else if(PPU_hook) + { + for(n=0;n<(8-ns);n++) + { + PPU_hook(0x2000); + PPU_hook(vofs); + } + } + numsprites=ns; + SpriteBlurp=sb; +} + +static void RefreshSprites(void) +{ + int n; + SPRB *spr; + + spork=0; + if(!numsprites) return; + + FCEU_dwmemset(sprlinebuf,0x80808080,256); + numsprites--; + spr = (SPRB*)SPRBUF+numsprites; + + for(n=numsprites;n>=0;n--,spr--) + { + register uint32 pixdata; + register uint8 J,atr; + + int x=spr->x; + uint8 *C; + uint8 *VB; + + pixdata=ppulut1[spr->ca[0]]|ppulut2[spr->ca[1]]; + J=spr->ca[0]|spr->ca[1]; + atr=spr->atr; + + if(J) + { + if(n==0 && SpriteBlurp && !(PPU_status&0x40)) + { + sphitx=x; + sphitdata=J; + if(atr&H_FLIP) + sphitdata= ((J<<7)&0x80) | + ((J<<5)&0x40) | + ((J<<3)&0x20) | + ((J<<1)&0x10) | + ((J>>1)&0x08) | + ((J>>3)&0x04) | + ((J>>5)&0x02) | + ((J>>7)&0x01); + } + + C = sprlinebuf+x; + VB = (PALRAM+0x10)+((atr&3)<<2); + + if(atr&SP_BACK) + { + if (atr&H_FLIP) + { + if(J&0x80) C[7]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x40) C[6]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x20) C[5]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x10) C[4]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x08) C[3]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x04) C[2]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x02) C[1]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x01) C[0]=VB[pixdata]|0x40; + } else { + if(J&0x80) C[0]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x40) C[1]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x20) C[2]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x10) C[3]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x08) C[4]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x04) C[5]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x02) C[6]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x01) C[7]=VB[pixdata]|0x40; + } + } else { + if (atr&H_FLIP) + { + if(J&0x80) C[7]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x40) C[6]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x20) C[5]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x10) C[4]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x08) C[3]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x04) C[2]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x02) C[1]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x01) C[0]=VB[pixdata]; + }else{ + if(J&0x80) C[0]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x40) C[1]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x20) C[2]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x10) C[3]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x08) C[4]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x04) C[5]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x02) C[6]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x01) C[7]=VB[pixdata]; + } + } + } + } + SpriteBlurp=0; + spork=1; +} + +static void CopySprites(uint8 *target) +{ + uint8 n=((PPU[1]&4)^4)<<1; + uint8 *P=target; + + if(!spork) + return; + spork=0; + +loopskie: + { + uint32 t=*(uint32 *)(sprlinebuf+n); + + if(t!=0x80808080) + { +#ifdef LSB_FIRST + if(!(t&0x80)) + { + if(!(t&0x40) || (P[n]&0x40)) /* Normal sprite || behind bg sprite*/ + P[n]=sprlinebuf[n]; + } + + if(!(t&0x8000)) + { + if(!(t&0x4000) || (P[n+1]&0x40)) /* Normal sprite || behind bg sprite*/ + P[n+1]=(sprlinebuf+1)[n]; + } + + if(!(t&0x800000)) + { + if(!(t&0x400000) || (P[n+2]&0x40)) /* Normal sprite || behind bg sprite*/ + P[n+2]=(sprlinebuf+2)[n]; + } + + if(!(t&0x80000000)) + { + if(!(t&0x40000000) || (P[n+3]&0x40)) /* Normal sprite || behind bg sprite*/ + P[n+3]=(sprlinebuf+3)[n]; + } +#else + /* TODO: Simplify */ + if(!(t&0x80000000)) + { + if(!(t&0x40000000)) /* Normal sprite*/ + P[n]=sprlinebuf[n]; + else if(P[n]&64) /* behind bg sprite*/ + P[n]=sprlinebuf[n]; + } + + if(!(t&0x800000)) + { + if(!(t&0x400000)) /* Normal sprite*/ + P[n+1]=(sprlinebuf+1)[n]; + else if(P[n+1]&64) /* behind bg sprite*/ + P[n+1]=(sprlinebuf+1)[n]; + } + + if(!(t&0x8000)) + { + if(!(t&0x4000)) /* Normal sprite*/ + P[n+2]=(sprlinebuf+2)[n]; + else if(P[n+2]&64) /* behind bg sprite*/ + P[n+2]=(sprlinebuf+2)[n]; + } + + if(!(t&0x80)) + { + if(!(t&0x40)) /* Normal sprite*/ + P[n+3]=(sprlinebuf+3)[n]; + else if(P[n+3]&64) /* behind bg sprite*/ + P[n+3]=(sprlinebuf+3)[n]; + } +#endif + } + } + n+=4; + if(n) goto loopskie; +} + +void FCEUPPU_SetVideoSystem(int w) +{ + if(w) + { + scanlines_per_frame=312; + FSettings.FirstSLine=FSettings.UsrFirstSLine[1]; + FSettings.LastSLine=FSettings.UsrLastSLine[1]; + } + else + { + scanlines_per_frame=262; + FSettings.FirstSLine=FSettings.UsrFirstSLine[0]; + FSettings.LastSLine=FSettings.UsrLastSLine[0]; + } +} + +void FCEUPPU_Init(void) +{ + int x; + int y; + int cc,xo,pixel; + + + for(x=0;x<256;x++) + { + ppulut1[x]=0; + for(y=0;y<8;y++) + ppulut1[x]|=((x>>(7-y))&1)<<(y*4); + ppulut2[x]=ppulut1[x]<<1; + } + + for(cc=0;cc<16;cc++) + { + for(xo=0;xo<8;xo++) + { + ppulut3[xo|(cc<<3)]=0; + for(pixel=0;pixel<8;pixel++) + { + int shiftr; + shiftr=(pixel+xo)/8; + shiftr*=2; + ppulut3[xo|(cc<<3)]|=(( cc>>shiftr )&3)<<(2+pixel*4); + } + } + } +} + +void FCEUPPU_Reset(void) +{ + VRAMBuffer=PPU[0]=PPU[1]=PPU_status=PPU[3]=0; + PPUSPL=0; + PPUGenLatch=0; + RefreshAddr=TempAddr=0; + vtoggle = 0; + ppudead = 2; + kook = 0; +} + +void FCEUPPU_Power(void) +{ + int x; + memset(NTARAM,0x00,0x800); + memset(PALRAM,0x00,0x20); + memset(SPRAM,0x00,0x100); + FCEUPPU_Reset(); +#ifdef COPYFAMI + for(x=0x2000;x<0x2010;x+=8) + { + ARead[x]=A200x; + BWrite[x]=B2000; + ARead[x+1]=A200x; + BWrite[x+1]=B2001; + ARead[x+2]=A2002; + BWrite[x+2]=B2002; + ARead[x+3]=A200x; + BWrite[x+3]=B2003; + ARead[x+4]=A200x; /*A2004;*/ + BWrite[x+4]=B2004; + ARead[x+5]=A200x; + BWrite[x+5]=B2005; + ARead[x+6]=A200x; + BWrite[x+6]=B2006; + ARead[x+7]=A2007; + BWrite[x+7]=B2007; + } +#else + for(x=0x2000;x<0x4000;x+=8) + { + ARead[x]=A200x; + BWrite[x]=B2000; + ARead[x+1]=A200x; + BWrite[x+1]=B2001; + ARead[x+2]=A2002; + BWrite[x+2]=B2002; + ARead[x+3]=A200x; + BWrite[x+3]=B2003; + ARead[x+4]=A200x; /*A2004;*/ + BWrite[x+4]=B2004; + ARead[x+5]=A200x; + BWrite[x+5]=B2005; + ARead[x+6]=A200x; + BWrite[x+6]=B2006; + ARead[x+7]=A2007; + BWrite[x+7]=B2007; + } +#endif + BWrite[0x4014]=B4014; +} + + +void FCEUPPU_Loop(void) +{ + if(ppudead) /* Needed for Knight Rider, possibly others. */ + { + memset(XBuf, 0x80, 256*240); + X6502_Run(scanlines_per_frame*(256+85)); + ppudead--; + } + else + { + int x,max,maxref; + + X6502_Run(256+85); + PPU_status |= 0x80; + PPU[3]=PPUSPL=0; /* Not sure if this is correct. According + to Matt Conte and my own tests, it is. Timing is probably + off, though. NOTE: Not having this here + breaks a Super Donkey Kong game. */ + /* I need to figure out the true nature and length + of this delay. + */ + X6502_Run(12); + if(VBlankON) + TriggerNMI(); + X6502_Run((scanlines_per_frame-242)*(256+85)-12); /*-12); */ + PPU_status&=0x1f; + X6502_Run(256); + + if(ScreenON || SpriteON) + { + if(GameHBIRQHook && ((PPU[0]&0x38)!=0x18)) + GameHBIRQHook(); + if(PPU_hook) + for( x=0;x<42;x++) {PPU_hook(0x2000); PPU_hook(0);} + if(GameHBIRQHook2) + GameHBIRQHook2(); + } + X6502_Run(85-16); + if(ScreenON || SpriteON) + { + RefreshAddr=TempAddr; + if(PPU_hook) PPU_hook(RefreshAddr&0x3fff); + } + + /* Clean this stuff up later. */ + spork=numsprites=0; + ResetRL(XBuf); + + X6502_Run(16-kook); + kook ^= 1; + + deemp=PPU[1]>>5; + for(scanline=0;scanline<240;) /*scanline is incremented in DoLine. Evil. */ + { + deempcnt[deemp]++; + DoLine(); + } + if(MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline); + for(x=1,max=0,maxref=0;x<7;x++) + { + if(deempcnt[x]>max) + { + max=deempcnt[x]; + maxref=x; + } + deempcnt[x]=0; + } + SetNESDeemph(maxref,0); + } /* else... to if(ppudead) */ +} + +static uint16 TempAddrT,RefreshAddrT; + +void FCEUPPU_LoadState(int version) +{ + TempAddr=TempAddrT; + RefreshAddr=RefreshAddrT; +} + +SFORMAT FCEUPPU_STATEINFO[]={ + { NTARAM, 0x800, "NTAR"}, + { PALRAM, 0x20, "PRAM"}, + { SPRAM, 0x100, "SPRA"}, + { PPU, 0x4, "PPUR"}, + { &kook, 1, "KOOK"}, + { &ppudead, 1, "DEAD"}, + { &PPUSPL, 1, "PSPL"}, + { &XOffset, 1, "XOFF"}, + { &vtoggle, 1, "VTOG"}, + { &RefreshAddrT, 2|FCEUSTATE_RLSB, "RADD"}, + { &TempAddrT, 2|FCEUSTATE_RLSB, "TADD"}, + { &VRAMBuffer, 1, "VBUF"}, + { &PPUGenLatch, 1, "PGEN"}, + { 0 } + }; + +void FCEUPPU_SaveState(void) +{ + TempAddrT=TempAddr; + RefreshAddrT=RefreshAddr; +} diff --git a/fceumm/src-fceumm/ppu.h b/fceumm/src-fceumm/ppu.h new file mode 100644 index 0000000..7fbda2e --- /dev/null +++ b/fceumm/src-fceumm/ppu.h @@ -0,0 +1,23 @@ +void FCEUPPU_Init(void); +void FCEUPPU_Reset(void); +void FCEUPPU_Power(void); +void FCEUPPU_Loop(void); + +void FCEUPPU_LineUpdate(); +void FCEUPPU_SetVideoSystem(int w); + +extern void (*PPU_hook)(uint32 A); +extern void (*GameHBIRQHook)(void), (*GameHBIRQHook2)(void); + +/* For cart.c and banksw.h, mostly */ +extern uint8 NTARAM[0x800],*vnapage[4]; +extern uint8 PPUNTARAM; +extern uint8 PPUCHRRAM; + +void FCEUPPU_SaveState(void); +void FCEUPPU_LoadState(int version); + +int FCEU_InitVirtualVideo(void); + +extern int scanline; +extern uint8 *XBuf; diff --git a/fceumm/src-fceumm/pputile.h b/fceumm/src-fceumm/pputile.h new file mode 100644 index 0000000..e4c65af --- /dev/null +++ b/fceumm/src-fceumm/pputile.h @@ -0,0 +1,102 @@ + uint8 *C; + register uint8 cc; + uint32 vadr; + + #ifndef PPUT_MMC5SP + register uint8 zz; + #else + uint8 xs,ys; + xs=X1; + ys=((scanline>>3)+MMC5HackSPScroll)&0x1F; + if(ys>=0x1E) ys-=0x1E; + #endif + + if(X1>=2) + { + uint8 *S=PALRAM; + uint32 pixdata; + + pixdata=ppulut1[(pshift[0]>>(8-XOffset))&0xFF]|ppulut2[(pshift[1]>>(8-XOffset))&0xFF]; + + pixdata|=ppulut3[XOffset|(atlatch<<3)]; + /*printf("%02x ",ppulut3[XOffset|(atlatch<<3)]);*/ + + P[0]=S[pixdata&0xF]; + pixdata>>=4; + P[1]=S[pixdata&0xF]; + pixdata>>=4; + P[2]=S[pixdata&0xF]; + pixdata>>=4; + P[3]=S[pixdata&0xF]; + pixdata>>=4; + P[4]=S[pixdata&0xF]; + pixdata>>=4; + P[5]=S[pixdata&0xF]; + pixdata>>=4; + P[6]=S[pixdata&0xF]; + pixdata>>=4; + P[7]=S[pixdata&0xF]; + P+=8; + } + + #ifdef PPUT_MMC5SP + vadr=(MMC5HackExNTARAMPtr[xs|(ys<<5)]<<4)+(vofs&7); + #else + zz=RefreshAddr&0x1F; + C=vnapage[(RefreshAddr>>10)&3]; + vadr=(C[RefreshAddr&0x3ff]<<4)+vofs; /* Fetch name table byte. */ + #endif + + #ifdef PPUT_HOOK + PPU_hook(0x2000|(RefreshAddr&0xfff)); + #endif + + #ifdef PPUT_MMC5SP + cc=MMC5HackExNTARAMPtr[0x3c0+(xs>>2)+((ys&0x1C)<<1)]; + cc=((cc >> ((xs&2) + ((ys&0x2)<<1))) &3); + #else + #ifdef PPUT_MMC5CHR1 + cc=(MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff] & 0xC0)>>6; + #else + cc=C[0x3c0+(zz>>2)+((RefreshAddr&0x380)>>4)]; /* Fetch attribute table byte. */ + cc=((cc >> ((zz&2) + ((RefreshAddr&0x40)>>4))) &3); + #endif + #endif + + atlatch>>=2; + atlatch|=cc<<2; + + pshift[0]<<=8; + pshift[1]<<=8; + + #ifdef PPUT_MMC5SP + C = MMC5HackVROMPTR+vadr; + C += ((MMC5HackSPPage & 0x3f & MMC5HackVROMMask) << 12); + #else + #ifdef PPUT_MMC5CHR1 + C = MMC5HackVROMPTR; + C += (((MMC5HackExNTARAMPtr[RefreshAddr & 0x3ff]) & 0x3f & + MMC5HackVROMMask) << 12) + (vadr & 0xfff); + #elif defined(PPUT_MMC5) + C=MMC5BGVRAMADR(vadr); + #else + C = VRAMADR(vadr); + #endif + #endif + + #ifdef PPUT_HOOK + PPU_hook(vadr); + #endif + + pshift[0]|=C[0]; + pshift[1]|=C[8]; + + if((RefreshAddr&0x1f)==0x1f) + RefreshAddr^=0x41F; + else + RefreshAddr++; + + #ifdef PPUT_HOOK + PPU_hook(0x2000|(RefreshAddr&0xfff)); + #endif + diff --git a/fceumm/src-fceumm/ppuview.h b/fceumm/src-fceumm/ppuview.h new file mode 100644 index 0000000..f072e30 --- /dev/null +++ b/fceumm/src-fceumm/ppuview.h @@ -0,0 +1,8 @@ +extern int PPUViewScanline; +extern int PPUViewer; +extern int scanline; + +void PPUViewDoBlit(); +void DoPPUView(); +void UpdatePPUView(int refreshchr); + diff --git a/fceumm/src-fceumm/sound.c b/fceumm/src-fceumm/sound.c new file mode 100644 index 0000000..c866ebe --- /dev/null +++ b/fceumm/src-fceumm/sound.c @@ -0,0 +1,25 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#if SOUND_QUALITY == 1 +#include "sound_hq_.h" +#else +#include "sound_lq_.h" +#endif diff --git a/fceumm/src-fceumm/sound.h b/fceumm/src-fceumm/sound.h new file mode 100644 index 0000000..68625df --- /dev/null +++ b/fceumm/src-fceumm/sound.h @@ -0,0 +1,60 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +typedef struct { + void (*Fill)(int Count); /* Low quality ext sound. */ + + /* NeoFill is for sound devices that are emulated in a more + high-level manner(VRC7) in HQ mode. Interestingly, + this device has slightly better sound quality(updated more + often) in lq mode than in high-quality mode. Maybe that + should be fixed. :) + */ + void (*NeoFill)(int32 *Wave, int Count); + void (*HiFill)(void); + void (*HiSync)(int32 ts); + + void (*RChange)(void); + void (*Kill)(void); +} EXPSOUND; + +extern EXPSOUND GameExpSound; + +extern int32 nesincsize; + +void SetSoundVariables(void); + +int GetSoundBuffer(int32 **W); +int FlushEmulateSound(void); +extern int32 Wave[2048+512]; +extern int32 WaveFinal[2048+512]; +extern int32 WaveHi[]; +extern uint32 soundtsinc; + +extern uint32 soundtsoffs; +#define SOUNDTS (timestamp + soundtsoffs) + +void SetNESSoundMap(void); + +void FCEUSND_Power(void); +void FCEUSND_Reset(void); +void FCEUSND_LoadState(int version); + +void FCEU_SoundCPUHook(int); diff --git a/fceumm/src-fceumm/sound_hq_.h b/fceumm/src-fceumm/sound_hq_.h new file mode 100644 index 0000000..902c8d7 --- /dev/null +++ b/fceumm/src-fceumm/sound_hq_.h @@ -0,0 +1,1298 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +#include + +#include "types.h" +#include "x6502.h" + +#include "fceu.h" +#include "sound.h" +#include "state.h" + +#include "fcoeffs.h" + +static uint32 wlookup1[32]; +static uint32 wlookup2[203]; + +int32 Wave[2048+512]; +int32 WaveHi[40000]; +int32 WaveFinal[2048+512]; + +EXPSOUND GameExpSound={0,0,0}; + +static uint8 TriCount=0; +static uint8 TriMode=0; + +static int32 tristep=0; + +static int32 wlcount[4]={0,0,0,0}; /* Wave length counters. */ + +static uint8 IRQFrameMode=0; /* $4017 / xx000000 */ +static uint8 PSG[0x10]; +static uint8 RawDALatch=0; /* $4011 0xxxxxxx */ + +uint8 EnabledChannels=0; /* Byte written to $4015 */ + +typedef struct { + uint8 Speed; + uint8 Mode; /* Fixed volume(1), and loop(2) */ + uint8 DecCountTo1; + uint8 decvolume; + int reloaddec; +} ENVUNIT; + +static ENVUNIT EnvUnits[3]; + +static const int RectDuties[4]={1,2,4,6}; + +static int32 RectDutyCount[2]; +static uint8 sweepon[2]; +static int32 curfreq[2]; +static uint8 SweepCount[2]; + +static uint16 nreg=0; + +static uint8 fcnt=0; +static int32 fhcnt=0; +static int32 fhinc=0; + +uint32 soundtsoffs=0; + +/* Variables exclusively for low-quality sound. */ +int32 nesincsize=0; +uint32 soundtsinc=0; +uint32 soundtsi=0; +static int32 sqacc[2]; +/* LQ variables segment ends. */ + +static int32 lengthcount[4]; +static const uint8 lengthtable[0x20]= +{ + 0x0A, 0xFE, 0x14, 0x02, 0x28, 0x04, 0x50, 0x06, + 0xa0, 0x08, 0x3c, 0x0a, 0x0e, 0x0c, 0x1a, 0x0e, + 0x0c, 0x10, 0x18, 0x12, 0x30, 0x14, 0x60, 0x16, + 0xc0, 0x18, 0x48, 0x1a, 0x10, 0x1c, 0x20, 0x1E +}; + +static const uint32 NTSCNoiseFreqTable[0x10]= +{ + 0x004, 0x008, 0x010, 0x020, 0x040, 0x060, 0x080, 0x0A0, + 0x0CA, 0x0FE, 0x17C, 0x1FC, 0x2FA, 0x3F8, 0x7F2, 0xFE4 +}; + +static const uint32 PALNoiseFreqTable[0x10]= +{ + 0x004, 0x007, 0x00E, 0x01E, 0x03C, 0x058, 0x076, 0x094, + 0x0BC, 0x0EC, 0x162, 0x1D8, 0x2C4, 0x3B0, 0x762, 0xEC2 +}; + +static const uint32 NTSCDMCTable[0x10]= +{ + 0x1AC, 0x17C, 0x154, 0x140, 0x11E, 0x0FE, 0x0E2, 0x0D6, + 0x0BE, 0x0A0, 0x08E, 0x080, 0x06A, 0x054, 0x048, 0x036 +}; + +static const uint32 PALDMCTable[0x10]= +{ + 0x18E, 0x162, 0x13C, 0x12A, 0x114, 0x0EC, 0x0D2, 0x0C6, + 0x0B0, 0x094, 0x084, 0x076, 0x062, 0x04E, 0x042, 0x032 +}; + +// $4010 - Frequency +// $4011 - Actual data outputted +// $4012 - Address register: $c000 + V*64 +// $4013 - Size register: Size in bytes = (V+1)*64 + +/*static*/ int32 DMCacc=1; +static int32 DMCPeriod=0; +/*static*/ uint8 DMCBitCount=0; + +static uint8 DMCAddressLatch=0,DMCSizeLatch=0; /* writes to 4012 and 4013 */ +static uint8 DMCFormat=0; /* Write to $4010 */ + +static uint32 DMCAddress=0; +static int32 DMCSize=0; +static uint8 DMCShift=0; +static uint8 SIRQStat=0; + +static char DMCHaveDMA=0; +static uint8 DMCDMABuf=0; +static char DMCHaveSample=0; + +static void Dummyfunc(void) {}; +static void (*DoNoise)(void)=Dummyfunc; +static void (*DoTriangle)(void)=Dummyfunc; +static void (*DoSQ1)(void)=Dummyfunc; +static void (*DoSQ2)(void)=Dummyfunc; + +static uint32 ChannelBC[5]; + +static void LoadDMCPeriod(uint8 V) +{ + if(PAL) + DMCPeriod=PALDMCTable[V]; + else + DMCPeriod=NTSCDMCTable[V]; +} + +static void PrepDPCM() +{ + DMCAddress=0x4000+(DMCAddressLatch<<6); + DMCSize=(DMCSizeLatch<<4)+1; +} + +/* Instantaneous? Maybe the new freq value is being calculated all of the time... */ + +static int CheckFreq(uint32 cf, uint8 sr) +{ + uint32 mod; + if(!(sr&0x8)) + { + mod=cf>>(sr&7); + if((mod+cf)&0x800) + return(0); + } + return(1); +} + +static void SQReload(int x, uint8 V) +{ + if(EnabledChannels&(1<>3)&0x1f]; + } + + sweepon[x]=PSG[(x<<2)|1]&0x80; + curfreq[x]=PSG[(x<<2)|0x2]|((V&7)<<8); + SweepCount[x]=((PSG[(x<<2)|0x1]>>4)&7)+1; + + RectDutyCount[x]=7; + EnvUnits[x].reloaddec=1; + //reloadfreq[x]=1; +} + +static void RDoPCM(void) +{ + uint32 V; + + for(V=ChannelBC[4];V>4; + EnvUnits[0].Speed=(V&0xF); + break; + case 0x1: + sweepon[0]=V&0x80; + break; + case 0x2: + DoSQ1(); + curfreq[0]&=0xFF00; + curfreq[0]|=V; + break; + case 0x3: + SQReload(0,V); + break; + case 0x4: + DoSQ2(); + EnvUnits[1].Mode=(V&0x30)>>4; + EnvUnits[1].Speed=(V&0xF); + break; + case 0x5: + sweepon[1]=V&0x80; + break; + case 0x6:DoSQ2(); + curfreq[1]&=0xFF00; + curfreq[1]|=V; + break; + case 0x7: + SQReload(1,V); + break; + case 0xa:DoTriangle(); + break; + case 0xb: + DoTriangle(); + if(EnabledChannels&0x4) + lengthcount[2]=lengthtable[(V>>3)&0x1f]; + TriMode=1; // Load mode + break; + case 0xC:DoNoise(); + EnvUnits[2].Mode=(V&0x30)>>4; + EnvUnits[2].Speed=(V&0xF); + break; + case 0xE:DoNoise(); + break; + case 0xF: + DoNoise(); + if(EnabledChannels&0x8) + lengthcount[3]=lengthtable[(V>>3)&0x1f]; + EnvUnits[2].reloaddec=1; + break; + case 0x10: + RDoPCM(); + LoadDMCPeriod(V&0xF); + + if(SIRQStat&0x80) + { + if(!(V&0x80)) + { + X6502_IRQEnd(FCEU_IQDPCM); + SIRQStat&=~0x80; + } + else X6502_IRQBegin(FCEU_IQDPCM); + } + break; + } + PSG[A]=V; +} + +static DECLFW(Write_DMCRegs) +{ + // FCEU_printf("APU1 %04x:%04x\n",A,V); + A&=0xF; + + switch(A) + { + case 0x00: + RDoPCM(); + LoadDMCPeriod(V&0xF); + + if(SIRQStat&0x80) + { + if(!(V&0x80)) + { + X6502_IRQEnd(FCEU_IQDPCM); + SIRQStat&=~0x80; + } + else X6502_IRQBegin(FCEU_IQDPCM); + } + DMCFormat=V; + break; + case 0x01: + RDoPCM(); + RawDALatch=V&0x7F; + break; + case 0x02:DMCAddressLatch=V;break; + case 0x03:DMCSizeLatch=V;break; + } + + +} + +static DECLFW(StatusWrite) +{ + int x; + // FCEU_printf("APU1 %04x:%04x\n",A,V); + + DoSQ1(); + DoSQ2(); + DoTriangle(); + DoNoise(); + RDoPCM(); + for(x=0;x<4;x++) + if(!(V&(1<0) + lengthcount[2]--; + + if(!(PSG[0xC]&0x20)) /* Make sure loop flag is not set. */ + if(lengthcount[3]>0) + lengthcount[3]--; + + for(P=0;P<2;P++) + { + if(!(PSG[P<<2]&0x20)) /* Make sure loop flag is not set. */ + if(lengthcount[P]>0) + lengthcount[P]--; + + /* Frequency Sweep Code Here */ + /* xxxx 0000 */ + /* xxxx = hz. 120/(x+1)*/ + if(sweepon[P]) + { + int32 mod=0; + + if(SweepCount[P]>0) + SweepCount[P]--; + if(SweepCount[P]<=0) + { + SweepCount[P]=((PSG[(P<<2)+0x1]>>4)&7)+1; //+1; + if(PSG[(P<<2)+0x1]&0x8) + { + mod-=(P^1)+((curfreq[P])>>(PSG[(P<<2)+0x1]&7)); + if(curfreq[P] && (PSG[(P<<2)+0x1]&7)/* && sweepon[P]&0x80*/) + curfreq[P]+=mod; + } + else + { + mod=curfreq[P]>>(PSG[(P<<2)+0x1]&7); + if((mod+curfreq[P])&0x800) + { + sweepon[P]=0; + curfreq[P]=0; + } + else + { + if(curfreq[P] && (PSG[(P<<2)+0x1]&7)/* && sweepon[P]&0x80*/) + curfreq[P]+=mod; + } + } + } + } + } + } + + /* Now do envelope decay + linear counter. */ + + if(TriMode) // In load mode? + TriCount=PSG[0x8]&0x7F; + else if(TriCount) + TriCount--; + + if(!(PSG[0x8]&0x80)) + TriMode=0; + + for(P=0;P<3;P++) + { + if(EnvUnits[P].reloaddec) + { + EnvUnits[P].decvolume=0xF; + EnvUnits[P].DecCountTo1=EnvUnits[P].Speed+1; + EnvUnits[P].reloaddec=0; + continue; + } + + if(EnvUnits[P].DecCountTo1>0) EnvUnits[P].DecCountTo1--; + if(EnvUnits[P].DecCountTo1==0) + { + EnvUnits[P].DecCountTo1=EnvUnits[P].Speed+1; + if(EnvUnits[P].decvolume || (EnvUnits[P].Mode&0x2)) + { + EnvUnits[P].decvolume--; + EnvUnits[P].decvolume&=0xF; + } + } + } +} + +static void FrameSoundUpdate(void) +{ + // Linear counter: Bit 0-6 of $4008 + // Length counter: Bit 4-7 of $4003, $4007, $400b, $400f + + if(!fcnt && !(IRQFrameMode&0x3)) + { + SIRQStat|=0x40; + X6502_IRQBegin(FCEU_IQFCOUNT); + } + + if(fcnt==3) + { + if(IRQFrameMode&0x2) + fhcnt+=fhinc; + } + FrameSoundStuff(fcnt); + fcnt=(fcnt+1)&3; +} + + +static INLINE void tester(void) +{ + if(DMCBitCount==0) + { + if(!DMCHaveDMA) + DMCHaveSample=0; + else + { + DMCHaveSample=1; + DMCShift=DMCDMABuf; + DMCHaveDMA=0; + } + } +} + +static INLINE void DMCDMA(void) +{ + if(DMCSize && !DMCHaveDMA) + { + X6502_DMR(0x8000+DMCAddress); + X6502_DMR(0x8000+DMCAddress); + X6502_DMR(0x8000+DMCAddress); + DMCDMABuf=X6502_DMR(0x8000+DMCAddress); + DMCHaveDMA=1; + DMCAddress=(DMCAddress+1)&0x7fff; + DMCSize--; + if(!DMCSize) + { + if(DMCFormat&0x40) + PrepDPCM(); + else + { + SIRQStat|=0x80; + if(DMCFormat&0x80) + X6502_IRQBegin(FCEU_IQDPCM); + } + } + } +} + +void FCEU_SoundCPUHook(int cycles) +{ + fhcnt-=cycles*48; + if(fhcnt<=0) + { + FrameSoundUpdate(); + fhcnt+=fhinc; + } + + DMCDMA(); + DMCacc-=cycles; + + while(DMCacc<=0) + { + if(DMCHaveSample) + { + uint8 bah=RawDALatch; + int t=((DMCShift&1)<<2)-2; + /* Unbelievably ugly hack */ + soundtsoffs+=DMCacc; + RDoPCM(); + soundtsoffs-=DMCacc; + RawDALatch+=t; + if(RawDALatch&0x80) + RawDALatch=bah; + } + + DMCacc+=DMCPeriod; + DMCBitCount=(DMCBitCount+1)&7; + DMCShift>>=1; + tester(); + } +} + + +/* This has the correct phase. Don't mess with it. */ +static INLINE void RDoSQ(int x) +{ + int32 V; + int32 amp; + int32 rthresh; + int32 *D; + int32 currdc; + int32 cf; + int32 rc; + + if(curfreq[x]<8 || curfreq[x]>0x7ff) + goto endit; + if(!CheckFreq(curfreq[x],PSG[(x<<2)|0x1])) + goto endit; + if(!lengthcount[x]) + goto endit; + + if(EnvUnits[x].Mode&0x1) + amp=EnvUnits[x].Speed; + else + amp=EnvUnits[x].decvolume; + amp<<=24; + + rthresh=RectDuties[(PSG[(x<<2)]&0xC0)>>6]; + + D=&WaveHi[ChannelBC[x]]; + V=SOUNDTS-ChannelBC[x]; + + currdc=RectDutyCount[x]; + cf=(curfreq[x]+1)*2; + rc=wlcount[x]; + + while(V>0) + { + if(currdc0x7ff) + inie[x]=0; + if(!CheckFreq(curfreq[x],PSG[(x<<2)|0x1])) + inie[x]=0; + if(!lengthcount[x]) + inie[x]=0; + + if(EnvUnits[x].Mode&0x1) + amp[x]=EnvUnits[x].Speed; + else + amp[x]=EnvUnits[x].decvolume; + + if(!inie[x]) amp[x]=0; /* Correct? Buzzing in MM2, others otherwise... */ + + rthresh[x]=RectDuties[(PSG[x*4]&0xC0)>>6]; + + for(y=0;y<8;y++) + { + if(y < rthresh[x]) + ttable[x][y] = amp[x]; + else + ttable[x][y] = 0; + } + freq[x]=(curfreq[x]+1)<<1; + freq[x]<<=17; + } + + totalout = wlookup1[ ttable[0][RectDutyCount[0]] + ttable[1][RectDutyCount[1]] ]; + + if(!inie[0] && !inie[1]) + { + for(V=start;V>4]+=totalout; + } + else + for(V=start;V>4]+=totalout; //tmpamp; + + sqacc[0]-=inie[0]; + sqacc[1]-=inie[1]; + + if(sqacc[0]<=0) + { +rea: + sqacc[0]+=freq[0]; + RectDutyCount[0]=(RectDutyCount[0]+1)&7; + if(sqacc[0]<=0) goto rea; + totalout = wlookup1[ ttable[0][RectDutyCount[0]] + ttable[1][RectDutyCount[1]] ]; + } + + if(sqacc[1]<=0) + { +rea2: + sqacc[1]+=freq[1]; + RectDutyCount[1]=(RectDutyCount[1]+1)&7; + if(sqacc[1]<=0) goto rea2; + totalout = wlookup1[ ttable[0][RectDutyCount[0]] + ttable[1][RectDutyCount[1]] ]; + } + } +} + +static void RDoTriangle(void) +{ + int32 V; + int32 tcout; + + tcout=(tristep&0xF); + if(!(tristep&0x10)) tcout^=0xF; + tcout=(tcout*3) << 16; //(tcout<<1); + + if(!lengthcount[2] || !TriCount) + { /* Counter is halted, but we still need to output. */ + int32 *start = &WaveHi[ChannelBC[2]]; + int32 count = SOUNDTS - ChannelBC[2]; + while(count--) + { + *start += tcout; + start++; + } + } + else + for(V=ChannelBC[2];V>0xe)&1]; + + if(PSG[0xE]&0x80) + nshift=8; + else + nshift=13; + + + totalout = wlookup2[tcout+noiseout+RawDALatch]; + + if(inie[0] && inie[1]) + { + for(V=start;V>4]+=totalout; + + triacc-=inie[0]; + noiseacc-=inie[1]; + + if(triacc<=0) + { +rea: + triacc+=freq[0]; //t; + tristep=(tristep+1)&0x1F; + if(triacc<=0) goto rea; + tcout=(tristep&0xF); + if(!(tristep&0x10)) tcout^=0xF; + tcout=tcout*3; + totalout = wlookup2[tcout+noiseout+RawDALatch]; + } + + if(noiseacc<=0) + { +rea2: + //used to added <<(16+2) when the noise table + //values were half. + if(PAL) + noiseacc+=PALNoiseFreqTable[PSG[0xE]&0xF]<<(16+1); + else + noiseacc+=NTSCNoiseFreqTable[PSG[0xE]&0xF]<<(16+1); + nreg=(nreg<<1)+(((nreg>>nshift)^(nreg>>14))&1); + nreg&=0x7fff; + noiseout=amptab[(nreg>>0xe)&1]; + if(noiseacc<=0) goto rea2; + totalout = wlookup2[tcout+noiseout+RawDALatch]; + } /* noiseacc<=0 */ + } /* for(V=... */ + } + else if(inie[0]) + { + for(V=start;V>4]+=totalout; + + triacc-=inie[0]; + + if(triacc<=0) + { +area: + triacc+=freq[0]; //t; + tristep=(tristep+1)&0x1F; + if(triacc<=0) goto area; + tcout=(tristep&0xF); + if(!(tristep&0x10)) tcout^=0xF; + tcout=tcout*3; + totalout = wlookup2[tcout+noiseout+RawDALatch]; + } + } + } + else if(inie[1]) + { + for(V=start;V>4]+=totalout; + noiseacc-=inie[1]; + if(noiseacc<=0) + { +area2: + //used to be added <<(16+2) when the noise table + //values were half. + if(PAL) + noiseacc+=PALNoiseFreqTable[PSG[0xE]&0xF]<<(16+1); + else + noiseacc+=NTSCNoiseFreqTable[PSG[0xE]&0xF]<<(16+1); + nreg=(nreg<<1)+(((nreg>>nshift)^(nreg>>14))&1); + nreg&=0x7fff; + noiseout=amptab[(nreg>>0xe)&1]; + if(noiseacc<=0) goto area2; + totalout = wlookup2[tcout+noiseout+RawDALatch]; + } /* noiseacc<=0 */ + } + } + else + { + for(V=start;V>4]+=totalout; + } +} + + +static void RDoNoise(void) +{ + uint32 V; + int32 outo; + uint32 amptab[2]; + + if(EnvUnits[2].Mode&0x1) + amptab[0]=EnvUnits[2].Speed; + else + amptab[0]=EnvUnits[2].decvolume; + + amptab[0]<<=16; + amptab[1]=0; + + amptab[0]<<=1; + + outo=amptab[(nreg>>0xe)&1]; + + if(!lengthcount[3]) + { + outo=amptab[0]=0; + } + + if(PSG[0xE]&0x80) // "short" noise + for(V=ChannelBC[3];V>8)&1)^((nreg>>14)&1); + nreg=(nreg<<1)+feedback; + nreg&=0x7fff; + outo=amptab[(nreg>>0xe)&1]; + } + } + else + for(V=ChannelBC[3];V>13)&1)^((nreg>>14)&1); + nreg=(nreg<<1)+feedback; + nreg&=0x7fff; + outo=amptab[(nreg>>0xe)&1]; + } + } + ChannelBC[3]=SOUNDTS; +} + +DECLFW(Write_IRQFM) +{ + V=(V&0xC0)>>6; + fcnt=0; + if(V&2) + FrameSoundUpdate(); + fcnt=1; + fhcnt=fhinc; + X6502_IRQEnd(FCEU_IQFCOUNT); + SIRQStat&=~0x40; + IRQFrameMode=V; +} + +void SetNESSoundMap(void) +{ + SetWriteHandler(0x4000,0x400F,Write_PSG); + SetWriteHandler(0x4010,0x4013,Write_DMCRegs); + SetWriteHandler(0x4017,0x4017,Write_IRQFM); + + SetWriteHandler(0x4015,0x4015,StatusWrite); + SetReadHandler(0x4015,0x4015,StatusRead); +} + +/* Returns number of samples written to out. */ +/* leftover is set to the number of samples that need to be copied + from the end of in to the beginning of in. +*/ + +//static uint32 mva=1000; + +/* This filtering code assumes that almost all input values stay below 32767. + Do not adjust the volume in the wlookup tables and the expansion sound + code to be higher, or you *might* overflow the FIR code. +*/ +static uint32 mrindex; +static uint32 mrratio; + +static void SexyFilter(int32 *in, int32 *out, int32 count) +{ + static int64 acc1=0,acc2=0; + int32 mul1,mul2,vmul; + + mul1=(94<<16)/FSettings.SndRate; + mul2=(24<<16)/FSettings.SndRate; + vmul=(FSettings.SoundVolume<<16)*3/4/100; + + vmul/=4; + + while(count) + { + int64 ino=(int64)*in*vmul; + acc1+=((ino-acc1)*mul1)>>16; + acc2+=((ino-acc1-acc2)*mul2)>>16; + *in=0; + { + int32 t=(acc1-ino+acc2)>>16; + if(t>32767) + t=32767; + if(t<-32768) + t=-32768; + *out=t; + } + in++; + out++; + count--; + } +} + +static int32 NeoFilterSound(int32 *in, int32 *out, uint32 inlen, int32 *leftover) +{ + uint32 x; + uint32 max; + int32 *outsave=out; + int32 count=0; + + max=(inlen-1)<<16; + + for(x=mrindex;x>16)-SQ2NCOEFFS],D=sq2coeffs;c;c--,D++) + { + acc+=(S[c]**D)>>6; + acc2+=(S[1+c]**D)>>6; + } + + acc=((int64)acc*(65536-(x&65535))+(int64)acc2*(x&65535))>>(16+11); + *out=acc; + out++; + count++; + } + + mrindex=x-max; + + mrindex+=SQ2NCOEFFS*65536; + *leftover=SQ2NCOEFFS+1; + + if(GameExpSound.NeoFill) + GameExpSound.NeoFill(outsave,count); + + SexyFilter(outsave,outsave,count); + return(count); +} + +static int32 inbuf=0; +int FlushEmulateSound(void) +{ + int x; + int32 end,left; + + DoSQ1(); + DoSQ2(); + DoTriangle(); + DoNoise(); + RDoPCM(); + + int32 *tmpo=&WaveHi[soundtsoffs]; + + if(GameExpSound.HiFill) + GameExpSound.HiFill(); + + for(x=timestamp;x;x--) + { + uint32 b=*tmpo; + *tmpo=(b&65535)+wlookup2[(b>>16)&255]+wlookup1[b>>24]; + tmpo++; + } + end=NeoFilterSound(WaveHi,WaveFinal,SOUNDTS,&left); + + memmove(WaveHi,WaveHi+SOUNDTS-left,left*sizeof(uint32)); + memset(WaveHi+left,0,sizeof(WaveHi)-left*sizeof(uint32)); + + if(GameExpSound.HiSync) GameExpSound.HiSync(left); + for(x=0;x<5;x++) + ChannelBC[x]=left; + + soundtsoffs=left; + + inbuf=end; + + return(end); +} + +int GetSoundBuffer(int32 **W) +{ + *W=WaveFinal; + return(inbuf); +} + +/* FIXME: Find out what sound registers get reset on reset. I know $4001/$4005 don't, +due to that whole MegaMan 2 Game Genie thing. +*/ + +void FCEUSND_Reset(void) +{ + int x; + + IRQFrameMode=0x0; + fhcnt=fhinc; + fcnt=0; + + nreg=1; + + for(x=0;x<2;x++) + { + wlcount[x]=2048; + if(nesincsize) // lq mode + sqacc[x]=((uint32)2048<<17)/nesincsize; + else + sqacc[x]=1; + sweepon[x]=0; + curfreq[x]=0; + } + wlcount[2]=1; //2048; + wlcount[3]=2048; + DMCHaveDMA=DMCHaveSample=0; + SIRQStat=0x00; + + RawDALatch=0x00; + TriCount=0; + TriMode=0; + tristep=0; + EnabledChannels=0; + for(x=0;x<4;x++) + lengthcount[x]=0; + + DMCAddressLatch=0; + DMCSizeLatch=0; + DMCFormat=0; + DMCAddress=0; + DMCSize=0; + DMCShift=0; +} + +void FCEUSND_Power(void) +{ + SetNESSoundMap(); + memset(PSG,0x00,sizeof(PSG)); + FCEUSND_Reset(); + + memset(Wave,0,sizeof(Wave)); + memset(WaveHi,0,sizeof(WaveHi)); + memset(&EnvUnits,0,sizeof(EnvUnits)); + + for(uint32_t x=0;x<5;x++) + ChannelBC[x]=0; + soundtsoffs=0; + LoadDMCPeriod(DMCFormat&0xF); +} + +static void MakeFilters(int32 rate) +{ + int32 *tabs[6]={C44100NTSC,C44100PAL,C48000NTSC,C48000PAL,C96000NTSC, + C96000PAL}; + int32 *sq2tabs[6]={SQ2C44100NTSC,SQ2C44100PAL,SQ2C48000NTSC,SQ2C48000PAL, + SQ2C96000NTSC,SQ2C96000PAL}; + + int32 *tmp; + int32 x; + uint32 nco= SQ2NCOEFFS; + + mrindex=(nco+1)<<16; + mrratio=(PAL?(int64)(PAL_CPU*65536):(int64)(NTSC_CPU*65536))/rate; + + tmp=sq2tabs[(PAL?1:0)|(rate==48000?2:0)|(rate==96000?4:0)]; + + for(x=0;x>1;x++) + sq2coeffs[x]=sq2coeffs[SQ2NCOEFFS-1-x]=tmp[x]; + +#ifdef MOO + /* Some tests involving precision and error. */ + { + static int64 acc=0; + int x; + for(x=0;x +#include +#include + +#include + +#include "types.h" +#include "x6502.h" + +#include "fceu.h" +#include "sound.h" +#include "state.h" + +#include "fcoeffs.h" + +static uint32 wlookup1[32]; +static uint32 wlookup2[203]; + +int32 Wave[2048+512]; +int32 WaveHi[40000]; +int32 WaveFinal[2048+512]; + +EXPSOUND GameExpSound={0,0,0}; + +static uint8 TriCount=0; +static uint8 TriMode=0; + +static int32 tristep=0; + +static int32 wlcount[4]={0,0,0,0}; /* Wave length counters. */ + +static uint8 IRQFrameMode=0; /* $4017 / xx000000 */ +static uint8 PSG[0x10]; +static uint8 RawDALatch=0; /* $4011 0xxxxxxx */ + +uint8 EnabledChannels=0; /* Byte written to $4015 */ + +typedef struct { + uint8 Speed; + uint8 Mode; /* Fixed volume(1), and loop(2) */ + uint8 DecCountTo1; + uint8 decvolume; + int reloaddec; +} ENVUNIT; + +static ENVUNIT EnvUnits[3]; + +static const int RectDuties[4]={1,2,4,6}; + +static int32 RectDutyCount[2]; +static uint8 sweepon[2]; +static int32 curfreq[2]; +static uint8 SweepCount[2]; + +static uint16 nreg=0; + +static uint8 fcnt=0; +static int32 fhcnt=0; +static int32 fhinc=0; + +uint32 soundtsoffs=0; + +/* Variables exclusively for low-quality sound. */ +int32 nesincsize=0; +uint32 soundtsinc=0; +uint32 soundtsi=0; +static int32 sqacc[2]; +/* LQ variables segment ends. */ + +static int32 lengthcount[4]; +static const uint8 lengthtable[0x20]= +{ + 0x0A, 0xFE, 0x14, 0x02, 0x28, 0x04, 0x50, 0x06, + 0xa0, 0x08, 0x3c, 0x0a, 0x0e, 0x0c, 0x1a, 0x0e, + 0x0c, 0x10, 0x18, 0x12, 0x30, 0x14, 0x60, 0x16, + 0xc0, 0x18, 0x48, 0x1a, 0x10, 0x1c, 0x20, 0x1E +}; + +static const uint32 NTSCNoiseFreqTable[0x10]= +{ + 0x004, 0x008, 0x010, 0x020, 0x040, 0x060, 0x080, 0x0A0, + 0x0CA, 0x0FE, 0x17C, 0x1FC, 0x2FA, 0x3F8, 0x7F2, 0xFE4 +}; + +static const uint32 PALNoiseFreqTable[0x10]= +{ + 0x004, 0x007, 0x00E, 0x01E, 0x03C, 0x058, 0x076, 0x094, + 0x0BC, 0x0EC, 0x162, 0x1D8, 0x2C4, 0x3B0, 0x762, 0xEC2 +}; + +static const uint32 NTSCDMCTable[0x10]= +{ + 0x1AC, 0x17C, 0x154, 0x140, 0x11E, 0x0FE, 0x0E2, 0x0D6, + 0x0BE, 0x0A0, 0x08E, 0x080, 0x06A, 0x054, 0x048, 0x036 +}; + +static const uint32 PALDMCTable[0x10]= +{ + 0x18E, 0x162, 0x13C, 0x12A, 0x114, 0x0EC, 0x0D2, 0x0C6, + 0x0B0, 0x094, 0x084, 0x076, 0x062, 0x04E, 0x042, 0x032 +}; + +/* $4010 - Frequency*/ +/* $4011 - Actual data outputted*/ +/* $4012 - Address register: $c000 + V*64*/ +/* $4013 - Size register: Size in bytes = (V+1)*64*/ + +/*static*/ int32 DMCacc=1; +static int32 DMCPeriod=0; +/*static*/ uint8 DMCBitCount=0; + +static uint8 DMCAddressLatch=0,DMCSizeLatch=0; /* writes to 4012 and 4013 */ +static uint8 DMCFormat=0; /* Write to $4010 */ + +static uint32 DMCAddress=0; +static int32 DMCSize=0; +static uint8 DMCShift=0; +static uint8 SIRQStat=0; + +static char DMCHaveDMA=0; +static uint8 DMCDMABuf=0; +static char DMCHaveSample=0; + +static uint32 ChannelBC[5]; + +static void LoadDMCPeriod(uint8 V) +{ + if(PAL) + DMCPeriod=PALDMCTable[V]; + else + DMCPeriod=NTSCDMCTable[V]; +} + +static void PrepDPCM() +{ + DMCAddress=0x4000+(DMCAddressLatch<<6); + DMCSize=(DMCSizeLatch<<4)+1; +} + +/* Instantaneous? Maybe the new freq value is being calculated all of the time... */ + +static int CheckFreq(uint32 cf, uint8 sr) +{ + uint32 mod; + if(!(sr&0x8)) + { + mod=cf>>(sr&7); + if((mod+cf)&0x800) + return(0); + } + return(1); +} + +static void RDoSQLQ(void) +{ + int32 start,end; + int32 V; + int32 amp[2]; + int32 rthresh[2]; + int32 freq[2]; + int x; + int32 inie[2]; + + int32 ttable[2][8]; + int32 totalout; + + start=ChannelBC[0]; + end=(SOUNDTS<<16)/soundtsinc; + if(end<=start) return; + ChannelBC[0]=end; + + for(x=0;x<2;x++) + { + int y; + + inie[x]=nesincsize; + if(curfreq[x]<8 || curfreq[x]>0x7ff) + inie[x]=0; + if(!CheckFreq(curfreq[x],PSG[(x<<2)|0x1])) + inie[x]=0; + if(!lengthcount[x]) + inie[x]=0; + + if(EnvUnits[x].Mode&0x1) + amp[x]=EnvUnits[x].Speed; + else + amp[x]=EnvUnits[x].decvolume; + + if(!inie[x]) amp[x]=0; /* Correct? Buzzing in MM2, others otherwise... */ + + rthresh[x]=RectDuties[(PSG[x*4]&0xC0)>>6]; + + for(y=0;y<8;y++) + { + if(y < rthresh[x]) + ttable[x][y] = amp[x]; + else + ttable[x][y] = 0; + } + freq[x]=(curfreq[x]+1)<<1; + freq[x]<<=17; + } + + totalout = wlookup1[ ttable[0][RectDutyCount[0]] + ttable[1][RectDutyCount[1]] ]; + + if(!inie[0] && !inie[1]) + { + for(V=start;V>4]+=totalout; + } + else + for(V=start;V>4]+=totalout; /*tmpamp;*/ + + sqacc[0]-=inie[0]; + sqacc[1]-=inie[1]; + + if(sqacc[0]<=0) + { +rea: + sqacc[0]+=freq[0]; + RectDutyCount[0]=(RectDutyCount[0]+1)&7; + if(sqacc[0]<=0) goto rea; + totalout = wlookup1[ ttable[0][RectDutyCount[0]] + ttable[1][RectDutyCount[1]] ]; + } + + if(sqacc[1]<=0) + { +rea2: + sqacc[1]+=freq[1]; + RectDutyCount[1]=(RectDutyCount[1]+1)&7; + if(sqacc[1]<=0) goto rea2; + totalout = wlookup1[ ttable[0][RectDutyCount[0]] + ttable[1][RectDutyCount[1]] ]; + } + } +} + +static void SQReload(int x, uint8 V) +{ + if(EnabledChannels&(1<>3)&0x1f]; + } + + sweepon[x]=PSG[(x<<2)|1]&0x80; + curfreq[x]=PSG[(x<<2)|0x2]|((V&7)<<8); + SweepCount[x]=((PSG[(x<<2)|0x1]>>4)&7)+1; + + RectDutyCount[x]=7; + EnvUnits[x].reloaddec=1; + /*reloadfreq[x]=1;*/ +} + +static void RDoTriangleNoisePCMLQ(void) +{ + static uint32 tcout=0; + static int32 triacc=0; + static int32 noiseacc=0; + + int32 V; + int32 start,end; + int32 freq[2]; + int32 inie[2]; + uint32 amptab[2]; + uint32 noiseout; + int nshift; + + int32 totalout; + + start=ChannelBC[2]; + end=(SOUNDTS<<16)/soundtsinc; + if(end<=start) return; + ChannelBC[2]=end; + + inie[0]=inie[1]=nesincsize; + + freq[0]=(((PSG[0xa]|((PSG[0xb]&7)<<8))+1)); + + if(!lengthcount[2] || !TriCount || freq[0]<=4) + inie[0]=0; + + freq[0]<<=17; + if(EnvUnits[2].Mode&0x1) + amptab[0]=EnvUnits[2].Speed; + else + amptab[0]=EnvUnits[2].decvolume; + amptab[1]=0; + amptab[0]<<=1; + + if(!lengthcount[3]) + amptab[0]=inie[1]=0; /* Quick hack speedup, set inie[1] to 0 */ + + noiseout=amptab[(nreg>>0xe)&1]; + + if(PSG[0xE]&0x80) + nshift=8; + else + nshift=13; + + + totalout = wlookup2[tcout+noiseout+RawDALatch]; + + if(inie[0] && inie[1]) + { + for(V=start;V>4]+=totalout; + + triacc-=inie[0]; + noiseacc-=inie[1]; + + if(triacc<=0) + { +rea: + triacc+=freq[0]; /*t;*/ + tristep=(tristep+1)&0x1F; + if(triacc<=0) goto rea; + tcout=(tristep&0xF); + if(!(tristep&0x10)) tcout^=0xF; + tcout=tcout*3; + totalout = wlookup2[tcout+noiseout+RawDALatch]; + } + + if(noiseacc<=0) + { +rea2: + /*used to added <<(16+2) when the noise table*/ + /*values were half.*/ + if(PAL) + noiseacc+=PALNoiseFreqTable[PSG[0xE]&0xF]<<(16+1); + else + noiseacc+=NTSCNoiseFreqTable[PSG[0xE]&0xF]<<(16+1); + nreg=(nreg<<1)+(((nreg>>nshift)^(nreg>>14))&1); + nreg&=0x7fff; + noiseout=amptab[(nreg>>0xe)&1]; + if(noiseacc<=0) goto rea2; + totalout = wlookup2[tcout+noiseout+RawDALatch]; + } /* noiseacc<=0 */ + } /* for(V=... */ + } + else if(inie[0]) + { + for(V=start;V>4]+=totalout; + + triacc-=inie[0]; + + if(triacc<=0) + { +area: + triacc+=freq[0]; /*t;*/ + tristep=(tristep+1)&0x1F; + if(triacc<=0) goto area; + tcout=(tristep&0xF); + if(!(tristep&0x10)) tcout^=0xF; + tcout=tcout*3; + totalout = wlookup2[tcout+noiseout+RawDALatch]; + } + } + } + else if(inie[1]) + { + for(V=start;V>4]+=totalout; + noiseacc-=inie[1]; + if(noiseacc<=0) + { +area2: + /*used to be added <<(16+2) when the noise table*/ + /*values were half.*/ + if(PAL) + noiseacc+=PALNoiseFreqTable[PSG[0xE]&0xF]<<(16+1); + else + noiseacc+=NTSCNoiseFreqTable[PSG[0xE]&0xF]<<(16+1); + nreg=(nreg<<1)+(((nreg>>nshift)^(nreg>>14))&1); + nreg&=0x7fff; + noiseout=amptab[(nreg>>0xe)&1]; + if(noiseacc<=0) goto area2; + totalout = wlookup2[tcout+noiseout+RawDALatch]; + } /* noiseacc<=0 */ + } + } + else + { + for(V=start;V>4]+=totalout; + } +} + +static DECLFW(Write_PSG) +{ + /* FCEU_printf("APU1 %04x:%04x\n",A,V);*/ + A&=0x1F; + switch(A) + { + case 0x0: + RDoSQLQ(); + EnvUnits[0].Mode=(V&0x30)>>4; + EnvUnits[0].Speed=(V&0xF); + break; + case 0x1: + sweepon[0]=V&0x80; + break; + case 0x2: + RDoSQLQ(); + curfreq[0]&=0xFF00; + curfreq[0]|=V; + break; + case 0x3: + SQReload(0,V); + break; + case 0x4: + RDoSQLQ(); + EnvUnits[1].Mode=(V&0x30)>>4; + EnvUnits[1].Speed=(V&0xF); + break; + case 0x5: + sweepon[1]=V&0x80; + break; + case 0x6: + RDoSQLQ(); + curfreq[1]&=0xFF00; + curfreq[1]|=V; + break; + case 0x7: + SQReload(1,V); + break; + case 0xa: + RDoTriangleNoisePCMLQ(); + break; + case 0xb: + RDoTriangleNoisePCMLQ(); + if(EnabledChannels&0x4) + lengthcount[2]=lengthtable[(V>>3)&0x1f]; + TriMode=1; /* Load mode*/ + break; + case 0xC: + RDoTriangleNoisePCMLQ(); + EnvUnits[2].Mode=(V&0x30)>>4; + EnvUnits[2].Speed=(V&0xF); + break; + case 0xE: + RDoTriangleNoisePCMLQ(); + break; + case 0xF: + RDoTriangleNoisePCMLQ(); + if(EnabledChannels&0x8) + lengthcount[3]=lengthtable[(V>>3)&0x1f]; + EnvUnits[2].reloaddec=1; + break; + case 0x10: + RDoTriangleNoisePCMLQ(); + LoadDMCPeriod(V&0xF); + + if(SIRQStat&0x80) + { + if(!(V&0x80)) + { + X6502_IRQEnd(FCEU_IQDPCM); + SIRQStat&=~0x80; + } + else X6502_IRQBegin(FCEU_IQDPCM); + } + break; + } + PSG[A]=V; +} + +static DECLFW(Write_DMCRegs) +{ + /* FCEU_printf("APU1 %04x:%04x\n",A,V);*/ + A&=0xF; + + switch(A) + { + case 0x00: + RDoTriangleNoisePCMLQ(); + LoadDMCPeriod(V&0xF); + + if(SIRQStat&0x80) + { + if(!(V&0x80)) + { + X6502_IRQEnd(FCEU_IQDPCM); + SIRQStat&=~0x80; + } + else X6502_IRQBegin(FCEU_IQDPCM); + } + DMCFormat=V; + break; + case 0x01: + RDoTriangleNoisePCMLQ(); + RawDALatch=V&0x7F; + break; + case 0x02:DMCAddressLatch=V;break; + case 0x03:DMCSizeLatch=V;break; + } + + +} + +static DECLFW(StatusWrite) +{ + int x; + /* FCEU_printf("APU1 %04x:%04x\n",A,V);*/ + + RDoSQLQ(); + RDoSQLQ(); + RDoTriangleNoisePCMLQ(); + RDoTriangleNoisePCMLQ(); + RDoTriangleNoisePCMLQ(); + for(x=0;x<4;x++) + if(!(V&(1<0) + lengthcount[2]--; + + if(!(PSG[0xC]&0x20)) /* Make sure loop flag is not set. */ + if(lengthcount[3]>0) + lengthcount[3]--; + + for(P=0;P<2;P++) + { + if(!(PSG[P<<2]&0x20)) /* Make sure loop flag is not set. */ + if(lengthcount[P]>0) + lengthcount[P]--; + + /* Frequency Sweep Code Here */ + /* xxxx 0000 */ + /* xxxx = hz. 120/(x+1)*/ + if(sweepon[P]) + { + int32 mod=0; + + if(SweepCount[P]>0) + SweepCount[P]--; + if(SweepCount[P]<=0) + { + SweepCount[P]=((PSG[(P<<2)+0x1]>>4)&7)+1; /*+1;*/ + if(PSG[(P<<2)+0x1]&0x8) + { + mod-=(P^1)+((curfreq[P])>>(PSG[(P<<2)+0x1]&7)); + if(curfreq[P] && (PSG[(P<<2)+0x1]&7)/* && sweepon[P]&0x80*/) + curfreq[P]+=mod; + } + else + { + mod=curfreq[P]>>(PSG[(P<<2)+0x1]&7); + if((mod+curfreq[P])&0x800) + { + sweepon[P]=0; + curfreq[P]=0; + } + else + { + if(curfreq[P] && (PSG[(P<<2)+0x1]&7)/* && sweepon[P]&0x80*/) + curfreq[P]+=mod; + } + } + } + } + } + } + + /* Now do envelope decay + linear counter. */ + + if(TriMode) /* In load mode?*/ + TriCount=PSG[0x8]&0x7F; + else if(TriCount) + TriCount--; + + if(!(PSG[0x8]&0x80)) + TriMode=0; + + for(P=0;P<3;P++) + { + if(EnvUnits[P].reloaddec) + { + EnvUnits[P].decvolume=0xF; + EnvUnits[P].DecCountTo1=EnvUnits[P].Speed+1; + EnvUnits[P].reloaddec=0; + continue; + } + + if(EnvUnits[P].DecCountTo1>0) EnvUnits[P].DecCountTo1--; + if(EnvUnits[P].DecCountTo1==0) + { + EnvUnits[P].DecCountTo1=EnvUnits[P].Speed+1; + if(EnvUnits[P].decvolume || (EnvUnits[P].Mode&0x2)) + { + EnvUnits[P].decvolume--; + EnvUnits[P].decvolume&=0xF; + } + } + } +} + +static void FrameSoundUpdate(void) +{ + /* Linear counter: Bit 0-6 of $4008*/ + /* Length counter: Bit 4-7 of $4003, $4007, $400b, $400f*/ + + if(!fcnt && !(IRQFrameMode&0x3)) + { + SIRQStat|=0x40; + X6502_IRQBegin(FCEU_IQFCOUNT); + } + + if(fcnt==3) + { + if(IRQFrameMode&0x2) + fhcnt+=fhinc; + } + FrameSoundStuff(fcnt); + fcnt=(fcnt+1)&3; +} + + +static INLINE void tester(void) +{ + if(DMCBitCount==0) + { + if(!DMCHaveDMA) + DMCHaveSample=0; + else + { + DMCHaveSample=1; + DMCShift=DMCDMABuf; + DMCHaveDMA=0; + } + } +} + +static INLINE void DMCDMA(void) +{ + if(DMCSize && !DMCHaveDMA) + { + X6502_DMR(0x8000+DMCAddress); + X6502_DMR(0x8000+DMCAddress); + X6502_DMR(0x8000+DMCAddress); + DMCDMABuf=X6502_DMR(0x8000+DMCAddress); + DMCHaveDMA=1; + DMCAddress=(DMCAddress+1)&0x7fff; + DMCSize--; + if(!DMCSize) + { + if(DMCFormat&0x40) + PrepDPCM(); + else + { + SIRQStat|=0x80; + if(DMCFormat&0x80) + X6502_IRQBegin(FCEU_IQDPCM); + } + } + } +} + +void FCEU_SoundCPUHook(int cycles) +{ + fhcnt-=cycles*48; + if(fhcnt<=0) + { + FrameSoundUpdate(); + fhcnt+=fhinc; + } + + DMCDMA(); + DMCacc-=cycles; + + while(DMCacc<=0) + { + if(DMCHaveSample) + { + uint8 bah=RawDALatch; + int t=((DMCShift&1)<<2)-2; + /* Unbelievably ugly hack */ + soundtsoffs+=DMCacc; + RDoTriangleNoisePCMLQ(); + soundtsoffs-=DMCacc; + RawDALatch+=t; + if(RawDALatch&0x80) + RawDALatch=bah; + } + + DMCacc+=DMCPeriod; + DMCBitCount=(DMCBitCount+1)&7; + DMCShift>>=1; + tester(); + } +} + +DECLFW(Write_IRQFM) +{ + V=(V&0xC0)>>6; + fcnt=0; + if(V&2) + FrameSoundUpdate(); + fcnt=1; + fhcnt=fhinc; + X6502_IRQEnd(FCEU_IQFCOUNT); + SIRQStat&=~0x40; + IRQFrameMode=V; +} + +void SetNESSoundMap(void) +{ + SetWriteHandler(0x4000,0x400F,Write_PSG); + SetWriteHandler(0x4010,0x4013,Write_DMCRegs); + SetWriteHandler(0x4017,0x4017,Write_IRQFM); + + SetWriteHandler(0x4015,0x4015,StatusWrite); + SetReadHandler(0x4015,0x4015,StatusRead); +} + +static uint32 mrindex; +static uint32 mrratio; + +static void SexyFilter(int32 *in, int32 *out, int32 count) +{ + static int64 acc1=0,acc2=0; + int32 mul1,mul2,vmul; + + mul1=(94<<16)/FSettings.SndRate; + mul2=(24<<16)/FSettings.SndRate; + vmul=(FSettings.SoundVolume<<16)*3/4/100; + + vmul*=2; /* TODO: Increase volume in low quality sound rendering code itself */ + + while(count) + { + int64 ino=(int64)*in*vmul; + acc1+=((ino-acc1)*mul1)>>16; + acc2+=((ino-acc1-acc2)*mul2)>>16; + *in=0; + { + int32 t=(acc1-ino+acc2)>>16; + if(t>32767) t=32767; + if(t<-32768) t=-32768; + *out=t; + } + in++; + out++; + count--; + } +} + +static int32 inbuf=0; +int FlushEmulateSound(void) +{ + int x; + int32 end,left; + + RDoSQLQ(); + RDoSQLQ(); + RDoTriangleNoisePCMLQ(); + RDoTriangleNoisePCMLQ(); + RDoTriangleNoisePCMLQ(); + + end=(SOUNDTS<<16)/soundtsinc; + if(GameExpSound.Fill) + GameExpSound.Fill(end&0xF); + + SexyFilter(Wave,WaveFinal,end>>4); + + if(end&0xF) + Wave[0]=Wave[(end>>4)]; + Wave[end>>4]=0; + + for(x=0;x<5;x++) + ChannelBC[x]=end & 0xF; + + soundtsoffs = (soundtsinc*(end&0xF))>>16; + end>>=4; + + inbuf=end; + + return(end); +} + +int GetSoundBuffer(int32 **W) +{ + *W=WaveFinal; + return(inbuf); +} + +/* FIXME: Find out what sound registers get reset on reset. I know $4001/$4005 don't, +due to that whole MegaMan 2 Game Genie thing. +*/ + +void FCEUSND_Reset(void) +{ + int x; + + IRQFrameMode=0x0; + fhcnt=fhinc; + fcnt=0; + + nreg=1; + + for(x=0;x<2;x++) + { + wlcount[x]=2048; + if(nesincsize) /* lq mode*/ + sqacc[x]=((uint32)2048<<17)/nesincsize; + else + sqacc[x]=1; + sweepon[x]=0; + curfreq[x]=0; + } + wlcount[2]=1; /*2048;*/ + wlcount[3]=2048; + DMCHaveDMA=DMCHaveSample=0; + SIRQStat=0x00; + + RawDALatch=0x00; + TriCount=0; + TriMode=0; + tristep=0; + EnabledChannels=0; + for(x=0;x<4;x++) + lengthcount[x]=0; + + DMCAddressLatch=0; + DMCSizeLatch=0; + DMCFormat=0; + DMCAddress=0; + DMCSize=0; + DMCShift=0; +} + +void FCEUSND_Power(void) +{ + uint32_t x; + + SetNESSoundMap(); + memset(PSG,0x00,sizeof(PSG)); + FCEUSND_Reset(); + + memset(Wave,0,sizeof(Wave)); + memset(WaveHi,0,sizeof(WaveHi)); + memset(&EnvUnits,0,sizeof(EnvUnits)); + + for( x=0;x<5;x++) + ChannelBC[x]=0; + soundtsoffs=0; + LoadDMCPeriod(DMCFormat&0xF); +} + +static void MakeFilters(int32 rate) +{ + int32 *tabs[6]={C44100NTSC,C44100PAL,C48000NTSC,C48000PAL,C96000NTSC, + C96000PAL}; + int32 *sq2tabs[6]={SQ2C44100NTSC,SQ2C44100PAL,SQ2C48000NTSC,SQ2C48000PAL, + SQ2C96000NTSC,SQ2C96000PAL}; + + int32 *tmp; + int32 x; + uint32 nco = NCOEFFS; + + mrindex=(nco+1)<<16; + mrratio=(PAL?(int64)(PAL_CPU*65536):(int64)(NTSC_CPU*65536))/rate; + + tmp=tabs[(PAL?1:0)|(rate==48000?2:0)|(rate==96000?4:0)]; + + for(x=0;x>1;x++) + coeffs[x]=coeffs[NCOEFFS-1-x]=tmp[x]; + +#ifdef MOO + /* Some tests involving precision and error. */ + { + static int64 acc=0; + int x; + for(x=0;x>= 4; + } + wlookup2[0]=0; + for(x=1;x<203;x++) + { + wlookup2[x]=(double)16*16*16*4*163.67/((double)24329/(double)x+100); + wlookup2[x] >>= 4; + } + } + else + { + return; + } + + MakeFilters(FSettings.SndRate); + + if(GameExpSound.RChange) + GameExpSound.RChange(); + + nesincsize=(int64)(((int64)1<<17)*(double)(PAL?PAL_CPU:NTSC_CPU)/(FSettings.SndRate * 16)); + memset(sqacc,0,sizeof(sqacc)); + memset(ChannelBC,0,sizeof(ChannelBC)); + + LoadDMCPeriod(DMCFormat&0xF); /* For changing from PAL to NTSC*/ + + soundtsinc=(uint32)((uint64)(PAL?(long double)PAL_CPU*65536:(long double)NTSC_CPU*65536)/(FSettings.SndRate * 16)); +} + +void FCEUI_Sound(int Rate) +{ + FSettings.SndRate=Rate; + SetSoundVariables(); +} + +void FCEUI_SetSoundVolume(uint32 volume) +{ + FSettings.SoundVolume=volume; +} + + +SFORMAT FCEUSND_STATEINFO[]={ + + { &fhcnt, 4|FCEUSTATE_RLSB,"FHCN"}, + { &fcnt, 1, "FCNT"}, + { PSG, 0x10, "PSG"}, + { &EnabledChannels, 1, "ENCH"}, + { &IRQFrameMode, 1, "IQFM"}, + { &nreg, 2|FCEUSTATE_RLSB, "NREG"}, + { &TriMode, 1, "TRIM"}, + { &TriCount, 1, "TRIC"}, + + { &EnvUnits[0].Speed, 1, "E0SP"}, + { &EnvUnits[1].Speed, 1, "E1SP"}, + { &EnvUnits[2].Speed, 1, "E2SP"}, + + { &EnvUnits[0].Mode, 1, "E0MO"}, + { &EnvUnits[1].Mode, 1, "E1MO"}, + { &EnvUnits[2].Mode, 1, "E2MO"}, + + { &EnvUnits[0].DecCountTo1, 1, "E0D1"}, + { &EnvUnits[1].DecCountTo1, 1, "E1D1"}, + { &EnvUnits[2].DecCountTo1, 1, "E2D1"}, + + { &EnvUnits[0].decvolume, 1, "E0DV"}, + { &EnvUnits[1].decvolume, 1, "E1DV"}, + { &EnvUnits[2].decvolume, 1, "E2DV"}, + + { &lengthcount[0], 4|FCEUSTATE_RLSB, "LEN0"}, + { &lengthcount[1], 4|FCEUSTATE_RLSB, "LEN1"}, + { &lengthcount[2], 4|FCEUSTATE_RLSB, "LEN2"}, + { &lengthcount[3], 4|FCEUSTATE_RLSB, "LEN3"}, + { sweepon, 2, "SWEE"}, + { &curfreq[0], 4|FCEUSTATE_RLSB,"CRF1"}, + { &curfreq[1], 4|FCEUSTATE_RLSB,"CRF2"}, + { SweepCount, 2,"SWCT"}, + + { &SIRQStat, 1, "SIRQ"}, + + { &DMCacc, 4|FCEUSTATE_RLSB, "5ACC"}, + { &DMCBitCount, 1, "5BIT"}, + { &DMCAddress, 4|FCEUSTATE_RLSB, "5ADD"}, + { &DMCSize, 4|FCEUSTATE_RLSB, "5SIZ"}, + { &DMCShift, 1, "5SHF"}, + + { &DMCHaveDMA, 1, "5HVDM"}, + { &DMCHaveSample, 1, "5HVSP"}, + + { &DMCSizeLatch, 1, "5SZL"}, + { &DMCAddressLatch, 1, "5ADL"}, + { &DMCFormat, 1, "5FMT"}, + { &RawDALatch, 1, "RWDA"}, + { 0 } +}; + +void FCEUSND_LoadState(int version) +{ + LoadDMCPeriod(DMCFormat&0xF); + RawDALatch&=0x7F; + DMCAddress&=0x7FFF; +} diff --git a/fceumm/src-fceumm/state.c b/fceumm/src-fceumm/state.c new file mode 100644 index 0000000..3d83a92 --- /dev/null +++ b/fceumm/src-fceumm/state.c @@ -0,0 +1,561 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* TODO: Add (better) file io error checking */ +/* TODO: Change save state file format. */ + +#include +#include +#include +#ifndef _MSC_VER +#include +#endif + +#include "types.h" +#include "x6502.h" +#include "fceu.h" +#include "sound.h" +#include "myendian.h" +#include "fds.h" +#include "general.h" +#include "state.h" +#include "memory.h" +#include "ppu.h" + + +static void (*SPreSave)(void); +static void (*SPostSave)(void); + +static SFORMAT SFMDATA[64]; +static int SFEXINDEX; + +#define RLSB FCEUSTATE_RLSB /*0x80000000*/ + +#define FCEU_VERSION_NUMERIC 21040 + +extern SFORMAT FCEUPPU_STATEINFO[]; +extern SFORMAT FCEUSND_STATEINFO[]; +extern SFORMAT FCEUCTRL_STATEINFO[]; + +SFORMAT SFCPU[]={ + { &X.PC, 2|RLSB, "PC\0"}, + { &X.A, 1, "A\0\0"}, + { &X.P, 1, "P\0\0"}, + { &X.X, 1, "X\0\0"}, + { &X.Y, 1, "Y\0\0"}, + { &X.S, 1, "S\0\0"}, +#ifdef COPYFAMI + { RAM, 0x4000, "RAM"}, +#else + { RAM, 0x800, "RAM"}, +#endif + { 0 } +}; + +SFORMAT SFCPUC[]={ + { &X.jammed, 1, "JAMM"}, + { &X.IRQlow, 4|RLSB, "IQLB"}, + { &X.tcount, 4|RLSB, "ICoa"}, + { &X.count, 4|RLSB, "ICou"}, + { ×tampbase, sizeof(timestampbase) | RLSB, "TSBS"}, + { 0 } +}; + +static int SubWrite(FILE *st, SFORMAT *sf) +{ + uint32 acc=0; + + while(sf->v) + { + if(sf->s==~0) /* Link to another struct. */ + { + uint32 tmp; + + if(!(tmp=SubWrite(st,(SFORMAT *)sf->v))) + return(0); + acc+=tmp; + sf++; + continue; + } + + acc+=8; /* Description + size */ + acc+=sf->s&(~RLSB); + + if(st) /* Are we writing or calculating the size of this block? */ + { + fwrite(sf->desc,1,4,st); + write32le(sf->s&(~RLSB),st); + +#ifndef LSB_FIRST + if(sf->s&RLSB) + FlipByteOrder(sf->v,sf->s&(~RLSB)); +#endif + + fwrite((uint8 *)sf->v,1,sf->s&(~RLSB),st); + /* Now restore the original byte order. */ +#ifndef LSB_FIRST + if(sf->s&RLSB) + FlipByteOrder(sf->v,sf->s&(~RLSB)); +#endif + } + sf++; + } + + return(acc); +} + +#ifdef __LIBSNES__ +static int SubWrite_Mem(memstream_t *mem, SFORMAT *sf) +{ + uint32 acc=0; + + while(sf->v) + { + if(sf->s==~0) /* Link to another struct. */ + { + uint32 tmp; + + if(!(tmp=SubWrite_Mem(mem, (SFORMAT *)sf->v))) + return(0); + acc+=tmp; + sf++; + continue; + } + + acc+=8; /* Description + size */ + acc+=sf->s&(~RLSB); + + if(mem) /* Are we writing or calculating the size of this block? */ + { + memstream_write(mem, sf->desc, 4); + write32le_mem(sf->s&(~RLSB), mem); + +#ifndef LSB_FIRST + if(sf->s&RLSB) + FlipByteOrder(sf->v,sf->s&(~RLSB)); +#endif + + memstream_write(mem, (uint8 *)sf->v, sf->s&(~RLSB)); + /* Now restore the original byte order. */ +#ifndef LSB_FIRST + if(sf->s&RLSB) + FlipByteOrder(sf->v,sf->s&(~RLSB)); +#endif + } + sf++; + } + + return acc; +} +#endif + +static int WriteStateChunk(FILE *st, int type, SFORMAT *sf) +{ + int bsize; + + fputc(type,st); + + bsize=SubWrite(0,sf); + write32le(bsize,st); + + if(!SubWrite(st,sf)) + return(0); + return (bsize+5); +} + +#ifdef __LIBSNES__ +static int WriteStateChunk_Mem(memstream_t *mem, int type, SFORMAT *sf) +{ + int bsize; + + memstream_putc(mem, type); + + bsize = SubWrite_Mem(0,sf); + write32le_mem(bsize, mem); + + if (!SubWrite_Mem(mem, sf)) + return 0; + return bsize + 5; +} +#endif + +static SFORMAT *CheckS(SFORMAT *sf, uint32 tsize, const char *desc) +{ + while(sf->v) + { + if(sf->s==~0) /* Link to another SFORMAT structure. */ + { + SFORMAT *tmp; + if((tmp= CheckS((SFORMAT *)sf->v, tsize, desc) )) + return(tmp); + sf++; + continue; + } + if(!memcmp(desc,sf->desc,4)) + { + if(tsize!=(sf->s&(~RLSB))) + return(0); + return(sf); + } + sf++; + } + return(0); +} + +static int ReadStateChunk(FILE *st, SFORMAT *sf, int size) +{ + SFORMAT *tmp; + int temp; + temp=ftell(st); + + while(ftell(st)v,1,tmp->s&(~RLSB),st); + +#ifndef LSB_FIRST + if(tmp->s&RLSB) + FlipByteOrder(tmp->v,tmp->s&(~RLSB)); +#endif + } + else + fseek(st,tsize,SEEK_CUR); + } + return 1; +} + +#ifdef __LIBSNES__ +static int ReadStateChunk_Mem(memstream_t *mem, SFORMAT *sf, int size) +{ + SFORMAT *tmp; + int temp; + temp=memstream_pos(mem); + + while(memstream_pos(mem)v, tmp->s&(~RLSB)); + +#ifndef LSB_FIRST + if(tmp->s&RLSB) + FlipByteOrder(tmp->v,tmp->s&(~RLSB)); +#endif + } + else + memstream_seek(mem,tsize,SEEK_CUR); + } + return 1; +} +#endif + +static int ReadStateChunks(FILE *st, int32 totalsize) +{ + int t; + uint32 size; + int ret=1; + + while(totalsize > 0) + { + t=fgetc(st); + if(t==EOF) break; + if(!read32le(&size,st)) break; + totalsize -= size + 5; + + switch(t) + { + case 1:if(!ReadStateChunk(st,SFCPU,size)) ret=0;break; + case 2:if(!ReadStateChunk(st,SFCPUC,size)) ret=0; + else + { + X.mooPI=X.P; /* Quick and dirty hack.*/ + } + break; + case 3:if(!ReadStateChunk(st,FCEUPPU_STATEINFO,size)) ret=0;break; + case 4:if(!ReadStateChunk(st,FCEUCTRL_STATEINFO,size)) ret=0;break; + case 5:if(!ReadStateChunk(st,FCEUSND_STATEINFO,size)) ret=0;break; + case 0x10:if(!ReadStateChunk(st,SFMDATA,size)) ret=0; + break; + default: if(fseek(st,size,SEEK_CUR)<0) goto endo;break; + } + } +endo: + return ret; +} + +#ifdef __LIBSNES__ +static int ReadStateChunks_Mem(memstream_t *st, int32 totalsize) +{ + int t; + uint32 size; + int ret = 1; + + while (totalsize > 0) + { + t = memstream_getc(st); + if (t == EOF) + break; + if (!read32le_mem(&size,st)) + break; + totalsize -= size + 5; + + switch(t) + { + case 1: + if (!ReadStateChunk_Mem(st, SFCPU, size)) + ret = 0; + break; + case 2: + if (!ReadStateChunk_Mem(st, SFCPUC, size)) + ret = 0; + else + X.mooPI = X.P; /* Quick and dirty hack.*/ + break; + case 3: + if (!ReadStateChunk_Mem(st, FCEUPPU_STATEINFO, size)) + ret = 0; + break; + case 4: + if (!ReadStateChunk_Mem(st, FCEUCTRL_STATEINFO, size)) + ret = 0; + break; + case 5: + if (!ReadStateChunk_Mem(st, FCEUSND_STATEINFO, size)) + ret = 0; + break; + case 0x10: + if (!ReadStateChunk_Mem(st, SFMDATA, size)) + ret = 0; + break; + default: + if (memstream_seek(st, size, SEEK_CUR) < 0) + goto endo; + break; + } + } +endo: + return ret; +} +#endif + + +extern int geniestage; + +#ifdef __LIBSNES__ +void FCEUSS_Load(void) +{ + int x, stateversion; + uint8 header[16]; + memstream_t *mem; + + mem = memstream_open(FALSE); + + memstream_read(mem, header, 16); + + if (memcmp(header,"FCS",3) != 0) + return; + + if (header[3] == 0xFF) + stateversion = FCEU_de32lsb(header + 8); + else + stateversion = header[3] * 100; + + x = ReadStateChunks_Mem(mem, *(uint32*)(header + 4)); + + if (stateversion < 9500) + X.IRQlow=0; + + if (GameStateRestore) + GameStateRestore(stateversion); + + if (x) + { + FCEUPPU_LoadState(stateversion); + FCEUSND_LoadState(stateversion); + } + + memstream_close(mem); +} + +void FCEUSS_Save(void) +{ + memstream_t *mem = memstream_open(TRUE); + + uint32 totalsize; + uint8 header[16] = {0}; + + header[0] = 'F'; + header[1] = 'C'; + header[2] = 'S'; + header[3] = 0xFF; + + FCEU_en32lsb(header + 8, FCEU_VERSION_NUMERIC); + memstream_write(mem, header, 16); + + FCEUPPU_SaveState(); + + totalsize = WriteStateChunk_Mem(mem, 1, SFCPU); + totalsize += WriteStateChunk_Mem(mem, 2, SFCPUC); + totalsize += WriteStateChunk_Mem(mem, 3, FCEUPPU_STATEINFO); + totalsize += WriteStateChunk_Mem(mem, 4, FCEUCTRL_STATEINFO); + totalsize += WriteStateChunk_Mem(mem, 5, FCEUSND_STATEINFO); + + if (SPreSave) + SPreSave(); + + totalsize += WriteStateChunk_Mem(mem, 0x10, SFMDATA); + + if (SPreSave) + SPostSave(); + + memstream_seek(mem, 4, SEEK_SET); + write32le_mem(totalsize, mem); + + memstream_close(mem); +} +#else +static int FCEUSS_SaveFP(FILE *st) +{ + static uint32 totalsize; + static uint8 header[16]="FCS"; + + memset(header+4,0,13); + header[3]=0xFF; + FCEU_en32lsb(header + 8, FCEU_VERSION_NUMERIC); + fwrite(header,1,16,st); + FCEUPPU_SaveState(); + totalsize=WriteStateChunk(st,1,SFCPU); + totalsize+=WriteStateChunk(st,2,SFCPUC); + totalsize+=WriteStateChunk(st,3,FCEUPPU_STATEINFO); + totalsize+=WriteStateChunk(st,4,FCEUCTRL_STATEINFO); + totalsize+=WriteStateChunk(st,5,FCEUSND_STATEINFO); + if(SPreSave) SPreSave(); + totalsize+=WriteStateChunk(st,0x10,SFMDATA); + if(SPreSave) SPostSave(); + + fseek(st,4,SEEK_SET); + write32le(totalsize,st); + return(1); +} + +void FCEUSS_Save(const char *fname) +{ + FILE * st = fopen(fname, "wb"); + + if(st == NULL || geniestage == 1) + return; /*State save error*/ + + FCEUSS_SaveFP(st); + + fclose(st); +} + +static int FCEUSS_LoadFP(FILE *st) +{ + int x; + uint8 header[16]; + int stateversion; + + fread(&header,1,16,st); + if(memcmp(header,"FCS",3)) + return(0); + + if(header[3] == 0xFF) + stateversion = FCEU_de32lsb(header + 8); + else + stateversion = header[3] * 100; + + x = ReadStateChunks(st,*(uint32*)(header+4)); + + if(stateversion < 9500) + X.IRQlow=0; + + if(GameStateRestore) + GameStateRestore(stateversion); + + if(x) + { + FCEUPPU_LoadState(stateversion); + FCEUSND_LoadState(stateversion); + } + return(x); +} + +int FCEUSS_Load(const char *fname) +{ + FILE * st= fopen(fname, "rb"); + + if(st == NULL || geniestage == 1) + return(0); /* State load error*/ + + int ret = FCEUSS_LoadFP(st); + fclose(st); + if(ret) + return 1; + else + return 0; +} +#endif + +void ResetExState(void (*PreSave)(void), void (*PostSave)(void)) +{ + int x; + + for(x=0;x + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __LIBSNES__ +void FCEUSS_Load(void); +void FCEUSS_Save(void); +#else +void FCEUSS_Save(const char * fname); +int FCEUSS_Load(const char * fname); +#endif + +typedef struct { + void *v; + uint32 s; + const char *desc; +} SFORMAT; + +void ResetExState(void (*PreSave)(void),void (*PostSave)(void)); +void AddExState(void *v, uint32 s, int type, const char *desc); + +#define FCEUSTATE_RLSB 0x80000000 + +#ifdef __cplusplus +} +#endif diff --git a/fceumm/src-fceumm/types.h b/fceumm/src-fceumm/types.h new file mode 100644 index 0000000..915a603 --- /dev/null +++ b/fceumm/src-fceumm/types.h @@ -0,0 +1,78 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2001 Aaron Oneal + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __FCEU_TYPES +#define __FCEU_TYPES + +#include +#ifndef _MSC_VER +#include +#else +typedef unsigned char bool; +#endif + +#define TRUE 1 +#define FALSE 0 + +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; + +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; + +#ifdef __GNUC__ + typedef unsigned long long uint64; + typedef long long int64; +#elif _MSC_VER + typedef __int64 int64; + typedef unsigned __int64 uint64; + #define PSS_STYLE 2 /* Does MSVC compile for anything + other than Windows/DOS targets? + */ +#endif + +#if PSS_STYLE==2 + +#define PSS "\\" +#define PS '\\' + +#elif PSS_STYLE==1 + +#define PSS "/" +#define PS '/' + +#elif PSS_STYLE==3 + +#define PSS "\\" +#define PS '\\' + +#elif PSS_STYLE==4 + +#define PSS ":" +#define PS ':' + +#endif + +typedef void (*writefunc)(uint32 A, uint8 V); +typedef uint8 (*readfunc)(uint32 A); +#endif diff --git a/fceumm/src-fceumm/unif.c b/fceumm/src-fceumm/unif.c new file mode 100644 index 0000000..6431ec3 --- /dev/null +++ b/fceumm/src-fceumm/unif.c @@ -0,0 +1,675 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* TODO: Battery backup file saving, mirror force */ +/* **INCOMPLETE** */ +/* Override stuff: CHR RAM instead of CHR ROM, mirroring. */ + +#include +#include +#include + + +#include "types.h" +#include "fceu.h" +#include "cart.h" +#include "unif.h" +#include "ines.h" +#include "general.h" +#include "state.h" +#include "myendian.h" +#include "file.h" +#include "memory.h" +#include "input.h" +#include "md5.h" + +typedef struct { + char ID[4]; + uint32 info; +} UNIF_HEADER; + +typedef struct { + char *name; + void (*init)(CartInfo *); + int flags; +} BMAPPING; + +typedef struct { + char *name; + int (*init)(FCEUFILE *fp); +} BFMAPPING; + +CartInfo UNIFCart; + +static int vramo; +static int mirrortodo; +static uint8 *boardname; +static uint8 *sboardname; + +static uint32 CHRRAMSize; +uint8 *UNIFchrrama=0; + +static UNIF_HEADER unhead; +static UNIF_HEADER uchead; + + +static uint8 *malloced[32]; +static uint32 mallocedsizes[32]; + +static int FixRomSize(uint32 size, uint32 minimum) +{ + int x=1; + + if(size0) + if(index<99) + namebuf[index++]=t; + + namebuf[index]=0; + #ifdef FCEU_LOG + FCEU_printf("%s\n",namebuf); + #endif + + if(!FCEUGameInfo->name) + { + FCEUGameInfo->name=malloc(strlen(namebuf)+1); + strcpy(FCEUGameInfo->name,namebuf); + } + return(1); +} +static int DINF(FCEUFILE *fp) +{ + char name[100], method[100]; + uint8 d, m; + uint16 y; + int t; + + if(FCEU_fread(name,1,100,fp)!=100) + return(0); + if((t=FCEU_fgetc(fp))==EOF) return(0); + d=t; + if((t=FCEU_fgetc(fp))==EOF) return(0); + m=t; + if((t=FCEU_fgetc(fp))==EOF) return(0); + y=t; + if((t=FCEU_fgetc(fp))==EOF) return(0); + y|=t<<8; + if(FCEU_fread(method,1,100,fp)!=100) + return(0); + name[99]=method[99]=0; +#ifdef FCEU_LOG + FCEU_printf(" Dumped by: %s\n",name); + FCEU_printf(" Dumped with: %s\n",method); + { + char *months[12]={"January","February","March","April","May","June","July", + "August","September","October","November","December"}; + FCEU_printf(" Dumped on: %s %d, %d\n",months[(m-1)%12],d,y); + } +#endif + return(1); +} + +static int CTRL(FCEUFILE *fp) +{ + int t; + + if((t=FCEU_fgetc(fp))==EOF) + return(0); + + /* The information stored in this byte isn't very helpful, but it's + better than nothing...maybe. */ + + if(t&1) FCEUGameInfo->input[0]=FCEUGameInfo->input[1]=SI_GAMEPAD; + else FCEUGameInfo->input[0]=FCEUGameInfo->input[1]=SI_NONE; + + if(t&2) FCEUGameInfo->input[1]=SI_ZAPPER; + /*else if(t&0x10) FCEUGameInfo->input[1]=SI_POWERPAD;*/ + + return(1); +} + +static int TVCI(FCEUFILE *fp) +{ + int t; + if( (t=FCEU_fgetc(fp)) ==EOF) + return(0); + if(t<=2) + { + char *stuffo[3]={"NTSC","PAL","NTSC and PAL"}; + if(t==0) + FCEUGameInfo->vidsys=GIV_NTSC; + else if(t==1) + FCEUGameInfo->vidsys=GIV_PAL; + #ifdef FCEU_LOG + FCEU_printf(" TV Standard Compatibility: %s\n",stuffo[t]); + #endif + } + return(1); +} + +static int EnableBattery(FCEUFILE *fp) +{ + #ifdef FCEU_LOG + FCEU_printf(" Battery-backed.\n"); + #endif + if(FCEU_fgetc(fp)==EOF) + return(0); + UNIFCart.battery=1; + return(1); +} + +static int LoadPRG(FCEUFILE *fp) +{ + int z,t; + z=uchead.ID[3]-'0'; + + if(z<0 || z>15) + return(0); +#ifdef FCEU_LOG + FCEU_printf(" PRG ROM %d size: %d",z,(int) uchead.info); +#endif + if(malloced[z]) + free(malloced[z]); + t=FixRomSize(uchead.info,2048); + if(!(malloced[z]=(uint8 *)FCEU_malloc(t))) + return(0); + mallocedsizes[z]=t; + memset(malloced[z]+uchead.info,0xFF,t-uchead.info); + if(FCEU_fread(malloced[z],1,uchead.info,fp)!=uchead.info) + { +#ifdef FCEU_LOG + FCEU_printf("Read Error!\n"); +#endif + return(0); + } +#ifdef FCEU_LOG + else + FCEU_printf("\n"); +#endif + + SetupCartPRGMapping(z,malloced[z],t,0); + return(1); +} + +static int SetBoardName(FCEUFILE *fp) +{ + if(!(boardname=(uint8 *)FCEU_malloc(uchead.info+1))) + return(0); + FCEU_fread(boardname,1,uchead.info,fp); + boardname[uchead.info]=0; + #ifdef FCEU_LOG + FCEU_printf(" Board name: %s\n",boardname); + #endif + sboardname=boardname; + if(!memcmp(boardname,"NES-",4) || !memcmp(boardname,"UNL-",4) || !memcmp(boardname,"HVC-",4) || !memcmp(boardname,"BTL-",4) || !memcmp(boardname,"BMC-",4)) + sboardname+=4; + return(1); +} + +static int LoadCHR(FCEUFILE *fp) +{ + int z,t; + z=uchead.ID[3]-'0'; + if(z<0 || z>15) + return(0); +#ifdef FCEU_LOG + FCEU_printf(" CHR ROM %d size: %d",z,(int) uchead.info); +#endif + if(malloced[16+z]) + free(malloced[16+z]); + t=FixRomSize(uchead.info,8192); + if(!(malloced[16+z]=(uint8 *)FCEU_malloc(t))) + return(0); + mallocedsizes[16+z]=t; + memset(malloced[16+z]+uchead.info,0xFF,t-uchead.info); + if(FCEU_fread(malloced[16+z],1,uchead.info,fp)!=uchead.info) + { +#ifdef FCEU_LOG + FCEU_printf("Read Error!\n"); +#endif + return(0); + } +#ifdef FCEU_LOG + else + FCEU_printf("\n"); +#endif + + SetupCartCHRMapping(z,malloced[16+z],t,0); + return(1); +} + + +#define BMCFLAG_FORCE4 1 +#define BMCFLAG_16KCHRR 2 +#define BMCFLAG_32KCHRR 4 +#define BMCFLAG_EXPCHRR 8 + +static BMAPPING bmap[] = { + +/* Sachen Carts */ + { "TC-U01-1.5M", TCU01_Init,0}, + { "Sachen-8259A", S8259A_Init,0}, + { "Sachen-8259B", S8259B_Init,0}, + { "Sachen-8259C", S8259C_Init,0}, + { "Sachen-8259D", S8259D_Init,0}, + { "Sachen-74LS374N", S74LS374N_Init,0}, + { "Sachen-74LS374NA", S74LS374NA_Init,0}, /*seems to be custom mapper*/ + { "SA-002", TCU02_Init, 0}, + { "SA-016-1M", SA0161M_Init,0}, + { "SA-72007", SA72007_Init,0}, + { "SA-72008", SA72008_Init,0}, + { "SA-009", SA009_Init,0}, + { "SA-0036", SA0036_Init,0}, + { "SA-0037", SA0037_Init,0}, + { "SA-NROM", TCA01_Init,0}, + +/* AVE carts. */ +/* { "MB-91", MB91_Init,0}, // DeathBots*/ +/* { "NINA-06", NINA06_Init,0}, // F-15 City War*/ +/* { "NINA-03", NINA03_Init,0}, // Tiles of Fate*/ +/* { "NINA-001", NINA001_Init,0}, // Impossible Mission 2*/ + + { "ANROM", ANROM_Init,0}, + + { "HKROM", HKROM_Init,0}, + + { "EWROM", EWROM_Init,0}, + { "EKROM", EKROM_Init,0}, + { "ELROM", ELROM_Init,0}, + { "ETROM", ETROM_Init,0}, + + { "SAROM", SAROM_Init,0}, + { "SBROM", SBROM_Init,0}, + { "SCROM", SCROM_Init,0}, + { "SEROM", SEROM_Init,0}, + { "SGROM", SGROM_Init,0}, + { "SKROM", SKROM_Init,0}, + { "SLROM", SLROM_Init,0}, + { "SL1ROM", SL1ROM_Init,0}, + { "SNROM", SNROM_Init,0}, + { "SOROM", SOROM_Init,0}, + + { "TGROM", TGROM_Init,0}, + { "TR1ROM", TFROM_Init,BMCFLAG_FORCE4}, + + { "TBROM", TBROM_Init,0}, + { "TEROM", TEROM_Init,0}, + { "TFROM", TFROM_Init,0}, + { "TLROM", TLROM_Init,0}, + { "TKROM", TKROM_Init,0}, + { "TSROM", TSROM_Init,0}, + + { "TLSROM", TLSROM_Init,0}, + { "TKSROM", TKSROM_Init,0}, + { "TQROM", TQROM_Init,0}, + { "TVROM", TLROM_Init,BMCFLAG_FORCE4}, + + { "NTBROM", Mapper68_Init,0}, + + { "CPROM", CPROM_Init,BMCFLAG_16KCHRR}, + { "CNROM", CNROM_Init,0}, + { "NROM", NROM_Init,0 }, /*NROM256_Init,0 },*/ + { "NROM-128", NROM_Init,0 }, /*NROM128_Init,0 },*/ + { "NROM-256", NROM_Init,0 }, /*NROM256_Init,0 },*/ + { "RROM", NROM_Init,0 }, /*NROM128_Init,0 },*/ + { "RROM-128", NROM_Init,0 }, /*NROM128_Init,0 },*/ + { "MHROM", MHROM_Init,0}, + { "UNROM", UNROM_Init,0}, + { "UOROM", UNROM_Init,0}, + { "SUNSOFT_UNROM", SUNSOFT_UNROM_Init,0}, + { "MARIO1-MALEE2", MALEE_Init,0}, + { "3D-BLOCK", UNL3DBlock_Init, 0}, + { "SMB2J", UNLSMB2J_Init, 0}, + { "AX5705", UNLAX5705_Init, 0}, + { "CC-21", UNLCC21_Init,0}, + { "LE05", LE05_Init,0}, + { "AC08", AC08_Init,0}, + { "LH10", LH10_Init,0}, + + { "H2288", UNLH2288_Init,0}, + { "KOF97", UNLKOF97_Init,0}, + { "SL1632", UNLSL1632_Init,0}, + { "SL12", UNLSL12_Init,0}, + { "SHERO", UNLSHeroes_Init,0}, + { "8237", UNL8237_Init,0}, + { "8237A", UNL8237A_Init,0}, + { "8157", UNL8157_Init,0}, + { "T-262", BMCT262_Init,0}, + { "FK23C", BMCFK23C_Init,BMCFLAG_EXPCHRR}, + { "FK23CA", BMCFK23CA_Init,BMCFLAG_EXPCHRR}, + { "A65AS", BMCA65AS_Init,0}, + { "YOKO", UNLYOKO_Init,0}, + { "FS304", UNLFS304_Init,0}, + { "43272", UNL43272_Init,0}, + { "EDU2000", UNLEDU2000_Init,0}, + { "603-5052", UNL6035052_Init,0}, + { "N625092", UNLN625092_Init,0}, + { "Supervision16in1", Supervision16_Init,0}, + { "NovelDiamond9999999in1", Novel_Init,0}, + { "Super24in1SC03", Super24_Init,0}, + { "64in1NoRepeat", BMC64in1nr_Init, 0}, + { "13in1JY110", BMC13in1JY110_Init, 0}, + { "70in1", BMC70in1_Init, 0}, + { "70in1B", BMC70in1B_Init, 0}, + { "D1038", BMCD1038_Init, 0}, + { "GK-192", BMCGK192_Init, 0}, + { "SuperHIK8in1", Mapper45_Init,0}, + { "22211", UNL22211_Init,0}, + { "TF1201", UNLTF1201_Init, 0}, + { "GS-2004", BMCGS2004_Init, 0}, + { "GS-2013", BMCGS2013_Init, 0}, + { "KS7057", UNLKS7057_Init, 0}, + { "KS7037", UNLKS7037_Init, 0}, + { "KS7032", UNLKS7032_Init, 0}, + { "KS7017", UNLKS7017_Init, 0}, + { "KS7012", UNLKS7012_Init, 0}, + { "KS7013B", UNLKS7013B_Init, 0}, + { "T-230", UNLT230_Init, 0}, + { "190in1", BMC190in1_Init, 0}, + { "Ghostbusters63in1", BMCGhostbusters63in1_Init, 0}, + { "BS-5",BMCBS5_Init, 0}, + { "411120-C",BMC411120C_Init, 0}, + { "830118C",BMC830118C_Init, 0}, + { "T-227-1",BMCT2271_Init,0}, + { "PEC-586",UNLPEC586Init,0}, + { "12-IN-1",BMC12IN1_Init,0}, + { "VRC7", UNLVRC7_Init,0}, + { "810544-C-A1", BMC810544CA1_Init,0}, + { "NTD-03", BMCNTD03_Init,0}, + + { "DREAMTECH01", DreamTech01_Init,0}, + { "KONAMI-QTAI", Mapper190_Init,0}, + + { "DANCE", UNLDANCE_Init,0}, + { "OneBus", UNLOneBus_Init,0}, + { "SC-127", UNLSC127_Init,0}, + { "DANCE2000", UNLD2000_Init,0}, + { "Transformer", Transformer_Init, 0}, + + { "TEK90", Mapper90_Init,0}, + +#ifdef COPYFAMI + { "COPYFAMI_MMC3", MapperCopyFamiMMC3_Init,0}, + { "COPYFAMI", MapperCopyFami_Init,0}, +#endif + + {0,0,0} +}; + +static BFMAPPING bfunc[] = { + { "CTRL", CTRL }, + { "TVCI", TVCI }, + { "BATR", EnableBattery }, + { "MIRR", DoMirroring }, + { "PRG", LoadPRG }, + { "CHR", LoadCHR }, + { "NAME", NAME }, + { "MAPR", SetBoardName }, + { "DINF", DINF }, + { 0, 0 } +}; + +int LoadUNIFChunks(FCEUFILE *fp) +{ + int x; + int t; + for(;;) + { + t=FCEU_fread(&uchead,1,4,fp); + if(t<4) + { + if(t>0) + return 0; + return 1; + } + if(!(FCEU_read32le(&uchead.info,fp))) + return 0; + t=0; + x=0; + /*printf("Funky: %s\n",((uint8 *)&uchead));*/ + while(bfunc[x].name) + { + if(!memcmp(&uchead,bfunc[x].name,strlen(bfunc[x].name))) + { + if(!bfunc[x].init(fp)) + return 0; + t=1; + break; + } + x++; + } + if(!t) + if(FCEU_fseek(fp,uchead.info,SEEK_CUR)) + return(0); + } +} + +static int InitializeBoard(void) +{ + int x=0; + + if(!sboardname) return(0); + + while(bmap[x].name) + { + if(!strcmp((char *)sboardname,(char *)bmap[x].name)) + { + if(!malloced[16]) + { + if(bmap[x].flags & BMCFLAG_16KCHRR) + CHRRAMSize = 16384; + else if(bmap[x].flags & BMCFLAG_32KCHRR) + CHRRAMSize = 32768; + else if(bmap[x].flags & BMCFLAG_EXPCHRR) + CHRRAMSize = 128 * 1024; + else + CHRRAMSize = 8192; + if((UNIFchrrama=(uint8 *)FCEU_malloc(CHRRAMSize))) + { + SetupCartCHRMapping(0,UNIFchrrama,CHRRAMSize,1); + AddExState(UNIFchrrama, CHRRAMSize, 0,"CHRR"); + } + else + return(-1); + } + if(bmap[x].flags&BMCFLAG_FORCE4) + mirrortodo=4; + MooMirroring(); + bmap[x].init(&UNIFCart); + return(1); + } + x++; + } + FCEU_PrintError("Board type not supported."); + return(0); +} + +static void UNIFGI(int h) +{ + switch(h) + { + case GI_RESETM2: + if(UNIFCart.Reset) + UNIFCart.Reset(); + break; + case GI_POWER: + if(UNIFCart.Power) + UNIFCart.Power(); + if(UNIFchrrama) memset(UNIFchrrama,0,8192); + break; + case GI_CLOSE: + FCEU_SaveGameSave(&UNIFCart); + if(UNIFCart.Close) + UNIFCart.Close(); + FreeUNIF(); + break; + } +} + +int UNIFLoad(const char *name, FCEUFILE *fp) +{ + FCEU_fseek(fp,0,SEEK_SET); + FCEU_fread(&unhead,1,4,fp); + if(memcmp(&unhead,"UNIF",4)) + return 0; + + ResetCartMapping(); + + ResetExState(0,0); + ResetUNIF(); + if(!FCEU_read32le(&unhead.info,fp)) + goto aborto; + if(FCEU_fseek(fp,0x20,SEEK_SET)<0) + goto aborto; + if(!LoadUNIFChunks(fp)) + goto aborto; + { + int x; + struct md5_context md5; + + md5_starts(&md5); + + for(x=0;x<32;x++) + if(malloced[x]) + { + md5_update(&md5,malloced[x],mallocedsizes[x]); + } + md5_finish(&md5,UNIFCart.MD5); +#ifdef FCEU_LOG + FCEU_printf(" ROM MD5: 0x%s\n",md5_asciistr(UNIFCart.MD5)); +#endif + memcpy(FCEUGameInfo->MD5,UNIFCart.MD5,sizeof(UNIFCart.MD5)); + } + + if(!InitializeBoard()) + goto aborto; + + FCEU_LoadGameSave(&UNIFCart); + GameInterface=UNIFGI; + return 1; + +aborto: + + FreeUNIF(); + ResetUNIF(); + return 0; +} + +int CopyFamiLoad() +{ + ResetCartMapping(); + ResetExState(0,0); + + sboardname = "COPYFAMI"; + if(!InitializeBoard()) + goto aborto; + + FCEU_LoadGameSave(&UNIFCart); + GameInterface=UNIFGI; + return 1; + + aborto: + + FreeUNIF(); + ResetUNIF(); + return 0; +} diff --git a/fceumm/src-fceumm/unif.h b/fceumm/src-fceumm/unif.h new file mode 100644 index 0000000..9f569f4 --- /dev/null +++ b/fceumm/src-fceumm/unif.h @@ -0,0 +1,156 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +void ANROM_Init(CartInfo *info); + +void HKROM_Init(CartInfo *info); + +void ETROM_Init(CartInfo *info); +void EKROM_Init(CartInfo *info); +void ELROM_Init(CartInfo *info); +void EWROM_Init(CartInfo *info); + +void SAROM_Init(CartInfo *info); +void SBROM_Init(CartInfo *info); +void SCROM_Init(CartInfo *info); +void SEROM_Init(CartInfo *info); +void SGROM_Init(CartInfo *info); +void SKROM_Init(CartInfo *info); +void SLROM_Init(CartInfo *info); +void SL1ROM_Init(CartInfo *info); +void SNROM_Init(CartInfo *info); +void SOROM_Init(CartInfo *info); + +void NROM_Init(CartInfo *info); +void MHROM_Init(CartInfo *info); +void UNROM_Init(CartInfo *info); +void SUNSOFT_UNROM_Init(CartInfo *info); /* "Shanghi" original version mapper*/ +void MALEE_Init(CartInfo *info); +void CNROM_Init(CartInfo *info); +void CPROM_Init(CartInfo *info); +void GNROM_Init(CartInfo *info); +void UNL3DBlock_Init(CartInfo *info); + +void TBROM_Init(CartInfo *info); +void TEROM_Init(CartInfo *info); +void TFROM_Init(CartInfo *info); +void TGROM_Init(CartInfo *info); +void TKROM_Init(CartInfo *info); +void TSROM_Init(CartInfo *info); +void TLROM_Init(CartInfo *info); +void TLSROM_Init(CartInfo *info); +void TKSROM_Init(CartInfo *info); +void TQROM_Init(CartInfo *info); +void TQROM_Init(CartInfo *info); + +void DEIROM_Init(CartInfo *info); + +void TCA01_Init(CartInfo *info); +void TCU01_Init(CartInfo *info); +void TCU02_Init(CartInfo *info); +void S8259A_Init(CartInfo *info); +void S8259B_Init(CartInfo *info); +void S8259C_Init(CartInfo *info); +void S8259D_Init(CartInfo *info); +void S74LS374N_Init(CartInfo *info); +void S74LS374NA_Init(CartInfo *info); +void SA0161M_Init(CartInfo *info); + +void SA72007_Init(CartInfo *info); +void SA72008_Init(CartInfo *info); +void SA009_Init(CartInfo *info); +void SA0036_Init(CartInfo *info); +void SA0037_Init(CartInfo *info); + +void Supervision16_Init(CartInfo *info); +void Super24_Init(CartInfo *info); +void Novel_Init(CartInfo *info); + +void BMC64in1nr_Init(CartInfo *info); +void BMC70in1_Init(CartInfo *info); +void BMC70in1B_Init(CartInfo *info); +void BMC13in1JY110_Init(CartInfo *info); +void BMCT262_Init(CartInfo *info); +void BMCFK23C_Init(CartInfo *info); +void BMCFK23CA_Init(CartInfo *info); +void BMCD1038_Init(CartInfo *info); +void BMCA65AS_Init(CartInfo *info); +void BMCGK192_Init(CartInfo *info); +void BMCGS2004_Init(CartInfo *info); +void BMCGS2013_Init(CartInfo *info); +void BMC190in1_Init(CartInfo *info); +void BMCGhostbusters63in1_Init(CartInfo *info); +void BMCBS5_Init(CartInfo *info); + +void DreamTech01_Init(CartInfo *info); +void Mapper190_Init(CartInfo *info); +void UNLCC21_Init(CartInfo *info); +void UNLYOKO_Init(CartInfo *info); +void UNLFS304_Init(CartInfo *info); +void UNL43272_Init(CartInfo *info); +void UNLSL1632_Init(CartInfo *info); +void UNLSL12_Init(CartInfo *info); +void UNLKOF97_Init(CartInfo *info); +void UNLA9746_Init(CartInfo *info); +void UNLSHeroes_Init(CartInfo *info); +void UNLH2288_Init(CartInfo *info); +void UNL8237_Init(CartInfo *info); +void UNL8237A_Init(CartInfo *info); +void UNL8157_Init(CartInfo *info); +void UNL22211_Init(CartInfo *info); +void UNLTF1201_Init(CartInfo *info); +void UNLKS7057_Init(CartInfo *info); +void UNLKS7037_Init(CartInfo *info); +void UNLKS7032_Init(CartInfo *info); +void UNLKS7017_Init(CartInfo *info); +void UNLKS7012_Init(CartInfo *info); +void UNLKS7013B_Init(CartInfo *info); +void UNLT230_Init(CartInfo *info); +void UNLAX5705_Init(CartInfo *info); +void UNLDANCE_Init(CartInfo *info); +void UNLOneBus_Init(CartInfo *info); +void UNLSC127_Init(CartInfo *info); +void UNLPEC586Init(CartInfo *info); +void UNLVRC7_Init(CartInfo *info); +void UNLD2000_Init(CartInfo *info); +void BMC810544CA1_Init(CartInfo *info); +void BMCNTD03_Init(CartInfo *info); + +void UNLEDU2000_Init(CartInfo *info); +void UNL6035052_Init(CartInfo *info); +void UNLN625092_Init(CartInfo *info); +void UNLSMB2J_Init(CartInfo *info); +/*void UNL09034A_Init(CartInfo *info);*/ +void BMC411120C_Init(CartInfo *info); +void BMC830118C_Init(CartInfo *info); +void BMCT2271_Init(CartInfo *info); +void BMC12IN1_Init(CartInfo *info); +void Transformer_Init(CartInfo *info); +void LE05_Init(CartInfo *info); +void AC08_Init(CartInfo *info); +void LH10_Init(CartInfo *info); + +#ifdef COPYFAMI +void MapperCopyFamiMMC3_Init(CartInfo *info); +void MapperCopyFami_Init(CartInfo *info); +#endif + +/* So I can stop CHR RAM* bank switcherooing with certain boards...*/ +extern uint8 *UNIFchrrama; diff --git a/fceumm/src-fceumm/unzip.c b/fceumm/src-fceumm/unzip.c new file mode 100644 index 0000000..d82c0be --- /dev/null +++ b/fceumm/src-fceumm/unzip.c @@ -0,0 +1,1302 @@ +/* unzip.c -- IO on .zip files using zlib + Version 0.15 beta, Mar 19th, 1998, + + Read unzip.h for more info +*/ + + +#include +#include +#include +#include "zlib.h" +#include "unzip.h" + +#ifdef STDC +# include +# include +# include +#endif +#ifdef NO_ERRNO_H + extern int errno; +#else +# include +#endif + +#include "driver.h" + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + + + +#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \ + !defined(CASESENSITIVITYDEFAULT_NO) +#define CASESENSITIVITYDEFAULT_NO +#endif + + +#ifndef UNZ_BUFSIZE +#define UNZ_BUFSIZE (16384) +#endif + +#ifndef UNZ_MAXFILENAMEINZIP +#define UNZ_MAXFILENAMEINZIP (256) +#endif + +#ifndef ALLOC +# define ALLOC(size) (malloc(size)) +#endif +#ifndef TRYFREE +# define TRYFREE(p) {if(p) free(p);} +#endif + +#define SIZECENTRALDIRITEM (0x2e) +#define SIZEZIPLOCALHEADER (0x1e) + + +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +const char unz_copyright[] = + " unzip 0.15 Copyright 1998 Gilles Vollant "; + +/* unz_file_info_interntal contain internal info about a file in zipfile*/ +typedef struct unz_file_info_internal_s +{ + uLong offset_curfile;/* relative offset of local header 4 bytes */ +} unz_file_info_internal; + + +/* file_in_zip_read_info_s contain internal information about a file in zipfile, + when reading and decompress it */ +typedef struct +{ + char *read_buffer; /* internal buffer for compressed data */ + z_stream stream; /* zLib stream structure for inflate */ + + uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ + uLong stream_initialised; /* flag set if stream structure is initialised*/ + + uLong offset_local_extrafield;/* offset of the local extra field */ + uInt size_local_extrafield;/* size of the local extra field */ + uLong pos_local_extrafield; /* position in the local extra field in read*/ + + uLong crc32; /* crc32 of all data uncompressed */ + uLong crc32_wait; /* crc32 we must obtain after decompress all */ + uLong rest_read_compressed; /* number of byte to be decompressed */ + uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ + FILE* file; /* io structore of the zipfile */ + uLong compression_method; /* compression method (0==store) */ + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ +} file_in_zip_read_info_s; + + +/* unz_s contain internal information about the zipfile +*/ +typedef struct +{ + FILE* file; /* io structore of the zipfile */ + unz_global_info gi; /* public global information */ + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ + uLong num_file; /* number of the current file in the zipfile*/ + uLong pos_in_central_dir; /* pos of the current file in the central dir*/ + uLong current_file_ok; /* flag about the usability of the current file*/ + uLong central_pos; /* position of the beginning of the central dir*/ + + uLong size_central_dir; /* size of the central directory */ + uLong offset_central_dir; /* offset of start of central directory with + respect to the starting disk number */ + + unz_file_info cur_file_info; /* public info about the current file in zip*/ + unz_file_info_internal cur_file_info_internal; /* private info about it*/ + file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current + file if we are decompressing it */ +} unz_s; + + +/* =========================================================================== + Read a byte from a gz_stream; update next_in and avail_in. Return EOF + for end of file. + IN assertion: the stream s has been sucessfully opened for reading. +*/ + + +local int unzlocal_getByte(fin,pi) + FILE *fin; + int *pi; +{ + unsigned char c; + int err = fread(&c, 1, 1, fin); + if(err==1) + { + *pi = (int)c; + return UNZ_OK; + } + else + { + if(ferror(fin)) + return UNZ_ERRNO; + else + return UNZ_EOF; + } +} + + +/* =========================================================================== + Reads a long in LSB order from the given gz_stream. Sets +*/ +local int unzlocal_getShort (fin,pX) + FILE* fin; + uLong *pX; +{ + uLong x ; + int i; + int err; + + err = unzlocal_getByte(fin,&i); + x = (uLong)i; + + if(err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<8; + + if(err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + +local int unzlocal_getLong (fin,pX) + FILE* fin; + uLong *pX; +{ + uLong x ; + int i; + int err; + + err = unzlocal_getByte(fin,&i); + x = (uLong)i; + + if(err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<8; + + if(err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<16; + + if(err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<24; + + if(err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + + +/* My own strcmpi / strcasecmp */ +local int strcmpcasenosensitive_internal (fileName1,fileName2) + const char* fileName1; + const char* fileName2; +{ + for (;;) + { + char c1=*(fileName1++); + char c2=*(fileName2++); + if((c1>='a') && (c1<='z')) + c1 -= 0x20; + if((c2>='a') && (c2<='z')) + c2 -= 0x20; + if(c1=='\0') + return ((c2=='\0') ? 0 : -1); + if(c2=='\0') + return 1; + if(c1c2) + return 1; + } +} + + +#ifdef CASESENSITIVITYDEFAULT_NO +#define CASESENSITIVITYDEFAULTVALUE 2 +#else +#define CASESENSITIVITYDEFAULTVALUE 1 +#endif + +#ifndef STRCMPCASENOSENTIVEFUNCTION +#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal +#endif + +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) + +*/ +extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) + const char* fileName1; + const char* fileName2; + int iCaseSensitivity; +{ + if(iCaseSensitivity==0) + iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; + + if(iCaseSensitivity==1) + return strcmp(fileName1,fileName2); + + return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); +} + +#define BUFREADCOMMENT (0x400) + +/* + Locate the Central directory of a zipfile (at the end, just before + the global comment) +*/ +local uLong unzlocal_SearchCentralDir(fin) + FILE *fin; +{ + unsigned char* buf; + uLong uSizeFile; + uLong uBackRead; + uLong uMaxBack=0xffff; /* maximum size of global comment */ + uLong uPosFound=0; + + if(fseek(fin,0,SEEK_END) != 0) + return 0; + + + uSizeFile = ftell( fin ); + + if(uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if(buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); + if(fseek(fin,uReadPos,SEEK_SET)!=0) + break; + + if(fread(buf,(uInt)uReadSize,1,fin)!=1) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + if(((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) + { + uPosFound = uReadPos+i; + break; + } + + if(uPosFound!=0) + break; + } + TRYFREE(buf); + return uPosFound; +} + +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer + "zlib/zlib109.zip". + If the zipfile cannot be opened (file don't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. +*/ +extern unzFile ZEXPORT unzOpen(path) + const char *path; +{ + unz_s us; + unz_s *s; + uLong central_pos,uL; + FILE * fin ; + + uLong number_disk; /* number of the current dist, used for + spaning ZIP, unsupported, always 0*/ + uLong number_disk_with_CD; /* number the the disk with central dir, used + for spaning ZIP, unsupported, always 0*/ + uLong number_entry_CD; /* total number of entries in + the central dir + (same than number_entry on nospan) */ + + int err=UNZ_OK; + + if(unz_copyright[0]!=' ') + return NULL; + + fin=fopen(path,"rb"); + if(fin==NULL) + return NULL; + + central_pos = unzlocal_SearchCentralDir(fin); + if(central_pos==0) + err=UNZ_ERRNO; + + if(fseek(fin,central_pos,SEEK_SET)!=0) + err=UNZ_ERRNO; + + /* the signature, already checked */ + if(unzlocal_getLong(fin,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of this disk */ + if(unzlocal_getShort(fin,&number_disk)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of the disk with the start of the central directory */ + if(unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central dir on this disk */ + if(unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central dir */ + if(unzlocal_getShort(fin,&number_entry_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + if((number_entry_CD!=us.gi.number_entry) || + (number_disk_with_CD!=0) || + (number_disk!=0)) + err=UNZ_BADZIPFILE; + + /* size of the central directory */ + if(unzlocal_getLong(fin,&us.size_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + /* offset of start of central directory with respect to the + starting disk number */ + if(unzlocal_getLong(fin,&us.offset_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + /* zipfile comment length */ + if(unzlocal_getShort(fin,&us.gi.size_comment)!=UNZ_OK) + err=UNZ_ERRNO; + + if((central_pospfile_in_zip_read!=NULL) + unzCloseCurrentFile(file); + + fclose(s->file); + TRYFREE(s); + return UNZ_OK; +} + + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ +extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info) + unzFile file; + unz_global_info *pglobal_info; +{ + unz_s* s; + if(file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + *pglobal_info=s->gi; + return UNZ_OK; +} + + +/* + Translate date/time from Dos format to tm_unz (readable more easilty) +*/ +local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) + uLong ulDosDate; + tm_unz* ptm; +{ + uLong uDate; + uDate = (uLong)(ulDosDate>>16); + ptm->tm_mday = (uInt)(uDate&0x1f) ; + ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; + ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; + + ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); + ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; + ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; +} + +/* + Get Info about the current file in the zipfile, with internal only info +*/ +local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, + unz_file_info *pfile_info, + unz_file_info_internal + *pfile_info_internal, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); + +local int unzlocal_GetCurrentFileInfoInternal (file, + pfile_info, + pfile_info_internal, + szFileName, fileNameBufferSize, + extraField, extraFieldBufferSize, + szComment, commentBufferSize) + unzFile file; + unz_file_info *pfile_info; + unz_file_info_internal *pfile_info_internal; + char *szFileName; + uLong fileNameBufferSize; + void *extraField; + uLong extraFieldBufferSize; + char *szComment; + uLong commentBufferSize; +{ + unz_s* s; + unz_file_info file_info; + unz_file_info_internal file_info_internal; + int err=UNZ_OK; + uLong uMagic; + long lSeek=0; + + if(file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if(fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0) + err=UNZ_ERRNO; + + + /* we check the magic */ + if(err==UNZ_OK) + { + if(unzlocal_getLong(s->file,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if(uMagic!=0x02014b50) + err=UNZ_BADZIPFILE; + } + + if(unzlocal_getShort(s->file,&file_info.version) != UNZ_OK) + err=UNZ_ERRNO; + + if(unzlocal_getShort(s->file,&file_info.version_needed) != UNZ_OK) + err=UNZ_ERRNO; + + if(unzlocal_getShort(s->file,&file_info.flag) != UNZ_OK) + err=UNZ_ERRNO; + + if(unzlocal_getShort(s->file,&file_info.compression_method) != UNZ_OK) + err=UNZ_ERRNO; + + if(unzlocal_getLong(s->file,&file_info.dosDate) != UNZ_OK) + err=UNZ_ERRNO; + + unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); + + if(unzlocal_getLong(s->file,&file_info.crc) != UNZ_OK) + err=UNZ_ERRNO; + + if(unzlocal_getLong(s->file,&file_info.compressed_size) != UNZ_OK) + err=UNZ_ERRNO; + + if(unzlocal_getLong(s->file,&file_info.uncompressed_size) != UNZ_OK) + err=UNZ_ERRNO; + + if(unzlocal_getShort(s->file,&file_info.size_filename) != UNZ_OK) + err=UNZ_ERRNO; + + if(unzlocal_getShort(s->file,&file_info.size_file_extra) != UNZ_OK) + err=UNZ_ERRNO; + + if(unzlocal_getShort(s->file,&file_info.size_file_comment) != UNZ_OK) + err=UNZ_ERRNO; + + if(unzlocal_getShort(s->file,&file_info.disk_num_start) != UNZ_OK) + err=UNZ_ERRNO; + + if(unzlocal_getShort(s->file,&file_info.internal_fa) != UNZ_OK) + err=UNZ_ERRNO; + + if(unzlocal_getLong(s->file,&file_info.external_fa) != UNZ_OK) + err=UNZ_ERRNO; + + if(unzlocal_getLong(s->file,&file_info_internal.offset_curfile) != UNZ_OK) + err=UNZ_ERRNO; + + lSeek+=file_info.size_filename; + if((err==UNZ_OK) && (szFileName!=NULL)) + { + uLong uSizeRead ; + if(file_info.size_filename0) && (fileNameBufferSize>0)) + if(fread(szFileName,(uInt)uSizeRead,1,s->file)!=1) + err=UNZ_ERRNO; + lSeek -= uSizeRead; + } + + + if((err==UNZ_OK) && (extraField!=NULL)) + { + uLong uSizeRead ; + if(file_info.size_file_extrafile,lSeek,SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + if((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) + if(fread(extraField,(uInt)uSizeRead,1,s->file)!=1) + err=UNZ_ERRNO; + lSeek += file_info.size_file_extra - uSizeRead; + } + else + lSeek+=file_info.size_file_extra; + + + if((err==UNZ_OK) && (szComment!=NULL)) + { + uLong uSizeRead ; + if(file_info.size_file_commentfile,lSeek,SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + if((file_info.size_file_comment>0) && (commentBufferSize>0)) + if(fread(szComment,(uInt)uSizeRead,1,s->file)!=1) + err=UNZ_ERRNO; + lSeek+=file_info.size_file_comment - uSizeRead; + } + else + lSeek+=file_info.size_file_comment; + + if((err==UNZ_OK) && (pfile_info!=NULL)) + *pfile_info=file_info; + + if((err==UNZ_OK) && (pfile_info_internal!=NULL)) + *pfile_info_internal=file_info_internal; + + return err; +} + + + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. +*/ +extern int ZEXPORT unzGetCurrentFileInfo (file, + pfile_info, + szFileName, fileNameBufferSize, + extraField, extraFieldBufferSize, + szComment, commentBufferSize) + unzFile file; + unz_file_info *pfile_info; + char *szFileName; + uLong fileNameBufferSize; + void *extraField; + uLong extraFieldBufferSize; + char *szComment; + uLong commentBufferSize; +{ + return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, + szFileName,fileNameBufferSize, + extraField,extraFieldBufferSize, + szComment,commentBufferSize); +} + +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ +extern int ZEXPORT unzGoToFirstFile (file) + unzFile file; +{ + int err=UNZ_OK; + unz_s* s; + if(file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + s->pos_in_central_dir=s->offset_central_dir; + s->num_file=0; + err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + + +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ +extern int ZEXPORT unzGoToNextFile (file) + unzFile file; +{ + unz_s* s; + int err; + + if(file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if(!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + if(s->num_file+1==s->gi.number_entry) + return UNZ_END_OF_LIST_OF_FILE; + + s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + + s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; + s->num_file++; + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + + +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzipStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ +extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) + unzFile file; + const char *szFileName; + int iCaseSensitivity; +{ + unz_s* s; + int err; + + + uLong num_fileSaved; + uLong pos_in_central_dirSaved; + + + if(file==NULL) + return UNZ_PARAMERROR; + + if(strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) + return UNZ_PARAMERROR; + + s=(unz_s*)file; + if(!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + + num_fileSaved = s->num_file; + pos_in_central_dirSaved = s->pos_in_central_dir; + + err = unzGoToFirstFile(file); + + while (err == UNZ_OK) + { + char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; + unzGetCurrentFileInfo(file,NULL, + szCurrentFileName,sizeof(szCurrentFileName)-1, + NULL,0,NULL,0); + if(unzStringFileNameCompare(szCurrentFileName, + szFileName,iCaseSensitivity)==0) + return UNZ_OK; + err = unzGoToNextFile(file); + } + + s->num_file = num_fileSaved ; + s->pos_in_central_dir = pos_in_central_dirSaved ; + return err; +} + + +/* + Read the local header of the current zipfile + Check the coherency of the local header and info in the end of central + directory about this file + store in *piSizeVar the size of extra info in local header + (filename and size of extra field data) +*/ +local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, + poffset_local_extrafield, + psize_local_extrafield) + unz_s* s; + uInt* piSizeVar; + uLong *poffset_local_extrafield; + uInt *psize_local_extrafield; +{ + uLong uMagic,uData,uFlags; + uLong size_filename; + uLong size_extra_field; + int err=UNZ_OK; + + *piSizeVar = 0; + *poffset_local_extrafield = 0; + *psize_local_extrafield = 0; + + if(fseek(s->file,s->cur_file_info_internal.offset_curfile + + s->byte_before_the_zipfile,SEEK_SET)!=0) + return UNZ_ERRNO; + + + if(err==UNZ_OK) + { + if(unzlocal_getLong(s->file,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if(uMagic!=0x04034b50) + err=UNZ_BADZIPFILE; + } + + if(unzlocal_getShort(s->file,&uData) != UNZ_OK) + err=UNZ_ERRNO; +/* + else if((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) + err=UNZ_BADZIPFILE; +*/ + if(unzlocal_getShort(s->file,&uFlags) != UNZ_OK) + err=UNZ_ERRNO; + + if(unzlocal_getShort(s->file,&uData) != UNZ_OK) + err=UNZ_ERRNO; + else if((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) + err=UNZ_BADZIPFILE; + + if((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && + (s->cur_file_info.compression_method!=Z_DEFLATED)) + err=UNZ_BADZIPFILE; + + if(unzlocal_getLong(s->file,&uData) != UNZ_OK) /* date/time */ + err=UNZ_ERRNO; + + if(unzlocal_getLong(s->file,&uData) != UNZ_OK) /* crc */ + err=UNZ_ERRNO; + else if((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if(unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size compr */ + err=UNZ_ERRNO; + else if((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if(unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size uncompr */ + err=UNZ_ERRNO; + else if((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + + if(unzlocal_getShort(s->file,&size_filename) != UNZ_OK) + err=UNZ_ERRNO; + else if((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) + err=UNZ_BADZIPFILE; + + *piSizeVar += (uInt)size_filename; + + if(unzlocal_getShort(s->file,&size_extra_field) != UNZ_OK) + err=UNZ_ERRNO; + *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + + SIZEZIPLOCALHEADER + size_filename; + *psize_local_extrafield = (uInt)size_extra_field; + + *piSizeVar += (uInt)size_extra_field; + + return err; +} + +/* + Open for reading data the current file in the zipfile. + If there is no error and the file is opened, the return value is UNZ_OK. +*/ +extern int ZEXPORT unzOpenCurrentFile (file) + unzFile file; +{ + int err=UNZ_OK; + int Store; + uInt iSizeVar; + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + uLong offset_local_extrafield; /* offset of the local extra field */ + uInt size_local_extrafield; /* size of the local extra field */ + + if(file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if(!s->current_file_ok) + return UNZ_PARAMERROR; + + if(s->pfile_in_zip_read != NULL) + unzCloseCurrentFile(file); + + if(unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, + &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) + return UNZ_BADZIPFILE; + + pfile_in_zip_read_info = (file_in_zip_read_info_s*) + ALLOC(sizeof(file_in_zip_read_info_s)); + if(pfile_in_zip_read_info==NULL) + return UNZ_INTERNALERROR; + + pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); + pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; + pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; + pfile_in_zip_read_info->pos_local_extrafield=0; + + if(pfile_in_zip_read_info->read_buffer==NULL) + { + TRYFREE(pfile_in_zip_read_info); + return UNZ_INTERNALERROR; + } + + pfile_in_zip_read_info->stream_initialised=0; + + if((s->cur_file_info.compression_method!=0) && + (s->cur_file_info.compression_method!=Z_DEFLATED)) + err=UNZ_BADZIPFILE; + Store = s->cur_file_info.compression_method==0; + + pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; + pfile_in_zip_read_info->crc32=0; + pfile_in_zip_read_info->compression_method = + s->cur_file_info.compression_method; + pfile_in_zip_read_info->file=s->file; + pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; + + pfile_in_zip_read_info->stream.total_out = 0; + + if(!Store) + { + pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; + pfile_in_zip_read_info->stream.zfree = (free_func)0; + pfile_in_zip_read_info->stream.opaque = (voidpf)0; + + err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); + if(err == Z_OK) + pfile_in_zip_read_info->stream_initialised=1; + /* windowBits is passed < 0 to tell that there is no zlib header. + * Note that in this case inflate *requires* an extra "dummy" byte + * after the compressed stream in order to complete decompression and + * return Z_STREAM_END. + * In unzip, i don't wait absolutely Z_STREAM_END because I known the + * size of both compressed and uncompressed data + */ + } + pfile_in_zip_read_info->rest_read_compressed = + s->cur_file_info.compressed_size ; + pfile_in_zip_read_info->rest_read_uncompressed = + s->cur_file_info.uncompressed_size ; + + + pfile_in_zip_read_info->pos_in_zipfile = + s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + + iSizeVar; + + pfile_in_zip_read_info->stream.avail_in = (uInt)0; + + + s->pfile_in_zip_read = pfile_in_zip_read_info; + return UNZ_OK; +} + + +/* + Read bytes from the current file. + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ +extern int ZEXPORT unzReadCurrentFile (file, buf, len) + unzFile file; + voidp buf; + unsigned len; +{ + int err=UNZ_OK; + uInt iRead = 0; + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if(file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if(pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + + if((pfile_in_zip_read_info->read_buffer == NULL)) + return UNZ_END_OF_LIST_OF_FILE; + if(len==0) + return 0; + + pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; + + pfile_in_zip_read_info->stream.avail_out = (uInt)len; + + if(len>pfile_in_zip_read_info->rest_read_uncompressed) + pfile_in_zip_read_info->stream.avail_out = + (uInt)pfile_in_zip_read_info->rest_read_uncompressed; + + while (pfile_in_zip_read_info->stream.avail_out>0) + { + if((pfile_in_zip_read_info->stream.avail_in==0) && + (pfile_in_zip_read_info->rest_read_compressed>0)) + { + uInt uReadThis = UNZ_BUFSIZE; + if(pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; + if(uReadThis == 0) + return UNZ_EOF; + if(fseek(pfile_in_zip_read_info->file, + pfile_in_zip_read_info->pos_in_zipfile + + pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0) + return UNZ_ERRNO; + if(fread(pfile_in_zip_read_info->read_buffer,uReadThis,1, + pfile_in_zip_read_info->file)!=1) + return UNZ_ERRNO; + pfile_in_zip_read_info->pos_in_zipfile += uReadThis; + + pfile_in_zip_read_info->rest_read_compressed-=uReadThis; + + pfile_in_zip_read_info->stream.next_in = + (Bytef*)pfile_in_zip_read_info->read_buffer; + pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; + } + + if(pfile_in_zip_read_info->compression_method==0) + { + uInt uDoCopy,i ; + if(pfile_in_zip_read_info->stream.avail_out < + pfile_in_zip_read_info->stream.avail_in) + uDoCopy = pfile_in_zip_read_info->stream.avail_out ; + else + uDoCopy = pfile_in_zip_read_info->stream.avail_in ; + + for (i=0;istream.next_out+i) = + *(pfile_in_zip_read_info->stream.next_in+i); + + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, + pfile_in_zip_read_info->stream.next_out, + uDoCopy); + pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; + pfile_in_zip_read_info->stream.avail_in -= uDoCopy; + pfile_in_zip_read_info->stream.avail_out -= uDoCopy; + pfile_in_zip_read_info->stream.next_out += uDoCopy; + pfile_in_zip_read_info->stream.next_in += uDoCopy; + pfile_in_zip_read_info->stream.total_out += uDoCopy; + iRead += uDoCopy; + } + else + { + uLong uTotalOutBefore,uTotalOutAfter; + const Bytef *bufBefore; + uLong uOutThis; + int flush=Z_SYNC_FLUSH; + + uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; + bufBefore = pfile_in_zip_read_info->stream.next_out; + + /* + if((pfile_in_zip_read_info->rest_read_uncompressed == + pfile_in_zip_read_info->stream.avail_out) && + (pfile_in_zip_read_info->rest_read_compressed == 0)) + flush = Z_FINISH; + */ + err=inflate(&pfile_in_zip_read_info->stream,flush); + + uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; + uOutThis = uTotalOutAfter-uTotalOutBefore; + + pfile_in_zip_read_info->crc32 = + crc32(pfile_in_zip_read_info->crc32,bufBefore, + (uInt)(uOutThis)); + + pfile_in_zip_read_info->rest_read_uncompressed -= + uOutThis; + + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); + + if(err==Z_STREAM_END) + return (iRead==0) ? UNZ_EOF : iRead; + if(err!=Z_OK) + break; + } + } + + if(err==Z_OK) + return iRead; + return err; +} + + +/* + Give the current position in uncompressed data +*/ +extern z_off_t ZEXPORT unztell (file) + unzFile file; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if(file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if(pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + return (z_off_t)pfile_in_zip_read_info->stream.total_out; +} + + +/* + return 1 if the end of file was reached, 0 elsewhere +*/ +extern int ZEXPORT unzeof (file) + unzFile file; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if(file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if(pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + if(pfile_in_zip_read_info->rest_read_uncompressed == 0) + return 1; + else + return 0; +} + + + +/* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field that can be read + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ +extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) + unzFile file; + voidp buf; + unsigned len; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + uInt read_now; + uLong size_to_read; + + if(file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if(pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + size_to_read = (pfile_in_zip_read_info->size_local_extrafield - + pfile_in_zip_read_info->pos_local_extrafield); + + if(buf==NULL) + return (int)size_to_read; + + if(len>size_to_read) + read_now = (uInt)size_to_read; + else + read_now = (uInt)len ; + + if(read_now==0) + return 0; + + if(fseek(pfile_in_zip_read_info->file, + pfile_in_zip_read_info->offset_local_extrafield + + pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0) + return UNZ_ERRNO; + + if(fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1) + return UNZ_ERRNO; + + return (int)read_now; +} + +/* + Close the file in zip opened with unzipOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ +extern int ZEXPORT unzCloseCurrentFile (file) + unzFile file; +{ + int err=UNZ_OK; + + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if(file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if(pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + + if(pfile_in_zip_read_info->rest_read_uncompressed == 0) + { + if(pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) + err=UNZ_CRCERROR; + } + + + TRYFREE(pfile_in_zip_read_info->read_buffer); + pfile_in_zip_read_info->read_buffer = NULL; + if(pfile_in_zip_read_info->stream_initialised) + inflateEnd(&pfile_in_zip_read_info->stream); + + pfile_in_zip_read_info->stream_initialised = 0; + TRYFREE(pfile_in_zip_read_info); + + s->pfile_in_zip_read=NULL; + + return err; +} + + +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ +extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) + unzFile file; + char *szComment; + uLong uSizeBuf; +{ + unz_s* s; + uLong uReadThis ; + if(file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + + uReadThis = uSizeBuf; + if(uReadThis>s->gi.size_comment) + uReadThis = s->gi.size_comment; + + if(fseek(s->file,s->central_pos+22,SEEK_SET)!=0) + return UNZ_ERRNO; + + if(uReadThis>0) + { + *szComment='\0'; + if(fread(szComment,(uInt)uReadThis,1,s->file)!=1) + return UNZ_ERRNO; + } + + if((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) + *(szComment+s->gi.size_comment)='\0'; + return (int)uReadThis; +} diff --git a/fceumm/src-fceumm/unzip.h b/fceumm/src-fceumm/unzip.h new file mode 100644 index 0000000..d89ebef --- /dev/null +++ b/fceumm/src-fceumm/unzip.h @@ -0,0 +1,275 @@ +/* unzip.h -- IO for uncompress .zip files using zlib + Version 0.15 beta, Mar 19th, 1998, + + Copyright (C) 1998 Gilles Vollant + + This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g + WinZip, InfoZip tools and compatible. + Encryption and multi volume ZipFile (span) are not supported. + Old compressions used by old PKZip 1.x are not supported + + THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE + CAN CHANGE IN FUTURE VERSION !! + I WAIT FEEDBACK at mail info@winimage.com + Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution + + Condition of use and distribution are the same than zlib : + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + +*/ +/* for more info about .ZIP format, see + ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip + PkWare has also a specification at : + ftp://ftp.pkware.com/probdesc.zip */ + +#ifndef _unz_H +#define _unz_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) +/* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ +typedef struct TagunzFile__ { int unused; } unzFile__; +typedef unzFile__ *unzFile; +#else +typedef voidp unzFile; +#endif + + +#define UNZ_OK (0) +#define UNZ_END_OF_LIST_OF_FILE (-100) +#define UNZ_ERRNO (Z_ERRNO) +#define UNZ_EOF (0) +#define UNZ_PARAMERROR (-102) +#define UNZ_BADZIPFILE (-103) +#define UNZ_INTERNALERROR (-104) +#define UNZ_CRCERROR (-105) + +/* tm_unz contain date/time info */ +typedef struct tm_unz_s +{ + uInt tm_sec; /* seconds after the minute - [0,59] */ + uInt tm_min; /* minutes after the hour - [0,59] */ + uInt tm_hour; /* hours since midnight - [0,23] */ + uInt tm_mday; /* day of the month - [1,31] */ + uInt tm_mon; /* months since January - [0,11] */ + uInt tm_year; /* years - [1980..2044] */ +} tm_unz; + +/* unz_global_info structure contain global data about the ZIPfile + These data comes from the end of central dir */ +typedef struct unz_global_info_s +{ + uLong number_entry; /* total number of entries in + the central dir on this disk */ + uLong size_comment; /* size of the global comment of the zipfile */ +} unz_global_info; + + +/* unz_file_info contain information about a file in the zipfile */ +typedef struct unz_file_info_s +{ + uLong version; /* version made by 2 bytes */ + uLong version_needed; /* version needed to extract 2 bytes */ + uLong flag; /* general purpose bit flag 2 bytes */ + uLong compression_method; /* compression method 2 bytes */ + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ + uLong crc; /* crc-32 4 bytes */ + uLong compressed_size; /* compressed size 4 bytes */ + uLong uncompressed_size; /* uncompressed size 4 bytes */ + uLong size_filename; /* filename length 2 bytes */ + uLong size_file_extra; /* extra field length 2 bytes */ + uLong size_file_comment; /* file comment length 2 bytes */ + + uLong disk_num_start; /* disk number start 2 bytes */ + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ + + tm_unz tmu_date; +} unz_file_info; + +extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, + const char* fileName2, + int iCaseSensitivity)); +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) +*/ + + +extern unzFile ZEXPORT unzOpen OF((const char *path)); +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer + "zlib/zlib111.zip". + If the zipfile cannot be opened (file don't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. +*/ + +extern int ZEXPORT unzClose OF((unzFile file)); +/* + Close a ZipFile opened with unzipOpen. + If there is files inside the .Zip opened with unzOpenCurrentFile (see later), + these files MUST be closed with unzipCloseCurrentFile before call unzipClose. + return UNZ_OK if there is no problem. */ + +extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, + unz_global_info *pglobal_info)); +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ + + +extern int ZEXPORT unzGetGlobalComment OF((unzFile file, + char *szComment, + uLong uSizeBuf)); +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ + + +/***************************************************************************/ +/* Unzip package allow you browse the directory of the zipfile */ + +extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ + +extern int ZEXPORT unzGoToNextFile OF((unzFile file)); +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ + +extern int ZEXPORT unzLocateFile OF((unzFile file, + const char *szFileName, + int iCaseSensitivity)); +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ + + +extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, + unz_file_info *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); +/* + Get Info about the current file + if pfile_info!=NULL, the *pfile_info structure will contain somes info about + the current file + if szFileName!=NULL, the filemane string will be copied in szFileName + (fileNameBufferSize is the size of the buffer) + if extraField!=NULL, the extra field information will be copied in extraField + (extraFieldBufferSize is the size of the buffer). + This is the Central-header version of the extra field + if szComment!=NULL, the comment string of the file will be copied in szComment + (commentBufferSize is the size of the buffer) +*/ + +/***************************************************************************/ +/* for reading the content of the current zipfile, you can open it, read data + from it, and close it (you can close it before reading all the file) + */ + +extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); +/* + Open for reading data the current file in the zipfile. + If there is no error, the return value is UNZ_OK. +*/ + +extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); +/* + Close the file in zip opened with unzOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ + + +extern int ZEXPORT unzReadCurrentFile OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read bytes from the current file (opened by unzOpenCurrentFile) + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ + +extern z_off_t ZEXPORT unztell OF((unzFile file)); +/* + Give the current position in uncompressed data +*/ + +extern int ZEXPORT unzeof OF((unzFile file)); +/* + return 1 if the end of file was reached, 0 elsewhere +*/ + +extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ + +#ifdef __cplusplus +} +#endif + +#endif /* _unz_H */ diff --git a/fceumm/src-fceumm/vsuni.c b/fceumm/src-fceumm/vsuni.c new file mode 100644 index 0000000..4ff8689 --- /dev/null +++ b/fceumm/src-fceumm/vsuni.c @@ -0,0 +1,421 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include + +#include "types.h" +#include "x6502.h" +#include "fceu.h" +#include "input.h" +#include "vsuni.h" +#include "state.h" + +#define IOPTION_GUN 0x1 +#define IOPTION_SWAPDIRAB 0x2 + +#define IOPTION_PREDIP 0x10 +typedef struct +{ + char *name; + uint64 md5partial; + int mapper; + int mirroring; + int ppu; + int ioption; + int predip; +} VSUNIENTRY; + +VSUNIENTRY *curvs; + +static uint8 DIPS=0; +uint8 vsdip=0; + +void FCEUI_VSUniToggleDIPView(void) +{ + DIPS=!DIPS; +} + +void FCEU_VSUniToggleDIP(int w) +{ + vsdip^=1<> w) & 1) != state) + FCEUI_VSUniToggleDIP(w); +} + +uint8 FCEUI_VSUniGetDIPs(void) +{ + return(vsdip); +} + +static uint8 secdata[2][32]= +{ + { + 0xff, 0xbf, 0xb7, 0x97, 0x97, 0x17, 0x57, 0x4f, + 0x6f, 0x6b, 0xeb, 0xa9, 0xb1, 0x90, 0x94, 0x14, + 0x56, 0x4e, 0x6f, 0x6b, 0xeb, 0xa9, 0xb1, 0x90, + 0xd4, 0x5c, 0x3e, 0x26, 0x87, 0x83, 0x13, 0x00 + }, + { + 0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, + 0x00, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x94, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + } +}; + +static uint8 *secptr; + +static uint8 VSindex; + +static DECLFR(VSSecRead) +{ + switch(A) + { + case 0x5e00: VSindex=0;return X.DB; + case 0x5e01: return(secptr[(VSindex++)&0x1F]); + } + return(0x00); +} +uint8 coinon=0; + +void FCEU_VSUniCoin(void) +{ + coinon=6; +} + +static int curppu; +static int64 curmd5; + +#define RP2C04_001 1 +#define RP2C04_002 2 +#define RP2C04_003 3 +#define RP2C05_004 4 +#define RCP2C03B 5 +#define RC2C05_01 6 +#define RC2C05_02 7 +#define RC2C05_03 8 +#define RC2C05_04 9 + +static readfunc OldReadPPU; +static writefunc OldWritePPU[2]; + +static DECLFR(A2002_Gumshoe) +{ + return( (OldReadPPU(A)&~0x3F) | 0x1C); +} + +static DECLFR(A2002_Topgun) +{ + return( (OldReadPPU(A)&~0x3F) | 0x1B); +} + +static DECLFR(A2002_MBJ) /* Mighty Bomb Jack*/ +{ + return( (OldReadPPU(A)&~0x3F) | 0x3D); +} + +static DECLFW(B2000_2001_2C05) +{ + OldWritePPU[(A&1)^1](A ^ 1, V); +} + +static uint8 xevselect = 0; + +static DECLFR(XevRead) +{ + /*printf("%04x\n",A);*/ + if(A == 0x54FF) + { + return(0x5); + } + else if(A == 0x5678) + { + return(xevselect?0:1); + } + else if(A == 0x578F) + { + return(xevselect?0xd1:0x89); + } + else if(A == 0x5567) + { + xevselect ^=1; + return(xevselect?0x37:0x3E); + } + return(X.DB); +} + +void FCEU_VSUniSwap(uint8 *j0, uint8 *j1) +{ + if(curvs->ioption & IOPTION_SWAPDIRAB) + { + uint16 t=*j0; + *j0=(*j0&0xC)|(*j1&0xF3); + *j1=(*j1&0xC)|(t&0xF3); + } +} + +void FCEU_VSUniPower(void) +{ + coinon = 0; + VSindex = 0; + + if(secptr) + SetReadHandler(0x5e00,0x5e01,VSSecRead); + + if(curppu == RC2C05_04) + { + OldReadPPU = GetReadHandler(0x2002); + SetReadHandler(0x2002, 0x2002, A2002_Topgun); + } + else if(curppu == RC2C05_03) + { + OldReadPPU = GetReadHandler(0x2002); + SetReadHandler(0x2002, 0x2002, A2002_Gumshoe); + } + else if(curppu == RC2C05_02) + { + OldReadPPU = GetReadHandler(0x2002); + SetReadHandler(0x2002, 0x2002, A2002_MBJ); + } + if(curppu == RC2C05_04 || curppu == RC2C05_01 || curppu == RC2C05_03 || curppu == RC2C05_02) + { + OldWritePPU[0] = GetWriteHandler(0x2000); + OldWritePPU[1] = GetWriteHandler(0x2001); + SetWriteHandler(0x2000, 0x2001, B2000_2001_2C05); + } + if(curmd5 == 0x2d396247cf58f9faLL) /* Super Xevious */ + { + SetReadHandler(0x5400,0x57FF,XevRead); + } +} + +/* Games that will probably not be supported ever(or for a long time), since they require + dual-system: + + Balloon Fight + VS Mahjong + VS Tennis + Wrecking Crew +*/ + +/* Games/PPU list. Information copied from MAME. ROMs are exchangable, so don't take + this list as "this game must use this PPU". + +RP2C04-001: +- Baseball +- Freedom Force +- Gradius +- Hogan's Alley +- Mach Rider (Japan, Fighting Course) +- Pinball +- Platoon +- Super Xevious + +RP2C04-002: +- Castlevania +- Ladies golf +- Mach Rider (Endurance Course) +- Raid on Bungeling Bay (Japan) +- Slalom +- Stroke N' Match Golf +- Wrecking Crew + +RP2C04-003: +- Dr mario +- Excite Bike +- Goonies +- Soccer +- TKO Boxing + +RP2c05-004: +- Clu Clu Land +- Excite Bike (Japan) +- Ice Climber +- Ice Climber Dual (Japan) +- Super Mario Bros. + +Rcp2c03b: +- Battle City +- Duck Hunt +- Mahjang +- Pinball (Japan) +- Rbi Baseball +- Star Luster +- Stroke and Match Golf (Japan) +- Super Skykid +- Tennis +- Tetris + +RC2C05-01: +- Ninja Jajamaru Kun (Japan) + +RC2C05-02: +- Mighty Bomb Jack (Japan) + +RC2C05-03: +- Gumshoe + +RC2C05-04: +- Top Gun +*/ + +VSUNIENTRY VSUniGames[] = +{ + {"Baseball", 0x691d4200ea42be45LL, 99, 2,RP2C04_001,0}, + {"Battle City", 0x8540949d74c4d0ebLL, 99, 2,RP2C04_001,0}, + {"Battle City(Bootleg)",0x8093cbe7137ac031LL, 99, 2,RP2C04_001,0}, + + {"Clu Clu Land", 0x1b8123218f62b1eeLL, 99, 2,RP2C05_004,IOPTION_SWAPDIRAB}, + {"Dr Mario", 0xe1af09c477dc0081LL, 1, 0,RP2C04_003,IOPTION_SWAPDIRAB}, + {"Duck Hunt", 0x47735d1e5f1205bbLL, 99, 2,RCP2C03B ,IOPTION_GUN}, + {"Excitebike", 0x3dcd1401bcafde77LL, 99, 2,RP2C04_003,0}, + {"Excitebike (J)", 0x7ea51c9d007375f0LL, 99, 2,RP2C05_004,0}, + {"Freedom Force", 0xed96436bd1b5e688LL, 4, 0,RP2C04_001,IOPTION_GUN}, /* Wrong color in game select screen? */ + {"Stroke and Match Golf",0x612325606e82bc66LL, 99, 2,RP2C04_002,IOPTION_SWAPDIRAB|IOPTION_PREDIP,0x01}, + + {"Goonies", 0xb4032d694e1d2733LL, 151,1,RP2C04_003,0}, + {"Gradius", 0x50687ae63bdad976LL,151, 1,RP2C04_001,IOPTION_SWAPDIRAB}, + {"Gumshoe", 0x87161f8ee37758d3LL, 99, 2,RC2C05_03,IOPTION_GUN}, + {"Hogan's Alley", 0xd78b7f0bb621fb45LL, 99, 2,RP2C04_001,IOPTION_GUN}, + {"Ice Climber", 0xd21e999513435e2aLL, 99, 2,RP2C05_004,IOPTION_SWAPDIRAB}, + {"Ladies Golf", 0x781b24be57ef6785LL, 99, 2,RP2C04_002,IOPTION_SWAPDIRAB|IOPTION_PREDIP,0x1}, + + {"Mach Rider", 0x015672618af06441LL, 99, 2, RP2C04_002,0}, + {"Mach Rider (J)", 0xa625afb399811a8aLL, 99, 2, RP2C04_001,0}, + {"Mighty Bomb Jack", 0xe6a89f4873fac37bLL, 0, 2, RC2C05_02,0}, + {"Ninja Jajamaru Kun", 0xb26a2c31474099c0LL, 99, 2,RC2C05_01 ,IOPTION_SWAPDIRAB}, + {"Pinball", 0xc5f49d3de7f2e9b8LL, 99, 2,RP2C04_001,IOPTION_PREDIP,0x01}, + {"Pinball (J)", 0x66ab1a3828cc901cLL, 99, 2,RCP2C03B,IOPTION_PREDIP,0x1}, + {"Platoon", 0x160f237351c19f1fLL, 68, 1,RP2C04_001,0}, + {"RBI Baseball", 0x6a02d345812938afLL, 4, 1,RP2C04_001 ,IOPTION_SWAPDIRAB}, + {"Soccer", 0xd4e7a9058780eda3LL, 99, 2,RP2C04_003,IOPTION_SWAPDIRAB}, + {"Star Luster", 0x8360e134b316d94cLL, 99, 2,RCP2C03B ,0}, + {"Stroke and Match Golf (J)",0x869bb83e02509747LL, 99, 2,RCP2C03B,IOPTION_SWAPDIRAB|IOPTION_PREDIP,0x1}, + {"Super Sky Kid", 0x78d04c1dd4ec0101LL, 4, 1,RCP2C03B ,IOPTION_SWAPDIRAB | IOPTION_PREDIP,0x20}, + + {"Super Xevious", 0x2d396247cf58f9faLL, 206, 0,RP2C04_001,0}, + {"Tetris", 0x531a5e8eea4ce157LL, 99, 2,RCP2C03B ,IOPTION_PREDIP,0x20}, + {"Top Gun", 0xf1dea36e6a7b531dLL, 2, 0,RC2C05_04 ,0}, + {"VS Castlevania", 0x92fd6909c81305b9LL, 2, 1,RP2C04_002,0}, + {"VS Slalom", 0x4889b5a50a623215LL, 0, 1,RP2C04_002,0}, + {"VS Super Mario Bros",0x39d8cfa788e20b6cLL, 99, 2,RP2C05_004,0}, + {"VS Super Mario Bros [a1]",0xfc182e5aefbce14dLL, 99, 2,RP2C05_004,0}, + {"VS TKO Boxing", 0x6e1ee06171d8ce3aLL,4, 1,RP2C04_003,IOPTION_PREDIP,0x00}, + {0} +}; + +extern uint8 pale; + +void FCEU_VSUniCheck(uint64 md5partial, int *MapperNo, uint8 *Mirroring) +{ + VSUNIENTRY *vs = VSUniGames; + + while(vs->name) + { + if(md5partial == vs->md5partial) + { + + if(vs->ppu < RCP2C03B) pale = vs->ppu; + /*puts(vs->name);*/ + *MapperNo = vs->mapper; + *Mirroring = vs->mirroring; + FCEUGameInfo->type = GIT_VSUNI; + FCEUGameInfo->cspecial = SIS_VSUNISYSTEM; + FCEUGameInfo->inputfc = SIFC_NONE; + curppu = vs->ppu; + curmd5 = md5partial; + + secptr = 0; + + { + static int64 tko=0x6e1ee06171d8ce3aULL, rbi=0x6a02d345812938afULL; + if(md5partial == tko) + secptr=secdata[0]; + if(md5partial == rbi) + secptr = secdata[1]; + } + + vsdip = 0x0; + if(vs->ioption & IOPTION_PREDIP) + { + vsdip= vs->predip; + } + if(vs->ioption & IOPTION_GUN) + { + FCEUGameInfo->input[0] = SI_ZAPPER; + FCEUGameInfo->input[1] = SI_NONE; + } + else + { + FCEUGameInfo->input[0] = FCEUGameInfo->input[1] = SI_GAMEPAD; + } + curvs = vs; + return; + } + vs++; + } +} + +void FCEU_VSUniDraw(uint8 *XBuf) +{ + uint32 *dest; + int y,x; + + if(!DIPS) return; + + dest=(uint32 *)(XBuf+256*12+164); + for(y=24;y;y--,dest+=(256-72)>>2) + { + for(x=72>>2;x;x--,dest++) + *dest=0; + } + + dest=(uint32 *)(XBuf+256*(12+4)+164+6 ); + for(y=16;y;y--,dest+=(256>>2)-16) + for(x=8;x;x--) + { + *dest=0x01010101; + dest+=2; + } + + dest=(uint32 *)(XBuf+256*(12+4)+164+6 ); + for(x=0;x<8;x++,dest+=2) + { + uint32 *da=dest+(256>>2); + + if(!((vsdip>>x)&1)) + da+=(256>>2)*10; + for(y=4;y;y--,da+=256>>2) + *da=0; + } +} + + +SFORMAT FCEUVSUNI_STATEINFO[]={ + { &vsdip, 1, "vsdp"}, + { &coinon, 1, "vscn"}, + { &VSindex, 1, "vsin"}, + { 0} +}; diff --git a/fceumm/src-fceumm/vsuni.h b/fceumm/src-fceumm/vsuni.h new file mode 100644 index 0000000..ee17551 --- /dev/null +++ b/fceumm/src-fceumm/vsuni.h @@ -0,0 +1,7 @@ +void FCEU_VSUniPower(void); +void FCEU_VSUniCheck(uint64 md5partial, int *, uint8 *); +void FCEU_VSUniDraw(uint8 *XBuf); + +void FCEU_VSUniToggleDIP(int); /* For movies and netplay */ +void FCEU_VSUniCoin(void); +void FCEU_VSUniSwap(uint8 *j0, uint8 *j1); diff --git a/fceumm/src-fceumm/x6502.c b/fceumm/src-fceumm/x6502.c new file mode 100644 index 0000000..918a0b4 --- /dev/null +++ b/fceumm/src-fceumm/x6502.c @@ -0,0 +1,458 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "types.h" +#include "x6502.h" +#include "x6502struct.h" +#include "fceu.h" +#include "sound.h" + +X6502 X; + +uint32 timestamp; +void (*MapIRQHook)(int a); + +#define _PC X.PC +#define _A X.A +#define _X X.X +#define _Y X.Y +#define _S X.S +#define _P X.P +#define _PI X.mooPI +#define _DB X.DB +#define _count X.count +#define _tcount X.tcount +#define _IRQlow X.IRQlow +#define _jammed X.jammed + +#define ADDCYC(x) \ +{ \ + int __x=x; \ + _tcount+=__x; \ + _count-=__x*48; \ + timestamp+=__x; \ +} + +#define RdMemNorm(A) (_DB=ARead[A](A)) +#define WrMemNorm(A, V) BWrite[A](A,V); +#define RdRAMFast(A) (_DB=RAM[A]) +#define WrRAMFast(A, V) RAM[A]=V; + +uint8 X6502_DMR(uint32 A) +{ + ADDCYC(1); + return(X.DB=ARead[A](A)); +} + +void X6502_DMW(uint32 A, uint8 V) +{ + ADDCYC(1); + BWrite[A](A,V); +} + +#define PUSH(V) \ +{ \ + uint8 VTMP=V; \ + WrRAM(0x100+_S,VTMP); \ + _S--; \ +} + +#define POP() RdRAM(0x100+(++_S)) + +static uint8 ZNTable[256]; +/* Some of these operations will only make sense if you know what the flag + constants are. */ + +#define X_ZN(zort) _P&=~(Z_FLAG|N_FLAG);_P|=ZNTable[zort] +#define X_ZNT(zort) _P|=ZNTable[zort] + +#define JR(cond); \ +{ \ + if(cond) \ + { \ + uint32 tmp; \ + int32 disp; \ + disp=(int8)RdMem(_PC); \ + _PC++; \ + ADDCYC(1); \ + tmp=_PC; \ + _PC+=disp; \ + if((tmp^_PC)&0x100) \ + ADDCYC(1); \ + } \ + else _PC++; \ +} + + +#define LDA _A=x;X_ZN(_A) +#define LDX _X=x;X_ZN(_X) +#define LDY _Y=x;X_ZN(_Y) + +/* All of the freaky arithmetic operations. */ +#define AND _A&=x;X_ZN(_A) +#define BIT _P&=~(Z_FLAG|V_FLAG|N_FLAG);_P|=ZNTable[x&_A]&Z_FLAG;_P|=x&(V_FLAG|N_FLAG) +#define EOR _A^=x;X_ZN(_A) +#define ORA _A|=x;X_ZN(_A) + +#define ADC { \ + uint32 l=_A+x+(_P&1); \ + _P&=~(Z_FLAG|C_FLAG|N_FLAG|V_FLAG); \ + _P|=((((_A^x)&0x80)^0x80) & ((_A^l)&0x80))>>1; \ + _P|=(l>>8)&C_FLAG; \ + _A=l; \ + X_ZNT(_A); \ + } + +#define SBC { \ + uint32 l=_A-x-((_P&1)^1); \ + _P&=~(Z_FLAG|C_FLAG|N_FLAG|V_FLAG); \ + _P|=((_A^l)&(_A^x)&0x80)>>1; \ + _P|=((l>>8)&C_FLAG)^C_FLAG; \ + _A=l; \ + X_ZNT(_A); \ + } + +#define CMPL(a1,a2) { \ + uint32 t=a1-a2; \ + X_ZN(t&0xFF); \ + _P&=~C_FLAG; \ + _P|=((t>>8)&C_FLAG)^C_FLAG; \ + } + +/* Special undocumented operation. Very similar to CMP. */ +#define AXS { \ + uint32 t=(_A&_X)-x; \ + X_ZN(t&0xFF); \ + _P&=~C_FLAG; \ + _P|=((t>>8)&C_FLAG)^C_FLAG; \ + _X=t; \ + } + +#define CMP CMPL(_A,x) +#define CPX CMPL(_X,x) +#define CPY CMPL(_Y,x) + +/* The following operations modify the byte being worked on. */ +#define DEC x--;X_ZN(x) +#define INC x++;X_ZN(x) + +#define ASL _P&=~C_FLAG;_P|=x>>7;x<<=1;X_ZN(x) +#define LSR _P&=~(C_FLAG|N_FLAG|Z_FLAG);_P|=x&1;x>>=1;X_ZNT(x) + +/* For undocumented instructions, maybe for other things later... */ +#define LSRA _P&=~(C_FLAG|N_FLAG|Z_FLAG);_P|=_A&1;_A>>=1;X_ZNT(_A) + +#define ROL { \ + uint8 l=x>>7; \ + x<<=1; \ + x|=_P&C_FLAG; \ + _P&=~(Z_FLAG|N_FLAG|C_FLAG); \ + _P|=l; \ + X_ZNT(x); \ + } +#define ROR { \ + uint8 l=x&1; \ + x>>=1; \ + x|=(_P&C_FLAG)<<7; \ + _P&=~(Z_FLAG|N_FLAG|C_FLAG); \ + _P|=l; \ + X_ZNT(x); \ + } + +/* Icky icky thing for some undocumented instructions. Can easily be + broken if names of local variables are changed. +*/ + +/* Absolute */ +#define GetAB(target) \ +{ \ + target=RdMem(_PC); \ + _PC++; \ + target|=RdMem(_PC)<<8; \ + _PC++; \ +} + +/* Absolute Indexed(for reads) */ +#define GetABIRD(target, i) \ +{ \ + unsigned int tmp; \ + GetAB(tmp); \ + target=tmp; \ + target+=i; \ + if((target^tmp)&0x100) \ + { \ + target&=0xFFFF; \ + RdMem(target^0x100); \ + ADDCYC(1); \ + } \ +} + +/* Absolute Indexed(for writes and rmws) */ +#define GetABIWR(target, i) \ +{ \ + unsigned int rt; \ + GetAB(rt); \ + target=rt; \ + target+=i; \ + target&=0xFFFF; \ + RdMem((target&0x00FF)|(rt&0xFF00)); \ +} + +/* Zero Page */ +#define GetZP(target) \ +{ \ + target=RdMem(_PC); \ + _PC++; \ +} + +/* Zero Page Indexed */ +#define GetZPI(target,i) \ +{ \ + target=i+RdMem(_PC); \ + _PC++; \ +} + +/* Indexed Indirect */ +#define GetIX(target) \ +{ \ + uint8 tmp; \ + tmp=RdMem(_PC); \ + _PC++; \ + tmp+=_X; \ + target=RdRAM(tmp); \ + tmp++; \ + target|=RdRAM(tmp)<<8; \ +} + +/* Indirect Indexed(for reads) */ +#define GetIYRD(target) \ +{ \ + unsigned int rt; \ + uint8 tmp; \ + tmp=RdMem(_PC); \ + _PC++; \ + rt=RdRAM(tmp); \ + tmp++; \ + rt|=RdRAM(tmp)<<8; \ + target=rt; \ + target+=_Y; \ + if((target^rt)&0x100) \ + { \ + target&=0xFFFF; \ + RdMem(target^0x100); \ + ADDCYC(1); \ + } \ +} + +/* Indirect Indexed(for writes and rmws) */ +#define GetIYWR(target) \ +{ \ + unsigned int rt; \ + uint8 tmp; \ + tmp=RdMem(_PC); \ + _PC++; \ + rt=RdRAM(tmp); \ + tmp++; \ + rt|=RdRAM(tmp)<<8; \ + target=rt; \ + target+=_Y; \ + target&=0xFFFF; \ + RdMem((target&0x00FF)|(rt&0xFF00)); \ +} + +/* Now come the macros to wrap up all of the above stuff addressing mode functions + and operation macros. Note that operation macros will always operate(redundant + redundant) on the variable "x". +*/ + +#define RMW_A(op) {uint8 x=_A; op; _A=x; break; } /* Meh... */ +#define RMW_AB(op) {unsigned int A; uint8 x; GetAB(A); x=RdMem(A); WrMem(A,x); op; WrMem(A,x); break; } +#define RMW_ABI(reg,op) {unsigned int A; uint8 x; GetABIWR(A,reg); x=RdMem(A); WrMem(A,x); op; WrMem(A,x); break; } +#define RMW_ABX(op) RMW_ABI(_X,op) +#define RMW_ABY(op) RMW_ABI(_Y,op) +#define RMW_IX(op) {unsigned int A; uint8 x; GetIX(A); x=RdMem(A); WrMem(A,x); op; WrMem(A,x); break; } +#define RMW_IY(op) {unsigned int A; uint8 x; GetIYWR(A); x=RdMem(A); WrMem(A,x); op; WrMem(A,x); break; } +#define RMW_ZP(op) {uint8 A; uint8 x; GetZP(A); x=RdRAM(A); op; WrRAM(A,x); break; } +#define RMW_ZPX(op) {uint8 A; uint8 x; GetZPI(A,_X); x=RdRAM(A); op; WrRAM(A,x); break;} + +#define LD_IM(op) {uint8 x; x=RdMem(_PC); _PC++; op; break;} +#define LD_ZP(op) {uint8 A; uint8 x; GetZP(A); x=RdRAM(A); op; break;} +#define LD_ZPX(op) {uint8 A; uint8 x; GetZPI(A,_X); x=RdRAM(A); op; break;} +#define LD_ZPY(op) {uint8 A; uint8 x; GetZPI(A,_Y); x=RdRAM(A); op; break;} +#define LD_AB(op) {unsigned int A; uint8 x; GetAB(A); x=RdMem(A); op; break; } +#define LD_ABI(reg,op) {unsigned int A; uint8 x; GetABIRD(A,reg); x=RdMem(A); op; break;} +#define LD_ABX(op) LD_ABI(_X,op) +#define LD_ABY(op) LD_ABI(_Y,op) +#define LD_IX(op) {unsigned int A; uint8 x; GetIX(A); x=RdMem(A); op; break;} +#define LD_IY(op) {unsigned int A; uint8 x; GetIYRD(A); x=RdMem(A); op; break;} + +#define ST_ZP(r) {uint8 A; GetZP(A); WrRAM(A,r); break;} +#define ST_ZPX(r) {uint8 A; GetZPI(A,_X); WrRAM(A,r); break;} +#define ST_ZPY(r) {uint8 A; GetZPI(A,_Y); WrRAM(A,r); break;} +#define ST_AB(r) {unsigned int A; GetAB(A); WrMem(A,r); break;} +#define ST_ABI(reg,r) {unsigned int A; GetABIWR(A,reg); WrMem(A,r); break; } +#define ST_ABX(r) ST_ABI(_X,r) +#define ST_ABY(r) ST_ABI(_Y,r) +#define ST_IX(r) {unsigned int A; GetIX(A); WrMem(A,r); break; } +#define ST_IY(r) {unsigned int A; GetIYWR(A); WrMem(A,r); break; } + +static uint8 CycTable[256] = +{ +/*0x00*/ 7,6,2,8,3,3,5,5,3,2,2,2,4,4,6,6, +/*0x10*/ 2,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7, +/*0x20*/ 6,6,2,8,3,3,5,5,4,2,2,2,4,4,6,6, +/*0x30*/ 2,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7, +/*0x40*/ 6,6,2,8,3,3,5,5,3,2,2,2,3,4,6,6, +/*0x50*/ 2,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7, +/*0x60*/ 6,6,2,8,3,3,5,5,4,2,2,2,5,4,6,6, +/*0x70*/ 2,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7, +/*0x80*/ 2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4, +/*0x90*/ 2,6,2,6,4,4,4,4,2,5,2,5,5,5,5,5, +/*0xA0*/ 2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4, +/*0xB0*/ 2,5,2,5,4,4,4,4,2,4,2,4,4,4,4,4, +/*0xC0*/ 2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6, +/*0xD0*/ 2,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7, +/*0xE0*/ 2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6, +/*0xF0*/ 2,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7, +}; + +void X6502_Init(void) +{ + int x; + + memset((void *)&X,0,sizeof(X)); + for(x=0;x<256;x++) + if(!x) ZNTable[x]=Z_FLAG; + else if(x&0x80) ZNTable[x]=N_FLAG; + else ZNTable[x]=0; +} + +void X6502_Power(void) +{ + _count=_tcount=_IRQlow=_PC=_A=_X=_Y=_S=_P=_PI=_DB=_jammed=0; + timestamp=0; + X6502_Reset(); +} + +void X6502_Run(int32 cycles) +{ +#define RdRAM RdRAMFast +#define WrRAM WrRAMFast +#define RdMem RdMemNorm +#define WrMem WrMemNorm + + uint16 pbackus; + + pbackus=_PC; + +#undef _PC +#define _PC pbackus + + if(PAL) + cycles*=15; /* 15*4=60*/ + else + cycles*=16; /* 16*4=64*/ + + _count+=cycles; + + while(_count>0) + { + int32 temp; + uint8 b1; + + /* XI.PC=pbackus;*/ + if(_IRQlow) + { + if(_IRQlow&FCEU_IQRESET) + { + _PC=RdMem(0xFFFC); + _PC|=RdMem(0xFFFD)<<8; + _jammed=0; + _PI=_P=I_FLAG; + _IRQlow&=~FCEU_IQRESET; + } + else if(_IRQlow&FCEU_IQNMI2) + { + _IRQlow&=~FCEU_IQNMI2; + _IRQlow|=FCEU_IQNMI; + } + else if(_IRQlow&FCEU_IQNMI) + { + if(!_jammed) + { + ADDCYC(7); + PUSH(_PC>>8); + PUSH(_PC); + PUSH((_P&~B_FLAG)|(U_FLAG)); + _P|=I_FLAG; + _PC=RdMem(0xFFFA); + _PC|=RdMem(0xFFFB)<<8; + _IRQlow&=~FCEU_IQNMI; + } + } + else + { + if(!(_PI&I_FLAG) && !_jammed) + { + ADDCYC(7); + PUSH(_PC>>8); + PUSH(_PC); + PUSH((_P&~B_FLAG)|(U_FLAG)); + _P|=I_FLAG; + _PC=RdMem(0xFFFE); + _PC|=RdMem(0xFFFF)<<8; + } + } + _IRQlow&=~(FCEU_IQTEMP); + if(_count<=0) + { + _PI=_P; + X.PC=pbackus; + return; + } /* Should increase accuracy without a */ + /* major speed hit. */ + } + + _PI=_P; + b1=RdMem(_PC); + + ADDCYC(CycTable[b1]); + + temp=_tcount; + _tcount=0; + if(MapIRQHook) MapIRQHook(temp); + FCEU_SoundCPUHook(temp); + /*printf("%04x\n",X.PC);*/ + X.PC=pbackus; + _PC++; + switch(b1) + { +#include "ops.h" + } + } + +#undef _PC +#define _PC X.PC + _PC=pbackus; +#undef RdRAM +#undef WrRAM +} diff --git a/fceumm/src-fceumm/x6502.h b/fceumm/src-fceumm/x6502.h new file mode 100644 index 0000000..daa2031 --- /dev/null +++ b/fceumm/src-fceumm/x6502.h @@ -0,0 +1,61 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _X6502H +#define _X6502H + +#include "x6502struct.h" + +void X6502_Run(int32 cycles); + +extern uint32 timestamp; +extern X6502 X; + +#define N_FLAG 0x80 +#define V_FLAG 0x40 +#define U_FLAG 0x20 +#define B_FLAG 0x10 +#define D_FLAG 0x08 +#define I_FLAG 0x04 +#define Z_FLAG 0x02 +#define C_FLAG 0x01 + +extern void (*MapIRQHook)(int a); + +#define NTSC_CPU 1789772.7272727272727272 +#define PAL_CPU 1662607.125 + +#define FCEU_IQEXT 0x001 +#define FCEU_IQEXT2 0x002 +/* ... */ +#define FCEU_IQRESET 0x020 +#define FCEU_IQNMI2 0x040 /* Delayed NMI, gets converted to *_IQNMI*/ +#define FCEU_IQNMI 0x080 +#define FCEU_IQDPCM 0x100 +#define FCEU_IQFCOUNT 0x200 +#define FCEU_IQTEMP 0x800 + +void X6502_Init(void); +void X6502_Power(void); + +uint8 X6502_DMR(uint32 A); +void X6502_DMW(uint32 A, uint8 V); + +#endif diff --git a/fceumm/src-fceumm/x6502struct.h b/fceumm/src-fceumm/x6502struct.h new file mode 100644 index 0000000..bc6930d --- /dev/null +++ b/fceumm/src-fceumm/x6502struct.h @@ -0,0 +1,26 @@ +#ifndef _X6502STRUCTH +#define _X6502STRUCTH + +typedef struct __X6502 { + int32 tcount; /* Temporary cycle counter */ + uint16 PC; /* I'll change this to uint32 later... */ + /* I'll need to AND PC after increments to 0xFFFF */ + /* when I do, though. Perhaps an IPC() macro? */ + uint8 A,X,Y,S,P,mooPI; + uint8 jammed; + + int32 count; + uint32 IRQlow; /* Simulated IRQ pin held low(or is it high?). + And other junk hooked on for speed reasons.*/ + uint8 DB; /* Data bus "cache" for reads from certain areas */ + + int preexec; /* Pre-exec'ing for debug breakpoints. */ +} X6502; + +#define TriggerNMI() X.IRQlow |= FCEU_IQNMI; +#define TriggerNMI2() X.IRQlow |= FCEU_IQNMI2; +#define X6502_Reset() X.IRQlow = FCEU_IQRESET; +#define X6502_IRQBegin(w) X.IRQlow |= w; +#define X6502_IRQEnd(w) X.IRQlow &= ~w; + +#endif diff --git a/fceumm/src-fceumm/zlib/adler32.c b/fceumm/src-fceumm/zlib/adler32.c new file mode 100644 index 0000000..a250f3f --- /dev/null +++ b/fceumm/src-fceumm/zlib/adler32.c @@ -0,0 +1,48 @@ +/* adler32.c -- compute the Adler-32 checksum of a data stream + * Copyright (C) 1995-2002 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: adler32.c,v 1.2 2002/03/13 17:45:56 xodnizel Exp $ */ + +#include "zlib.h" + +#define BASE 65521L /* largest prime smaller than 65536 */ +#define NMAX 5552 +/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ + +#define DO1(buf,i) {s1 += buf[i]; s2 += s1;} +#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); +#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); +#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); +#define DO16(buf) DO8(buf,0); DO8(buf,8); + +/* ========================================================================= */ +uLong ZEXPORT adler32(adler, buf, len) + uLong adler; + const Bytef *buf; + uInt len; +{ + unsigned long s1 = adler & 0xffff; + unsigned long s2 = (adler >> 16) & 0xffff; + int k; + + if (buf == Z_NULL) return 1L; + + while (len > 0) { + k = len < NMAX ? len : NMAX; + len -= k; + while (k >= 16) { + DO16(buf); + buf += 16; + k -= 16; + } + if (k != 0) do { + s1 += *buf++; + s2 += s1; + } while (--k); + s1 %= BASE; + s2 %= BASE; + } + return (s2 << 16) | s1; +} diff --git a/fceumm/src-fceumm/zlib/compress.c b/fceumm/src-fceumm/zlib/compress.c new file mode 100644 index 0000000..c0eecda --- /dev/null +++ b/fceumm/src-fceumm/zlib/compress.c @@ -0,0 +1,68 @@ +/* compress.c -- compress a memory buffer + * Copyright (C) 1995-2002 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: compress.c,v 1.2 2002/03/13 17:45:56 xodnizel Exp $ */ + +#include "zlib.h" + +/* =========================================================================== + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least 0.1% larger than sourceLen plus + 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ +int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) + Bytef *dest; + uLongf *destLen; + const Bytef *source; + uLong sourceLen; + int level; +{ + z_stream stream; + int err; + + stream.next_in = (Bytef*)source; + stream.avail_in = (uInt)sourceLen; +#ifdef MAXSEG_64K + /* Check for source > 64K on 16-bit machine: */ + if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; +#endif + stream.next_out = dest; + stream.avail_out = (uInt)*destLen; + if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; + + stream.zalloc = (alloc_func)0; + stream.zfree = (free_func)0; + stream.opaque = (voidpf)0; + + err = deflateInit(&stream, level); + if (err != Z_OK) return err; + + err = deflate(&stream, Z_FINISH); + if (err != Z_STREAM_END) { + deflateEnd(&stream); + return err == Z_OK ? Z_BUF_ERROR : err; + } + *destLen = stream.total_out; + + err = deflateEnd(&stream); + return err; +} + +/* =========================================================================== + */ +int ZEXPORT compress (dest, destLen, source, sourceLen) + Bytef *dest; + uLongf *destLen; + const Bytef *source; + uLong sourceLen; +{ + return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); +} diff --git a/fceumm/src-fceumm/zlib/crc32.c b/fceumm/src-fceumm/zlib/crc32.c new file mode 100644 index 0000000..558f6f6 --- /dev/null +++ b/fceumm/src-fceumm/zlib/crc32.c @@ -0,0 +1,162 @@ +/* crc32.c -- compute the CRC-32 of a data stream + * Copyright (C) 1995-2002 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: crc32.c,v 1.2 2002/03/13 17:45:56 xodnizel Exp $ */ + +#include "zlib.h" + +#define local static + +#ifdef DYNAMIC_CRC_TABLE + +local int crc_table_empty = 1; +local uLongf crc_table[256]; +local void make_crc_table OF((void)); + +/* + Generate a table for a byte-wise 32-bit CRC calculation on the polynomial: + x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. + + Polynomials over GF(2) are represented in binary, one bit per coefficient, + with the lowest powers in the most significant bit. Then adding polynomials + is just exclusive-or, and multiplying a polynomial by x is a right shift by + one. If we call the above polynomial p, and represent a byte as the + polynomial q, also with the lowest power in the most significant bit (so the + byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, + where a mod b means the remainder after dividing a by b. + + This calculation is done using the shift-register method of multiplying and + taking the remainder. The register is initialized to zero, and for each + incoming bit, x^32 is added mod p to the register if the bit is a one (where + x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by + x (which is shifting right by one and adding x^32 mod p if the bit shifted + out is a one). We start with the highest power (least significant bit) of + q and repeat for all eight bits of q. + + The table is simply the CRC of all possible eight bit values. This is all + the information needed to generate CRC's on data a byte at a time for all + combinations of CRC register values and incoming bytes. +*/ +local void make_crc_table() +{ + uLong c; + int n, k; + uLong poly; /* polynomial exclusive-or pattern */ + /* terms of polynomial defining this crc (except x^32): */ + static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; + + /* make exclusive-or pattern from polynomial (0xedb88320L) */ + poly = 0L; + for (n = 0; n < sizeof(p)/sizeof(Byte); n++) + poly |= 1L << (31 - p[n]); + + for (n = 0; n < 256; n++) + { + c = (uLong)n; + for (k = 0; k < 8; k++) + c = c & 1 ? poly ^ (c >> 1) : c >> 1; + crc_table[n] = c; + } + crc_table_empty = 0; +} +#else +/* ======================================================================== + * Table of CRC-32's of all single-byte values (made by make_crc_table) + */ +local const uLongf crc_table[256] = { + 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, + 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, + 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, + 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, + 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, + 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, + 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, + 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL, + 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, + 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL, + 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, + 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, + 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L, + 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, + 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, + 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L, + 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, + 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L, + 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, + 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, + 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL, + 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, + 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L, + 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL, + 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, + 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L, + 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, + 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, + 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L, + 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, + 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, + 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L, + 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, + 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL, + 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, + 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, + 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL, + 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, + 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, + 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L, + 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, + 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L, + 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, + 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, + 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L, + 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, + 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, + 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L, + 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, + 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L, + 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, + 0x2d02ef8dL +}; +#endif + +/* ========================================================================= + * This function can be used by asm versions of crc32() + */ +const uLongf * ZEXPORT get_crc_table() +{ +#ifdef DYNAMIC_CRC_TABLE + if (crc_table_empty) make_crc_table(); +#endif + return (const uLongf *)crc_table; +} + +/* ========================================================================= */ +#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); +#define DO2(buf) DO1(buf); DO1(buf); +#define DO4(buf) DO2(buf); DO2(buf); +#define DO8(buf) DO4(buf); DO4(buf); + +/* ========================================================================= */ +uLong ZEXPORT crc32(crc, buf, len) + uLong crc; + const Bytef *buf; + uInt len; +{ + if (buf == Z_NULL) return 0L; +#ifdef DYNAMIC_CRC_TABLE + if (crc_table_empty) + make_crc_table(); +#endif + crc = crc ^ 0xffffffffL; + while (len >= 8) + { + DO8(buf); + len -= 8; + } + if (len) do { + DO1(buf); + } while (--len); + return crc ^ 0xffffffffL; +} diff --git a/fceumm/src-fceumm/zlib/deflate.c b/fceumm/src-fceumm/zlib/deflate.c new file mode 100644 index 0000000..0b79a14 --- /dev/null +++ b/fceumm/src-fceumm/zlib/deflate.c @@ -0,0 +1,1350 @@ +/* deflate.c -- compress data using the deflation algorithm + * Copyright (C) 1995-2002 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + * ALGORITHM + * + * The "deflation" process depends on being able to identify portions + * of the input text which are identical to earlier input (within a + * sliding window trailing behind the input currently being processed). + * + * The most straightforward technique turns out to be the fastest for + * most input files: try all possible matches and select the longest. + * The key feature of this algorithm is that insertions into the string + * dictionary are very simple and thus fast, and deletions are avoided + * completely. Insertions are performed at each input character, whereas + * string matches are performed only when the previous match ends. So it + * is preferable to spend more time in matches to allow very fast string + * insertions and avoid deletions. The matching algorithm for small + * strings is inspired from that of Rabin & Karp. A brute force approach + * is used to find longer strings when a small match has been found. + * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze + * (by Leonid Broukhis). + * A previous version of this file used a more sophisticated algorithm + * (by Fiala and Greene) which is guaranteed to run in linear amortized + * time, but has a larger average cost, uses more memory and is patented. + * However the F&G algorithm may be faster for some highly redundant + * files if the parameter max_chain_length (described below) is too large. + * + * ACKNOWLEDGEMENTS + * + * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and + * I found it in 'freeze' written by Leonid Broukhis. + * Thanks to many people for bug reports and testing. + * + * REFERENCES + * + * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". + * Available in ftp://ds.internic.net/rfc/rfc1951.txt + * + * A description of the Rabin and Karp algorithm is given in the book + * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. + * + * Fiala,E.R., and Greene,D.H. + * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 + * + */ + +/* @(#) $Id: deflate.c,v 1.2 2002/03/13 17:45:56 xodnizel Exp $ */ + +#include "deflate.h" + +const char deflate_copyright[] = + " deflate 1.1.4 Copyright 1995-2002 Jean-loup Gailly "; +/* + If you use the zlib library in a product, an acknowledgment is welcome + in the documentation of your product. If for some reason you cannot + include such an acknowledgment, I would appreciate that you keep this + copyright string in the executable of your product. + */ + +/* =========================================================================== + * Function prototypes. + */ +typedef enum { + need_more, /* block not completed, need more input or more output */ + block_done, /* block flush performed */ + finish_started, /* finish started, need only more output at next deflate */ + finish_done /* finish done, accept no more input or output */ +} block_state; + +typedef block_state (*compress_func) OF((deflate_state *s, int flush)); +/* Compression function. Returns the block state after the call. */ + +local void fill_window OF((deflate_state *s)); +local block_state deflate_stored OF((deflate_state *s, int flush)); +local block_state deflate_fast OF((deflate_state *s, int flush)); +local block_state deflate_slow OF((deflate_state *s, int flush)); +local void lm_init OF((deflate_state *s)); +local void putShortMSB OF((deflate_state *s, uInt b)); +local void flush_pending OF((z_streamp strm)); +local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); +#ifdef ASMV + void match_init OF((void)); /* asm code initialization */ + uInt longest_match OF((deflate_state *s, IPos cur_match)); +#else +local uInt longest_match OF((deflate_state *s, IPos cur_match)); +#endif + +#ifdef DEBUG +local void check_match OF((deflate_state *s, IPos start, IPos match, + int length)); +#endif + +/* =========================================================================== + * Local data + */ + +#define NIL 0 +/* Tail of hash chains */ + +#ifndef TOO_FAR +# define TOO_FAR 4096 +#endif +/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ + +#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) +/* Minimum amount of lookahead, except at the end of the input file. + * See deflate.c for comments about the MIN_MATCH+1. + */ + +/* Values for max_lazy_match, good_match and max_chain_length, depending on + * the desired pack level (0..9). The values given below have been tuned to + * exclude worst case performance for pathological files. Better values may be + * found for specific files. + */ +typedef struct config_s { + ush good_length; /* reduce lazy search above this match length */ + ush max_lazy; /* do not perform lazy search above this match length */ + ush nice_length; /* quit search above this match length */ + ush max_chain; + compress_func func; +} config; + +local const config configuration_table[10] = { +/* good lazy nice chain */ +/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ +/* 1 */ {4, 4, 8, 4, deflate_fast}, /* maximum speed, no lazy matches */ +/* 2 */ {4, 5, 16, 8, deflate_fast}, +/* 3 */ {4, 6, 32, 32, deflate_fast}, + +/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ +/* 5 */ {8, 16, 32, 32, deflate_slow}, +/* 6 */ {8, 16, 128, 128, deflate_slow}, +/* 7 */ {8, 32, 128, 256, deflate_slow}, +/* 8 */ {32, 128, 258, 1024, deflate_slow}, +/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* maximum compression */ + +/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 + * For deflate_fast() (levels <= 3) good is ignored and lazy has a different + * meaning. + */ + +#define EQUAL 0 +/* result of memcmp for equal strings */ + +struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ + +/* =========================================================================== + * Update a hash value with the given input byte + * IN assertion: all calls to to UPDATE_HASH are made with consecutive + * input characters, so that a running hash key can be computed from the + * previous key instead of complete recalculation each time. + */ +#define UPDATE_HASH(s,h,c) (h = (((h)<hash_shift) ^ (c)) & s->hash_mask) + + +/* =========================================================================== + * Insert string str in the dictionary and set match_head to the previous head + * of the hash chain (the most recent string with same hash key). Return + * the previous length of the hash chain. + * If this file is compiled with -DFASTEST, the compression level is forced + * to 1, and no hash chains are maintained. + * IN assertion: all calls to to INSERT_STRING are made with consecutive + * input characters and the first MIN_MATCH bytes of str are valid + * (except for the last MIN_MATCH-1 bytes of the input file). + */ +#ifdef FASTEST +#define INSERT_STRING(s, str, match_head) \ + (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ + match_head = s->head[s->ins_h], \ + s->head[s->ins_h] = (Pos)(str)) +#else +#define INSERT_STRING(s, str, match_head) \ + (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ + s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \ + s->head[s->ins_h] = (Pos)(str)) +#endif + +/* =========================================================================== + * Initialize the hash table (avoiding 64K overflow for 16 bit systems). + * prev[] will be initialized on the fly. + */ +#define CLEAR_HASH(s) \ + s->head[s->hash_size-1] = NIL; \ + zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); + +/* ========================================================================= */ +int ZEXPORT deflateInit_(strm, level, version, stream_size) + z_streamp strm; + int level; + const char *version; + int stream_size; +{ + return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, + Z_DEFAULT_STRATEGY, version, stream_size); + /* To do: ignore strm->next_in if we use it as window */ +} + +/* ========================================================================= */ +int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, + version, stream_size) + z_streamp strm; + int level; + int method; + int windowBits; + int memLevel; + int strategy; + const char *version; + int stream_size; +{ + deflate_state *s; + int noheader = 0; + static const char* my_version = ZLIB_VERSION; + + ushf *overlay; + /* We overlay pending_buf and d_buf+l_buf. This works since the average + * output size for (length,distance) codes is <= 24 bits. + */ + + if (version == Z_NULL || version[0] != my_version[0] || + stream_size != sizeof(z_stream)) { + return Z_VERSION_ERROR; + } + if (strm == Z_NULL) return Z_STREAM_ERROR; + + strm->msg = Z_NULL; + if (strm->zalloc == Z_NULL) { + strm->zalloc = zcalloc; + strm->opaque = (voidpf)0; + } + if (strm->zfree == Z_NULL) strm->zfree = zcfree; + + if (level == Z_DEFAULT_COMPRESSION) level = 6; +#ifdef FASTEST + level = 1; +#endif + + if (windowBits < 0) { /* undocumented feature: suppress zlib header */ + noheader = 1; + windowBits = -windowBits; + } + if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || + windowBits < 9 || windowBits > 15 || level < 0 || level > 9 || + strategy < 0 || strategy > Z_HUFFMAN_ONLY) { + return Z_STREAM_ERROR; + } + s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); + if (s == Z_NULL) return Z_MEM_ERROR; + strm->state = (struct internal_state FAR *)s; + s->strm = strm; + + s->noheader = noheader; + s->w_bits = windowBits; + s->w_size = 1 << s->w_bits; + s->w_mask = s->w_size - 1; + + s->hash_bits = memLevel + 7; + s->hash_size = 1 << s->hash_bits; + s->hash_mask = s->hash_size - 1; + s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); + + s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); + s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); + s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); + + s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ + + overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); + s->pending_buf = (uchf *) overlay; + s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); + + if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || + s->pending_buf == Z_NULL) { + strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); + deflateEnd (strm); + return Z_MEM_ERROR; + } + s->d_buf = overlay + s->lit_bufsize/sizeof(ush); + s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; + + s->level = level; + s->strategy = strategy; + s->method = (Byte)method; + + return deflateReset(strm); +} + +/* ========================================================================= */ +int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) + z_streamp strm; + const Bytef *dictionary; + uInt dictLength; +{ + deflate_state *s; + uInt length = dictLength; + uInt n; + IPos hash_head = 0; + + if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL || + strm->state->status != INIT_STATE) return Z_STREAM_ERROR; + + s = strm->state; + strm->adler = adler32(strm->adler, dictionary, dictLength); + + if (length < MIN_MATCH) return Z_OK; + if (length > MAX_DIST(s)) { + length = MAX_DIST(s); +#ifndef USE_DICT_HEAD + dictionary += dictLength - length; /* use the tail of the dictionary */ +#endif + } + zmemcpy(s->window, dictionary, length); + s->strstart = length; + s->block_start = (long)length; + + /* Insert all strings in the hash table (except for the last two bytes). + * s->lookahead stays null, so s->ins_h will be recomputed at the next + * call of fill_window. + */ + s->ins_h = s->window[0]; + UPDATE_HASH(s, s->ins_h, s->window[1]); + for (n = 0; n <= length - MIN_MATCH; n++) { + INSERT_STRING(s, n, hash_head); + } + if (hash_head) hash_head = 0; /* to make compiler happy */ + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflateReset (strm) + z_streamp strm; +{ + deflate_state *s; + + if (strm == Z_NULL || strm->state == Z_NULL || + strm->zalloc == Z_NULL || strm->zfree == Z_NULL) return Z_STREAM_ERROR; + + strm->total_in = strm->total_out = 0; + strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ + strm->data_type = Z_UNKNOWN; + + s = (deflate_state *)strm->state; + s->pending = 0; + s->pending_out = s->pending_buf; + + if (s->noheader < 0) { + s->noheader = 0; /* was set to -1 by deflate(..., Z_FINISH); */ + } + s->status = s->noheader ? BUSY_STATE : INIT_STATE; + strm->adler = 1; + s->last_flush = Z_NO_FLUSH; + + _tr_init(s); + lm_init(s); + + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflateParams(strm, level, strategy) + z_streamp strm; + int level; + int strategy; +{ + deflate_state *s; + compress_func func; + int err = Z_OK; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + s = strm->state; + + if (level == Z_DEFAULT_COMPRESSION) { + level = 6; + } + if (level < 0 || level > 9 || strategy < 0 || strategy > Z_HUFFMAN_ONLY) { + return Z_STREAM_ERROR; + } + func = configuration_table[s->level].func; + + if (func != configuration_table[level].func && strm->total_in != 0) { + /* Flush the last buffer: */ + err = deflate(strm, Z_PARTIAL_FLUSH); + } + if (s->level != level) { + s->level = level; + s->max_lazy_match = configuration_table[level].max_lazy; + s->good_match = configuration_table[level].good_length; + s->nice_match = configuration_table[level].nice_length; + s->max_chain_length = configuration_table[level].max_chain; + } + s->strategy = strategy; + return err; +} + +/* ========================================================================= + * Put a short in the pending buffer. The 16-bit value is put in MSB order. + * IN assertion: the stream state is correct and there is enough room in + * pending_buf. + */ +local void putShortMSB (s, b) + deflate_state *s; + uInt b; +{ + put_byte(s, (Byte)(b >> 8)); + put_byte(s, (Byte)(b & 0xff)); +} + +/* ========================================================================= + * Flush as much pending output as possible. All deflate() output goes + * through this function so some applications may wish to modify it + * to avoid allocating a large strm->next_out buffer and copying into it. + * (See also read_buf()). + */ +local void flush_pending(strm) + z_streamp strm; +{ + unsigned len = strm->state->pending; + + if (len > strm->avail_out) len = strm->avail_out; + if (len == 0) return; + + zmemcpy(strm->next_out, strm->state->pending_out, len); + strm->next_out += len; + strm->state->pending_out += len; + strm->total_out += len; + strm->avail_out -= len; + strm->state->pending -= len; + if (strm->state->pending == 0) { + strm->state->pending_out = strm->state->pending_buf; + } +} + +/* ========================================================================= */ +int ZEXPORT deflate (strm, flush) + z_streamp strm; + int flush; +{ + int old_flush; /* value of flush param for previous deflate call */ + deflate_state *s; + + if (strm == Z_NULL || strm->state == Z_NULL || + flush > Z_FINISH || flush < 0) { + return Z_STREAM_ERROR; + } + s = strm->state; + + if (strm->next_out == Z_NULL || + (strm->next_in == Z_NULL && strm->avail_in != 0) || + (s->status == FINISH_STATE && flush != Z_FINISH)) { + ERR_RETURN(strm, Z_STREAM_ERROR); + } + if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); + + s->strm = strm; /* just in case */ + old_flush = s->last_flush; + s->last_flush = flush; + + /* Write the zlib header */ + if (s->status == INIT_STATE) { + + uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; + uInt level_flags = (s->level-1) >> 1; + + if (level_flags > 3) level_flags = 3; + header |= (level_flags << 6); + if (s->strstart != 0) header |= PRESET_DICT; + header += 31 - (header % 31); + + s->status = BUSY_STATE; + putShortMSB(s, header); + + /* Save the adler32 of the preset dictionary: */ + if (s->strstart != 0) { + putShortMSB(s, (uInt)(strm->adler >> 16)); + putShortMSB(s, (uInt)(strm->adler & 0xffff)); + } + strm->adler = 1L; + } + + /* Flush as much pending output as possible */ + if (s->pending != 0) { + flush_pending(strm); + if (strm->avail_out == 0) { + /* Since avail_out is 0, deflate will be called again with + * more output space, but possibly with both pending and + * avail_in equal to zero. There won't be anything to do, + * but this is not an error situation so make sure we + * return OK instead of BUF_ERROR at next call of deflate: + */ + s->last_flush = -1; + return Z_OK; + } + + /* Make sure there is something to do and avoid duplicate consecutive + * flushes. For repeated and useless calls with Z_FINISH, we keep + * returning Z_STREAM_END instead of Z_BUFF_ERROR. + */ + } else if (strm->avail_in == 0 && flush <= old_flush && + flush != Z_FINISH) { + ERR_RETURN(strm, Z_BUF_ERROR); + } + + /* User must not provide more input after the first FINISH: */ + if (s->status == FINISH_STATE && strm->avail_in != 0) { + ERR_RETURN(strm, Z_BUF_ERROR); + } + + /* Start a new block or continue the current one. + */ + if (strm->avail_in != 0 || s->lookahead != 0 || + (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { + block_state bstate; + + bstate = (*(configuration_table[s->level].func))(s, flush); + + if (bstate == finish_started || bstate == finish_done) { + s->status = FINISH_STATE; + } + if (bstate == need_more || bstate == finish_started) { + if (strm->avail_out == 0) { + s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ + } + return Z_OK; + /* If flush != Z_NO_FLUSH && avail_out == 0, the next call + * of deflate should use the same flush parameter to make sure + * that the flush is complete. So we don't have to output an + * empty block here, this will be done at next call. This also + * ensures that for a very small output buffer, we emit at most + * one empty block. + */ + } + if (bstate == block_done) { + if (flush == Z_PARTIAL_FLUSH) { + _tr_align(s); + } else { /* FULL_FLUSH or SYNC_FLUSH */ + _tr_stored_block(s, (char*)0, 0L, 0); + /* For a full flush, this empty block will be recognized + * as a special marker by inflate_sync(). + */ + if (flush == Z_FULL_FLUSH) { + CLEAR_HASH(s); /* forget history */ + } + } + flush_pending(strm); + if (strm->avail_out == 0) { + s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ + return Z_OK; + } + } + } + Assert(strm->avail_out > 0, "bug2"); + + if (flush != Z_FINISH) return Z_OK; + if (s->noheader) return Z_STREAM_END; + + /* Write the zlib trailer (adler32) */ + putShortMSB(s, (uInt)(strm->adler >> 16)); + putShortMSB(s, (uInt)(strm->adler & 0xffff)); + flush_pending(strm); + /* If avail_out is zero, the application will call deflate again + * to flush the rest. + */ + s->noheader = -1; /* write the trailer only once! */ + return s->pending != 0 ? Z_OK : Z_STREAM_END; +} + +/* ========================================================================= */ +int ZEXPORT deflateEnd (strm) + z_streamp strm; +{ + int status; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + + status = strm->state->status; + if (status != INIT_STATE && status != BUSY_STATE && + status != FINISH_STATE) { + return Z_STREAM_ERROR; + } + + /* Deallocate in reverse order of allocations: */ + TRY_FREE(strm, strm->state->pending_buf); + TRY_FREE(strm, strm->state->head); + TRY_FREE(strm, strm->state->prev); + TRY_FREE(strm, strm->state->window); + + ZFREE(strm, strm->state); + strm->state = Z_NULL; + + return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; +} + +/* ========================================================================= + * Copy the source state to the destination state. + * To simplify the source, this is not supported for 16-bit MSDOS (which + * doesn't have enough memory anyway to duplicate compression states). + */ +int ZEXPORT deflateCopy (dest, source) + z_streamp dest; + z_streamp source; +{ +#ifdef MAXSEG_64K + return Z_STREAM_ERROR; +#else + deflate_state *ds; + deflate_state *ss; + ushf *overlay; + + + if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { + return Z_STREAM_ERROR; + } + + ss = source->state; + + *dest = *source; + + ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); + if (ds == Z_NULL) return Z_MEM_ERROR; + dest->state = (struct internal_state FAR *) ds; + *ds = *ss; + ds->strm = dest; + + ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); + ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); + ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); + overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); + ds->pending_buf = (uchf *) overlay; + + if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || + ds->pending_buf == Z_NULL) { + deflateEnd (dest); + return Z_MEM_ERROR; + } + /* following zmemcpy do not work for 16-bit MSDOS */ + zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); + zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos)); + zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos)); + zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); + + ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); + ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); + ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; + + ds->l_desc.dyn_tree = ds->dyn_ltree; + ds->d_desc.dyn_tree = ds->dyn_dtree; + ds->bl_desc.dyn_tree = ds->bl_tree; + + return Z_OK; +#endif +} + +/* =========================================================================== + * Read a new buffer from the current input stream, update the adler32 + * and total number of bytes read. All deflate() input goes through + * this function so some applications may wish to modify it to avoid + * allocating a large strm->next_in buffer and copying from it. + * (See also flush_pending()). + */ +local int read_buf(strm, buf, size) + z_streamp strm; + Bytef *buf; + unsigned size; +{ + unsigned len = strm->avail_in; + + if (len > size) len = size; + if (len == 0) return 0; + + strm->avail_in -= len; + + if (!strm->state->noheader) { + strm->adler = adler32(strm->adler, strm->next_in, len); + } + zmemcpy(buf, strm->next_in, len); + strm->next_in += len; + strm->total_in += len; + + return (int)len; +} + +/* =========================================================================== + * Initialize the "longest match" routines for a new zlib stream + */ +local void lm_init (s) + deflate_state *s; +{ + s->window_size = (ulg)2L*s->w_size; + + CLEAR_HASH(s); + + /* Set the default configuration parameters: + */ + s->max_lazy_match = configuration_table[s->level].max_lazy; + s->good_match = configuration_table[s->level].good_length; + s->nice_match = configuration_table[s->level].nice_length; + s->max_chain_length = configuration_table[s->level].max_chain; + + s->strstart = 0; + s->block_start = 0L; + s->lookahead = 0; + s->match_length = s->prev_length = MIN_MATCH-1; + s->match_available = 0; + s->ins_h = 0; +#ifdef ASMV + match_init(); /* initialize the asm code */ +#endif +} + +/* =========================================================================== + * Set match_start to the longest match starting at the given string and + * return its length. Matches shorter or equal to prev_length are discarded, + * in which case the result is equal to prev_length and match_start is + * garbage. + * IN assertions: cur_match is the head of the hash chain for the current + * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 + * OUT assertion: the match length is not greater than s->lookahead. + */ +#ifndef ASMV +/* For 80x86 and 680x0, an optimized version will be provided in match.asm or + * match.S. The code will be functionally equivalent. + */ +#ifndef FASTEST +local uInt longest_match(s, cur_match) + deflate_state *s; + IPos cur_match; /* current match */ +{ + unsigned chain_length = s->max_chain_length;/* max hash chain length */ + register Bytef *scan = s->window + s->strstart; /* current string */ + register Bytef *match; /* matched string */ + register int len; /* length of current match */ + int best_len = s->prev_length; /* best match length so far */ + int nice_match = s->nice_match; /* stop if match long enough */ + IPos limit = s->strstart > (IPos)MAX_DIST(s) ? + s->strstart - (IPos)MAX_DIST(s) : NIL; + /* Stop when cur_match becomes <= limit. To simplify the code, + * we prevent matches with the string of window index 0. + */ + Posf *prev = s->prev; + uInt wmask = s->w_mask; + +#ifdef UNALIGNED_OK + /* Compare two bytes at a time. Note: this is not always beneficial. + * Try with and without -DUNALIGNED_OK to check. + */ + register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; + register ush scan_start = *(ushf*)scan; + register ush scan_end = *(ushf*)(scan+best_len-1); +#else + register Bytef *strend = s->window + s->strstart + MAX_MATCH; + register Byte scan_end1 = scan[best_len-1]; + register Byte scan_end = scan[best_len]; +#endif + + /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. + * It is easy to get rid of this optimization if necessary. + */ + Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); + + /* Do not waste too much time if we already have a good match: */ + if (s->prev_length >= s->good_match) { + chain_length >>= 2; + } + /* Do not look for matches beyond the end of the input. This is necessary + * to make deflate deterministic. + */ + if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; + + Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); + + do { + Assert(cur_match < s->strstart, "no future"); + match = s->window + cur_match; + + /* Skip to next match if the match length cannot increase + * or if the match length is less than 2: + */ +#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) + /* This code assumes sizeof(unsigned short) == 2. Do not use + * UNALIGNED_OK if your compiler uses a different size. + */ + if (*(ushf*)(match+best_len-1) != scan_end || + *(ushf*)match != scan_start) continue; + + /* It is not necessary to compare scan[2] and match[2] since they are + * always equal when the other bytes match, given that the hash keys + * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at + * strstart+3, +5, ... up to strstart+257. We check for insufficient + * lookahead only every 4th comparison; the 128th check will be made + * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is + * necessary to put more guard bytes at the end of the window, or + * to check more often for insufficient lookahead. + */ + Assert(scan[2] == match[2], "scan[2]?"); + scan++, match++; + do { + } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && + scan < strend); + /* The funny "do {}" generates better code on most compilers */ + + /* Here, scan <= window+strstart+257 */ + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + if (*scan == *match) scan++; + + len = (MAX_MATCH - 1) - (int)(strend-scan); + scan = strend - (MAX_MATCH-1); + +#else /* UNALIGNED_OK */ + + if (match[best_len] != scan_end || + match[best_len-1] != scan_end1 || + *match != *scan || + *++match != scan[1]) continue; + + /* The check at best_len-1 can be removed because it will be made + * again later. (This heuristic is not always a win.) + * It is not necessary to compare scan[2] and match[2] since they + * are always equal when the other bytes match, given that + * the hash keys are equal and that HASH_BITS >= 8. + */ + scan += 2, match++; + Assert(*scan == *match, "match[2]?"); + + /* We check for insufficient lookahead only every 8th comparison; + * the 256th check will be made at strstart+258. + */ + do { + } while (*++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + scan < strend); + + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + + len = MAX_MATCH - (int)(strend - scan); + scan = strend - MAX_MATCH; + +#endif /* UNALIGNED_OK */ + + if (len > best_len) { + s->match_start = cur_match; + best_len = len; + if (len >= nice_match) break; +#ifdef UNALIGNED_OK + scan_end = *(ushf*)(scan+best_len-1); +#else + scan_end1 = scan[best_len-1]; + scan_end = scan[best_len]; +#endif + } + } while ((cur_match = prev[cur_match & wmask]) > limit + && --chain_length != 0); + + if ((uInt)best_len <= s->lookahead) return (uInt)best_len; + return s->lookahead; +} + +#else /* FASTEST */ +/* --------------------------------------------------------------------------- + * Optimized version for level == 1 only + */ +local uInt longest_match(s, cur_match) + deflate_state *s; + IPos cur_match; /* current match */ +{ + register Bytef *scan = s->window + s->strstart; /* current string */ + register Bytef *match; /* matched string */ + register int len; /* length of current match */ + register Bytef *strend = s->window + s->strstart + MAX_MATCH; + + /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. + * It is easy to get rid of this optimization if necessary. + */ + Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); + + Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); + + Assert(cur_match < s->strstart, "no future"); + + match = s->window + cur_match; + + /* Return failure if the match length is less than 2: + */ + if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; + + /* The check at best_len-1 can be removed because it will be made + * again later. (This heuristic is not always a win.) + * It is not necessary to compare scan[2] and match[2] since they + * are always equal when the other bytes match, given that + * the hash keys are equal and that HASH_BITS >= 8. + */ + scan += 2, match += 2; + Assert(*scan == *match, "match[2]?"); + + /* We check for insufficient lookahead only every 8th comparison; + * the 256th check will be made at strstart+258. + */ + do { + } while (*++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + scan < strend); + + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + + len = MAX_MATCH - (int)(strend - scan); + + if (len < MIN_MATCH) return MIN_MATCH - 1; + + s->match_start = cur_match; + return len <= s->lookahead ? len : s->lookahead; +} +#endif /* FASTEST */ +#endif /* ASMV */ + +#ifdef DEBUG +/* =========================================================================== + * Check that the match at match_start is indeed a match. + */ +local void check_match(s, start, match, length) + deflate_state *s; + IPos start, match; + int length; +{ + /* check that the match is indeed a match */ + if (zmemcmp(s->window + match, + s->window + start, length) != EQUAL) { + fprintf(stderr, " start %u, match %u, length %d\n", + start, match, length); + do { + fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); + } while (--length != 0); + z_error("invalid match"); + } + if (z_verbose > 1) { + fprintf(stderr,"\\[%d,%d]", start-match, length); + do { putc(s->window[start++], stderr); } while (--length != 0); + } +} +#else +# define check_match(s, start, match, length) +#endif + +/* =========================================================================== + * Fill the window when the lookahead becomes insufficient. + * Updates strstart and lookahead. + * + * IN assertion: lookahead < MIN_LOOKAHEAD + * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD + * At least one byte has been read, or avail_in == 0; reads are + * performed for at least two bytes (required for the zip translate_eol + * option -- not supported here). + */ +local void fill_window(s) + deflate_state *s; +{ + register unsigned n, m; + register Posf *p; + unsigned more; /* Amount of free space at the end of the window. */ + uInt wsize = s->w_size; + + do { + more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); + + /* Deal with !@#$% 64K limit: */ + if (more == 0 && s->strstart == 0 && s->lookahead == 0) { + more = wsize; + + } else if (more == (unsigned)(-1)) { + /* Very unlikely, but possible on 16 bit machine if strstart == 0 + * and lookahead == 1 (input done one byte at time) + */ + more--; + + /* If the window is almost full and there is insufficient lookahead, + * move the upper half to the lower one to make room in the upper half. + */ + } else if (s->strstart >= wsize+MAX_DIST(s)) { + + zmemcpy(s->window, s->window+wsize, (unsigned)wsize); + s->match_start -= wsize; + s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ + s->block_start -= (long) wsize; + + /* Slide the hash table (could be avoided with 32 bit values + at the expense of memory usage). We slide even when level == 0 + to keep the hash table consistent if we switch back to level > 0 + later. (Using level 0 permanently is not an optimal usage of + zlib, so we don't care about this pathological case.) + */ + n = s->hash_size; + p = &s->head[n]; + do { + m = *--p; + *p = (Pos)(m >= wsize ? m-wsize : NIL); + } while (--n); + + n = wsize; +#ifndef FASTEST + p = &s->prev[n]; + do { + m = *--p; + *p = (Pos)(m >= wsize ? m-wsize : NIL); + /* If n is not on any hash chain, prev[n] is garbage but + * its value will never be used. + */ + } while (--n); +#endif + more += wsize; + } + if (s->strm->avail_in == 0) return; + + /* If there was no sliding: + * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && + * more == window_size - lookahead - strstart + * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) + * => more >= window_size - 2*WSIZE + 2 + * In the BIG_MEM or MMAP case (not yet supported), + * window_size == input_size + MIN_LOOKAHEAD && + * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. + * Otherwise, window_size == 2*WSIZE so more >= 2. + * If there was sliding, more >= WSIZE. So in all cases, more >= 2. + */ + Assert(more >= 2, "more < 2"); + + n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); + s->lookahead += n; + + /* Initialize the hash value now that we have some input: */ + if (s->lookahead >= MIN_MATCH) { + s->ins_h = s->window[s->strstart]; + UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); +#if MIN_MATCH != 3 + Call UPDATE_HASH() MIN_MATCH-3 more times +#endif + } + /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, + * but this is not important since only literal bytes will be emitted. + */ + + } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); +} + +/* =========================================================================== + * Flush the current block, with given end-of-file flag. + * IN assertion: strstart is set to the end of the current match. + */ +#define FLUSH_BLOCK_ONLY(s, eof) { \ + _tr_flush_block(s, (s->block_start >= 0L ? \ + (charf *)&s->window[(unsigned)s->block_start] : \ + (charf *)Z_NULL), \ + (ulg)((long)s->strstart - s->block_start), \ + (eof)); \ + s->block_start = s->strstart; \ + flush_pending(s->strm); \ + Tracev((stderr,"[FLUSH]")); \ +} + +/* Same but force premature exit if necessary. */ +#define FLUSH_BLOCK(s, eof) { \ + FLUSH_BLOCK_ONLY(s, eof); \ + if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \ +} + +/* =========================================================================== + * Copy without compression as much as possible from the input stream, return + * the current block state. + * This function does not insert new strings in the dictionary since + * uncompressible data is probably not useful. This function is used + * only for the level=0 compression option. + * NOTE: this function should be optimized to avoid extra copying from + * window to pending_buf. + */ +local block_state deflate_stored(s, flush) + deflate_state *s; + int flush; +{ + /* Stored blocks are limited to 0xffff bytes, pending_buf is limited + * to pending_buf_size, and each stored block has a 5 byte header: + */ + ulg max_block_size = 0xffff; + ulg max_start; + + if (max_block_size > s->pending_buf_size - 5) { + max_block_size = s->pending_buf_size - 5; + } + + /* Copy as much as possible from input to output: */ + for (;;) { + /* Fill the window as much as possible: */ + if (s->lookahead <= 1) { + + Assert(s->strstart < s->w_size+MAX_DIST(s) || + s->block_start >= (long)s->w_size, "slide too late"); + + fill_window(s); + if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; + + if (s->lookahead == 0) break; /* flush the current block */ + } + Assert(s->block_start >= 0L, "block gone"); + + s->strstart += s->lookahead; + s->lookahead = 0; + + /* Emit a stored block if pending_buf will be full: */ + max_start = s->block_start + max_block_size; + if (s->strstart == 0 || (ulg)s->strstart >= max_start) { + /* strstart == 0 is possible when wraparound on 16-bit machine */ + s->lookahead = (uInt)(s->strstart - max_start); + s->strstart = (uInt)max_start; + FLUSH_BLOCK(s, 0); + } + /* Flush if we may have to slide, otherwise block_start may become + * negative and the data will be gone: + */ + if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { + FLUSH_BLOCK(s, 0); + } + } + FLUSH_BLOCK(s, flush == Z_FINISH); + return flush == Z_FINISH ? finish_done : block_done; +} + +/* =========================================================================== + * Compress as much as possible from the input stream, return the current + * block state. + * This function does not perform lazy evaluation of matches and inserts + * new strings in the dictionary only for unmatched strings or for short + * matches. It is used only for the fast compression options. + */ +local block_state deflate_fast(s, flush) + deflate_state *s; + int flush; +{ + IPos hash_head = NIL; /* head of the hash chain */ + int bflush; /* set if current block must be flushed */ + + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the next match, plus MIN_MATCH bytes to insert the + * string following the next match. + */ + if (s->lookahead < MIN_LOOKAHEAD) { + fill_window(s); + if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { + return need_more; + } + if (s->lookahead == 0) break; /* flush the current block */ + } + + /* Insert the string window[strstart .. strstart+2] in the + * dictionary, and set hash_head to the head of the hash chain: + */ + if (s->lookahead >= MIN_MATCH) { + INSERT_STRING(s, s->strstart, hash_head); + } + + /* Find the longest match, discarding those <= prev_length. + * At this point we have always match_length < MIN_MATCH + */ + if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { + /* To simplify the code, we prevent matches with the string + * of window index 0 (in particular we have to avoid a match + * of the string with itself at the start of the input file). + */ + if (s->strategy != Z_HUFFMAN_ONLY) { + s->match_length = longest_match (s, hash_head); + } + /* longest_match() sets match_start */ + } + if (s->match_length >= MIN_MATCH) { + check_match(s, s->strstart, s->match_start, s->match_length); + + _tr_tally_dist(s, s->strstart - s->match_start, + s->match_length - MIN_MATCH, bflush); + + s->lookahead -= s->match_length; + + /* Insert new strings in the hash table only if the match length + * is not too large. This saves time but degrades compression. + */ +#ifndef FASTEST + if (s->match_length <= s->max_insert_length && + s->lookahead >= MIN_MATCH) { + s->match_length--; /* string at strstart already in hash table */ + do { + s->strstart++; + INSERT_STRING(s, s->strstart, hash_head); + /* strstart never exceeds WSIZE-MAX_MATCH, so there are + * always MIN_MATCH bytes ahead. + */ + } while (--s->match_length != 0); + s->strstart++; + } else +#endif + { + s->strstart += s->match_length; + s->match_length = 0; + s->ins_h = s->window[s->strstart]; + UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); +#if MIN_MATCH != 3 + Call UPDATE_HASH() MIN_MATCH-3 more times +#endif + /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not + * matter since it will be recomputed at next deflate call. + */ + } + } else { + /* No match, output a literal byte */ + Tracevv((stderr,"%c", s->window[s->strstart])); + _tr_tally_lit (s, s->window[s->strstart], bflush); + s->lookahead--; + s->strstart++; + } + if (bflush) FLUSH_BLOCK(s, 0); + } + FLUSH_BLOCK(s, flush == Z_FINISH); + return flush == Z_FINISH ? finish_done : block_done; +} + +/* =========================================================================== + * Same as above, but achieves better compression. We use a lazy + * evaluation for matches: a match is finally adopted only if there is + * no better match at the next window position. + */ +local block_state deflate_slow(s, flush) + deflate_state *s; + int flush; +{ + IPos hash_head = NIL; /* head of hash chain */ + int bflush; /* set if current block must be flushed */ + + /* Process the input block. */ + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the next match, plus MIN_MATCH bytes to insert the + * string following the next match. + */ + if (s->lookahead < MIN_LOOKAHEAD) { + fill_window(s); + if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { + return need_more; + } + if (s->lookahead == 0) break; /* flush the current block */ + } + + /* Insert the string window[strstart .. strstart+2] in the + * dictionary, and set hash_head to the head of the hash chain: + */ + if (s->lookahead >= MIN_MATCH) { + INSERT_STRING(s, s->strstart, hash_head); + } + + /* Find the longest match, discarding those <= prev_length. + */ + s->prev_length = s->match_length, s->prev_match = s->match_start; + s->match_length = MIN_MATCH-1; + + if (hash_head != NIL && s->prev_length < s->max_lazy_match && + s->strstart - hash_head <= MAX_DIST(s)) { + /* To simplify the code, we prevent matches with the string + * of window index 0 (in particular we have to avoid a match + * of the string with itself at the start of the input file). + */ + if (s->strategy != Z_HUFFMAN_ONLY) { + s->match_length = longest_match (s, hash_head); + } + /* longest_match() sets match_start */ + + if (s->match_length <= 5 && (s->strategy == Z_FILTERED || + (s->match_length == MIN_MATCH && + s->strstart - s->match_start > TOO_FAR))) { + + /* If prev_match is also MIN_MATCH, match_start is garbage + * but we will ignore the current match anyway. + */ + s->match_length = MIN_MATCH-1; + } + } + /* If there was a match at the previous step and the current + * match is not better, output the previous match: + */ + if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { + uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; + /* Do not insert strings in hash table beyond this. */ + + check_match(s, s->strstart-1, s->prev_match, s->prev_length); + + _tr_tally_dist(s, s->strstart -1 - s->prev_match, + s->prev_length - MIN_MATCH, bflush); + + /* Insert in hash table all strings up to the end of the match. + * strstart-1 and strstart are already inserted. If there is not + * enough lookahead, the last two strings are not inserted in + * the hash table. + */ + s->lookahead -= s->prev_length-1; + s->prev_length -= 2; + do { + if (++s->strstart <= max_insert) { + INSERT_STRING(s, s->strstart, hash_head); + } + } while (--s->prev_length != 0); + s->match_available = 0; + s->match_length = MIN_MATCH-1; + s->strstart++; + + if (bflush) FLUSH_BLOCK(s, 0); + + } else if (s->match_available) { + /* If there was no match at the previous position, output a + * single literal. If there was a match but the current match + * is longer, truncate the previous match to a single literal. + */ + Tracevv((stderr,"%c", s->window[s->strstart-1])); + _tr_tally_lit(s, s->window[s->strstart-1], bflush); + if (bflush) { + FLUSH_BLOCK_ONLY(s, 0); + } + s->strstart++; + s->lookahead--; + if (s->strm->avail_out == 0) return need_more; + } else { + /* There is no previous match to compare with, wait for + * the next step to decide. + */ + s->match_available = 1; + s->strstart++; + s->lookahead--; + } + } + Assert (flush != Z_NO_FLUSH, "no flush?"); + if (s->match_available) { + Tracevv((stderr,"%c", s->window[s->strstart-1])); + _tr_tally_lit(s, s->window[s->strstart-1], bflush); + s->match_available = 0; + } + FLUSH_BLOCK(s, flush == Z_FINISH); + return flush == Z_FINISH ? finish_done : block_done; +} diff --git a/fceumm/src-fceumm/zlib/deflate.h b/fceumm/src-fceumm/zlib/deflate.h new file mode 100644 index 0000000..9bd8cb0 --- /dev/null +++ b/fceumm/src-fceumm/zlib/deflate.h @@ -0,0 +1,318 @@ +/* deflate.h -- internal compression state + * Copyright (C) 1995-2002 Jean-loup Gailly + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* @(#) $Id: deflate.h,v 1.2 2002/03/13 17:45:56 xodnizel Exp $ */ + +#ifndef _DEFLATE_H +#define _DEFLATE_H + +#include "zutil.h" + +/* =========================================================================== + * Internal compression state. + */ + +#define LENGTH_CODES 29 +/* number of length codes, not counting the special END_BLOCK code */ + +#define LITERALS 256 +/* number of literal bytes 0..255 */ + +#define L_CODES (LITERALS+1+LENGTH_CODES) +/* number of Literal or Length codes, including the END_BLOCK code */ + +#define D_CODES 30 +/* number of distance codes */ + +#define BL_CODES 19 +/* number of codes used to transfer the bit lengths */ + +#define HEAP_SIZE (2*L_CODES+1) +/* maximum heap size */ + +#define MAX_BITS 15 +/* All codes must not exceed MAX_BITS bits */ + +#define INIT_STATE 42 +#define BUSY_STATE 113 +#define FINISH_STATE 666 +/* Stream status */ + + +/* Data structure describing a single value and its code string. */ +typedef struct ct_data_s { + union { + ush freq; /* frequency count */ + ush code; /* bit string */ + } fc; + union { + ush dad; /* father node in Huffman tree */ + ush len; /* length of bit string */ + } dl; +} FAR ct_data; + +#define Freq fc.freq +#define Code fc.code +#define Dad dl.dad +#define Len dl.len + +typedef struct static_tree_desc_s static_tree_desc; + +typedef struct tree_desc_s { + ct_data *dyn_tree; /* the dynamic tree */ + int max_code; /* largest code with non zero frequency */ + static_tree_desc *stat_desc; /* the corresponding static tree */ +} FAR tree_desc; + +typedef ush Pos; +typedef Pos FAR Posf; +typedef unsigned IPos; + +/* A Pos is an index in the character window. We use short instead of int to + * save space in the various tables. IPos is used only for parameter passing. + */ + +typedef struct internal_state { + z_streamp strm; /* pointer back to this zlib stream */ + int status; /* as the name implies */ + Bytef *pending_buf; /* output still pending */ + ulg pending_buf_size; /* size of pending_buf */ + Bytef *pending_out; /* next pending byte to output to the stream */ + int pending; /* nb of bytes in the pending buffer */ + int noheader; /* suppress zlib header and adler32 */ + Byte data_type; /* UNKNOWN, BINARY or ASCII */ + Byte method; /* STORED (for zip only) or DEFLATED */ + int last_flush; /* value of flush param for previous deflate call */ + + /* used by deflate.c: */ + + uInt w_size; /* LZ77 window size (32K by default) */ + uInt w_bits; /* log2(w_size) (8..16) */ + uInt w_mask; /* w_size - 1 */ + + Bytef *window; + /* Sliding window. Input bytes are read into the second half of the window, + * and move to the first half later to keep a dictionary of at least wSize + * bytes. With this organization, matches are limited to a distance of + * wSize-MAX_MATCH bytes, but this ensures that IO is always + * performed with a length multiple of the block size. Also, it limits + * the window size to 64K, which is quite useful on MSDOS. + * To do: use the user input buffer as sliding window. + */ + + ulg window_size; + /* Actual size of window: 2*wSize, except when the user input buffer + * is directly used as sliding window. + */ + + Posf *prev; + /* Link to older string with same hash index. To limit the size of this + * array to 64K, this link is maintained only for the last 32K strings. + * An index in this array is thus a window index modulo 32K. + */ + + Posf *head; /* Heads of the hash chains or NIL. */ + + uInt ins_h; /* hash index of string to be inserted */ + uInt hash_size; /* number of elements in hash table */ + uInt hash_bits; /* log2(hash_size) */ + uInt hash_mask; /* hash_size-1 */ + + uInt hash_shift; + /* Number of bits by which ins_h must be shifted at each input + * step. It must be such that after MIN_MATCH steps, the oldest + * byte no longer takes part in the hash key, that is: + * hash_shift * MIN_MATCH >= hash_bits + */ + + long block_start; + /* Window position at the beginning of the current output block. Gets + * negative when the window is moved backwards. + */ + + uInt match_length; /* length of best match */ + IPos prev_match; /* previous match */ + int match_available; /* set if previous match exists */ + uInt strstart; /* start of string to insert */ + uInt match_start; /* start of matching string */ + uInt lookahead; /* number of valid bytes ahead in window */ + + uInt prev_length; + /* Length of the best match at previous step. Matches not greater than this + * are discarded. This is used in the lazy match evaluation. + */ + + uInt max_chain_length; + /* To speed up deflation, hash chains are never searched beyond this + * length. A higher limit improves compression ratio but degrades the + * speed. + */ + + uInt max_lazy_match; + /* Attempt to find a better match only when the current match is strictly + * smaller than this value. This mechanism is used only for compression + * levels >= 4. + */ +# define max_insert_length max_lazy_match + /* Insert new strings in the hash table only if the match length is not + * greater than this length. This saves time but degrades compression. + * max_insert_length is used only for compression levels <= 3. + */ + + int level; /* compression level (1..9) */ + int strategy; /* favor or force Huffman coding*/ + + uInt good_match; + /* Use a faster search when the previous match is longer than this */ + + int nice_match; /* Stop searching when current match exceeds this */ + + /* used by trees.c: */ + /* Didn't use ct_data typedef below to supress compiler warning */ + struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ + struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ + struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ + + struct tree_desc_s l_desc; /* desc. for literal tree */ + struct tree_desc_s d_desc; /* desc. for distance tree */ + struct tree_desc_s bl_desc; /* desc. for bit length tree */ + + ush bl_count[MAX_BITS+1]; + /* number of codes at each bit length for an optimal tree */ + + int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ + int heap_len; /* number of elements in the heap */ + int heap_max; /* element of largest frequency */ + /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. + * The same heap array is used to build all trees. + */ + + uch depth[2*L_CODES+1]; + /* Depth of each subtree used as tie breaker for trees of equal frequency + */ + + uchf *l_buf; /* buffer for literals or lengths */ + + uInt lit_bufsize; + /* Size of match buffer for literals/lengths. There are 4 reasons for + * limiting lit_bufsize to 64K: + * - frequencies can be kept in 16 bit counters + * - if compression is not successful for the first block, all input + * data is still in the window so we can still emit a stored block even + * when input comes from standard input. (This can also be done for + * all blocks if lit_bufsize is not greater than 32K.) + * - if compression is not successful for a file smaller than 64K, we can + * even emit a stored file instead of a stored block (saving 5 bytes). + * This is applicable only for zip (not gzip or zlib). + * - creating new Huffman trees less frequently may not provide fast + * adaptation to changes in the input data statistics. (Take for + * example a binary file with poorly compressible code followed by + * a highly compressible string table.) Smaller buffer sizes give + * fast adaptation but have of course the overhead of transmitting + * trees more frequently. + * - I can't count above 4 + */ + + uInt last_lit; /* running index in l_buf */ + + ushf *d_buf; + /* Buffer for distances. To simplify the code, d_buf and l_buf have + * the same number of elements. To use different lengths, an extra flag + * array would be necessary. + */ + + ulg opt_len; /* bit length of current block with optimal trees */ + ulg static_len; /* bit length of current block with static trees */ + uInt matches; /* number of string matches in current block */ + int last_eob_len; /* bit length of EOB code for last block */ + +#ifdef DEBUG + ulg compressed_len; /* total bit length of compressed file mod 2^32 */ + ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ +#endif + + ush bi_buf; + /* Output buffer. bits are inserted starting at the bottom (least + * significant bits). + */ + int bi_valid; + /* Number of valid bits in bi_buf. All bits above the last valid bit + * are always zero. + */ + +} FAR deflate_state; + +/* Output a byte on the stream. + * IN assertion: there is enough room in pending_buf. + */ +#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} + + +#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) +/* Minimum amount of lookahead, except at the end of the input file. + * See deflate.c for comments about the MIN_MATCH+1. + */ + +#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) +/* In order to simplify the code, particularly on 16 bit machines, match + * distances are limited to MAX_DIST instead of WSIZE. + */ + + /* in trees.c */ +void _tr_init OF((deflate_state *s)); +int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); +void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len, + int eof)); +void _tr_align OF((deflate_state *s)); +void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len, + int eof)); + +#define d_code(dist) \ + ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) +/* Mapping from a distance to a distance code. dist is the distance - 1 and + * must not have side effects. _dist_code[256] and _dist_code[257] are never + * used. + */ + +#ifndef DEBUG +/* Inline versions of _tr_tally for speed: */ + +#if defined(GEN_TREES_H) || !defined(STDC) + extern uch _length_code[]; + extern uch _dist_code[]; +#else + extern const uch _length_code[]; + extern const uch _dist_code[]; +#endif + +# define _tr_tally_lit(s, c, flush) \ + { uch cc = (c); \ + s->d_buf[s->last_lit] = 0; \ + s->l_buf[s->last_lit++] = cc; \ + s->dyn_ltree[cc].Freq++; \ + flush = (s->last_lit == s->lit_bufsize-1); \ + } +# define _tr_tally_dist(s, distance, length, flush) \ + { uch len = (length); \ + ush dist = (distance); \ + s->d_buf[s->last_lit] = dist; \ + s->l_buf[s->last_lit++] = len; \ + dist--; \ + s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ + s->dyn_dtree[d_code(dist)].Freq++; \ + flush = (s->last_lit == s->lit_bufsize-1); \ + } +#else +# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) +# define _tr_tally_dist(s, distance, length, flush) \ + flush = _tr_tally(s, distance, length) +#endif + +#endif diff --git a/fceumm/src-fceumm/zlib/gzio.c b/fceumm/src-fceumm/zlib/gzio.c new file mode 100644 index 0000000..6142b0a --- /dev/null +++ b/fceumm/src-fceumm/zlib/gzio.c @@ -0,0 +1,875 @@ +/* gzio.c -- IO on .gz files + * Copyright (C) 1995-2002 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + * + * Compile this file with -DNO_DEFLATE to avoid the compression code. + */ + +/* @(#) $Id: gzio.c,v 1.2 2002/03/13 17:45:56 xodnizel Exp $ */ + +#include + +#include "zutil.h" + +struct internal_state {int dummy;}; /* for buggy compilers */ + +#ifndef Z_BUFSIZE +# ifdef MAXSEG_64K +# define Z_BUFSIZE 4096 /* minimize memory usage for 16-bit DOS */ +# else +# define Z_BUFSIZE 16384 +# endif +#endif +#ifndef Z_PRINTF_BUFSIZE +# define Z_PRINTF_BUFSIZE 4096 +#endif + +#define ALLOC(size) malloc(size) +#define TRYFREE(p) {if (p) free(p);} + +static int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */ + +/* gzip flag byte */ +#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ +#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */ +#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ +#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ +#define COMMENT 0x10 /* bit 4 set: file comment present */ +#define RESERVED 0xE0 /* bits 5..7: reserved */ + +typedef struct gz_stream { + z_stream stream; + int z_err; /* error code for last stream operation */ + int z_eof; /* set if end of input file */ + FILE *file; /* .gz file */ + Byte *inbuf; /* input buffer */ + Byte *outbuf; /* output buffer */ + uLong crc; /* crc32 of uncompressed data */ + char *msg; /* error message */ + char *path; /* path name for debugging only */ + int transparent; /* 1 if input file is not a .gz file */ + char mode; /* 'w' or 'r' */ + long startpos; /* start of compressed data in file (header skipped) */ +} gz_stream; + + +local gzFile gz_open OF((const char *path, const char *mode, int fd)); +local int do_flush OF((gzFile file, int flush)); +local int get_byte OF((gz_stream *s)); +local void check_header OF((gz_stream *s)); +local int destroy OF((gz_stream *s)); +local void putLong OF((FILE *file, uLong x)); +local uLong getLong OF((gz_stream *s)); + +/* =========================================================================== + Opens a gzip (.gz) file for reading or writing. The mode parameter + is as in fopen ("rb" or "wb"). The file is given either by file descriptor + or path name (if fd == -1). + gz_open return NULL if the file could not be opened or if there was + insufficient memory to allocate the (de)compression state; errno + can be checked to distinguish the two cases (if errno is zero, the + zlib error is Z_MEM_ERROR). +*/ +local gzFile gz_open (path, mode, fd) + const char *path; + const char *mode; + int fd; +{ + int err; + int level = Z_DEFAULT_COMPRESSION; /* compression level */ + int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */ + char *p = (char*)mode; + gz_stream *s; + char fmode[80]; /* copy of mode, without the compression level */ + char *m = fmode; + + if (!path || !mode) return Z_NULL; + + s = (gz_stream *)ALLOC(sizeof(gz_stream)); + if (!s) return Z_NULL; + + s->stream.zalloc = (alloc_func)0; + s->stream.zfree = (free_func)0; + s->stream.opaque = (voidpf)0; + s->stream.next_in = s->inbuf = Z_NULL; + s->stream.next_out = s->outbuf = Z_NULL; + s->stream.avail_in = s->stream.avail_out = 0; + s->file = NULL; + s->z_err = Z_OK; + s->z_eof = 0; + s->crc = crc32(0L, Z_NULL, 0); + s->msg = NULL; + s->transparent = 0; + + s->path = (char*)ALLOC(strlen(path)+1); + if (s->path == NULL) { + return destroy(s), (gzFile)Z_NULL; + } + strcpy(s->path, path); /* do this early for debugging */ + + s->mode = '\0'; + do { + if (*p == 'r') s->mode = 'r'; + if (*p == 'w' || *p == 'a') s->mode = 'w'; + if (*p >= '0' && *p <= '9') { + level = *p - '0'; + } else if (*p == 'f') { + strategy = Z_FILTERED; + } else if (*p == 'h') { + strategy = Z_HUFFMAN_ONLY; + } else { + *m++ = *p; /* copy the mode */ + } + } while (*p++ && m != fmode + sizeof(fmode)); + if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL; + + if (s->mode == 'w') { +#ifdef NO_DEFLATE + err = Z_STREAM_ERROR; +#else + err = deflateInit2(&(s->stream), level, + Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy); + /* windowBits is passed < 0 to suppress zlib header */ + + s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE); +#endif + if (err != Z_OK || s->outbuf == Z_NULL) { + return destroy(s), (gzFile)Z_NULL; + } + } else { + s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); + + err = inflateInit2(&(s->stream), -MAX_WBITS); + /* windowBits is passed < 0 to tell that there is no zlib header. + * Note that in this case inflate *requires* an extra "dummy" byte + * after the compressed stream in order to complete decompression and + * return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are + * present after the compressed stream. + */ + if (err != Z_OK || s->inbuf == Z_NULL) { + return destroy(s), (gzFile)Z_NULL; + } + } + s->stream.avail_out = Z_BUFSIZE; + + errno = 0; + s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode); + + if (s->file == NULL) { + return destroy(s), (gzFile)Z_NULL; + } + if (s->mode == 'w') { + /* Write a very simple .gz header: + */ + fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1], + Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE); + s->startpos = 10L; + /* We use 10L instead of ftell(s->file) to because ftell causes an + * fflush on some systems. This version of the library doesn't use + * startpos anyway in write mode, so this initialization is not + * necessary. + */ + } else { + check_header(s); /* skip the .gz header */ + s->startpos = (ftell(s->file) - s->stream.avail_in); + } + + return (gzFile)s; +} + +/* =========================================================================== + Opens a gzip (.gz) file for reading or writing. +*/ +gzFile ZEXPORT gzopen (path, mode) + const char *path; + const char *mode; +{ + return gz_open (path, mode, -1); +} + +/* =========================================================================== + Associate a gzFile with the file descriptor fd. fd is not dup'ed here + to mimic the behavio(u)r of fdopen. +*/ +gzFile ZEXPORT gzdopen (fd, mode) + int fd; + const char *mode; +{ + char name[20]; + + if (fd < 0) return (gzFile)Z_NULL; + sprintf(name, "", fd); /* for debugging */ + + return gz_open (name, mode, fd); +} + +/* =========================================================================== + * Update the compression level and strategy + */ +int ZEXPORT gzsetparams (file, level, strategy) + gzFile file; + int level; + int strategy; +{ + gz_stream *s = (gz_stream*)file; + + if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; + + /* Make room to allow flushing */ + if (s->stream.avail_out == 0) { + + s->stream.next_out = s->outbuf; + if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) { + s->z_err = Z_ERRNO; + } + s->stream.avail_out = Z_BUFSIZE; + } + + return deflateParams (&(s->stream), level, strategy); +} + +/* =========================================================================== + Read a byte from a gz_stream; update next_in and avail_in. Return EOF + for end of file. + IN assertion: the stream s has been sucessfully opened for reading. +*/ +local int get_byte(s) + gz_stream *s; +{ + if (s->z_eof) return EOF; + if (s->stream.avail_in == 0) { + errno = 0; + s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file); + if (s->stream.avail_in == 0) { + s->z_eof = 1; + if (ferror(s->file)) s->z_err = Z_ERRNO; + return EOF; + } + s->stream.next_in = s->inbuf; + } + s->stream.avail_in--; + return *(s->stream.next_in)++; +} + +/* =========================================================================== + Check the gzip header of a gz_stream opened for reading. Set the stream + mode to transparent if the gzip magic header is not present; set s->err + to Z_DATA_ERROR if the magic header is present but the rest of the header + is incorrect. + IN assertion: the stream s has already been created sucessfully; + s->stream.avail_in is zero for the first time, but may be non-zero + for concatenated .gz files. +*/ +local void check_header(s) + gz_stream *s; +{ + int method; /* method byte */ + int flags; /* flags byte */ + uInt len; + int c; + + /* Check the gzip magic header */ + for (len = 0; len < 2; len++) { + c = get_byte(s); + if (c != gz_magic[len]) { + if (len != 0) s->stream.avail_in++, s->stream.next_in--; + if (c != EOF) { + s->stream.avail_in++, s->stream.next_in--; + s->transparent = 1; + } + s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END; + return; + } + } + method = get_byte(s); + flags = get_byte(s); + if (method != Z_DEFLATED || (flags & RESERVED) != 0) { + s->z_err = Z_DATA_ERROR; + return; + } + + /* Discard time, xflags and OS code: */ + for (len = 0; len < 6; len++) (void)get_byte(s); + + if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */ + len = (uInt)get_byte(s); + len += ((uInt)get_byte(s))<<8; + /* len is garbage if EOF but the loop below will quit anyway */ + while (len-- != 0 && get_byte(s) != EOF) ; + } + if ((flags & ORIG_NAME) != 0) { /* skip the original file name */ + while ((c = get_byte(s)) != 0 && c != EOF) ; + } + if ((flags & COMMENT) != 0) { /* skip the .gz file comment */ + while ((c = get_byte(s)) != 0 && c != EOF) ; + } + if ((flags & HEAD_CRC) != 0) { /* skip the header crc */ + for (len = 0; len < 2; len++) (void)get_byte(s); + } + s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK; +} + + /* =========================================================================== + * Cleanup then free the given gz_stream. Return a zlib error code. + Try freeing in the reverse order of allocations. + */ +local int destroy (s) + gz_stream *s; +{ + int err = Z_OK; + + if (!s) return Z_STREAM_ERROR; + + TRYFREE(s->msg); + + if (s->stream.state != NULL) { + if (s->mode == 'w') { +#ifdef NO_DEFLATE + err = Z_STREAM_ERROR; +#else + err = deflateEnd(&(s->stream)); +#endif + } else if (s->mode == 'r') { + err = inflateEnd(&(s->stream)); + } + } + if (s->file != NULL && fclose(s->file)) { +#ifdef ESPIPE + if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */ +#endif + err = Z_ERRNO; + } + if (s->z_err < 0) err = s->z_err; + + TRYFREE(s->inbuf); + TRYFREE(s->outbuf); + TRYFREE(s->path); + TRYFREE(s); + return err; +} + +/* =========================================================================== + Reads the given number of uncompressed bytes from the compressed file. + gzread returns the number of bytes actually read (0 for end of file). +*/ +int ZEXPORT gzread (file, buf, len) + gzFile file; + voidp buf; + unsigned len; +{ + gz_stream *s = (gz_stream*)file; + Bytef *start = (Bytef*)buf; /* starting point for crc computation */ + Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */ + + if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR; + + if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1; + if (s->z_err == Z_STREAM_END) return 0; /* EOF */ + + next_out = (Byte*)buf; + s->stream.next_out = (Bytef*)buf; + s->stream.avail_out = len; + + while (s->stream.avail_out != 0) { + + if (s->transparent) { + /* Copy first the lookahead bytes: */ + uInt n = s->stream.avail_in; + if (n > s->stream.avail_out) n = s->stream.avail_out; + if (n > 0) { + zmemcpy(s->stream.next_out, s->stream.next_in, n); + next_out += n; + s->stream.next_out = next_out; + s->stream.next_in += n; + s->stream.avail_out -= n; + s->stream.avail_in -= n; + } + if (s->stream.avail_out > 0) { + s->stream.avail_out -= fread(next_out, 1, s->stream.avail_out, + s->file); + } + len -= s->stream.avail_out; + s->stream.total_in += (uLong)len; + s->stream.total_out += (uLong)len; + if (len == 0) s->z_eof = 1; + return (int)len; + } + if (s->stream.avail_in == 0 && !s->z_eof) { + + errno = 0; + s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file); + if (s->stream.avail_in == 0) { + s->z_eof = 1; + if (ferror(s->file)) { + s->z_err = Z_ERRNO; + break; + } + } + s->stream.next_in = s->inbuf; + } + s->z_err = inflate(&(s->stream), Z_NO_FLUSH); + + if (s->z_err == Z_STREAM_END) { + /* Check CRC and original size */ + s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start)); + start = s->stream.next_out; + + if (getLong(s) != s->crc) { + s->z_err = Z_DATA_ERROR; + } else { + (void)getLong(s); + /* The uncompressed length returned by above getlong() may + * be different from s->stream.total_out) in case of + * concatenated .gz files. Check for such files: + */ + check_header(s); + if (s->z_err == Z_OK) { + uLong total_in = s->stream.total_in; + uLong total_out = s->stream.total_out; + + inflateReset(&(s->stream)); + s->stream.total_in = total_in; + s->stream.total_out = total_out; + s->crc = crc32(0L, Z_NULL, 0); + } + } + } + if (s->z_err != Z_OK || s->z_eof) break; + } + s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start)); + + return (int)(len - s->stream.avail_out); +} + + +/* =========================================================================== + Reads one byte from the compressed file. gzgetc returns this byte + or -1 in case of end of file or error. +*/ +int ZEXPORT gzgetc(file) + gzFile file; +{ + unsigned char c; + + return gzread(file, &c, 1) == 1 ? c : -1; +} + + +/* =========================================================================== + Reads bytes from the compressed file until len-1 characters are + read, or a newline character is read and transferred to buf, or an + end-of-file condition is encountered. The string is then terminated + with a null character. + gzgets returns buf, or Z_NULL in case of error. + + The current implementation is not optimized at all. +*/ +char * ZEXPORT gzgets(file, buf, len) + gzFile file; + char *buf; + int len; +{ + char *b = buf; + if (buf == Z_NULL || len <= 0) return Z_NULL; + + while (--len > 0 && gzread(file, buf, 1) == 1 && *buf++ != '\n') ; + *buf = '\0'; + return b == buf && len > 0 ? Z_NULL : b; +} + + +#ifndef NO_DEFLATE +/* =========================================================================== + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of bytes actually written (0 in case of error). +*/ +int ZEXPORT gzwrite (file, buf, len) + gzFile file; + const voidp buf; + unsigned len; +{ + gz_stream *s = (gz_stream*)file; + + if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; + + s->stream.next_in = (Bytef*)buf; + s->stream.avail_in = len; + + while (s->stream.avail_in != 0) { + + if (s->stream.avail_out == 0) { + + s->stream.next_out = s->outbuf; + if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) { + s->z_err = Z_ERRNO; + break; + } + s->stream.avail_out = Z_BUFSIZE; + } + s->z_err = deflate(&(s->stream), Z_NO_FLUSH); + if (s->z_err != Z_OK) break; + } + s->crc = crc32(s->crc, (const Bytef *)buf, len); + + return (int)(len - s->stream.avail_in); +} + +/* =========================================================================== + Converts, formats, and writes the args to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written (0 in case of error). +*/ +#ifdef STDC +#include + +int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...) +{ + char buf[Z_PRINTF_BUFSIZE]; + va_list va; + int len; + + va_start(va, format); +#ifdef HAS_vsnprintf + (void)vsnprintf(buf, sizeof(buf), format, va); +#else + (void)vsprintf(buf, format, va); +#endif + va_end(va); + len = strlen(buf); /* some *sprintf don't return the nb of bytes written */ + if (len <= 0) return 0; + + return gzwrite(file, buf, (unsigned)len); +} +#else /* not ANSI C */ + +int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) + gzFile file; + const char *format; + int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; +{ + char buf[Z_PRINTF_BUFSIZE]; + int len; + +#ifdef HAS_snprintf + snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); +#else + sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); +#endif + len = strlen(buf); /* old sprintf doesn't return the nb of bytes written */ + if (len <= 0) return 0; + + return gzwrite(file, buf, len); +} +#endif + +/* =========================================================================== + Writes c, converted to an unsigned char, into the compressed file. + gzputc returns the value that was written, or -1 in case of error. +*/ +int ZEXPORT gzputc(file, c) + gzFile file; + int c; +{ + unsigned char cc = (unsigned char) c; /* required for big endian systems */ + + return gzwrite(file, &cc, 1) == 1 ? (int)cc : -1; +} + + +/* =========================================================================== + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + gzputs returns the number of characters written, or -1 in case of error. +*/ +int ZEXPORT gzputs(file, s) + gzFile file; + const char *s; +{ + return gzwrite(file, (char*)s, (unsigned)strlen(s)); +} + + +/* =========================================================================== + Flushes all pending output into the compressed file. The parameter + flush is as in the deflate() function. +*/ +local int do_flush (file, flush) + gzFile file; + int flush; +{ + uInt len; + int done = 0; + gz_stream *s = (gz_stream*)file; + + if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; + + s->stream.avail_in = 0; /* should be zero already anyway */ + + for (;;) { + len = Z_BUFSIZE - s->stream.avail_out; + + if (len != 0) { + if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) { + s->z_err = Z_ERRNO; + return Z_ERRNO; + } + s->stream.next_out = s->outbuf; + s->stream.avail_out = Z_BUFSIZE; + } + if (done) break; + s->z_err = deflate(&(s->stream), flush); + + /* Ignore the second of two consecutive flushes: */ + if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK; + + /* deflate has finished flushing only when it hasn't used up + * all the available space in the output buffer: + */ + done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END); + + if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break; + } + return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; +} + +int ZEXPORT gzflush (file, flush) + gzFile file; + int flush; +{ + gz_stream *s = (gz_stream*)file; + int err = do_flush (file, flush); + + if (err) return err; + fflush(s->file); + return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; +} +#endif /* NO_DEFLATE */ + +/* =========================================================================== + Sets the starting position for the next gzread or gzwrite on the given + compressed file. The offset represents a number of bytes in the + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error. + SEEK_END is not implemented, returns error. + In this version of the library, gzseek can be extremely slow. +*/ +z_off_t ZEXPORT gzseek (file, offset, whence) + gzFile file; + z_off_t offset; + int whence; +{ + gz_stream *s = (gz_stream*)file; + + if (s == NULL || whence == SEEK_END || + s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) { + return -1L; + } + + if (s->mode == 'w') { +#ifdef NO_DEFLATE + return -1L; +#else + if (whence == SEEK_SET) { + offset -= s->stream.total_in; + } + if (offset < 0) return -1L; + + /* At this point, offset is the number of zero bytes to write. */ + if (s->inbuf == Z_NULL) { + s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */ + zmemzero(s->inbuf, Z_BUFSIZE); + } + while (offset > 0) { + uInt size = Z_BUFSIZE; + if (offset < Z_BUFSIZE) size = (uInt)offset; + + size = gzwrite(file, s->inbuf, size); + if (size == 0) return -1L; + + offset -= size; + } + return (z_off_t)s->stream.total_in; +#endif + } + /* Rest of function is for reading only */ + + /* compute absolute position */ + if (whence == SEEK_CUR) { + offset += s->stream.total_out; + } + if (offset < 0) return -1L; + + if (s->transparent) { + /* map to fseek */ + s->stream.avail_in = 0; + s->stream.next_in = s->inbuf; + if (fseek(s->file, offset, SEEK_SET) < 0) return -1L; + + s->stream.total_in = s->stream.total_out = (uLong)offset; + return offset; + } + + /* For a negative seek, rewind and use positive seek */ + if ((uLong)offset >= s->stream.total_out) { + offset -= s->stream.total_out; + } else if (gzrewind(file) < 0) { + return -1L; + } + /* offset is now the number of bytes to skip. */ + + if (offset != 0 && s->outbuf == Z_NULL) { + s->outbuf = (Byte*)ALLOC(Z_BUFSIZE); + } + while (offset > 0) { + int size = Z_BUFSIZE; + if (offset < Z_BUFSIZE) size = (int)offset; + + size = gzread(file, s->outbuf, (uInt)size); + if (size <= 0) return -1L; + offset -= size; + } + return (z_off_t)s->stream.total_out; +} + +/* =========================================================================== + Rewinds input file. +*/ +int ZEXPORT gzrewind (file) + gzFile file; +{ + gz_stream *s = (gz_stream*)file; + + if (s == NULL || s->mode != 'r') return -1; + + s->z_err = Z_OK; + s->z_eof = 0; + s->stream.avail_in = 0; + s->stream.next_in = s->inbuf; + s->crc = crc32(0L, Z_NULL, 0); + + if (s->startpos == 0) { /* not a compressed file */ + rewind(s->file); + return 0; + } + + (void) inflateReset(&s->stream); + return fseek(s->file, s->startpos, SEEK_SET); +} + +/* =========================================================================== + Returns the starting position for the next gzread or gzwrite on the + given compressed file. This position represents a number of bytes in the + uncompressed data stream. +*/ +z_off_t ZEXPORT gztell (file) + gzFile file; +{ + return gzseek(file, 0L, SEEK_CUR); +} + +/* =========================================================================== + Returns 1 when EOF has previously been detected reading the given + input stream, otherwise zero. +*/ +int ZEXPORT gzeof (file) + gzFile file; +{ + gz_stream *s = (gz_stream*)file; + + return (s == NULL || s->mode != 'r') ? 0 : s->z_eof; +} + +/* =========================================================================== + Outputs a long in LSB order to the given file +*/ +local void putLong (file, x) + FILE *file; + uLong x; +{ + int n; + for (n = 0; n < 4; n++) { + fputc((int)(x & 0xff), file); + x >>= 8; + } +} + +/* =========================================================================== + Reads a long in LSB order from the given gz_stream. Sets z_err in case + of error. +*/ +local uLong getLong (s) + gz_stream *s; +{ + uLong x = (uLong)get_byte(s); + int c; + + x += ((uLong)get_byte(s))<<8; + x += ((uLong)get_byte(s))<<16; + c = get_byte(s); + if (c == EOF) s->z_err = Z_DATA_ERROR; + x += ((uLong)c)<<24; + return x; +} + +/* =========================================================================== + Flushes all pending output if necessary, closes the compressed file + and deallocates all the (de)compression state. +*/ +int ZEXPORT gzclose (file) + gzFile file; +{ + int err; + gz_stream *s = (gz_stream*)file; + + if (s == NULL) return Z_STREAM_ERROR; + + if (s->mode == 'w') { +#ifdef NO_DEFLATE + return Z_STREAM_ERROR; +#else + err = do_flush (file, Z_FINISH); + if (err != Z_OK) return destroy((gz_stream*)file); + + putLong (s->file, s->crc); + putLong (s->file, s->stream.total_in); +#endif + } + return destroy((gz_stream*)file); +} + +/* =========================================================================== + Returns the error message for the last error which occured on the + given compressed file. errnum is set to zlib error number. If an + error occured in the file system and not in the compression library, + errnum is set to Z_ERRNO and the application may consult errno + to get the exact error code. +*/ +const char* ZEXPORT gzerror (file, errnum) + gzFile file; + int *errnum; +{ + char *m; + gz_stream *s = (gz_stream*)file; + + if (s == NULL) { + *errnum = Z_STREAM_ERROR; + return (const char*)ERR_MSG(Z_STREAM_ERROR); + } + *errnum = s->z_err; + if (*errnum == Z_OK) return (const char*)""; + + m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg); + + if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err); + + TRYFREE(s->msg); + s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3); + strcpy(s->msg, s->path); + strcat(s->msg, ": "); + strcat(s->msg, m); + return (const char*)s->msg; +} diff --git a/fceumm/src-fceumm/zlib/infblock.c b/fceumm/src-fceumm/zlib/infblock.c new file mode 100644 index 0000000..dd7a6d4 --- /dev/null +++ b/fceumm/src-fceumm/zlib/infblock.c @@ -0,0 +1,403 @@ +/* infblock.c -- interpret and process block types to last block + * Copyright (C) 1995-2002 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "zutil.h" +#include "infblock.h" +#include "inftrees.h" +#include "infcodes.h" +#include "infutil.h" + +struct inflate_codes_state {int dummy;}; /* for buggy compilers */ + +/* simplify the use of the inflate_huft type with some defines */ +#define exop word.what.Exop +#define bits word.what.Bits + +/* Table for deflate from PKZIP's appnote.txt. */ +local const uInt border[] = { /* Order of the bit length code lengths */ + 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; + +/* + Notes beyond the 1.93a appnote.txt: + + 1. Distance pointers never point before the beginning of the output + stream. + 2. Distance pointers can point back across blocks, up to 32k away. + 3. There is an implied maximum of 7 bits for the bit length table and + 15 bits for the actual data. + 4. If only one code exists, then it is encoded using one bit. (Zero + would be more efficient, but perhaps a little confusing.) If two + codes exist, they are coded using one bit each (0 and 1). + 5. There is no way of sending zero distance codes--a dummy must be + sent if there are none. (History: a pre 2.0 version of PKZIP would + store blocks with no distance codes, but this was discovered to be + too harsh a criterion.) Valid only for 1.93a. 2.04c does allow + zero distance codes, which is sent as one code of zero bits in + length. + 6. There are up to 286 literal/length codes. Code 256 represents the + end-of-block. Note however that the static length tree defines + 288 codes just to fill out the Huffman codes. Codes 286 and 287 + cannot be used though, since there is no length base or extra bits + defined for them. Similarily, there are up to 30 distance codes. + However, static trees define 32 codes (all 5 bits) to fill out the + Huffman codes, but the last two had better not show up in the data. + 7. Unzip can check dynamic Huffman blocks for complete code sets. + The exception is that a single code would not be complete (see #4). + 8. The five bits following the block type is really the number of + literal codes sent minus 257. + 9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits + (1+6+6). Therefore, to output three times the length, you output + three codes (1+1+1), whereas to output four times the same length, + you only need two codes (1+3). Hmm. + 10. In the tree reconstruction algorithm, Code = Code + Increment + only if BitLength(i) is not zero. (Pretty obvious.) + 11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19) + 12. Note: length code 284 can represent 227-258, but length code 285 + really is 258. The last length deserves its own, short code + since it gets used a lot in very redundant files. The length + 258 is special since 258 - 3 (the min match length) is 255. + 13. The literal/length and distance code bit lengths are read as a + single stream of lengths. It is possible (and advantageous) for + a repeat code (16, 17, or 18) to go across the boundary between + the two sets of lengths. + */ + + +void inflate_blocks_reset(s, z, c) +inflate_blocks_statef *s; +z_streamp z; +uLongf *c; +{ + if (c != Z_NULL) + *c = s->check; + if (s->mode == BTREE || s->mode == DTREE) + ZFREE(z, s->sub.trees.blens); + if (s->mode == CODES) + inflate_codes_free(s->sub.decode.codes, z); + s->mode = TYPE; + s->bitk = 0; + s->bitb = 0; + s->read = s->write = s->window; + if (s->checkfn != Z_NULL) + z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0); + Tracev((stderr, "inflate: blocks reset\n")); +} + + +inflate_blocks_statef *inflate_blocks_new(z, c, w) +z_streamp z; +check_func c; +uInt w; +{ + inflate_blocks_statef *s; + + if ((s = (inflate_blocks_statef *)ZALLOC + (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL) + return s; + if ((s->hufts = + (inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL) + { + ZFREE(z, s); + return Z_NULL; + } + if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL) + { + ZFREE(z, s->hufts); + ZFREE(z, s); + return Z_NULL; + } + s->end = s->window + w; + s->checkfn = c; + s->mode = TYPE; + Tracev((stderr, "inflate: blocks allocated\n")); + inflate_blocks_reset(s, z, Z_NULL); + return s; +} + + +int inflate_blocks(s, z, r) +inflate_blocks_statef *s; +z_streamp z; +int r; +{ + uInt t; /* temporary storage */ + uLong b; /* bit buffer */ + uInt k; /* bits in bit buffer */ + Bytef *p; /* input data pointer */ + uInt n; /* bytes available there */ + Bytef *q; /* output window write pointer */ + uInt m; /* bytes to end of window or read pointer */ + + /* copy input/output information to locals (UPDATE macro restores) */ + LOAD + + /* process input based on current state */ + while (1) switch (s->mode) + { + case TYPE: + NEEDBITS(3) + t = (uInt)b & 7; + s->last = t & 1; + switch (t >> 1) + { + case 0: /* stored */ + Tracev((stderr, "inflate: stored block%s\n", + s->last ? " (last)" : "")); + DUMPBITS(3) + t = k & 7; /* go to byte boundary */ + DUMPBITS(t) + s->mode = LENS; /* get length of stored block */ + break; + case 1: /* fixed */ + Tracev((stderr, "inflate: fixed codes block%s\n", + s->last ? " (last)" : "")); + { + uInt bl, bd; + inflate_huft *tl, *td; + + inflate_trees_fixed(&bl, &bd, &tl, &td, z); + s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z); + if (s->sub.decode.codes == Z_NULL) + { + r = Z_MEM_ERROR; + LEAVE + } + } + DUMPBITS(3) + s->mode = CODES; + break; + case 2: /* dynamic */ + Tracev((stderr, "inflate: dynamic codes block%s\n", + s->last ? " (last)" : "")); + DUMPBITS(3) + s->mode = TABLE; + break; + case 3: /* illegal */ + DUMPBITS(3) + s->mode = BAD; + z->msg = (char*)"invalid block type"; + r = Z_DATA_ERROR; + LEAVE + } + break; + case LENS: + NEEDBITS(32) + if ((((~b) >> 16) & 0xffff) != (b & 0xffff)) + { + s->mode = BAD; + z->msg = (char*)"invalid stored block lengths"; + r = Z_DATA_ERROR; + LEAVE + } + s->sub.left = (uInt)b & 0xffff; + b = k = 0; /* dump bits */ + Tracev((stderr, "inflate: stored length %u\n", s->sub.left)); + s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE); + break; + case STORED: + if (n == 0) + LEAVE + NEEDOUT + t = s->sub.left; + if (t > n) t = n; + if (t > m) t = m; + zmemcpy(q, p, t); + p += t; n -= t; + q += t; m -= t; + if ((s->sub.left -= t) != 0) + break; + Tracev((stderr, "inflate: stored end, %lu total out\n", + z->total_out + (q >= s->read ? q - s->read : + (s->end - s->read) + (q - s->window)))); + s->mode = s->last ? DRY : TYPE; + break; + case TABLE: + NEEDBITS(14) + s->sub.trees.table = t = (uInt)b & 0x3fff; +#ifndef PKZIP_BUG_WORKAROUND + if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) + { + s->mode = BAD; + z->msg = (char*)"too many length or distance symbols"; + r = Z_DATA_ERROR; + LEAVE + } +#endif + t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f); + if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL) + { + r = Z_MEM_ERROR; + LEAVE + } + DUMPBITS(14) + s->sub.trees.index = 0; + Tracev((stderr, "inflate: table sizes ok\n")); + s->mode = BTREE; + case BTREE: + while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10)) + { + NEEDBITS(3) + s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7; + DUMPBITS(3) + } + while (s->sub.trees.index < 19) + s->sub.trees.blens[border[s->sub.trees.index++]] = 0; + s->sub.trees.bb = 7; + t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb, + &s->sub.trees.tb, s->hufts, z); + if (t != Z_OK) + { + r = t; + if (r == Z_DATA_ERROR) + { + ZFREE(z, s->sub.trees.blens); + s->mode = BAD; + } + LEAVE + } + s->sub.trees.index = 0; + Tracev((stderr, "inflate: bits tree ok\n")); + s->mode = DTREE; + case DTREE: + while (t = s->sub.trees.table, + s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f)) + { + inflate_huft *h; + uInt i, j, c; + + t = s->sub.trees.bb; + NEEDBITS(t) + h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]); + t = h->bits; + c = h->base; + if (c < 16) + { + DUMPBITS(t) + s->sub.trees.blens[s->sub.trees.index++] = c; + } + else /* c == 16..18 */ + { + i = c == 18 ? 7 : c - 14; + j = c == 18 ? 11 : 3; + NEEDBITS(t + i) + DUMPBITS(t) + j += (uInt)b & inflate_mask[i]; + DUMPBITS(i) + i = s->sub.trees.index; + t = s->sub.trees.table; + if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || + (c == 16 && i < 1)) + { + ZFREE(z, s->sub.trees.blens); + s->mode = BAD; + z->msg = (char*)"invalid bit length repeat"; + r = Z_DATA_ERROR; + LEAVE + } + c = c == 16 ? s->sub.trees.blens[i - 1] : 0; + do { + s->sub.trees.blens[i++] = c; + } while (--j); + s->sub.trees.index = i; + } + } + s->sub.trees.tb = Z_NULL; + { + uInt bl, bd; + inflate_huft *tl, *td; + inflate_codes_statef *c; + + bl = 9; /* must be <= 9 for lookahead assumptions */ + bd = 6; /* must be <= 9 for lookahead assumptions */ + t = s->sub.trees.table; + t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), + s->sub.trees.blens, &bl, &bd, &tl, &td, + s->hufts, z); + if (t != Z_OK) + { + if (t == (uInt)Z_DATA_ERROR) + { + ZFREE(z, s->sub.trees.blens); + s->mode = BAD; + } + r = t; + LEAVE + } + Tracev((stderr, "inflate: trees ok\n")); + if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL) + { + r = Z_MEM_ERROR; + LEAVE + } + s->sub.decode.codes = c; + } + ZFREE(z, s->sub.trees.blens); + s->mode = CODES; + case CODES: + UPDATE + if ((r = inflate_codes(s, z, r)) != Z_STREAM_END) + return inflate_flush(s, z, r); + r = Z_OK; + inflate_codes_free(s->sub.decode.codes, z); + LOAD + Tracev((stderr, "inflate: codes end, %lu total out\n", + z->total_out + (q >= s->read ? q - s->read : + (s->end - s->read) + (q - s->window)))); + if (!s->last) + { + s->mode = TYPE; + break; + } + s->mode = DRY; + case DRY: + FLUSH + if (s->read != s->write) + LEAVE + s->mode = DONE; + case DONE: + r = Z_STREAM_END; + LEAVE + case BAD: + r = Z_DATA_ERROR; + LEAVE + default: + r = Z_STREAM_ERROR; + LEAVE + } +} + + +int inflate_blocks_free(s, z) +inflate_blocks_statef *s; +z_streamp z; +{ + inflate_blocks_reset(s, z, Z_NULL); + ZFREE(z, s->window); + ZFREE(z, s->hufts); + ZFREE(z, s); + Tracev((stderr, "inflate: blocks freed\n")); + return Z_OK; +} + + +void inflate_set_dictionary(s, d, n) +inflate_blocks_statef *s; +const Bytef *d; +uInt n; +{ + zmemcpy(s->window, d, n); + s->read = s->write = s->window + n; +} + + +/* Returns true if inflate is currently at the end of a block generated + * by Z_SYNC_FLUSH or Z_FULL_FLUSH. + * IN assertion: s != Z_NULL + */ +int inflate_blocks_sync_point(s) +inflate_blocks_statef *s; +{ + return s->mode == LENS; +} diff --git a/fceumm/src-fceumm/zlib/infblock.h b/fceumm/src-fceumm/zlib/infblock.h new file mode 100644 index 0000000..173b226 --- /dev/null +++ b/fceumm/src-fceumm/zlib/infblock.h @@ -0,0 +1,39 @@ +/* infblock.h -- header to use infblock.c + * Copyright (C) 1995-2002 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +struct inflate_blocks_state; +typedef struct inflate_blocks_state FAR inflate_blocks_statef; + +extern inflate_blocks_statef * inflate_blocks_new OF(( + z_streamp z, + check_func c, /* check function */ + uInt w)); /* window size */ + +extern int inflate_blocks OF(( + inflate_blocks_statef *, + z_streamp , + int)); /* initial return code */ + +extern void inflate_blocks_reset OF(( + inflate_blocks_statef *, + z_streamp , + uLongf *)); /* check value on output */ + +extern int inflate_blocks_free OF(( + inflate_blocks_statef *, + z_streamp)); + +extern void inflate_set_dictionary OF(( + inflate_blocks_statef *s, + const Bytef *d, /* dictionary */ + uInt n)); /* dictionary length */ + +extern int inflate_blocks_sync_point OF(( + inflate_blocks_statef *s)); diff --git a/fceumm/src-fceumm/zlib/infcodes.c b/fceumm/src-fceumm/zlib/infcodes.c new file mode 100644 index 0000000..9abe541 --- /dev/null +++ b/fceumm/src-fceumm/zlib/infcodes.c @@ -0,0 +1,251 @@ +/* infcodes.c -- process literals and length/distance pairs + * Copyright (C) 1995-2002 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "zutil.h" +#include "inftrees.h" +#include "infblock.h" +#include "infcodes.h" +#include "infutil.h" +#include "inffast.h" + +/* simplify the use of the inflate_huft type with some defines */ +#define exop word.what.Exop +#define bits word.what.Bits + +typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */ + START, /* x: set up for LEN */ + LEN, /* i: get length/literal/eob next */ + LENEXT, /* i: getting length extra (have base) */ + DIST, /* i: get distance next */ + DISTEXT, /* i: getting distance extra */ + COPY, /* o: copying bytes in window, waiting for space */ + LIT, /* o: got literal, waiting for output space */ + WASH, /* o: got eob, possibly still output waiting */ + END, /* x: got eob and all data flushed */ + BADCODE} /* x: got error */ +inflate_codes_mode; + +/* inflate codes private state */ +struct inflate_codes_state { + + /* mode */ + inflate_codes_mode mode; /* current inflate_codes mode */ + + /* mode dependent information */ + uInt len; + union { + struct { + inflate_huft *tree; /* pointer into tree */ + uInt need; /* bits needed */ + } code; /* if LEN or DIST, where in tree */ + uInt lit; /* if LIT, literal */ + struct { + uInt get; /* bits to get for extra */ + uInt dist; /* distance back to copy from */ + } copy; /* if EXT or COPY, where and how much */ + } sub; /* submode */ + + /* mode independent information */ + Byte lbits; /* ltree bits decoded per branch */ + Byte dbits; /* dtree bits decoder per branch */ + inflate_huft *ltree; /* literal/length/eob tree */ + inflate_huft *dtree; /* distance tree */ + +}; + + +inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z) +uInt bl, bd; +inflate_huft *tl; +inflate_huft *td; /* need separate declaration for Borland C++ */ +z_streamp z; +{ + inflate_codes_statef *c; + + if ((c = (inflate_codes_statef *) + ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL) + { + c->mode = START; + c->lbits = (Byte)bl; + c->dbits = (Byte)bd; + c->ltree = tl; + c->dtree = td; + Tracev((stderr, "inflate: codes new\n")); + } + return c; +} + + +int inflate_codes(s, z, r) +inflate_blocks_statef *s; +z_streamp z; +int r; +{ + uInt j; /* temporary storage */ + inflate_huft *t; /* temporary pointer */ + uInt e; /* extra bits or operation */ + uLong b; /* bit buffer */ + uInt k; /* bits in bit buffer */ + Bytef *p; /* input data pointer */ + uInt n; /* bytes available there */ + Bytef *q; /* output window write pointer */ + uInt m; /* bytes to end of window or read pointer */ + Bytef *f; /* pointer to copy strings from */ + inflate_codes_statef *c = s->sub.decode.codes; /* codes state */ + + /* copy input/output information to locals (UPDATE macro restores) */ + LOAD + + /* process input and output based on current state */ + while (1) switch (c->mode) + { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */ + case START: /* x: set up for LEN */ +#ifndef SLOW + if (m >= 258 && n >= 10) + { + UPDATE + r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z); + LOAD + if (r != Z_OK) + { + c->mode = r == Z_STREAM_END ? WASH : BADCODE; + break; + } + } +#endif /* !SLOW */ + c->sub.code.need = c->lbits; + c->sub.code.tree = c->ltree; + c->mode = LEN; + case LEN: /* i: get length/literal/eob next */ + j = c->sub.code.need; + NEEDBITS(j) + t = c->sub.code.tree + ((uInt)b & inflate_mask[j]); + DUMPBITS(t->bits) + e = (uInt)(t->exop); + if (e == 0) /* literal */ + { + c->sub.lit = t->base; + Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? + "inflate: literal '%c'\n" : + "inflate: literal 0x%02x\n", t->base)); + c->mode = LIT; + break; + } + if (e & 16) /* length */ + { + c->sub.copy.get = e & 15; + c->len = t->base; + c->mode = LENEXT; + break; + } + if ((e & 64) == 0) /* next table */ + { + c->sub.code.need = e; + c->sub.code.tree = t + t->base; + break; + } + if (e & 32) /* end of block */ + { + Tracevv((stderr, "inflate: end of block\n")); + c->mode = WASH; + break; + } + c->mode = BADCODE; /* invalid code */ + z->msg = (char*)"invalid literal/length code"; + r = Z_DATA_ERROR; + LEAVE + case LENEXT: /* i: getting length extra (have base) */ + j = c->sub.copy.get; + NEEDBITS(j) + c->len += (uInt)b & inflate_mask[j]; + DUMPBITS(j) + c->sub.code.need = c->dbits; + c->sub.code.tree = c->dtree; + Tracevv((stderr, "inflate: length %u\n", c->len)); + c->mode = DIST; + case DIST: /* i: get distance next */ + j = c->sub.code.need; + NEEDBITS(j) + t = c->sub.code.tree + ((uInt)b & inflate_mask[j]); + DUMPBITS(t->bits) + e = (uInt)(t->exop); + if (e & 16) /* distance */ + { + c->sub.copy.get = e & 15; + c->sub.copy.dist = t->base; + c->mode = DISTEXT; + break; + } + if ((e & 64) == 0) /* next table */ + { + c->sub.code.need = e; + c->sub.code.tree = t + t->base; + break; + } + c->mode = BADCODE; /* invalid code */ + z->msg = (char*)"invalid distance code"; + r = Z_DATA_ERROR; + LEAVE + case DISTEXT: /* i: getting distance extra */ + j = c->sub.copy.get; + NEEDBITS(j) + c->sub.copy.dist += (uInt)b & inflate_mask[j]; + DUMPBITS(j) + Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist)); + c->mode = COPY; + case COPY: /* o: copying bytes in window, waiting for space */ + f = q - c->sub.copy.dist; + while (f < s->window) /* modulo window size-"while" instead */ + f += s->end - s->window; /* of "if" handles invalid distances */ + while (c->len) + { + NEEDOUT + OUTBYTE(*f++) + if (f == s->end) + f = s->window; + c->len--; + } + c->mode = START; + break; + case LIT: /* o: got literal, waiting for output space */ + NEEDOUT + OUTBYTE(c->sub.lit) + c->mode = START; + break; + case WASH: /* o: got eob, possibly more output */ + if (k > 7) /* return unused byte, if any */ + { + Assert(k < 16, "inflate_codes grabbed too many bytes") + k -= 8; + n++; + p--; /* can always return one */ + } + FLUSH + if (s->read != s->write) + LEAVE + c->mode = END; + case END: + r = Z_STREAM_END; + LEAVE + case BADCODE: /* x: got error */ + r = Z_DATA_ERROR; + LEAVE + default: + r = Z_STREAM_ERROR; + LEAVE + } +#ifdef NEED_DUMMY_RETURN + return Z_STREAM_ERROR; /* Some dumb compilers complain without this */ +#endif +} + + +void inflate_codes_free(c, z) +inflate_codes_statef *c; +z_streamp z; +{ + ZFREE(z, c); + Tracev((stderr, "inflate: codes free\n")); +} diff --git a/fceumm/src-fceumm/zlib/infcodes.h b/fceumm/src-fceumm/zlib/infcodes.h new file mode 100644 index 0000000..46821a0 --- /dev/null +++ b/fceumm/src-fceumm/zlib/infcodes.h @@ -0,0 +1,27 @@ +/* infcodes.h -- header to use infcodes.c + * Copyright (C) 1995-2002 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +struct inflate_codes_state; +typedef struct inflate_codes_state FAR inflate_codes_statef; + +extern inflate_codes_statef *inflate_codes_new OF(( + uInt, uInt, + inflate_huft *, inflate_huft *, + z_streamp )); + +extern int inflate_codes OF(( + inflate_blocks_statef *, + z_streamp , + int)); + +extern void inflate_codes_free OF(( + inflate_codes_statef *, + z_streamp )); + diff --git a/fceumm/src-fceumm/zlib/inffast.c b/fceumm/src-fceumm/zlib/inffast.c new file mode 100644 index 0000000..aa7f1d4 --- /dev/null +++ b/fceumm/src-fceumm/zlib/inffast.c @@ -0,0 +1,183 @@ +/* inffast.c -- process literals and length/distance pairs fast + * Copyright (C) 1995-2002 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "zutil.h" +#include "inftrees.h" +#include "infblock.h" +#include "infcodes.h" +#include "infutil.h" +#include "inffast.h" + +struct inflate_codes_state {int dummy;}; /* for buggy compilers */ + +/* simplify the use of the inflate_huft type with some defines */ +#define exop word.what.Exop +#define bits word.what.Bits + +/* macros for bit input with no checking and for returning unused bytes */ +#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<avail_in-n;c=(k>>3)>3:c;n+=c;p-=c;k-=c<<3;} + +/* Called with number of bytes left to write in window at least 258 + (the maximum string length) and number of input bytes available + at least ten. The ten bytes are six bytes for the longest length/ + distance pair plus four bytes for overloading the bit buffer. */ + +int inflate_fast(bl, bd, tl, td, s, z) +uInt bl, bd; +inflate_huft *tl; +inflate_huft *td; /* need separate declaration for Borland C++ */ +inflate_blocks_statef *s; +z_streamp z; +{ + inflate_huft *t; /* temporary pointer */ + uInt e; /* extra bits or operation */ + uLong b; /* bit buffer */ + uInt k; /* bits in bit buffer */ + Bytef *p; /* input data pointer */ + uInt n; /* bytes available there */ + Bytef *q; /* output window write pointer */ + uInt m; /* bytes to end of window or read pointer */ + uInt ml; /* mask for literal/length tree */ + uInt md; /* mask for distance tree */ + uInt c; /* bytes to copy */ + uInt d; /* distance back to copy from */ + Bytef *r; /* copy source pointer */ + + /* load input, output, bit values */ + LOAD + + /* initialize masks */ + ml = inflate_mask[bl]; + md = inflate_mask[bd]; + + /* do until not enough input or output space for fast loop */ + do { /* assume called with m >= 258 && n >= 10 */ + /* get literal/length code */ + GRABBITS(20) /* max bits for literal/length code */ + if ((e = (t = tl + ((uInt)b & ml))->exop) == 0) + { + DUMPBITS(t->bits) + Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? + "inflate: * literal '%c'\n" : + "inflate: * literal 0x%02x\n", t->base)); + *q++ = (Byte)t->base; + m--; + continue; + } + do { + DUMPBITS(t->bits) + if (e & 16) + { + /* get extra bits for length */ + e &= 15; + c = t->base + ((uInt)b & inflate_mask[e]); + DUMPBITS(e) + Tracevv((stderr, "inflate: * length %u\n", c)); + + /* decode distance base of block to copy */ + GRABBITS(15); /* max bits for distance code */ + e = (t = td + ((uInt)b & md))->exop; + do { + DUMPBITS(t->bits) + if (e & 16) + { + /* get extra bits to add to distance base */ + e &= 15; + GRABBITS(e) /* get extra bits (up to 13) */ + d = t->base + ((uInt)b & inflate_mask[e]); + DUMPBITS(e) + Tracevv((stderr, "inflate: * distance %u\n", d)); + + /* do the copy */ + m -= c; + r = q - d; + if (r < s->window) /* wrap if needed */ + { + do { + r += s->end - s->window; /* force pointer in window */ + } while (r < s->window); /* covers invalid distances */ + e = s->end - r; + if (c > e) + { + c -= e; /* wrapped copy */ + do { + *q++ = *r++; + } while (--e); + r = s->window; + do { + *q++ = *r++; + } while (--c); + } + else /* normal copy */ + { + *q++ = *r++; c--; + *q++ = *r++; c--; + do { + *q++ = *r++; + } while (--c); + } + } + else /* normal copy */ + { + *q++ = *r++; c--; + *q++ = *r++; c--; + do { + *q++ = *r++; + } while (--c); + } + break; + } + else if ((e & 64) == 0) + { + t += t->base; + e = (t += ((uInt)b & inflate_mask[e]))->exop; + } + else + { + z->msg = (char*)"invalid distance code"; + UNGRAB + UPDATE + return Z_DATA_ERROR; + } + } while (1); + break; + } + if ((e & 64) == 0) + { + t += t->base; + if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0) + { + DUMPBITS(t->bits) + Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? + "inflate: * literal '%c'\n" : + "inflate: * literal 0x%02x\n", t->base)); + *q++ = (Byte)t->base; + m--; + break; + } + } + else if (e & 32) + { + Tracevv((stderr, "inflate: * end of block\n")); + UNGRAB + UPDATE + return Z_STREAM_END; + } + else + { + z->msg = (char*)"invalid literal/length code"; + UNGRAB + UPDATE + return Z_DATA_ERROR; + } + } while (1); + } while (m >= 258 && n >= 10); + + /* not enough input or output--restore pointers and return */ + UNGRAB + UPDATE + return Z_OK; +} diff --git a/fceumm/src-fceumm/zlib/inffast.h b/fceumm/src-fceumm/zlib/inffast.h new file mode 100644 index 0000000..a31a4bb --- /dev/null +++ b/fceumm/src-fceumm/zlib/inffast.h @@ -0,0 +1,17 @@ +/* inffast.h -- header to use inffast.c + * Copyright (C) 1995-2002 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +extern int inflate_fast OF(( + uInt, + uInt, + inflate_huft *, + inflate_huft *, + inflate_blocks_statef *, + z_streamp )); diff --git a/fceumm/src-fceumm/zlib/inffixed.h b/fceumm/src-fceumm/zlib/inffixed.h new file mode 100644 index 0000000..77f7e76 --- /dev/null +++ b/fceumm/src-fceumm/zlib/inffixed.h @@ -0,0 +1,151 @@ +/* inffixed.h -- table for decoding fixed codes + * Generated automatically by the maketree.c program + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +local uInt fixed_bl = 9; +local uInt fixed_bd = 5; +local inflate_huft fixed_tl[] = { + {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115}, + {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},192}, + {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},160}, + {{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},224}, + {{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},144}, + {{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},208}, + {{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},176}, + {{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},240}, + {{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227}, + {{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},200}, + {{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},168}, + {{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},232}, + {{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},152}, + {{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},216}, + {{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},184}, + {{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},248}, + {{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163}, + {{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},196}, + {{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},164}, + {{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},228}, + {{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},148}, + {{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},212}, + {{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},180}, + {{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},244}, + {{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0}, + {{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},204}, + {{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},172}, + {{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},236}, + {{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},156}, + {{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},220}, + {{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},188}, + {{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},252}, + {{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131}, + {{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},194}, + {{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},162}, + {{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},226}, + {{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},146}, + {{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},210}, + {{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},178}, + {{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},242}, + {{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258}, + {{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},202}, + {{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},170}, + {{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},234}, + {{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},154}, + {{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},218}, + {{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},186}, + {{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},250}, + {{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195}, + {{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},198}, + {{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},166}, + {{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},230}, + {{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},150}, + {{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},214}, + {{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},182}, + {{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},246}, + {{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0}, + {{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},206}, + {{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},174}, + {{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},238}, + {{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},158}, + {{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},222}, + {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},190}, + {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},254}, + {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115}, + {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},193}, + {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},161}, + {{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},225}, + {{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},145}, + {{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},209}, + {{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},177}, + {{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},241}, + {{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227}, + {{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},201}, + {{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},169}, + {{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},233}, + {{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},153}, + {{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},217}, + {{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},185}, + {{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},249}, + {{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163}, + {{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},197}, + {{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},165}, + {{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},229}, + {{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},149}, + {{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},213}, + {{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},181}, + {{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},245}, + {{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0}, + {{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},205}, + {{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},173}, + {{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},237}, + {{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},157}, + {{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},221}, + {{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},189}, + {{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},253}, + {{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131}, + {{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},195}, + {{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},163}, + {{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},227}, + {{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},147}, + {{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},211}, + {{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},179}, + {{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},243}, + {{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258}, + {{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},203}, + {{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},171}, + {{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},235}, + {{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},155}, + {{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},219}, + {{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},187}, + {{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},251}, + {{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195}, + {{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},199}, + {{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},167}, + {{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},231}, + {{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},151}, + {{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},215}, + {{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},183}, + {{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},247}, + {{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0}, + {{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},207}, + {{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},175}, + {{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},239}, + {{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},159}, + {{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},223}, + {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},191}, + {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},255} + }; +local inflate_huft fixed_td[] = { + {{{80,5}},1}, {{{87,5}},257}, {{{83,5}},17}, {{{91,5}},4097}, + {{{81,5}},5}, {{{89,5}},1025}, {{{85,5}},65}, {{{93,5}},16385}, + {{{80,5}},3}, {{{88,5}},513}, {{{84,5}},33}, {{{92,5}},8193}, + {{{82,5}},9}, {{{90,5}},2049}, {{{86,5}},129}, {{{192,5}},24577}, + {{{80,5}},2}, {{{87,5}},385}, {{{83,5}},25}, {{{91,5}},6145}, + {{{81,5}},7}, {{{89,5}},1537}, {{{85,5}},97}, {{{93,5}},24577}, + {{{80,5}},4}, {{{88,5}},769}, {{{84,5}},49}, {{{92,5}},12289}, + {{{82,5}},13}, {{{90,5}},3073}, {{{86,5}},193}, {{{192,5}},24577} + }; diff --git a/fceumm/src-fceumm/zlib/inflate.c b/fceumm/src-fceumm/zlib/inflate.c new file mode 100644 index 0000000..dfb2e86 --- /dev/null +++ b/fceumm/src-fceumm/zlib/inflate.c @@ -0,0 +1,366 @@ +/* inflate.c -- zlib interface to inflate modules + * Copyright (C) 1995-2002 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "zutil.h" +#include "infblock.h" + +struct inflate_blocks_state {int dummy;}; /* for buggy compilers */ + +typedef enum { + METHOD, /* waiting for method byte */ + FLAG, /* waiting for flag byte */ + DICT4, /* four dictionary check bytes to go */ + DICT3, /* three dictionary check bytes to go */ + DICT2, /* two dictionary check bytes to go */ + DICT1, /* one dictionary check byte to go */ + DICT0, /* waiting for inflateSetDictionary */ + BLOCKS, /* decompressing blocks */ + CHECK4, /* four check bytes to go */ + CHECK3, /* three check bytes to go */ + CHECK2, /* two check bytes to go */ + CHECK1, /* one check byte to go */ + DONE, /* finished check, done */ + BAD} /* got an error--stay here */ +inflate_mode; + +/* inflate private state */ +struct internal_state { + + /* mode */ + inflate_mode mode; /* current inflate mode */ + + /* mode dependent information */ + union { + uInt method; /* if FLAGS, method byte */ + struct { + uLong was; /* computed check value */ + uLong need; /* stream check value */ + } check; /* if CHECK, check values to compare */ + uInt marker; /* if BAD, inflateSync's marker bytes count */ + } sub; /* submode */ + + /* mode independent information */ + int nowrap; /* flag for no wrapper */ + uInt wbits; /* log2(window size) (8..15, defaults to 15) */ + inflate_blocks_statef + *blocks; /* current inflate_blocks state */ + +}; + + +int ZEXPORT inflateReset(z) +z_streamp z; +{ + if (z == Z_NULL || z->state == Z_NULL) + return Z_STREAM_ERROR; + z->total_in = z->total_out = 0; + z->msg = Z_NULL; + z->state->mode = z->state->nowrap ? BLOCKS : METHOD; + inflate_blocks_reset(z->state->blocks, z, Z_NULL); + Tracev((stderr, "inflate: reset\n")); + return Z_OK; +} + + +int ZEXPORT inflateEnd(z) +z_streamp z; +{ + if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL) + return Z_STREAM_ERROR; + if (z->state->blocks != Z_NULL) + inflate_blocks_free(z->state->blocks, z); + ZFREE(z, z->state); + z->state = Z_NULL; + Tracev((stderr, "inflate: end\n")); + return Z_OK; +} + + +int ZEXPORT inflateInit2_(z, w, version, stream_size) +z_streamp z; +int w; +const char *version; +int stream_size; +{ + if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || + stream_size != sizeof(z_stream)) + return Z_VERSION_ERROR; + + /* initialize state */ + if (z == Z_NULL) + return Z_STREAM_ERROR; + z->msg = Z_NULL; + if (z->zalloc == Z_NULL) + { + z->zalloc = zcalloc; + z->opaque = (voidpf)0; + } + if (z->zfree == Z_NULL) z->zfree = zcfree; + if ((z->state = (struct internal_state FAR *) + ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL) + return Z_MEM_ERROR; + z->state->blocks = Z_NULL; + + /* handle undocumented nowrap option (no zlib header or check) */ + z->state->nowrap = 0; + if (w < 0) + { + w = - w; + z->state->nowrap = 1; + } + + /* set window size */ + if (w < 8 || w > 15) + { + inflateEnd(z); + return Z_STREAM_ERROR; + } + z->state->wbits = (uInt)w; + + /* create inflate_blocks state */ + if ((z->state->blocks = + inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w)) + == Z_NULL) + { + inflateEnd(z); + return Z_MEM_ERROR; + } + Tracev((stderr, "inflate: allocated\n")); + + /* reset state */ + inflateReset(z); + return Z_OK; +} + + +int ZEXPORT inflateInit_(z, version, stream_size) +z_streamp z; +const char *version; +int stream_size; +{ + return inflateInit2_(z, DEF_WBITS, version, stream_size); +} + + +#define NEEDBYTE {if(z->avail_in==0)return r;r=f;} +#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++) + +int ZEXPORT inflate(z, f) +z_streamp z; +int f; +{ + int r; + uInt b; + + if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL) + return Z_STREAM_ERROR; + f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK; + r = Z_BUF_ERROR; + while (1) switch (z->state->mode) + { + case METHOD: + NEEDBYTE + if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED) + { + z->state->mode = BAD; + z->msg = (char*)"unknown compression method"; + z->state->sub.marker = 5; /* can't try inflateSync */ + break; + } + if ((z->state->sub.method >> 4) + 8 > z->state->wbits) + { + z->state->mode = BAD; + z->msg = (char*)"invalid window size"; + z->state->sub.marker = 5; /* can't try inflateSync */ + break; + } + z->state->mode = FLAG; + case FLAG: + NEEDBYTE + b = NEXTBYTE; + if (((z->state->sub.method << 8) + b) % 31) + { + z->state->mode = BAD; + z->msg = (char*)"incorrect header check"; + z->state->sub.marker = 5; /* can't try inflateSync */ + break; + } + Tracev((stderr, "inflate: zlib header ok\n")); + if (!(b & PRESET_DICT)) + { + z->state->mode = BLOCKS; + break; + } + z->state->mode = DICT4; + case DICT4: + NEEDBYTE + z->state->sub.check.need = (uLong)NEXTBYTE << 24; + z->state->mode = DICT3; + case DICT3: + NEEDBYTE + z->state->sub.check.need += (uLong)NEXTBYTE << 16; + z->state->mode = DICT2; + case DICT2: + NEEDBYTE + z->state->sub.check.need += (uLong)NEXTBYTE << 8; + z->state->mode = DICT1; + case DICT1: + NEEDBYTE + z->state->sub.check.need += (uLong)NEXTBYTE; + z->adler = z->state->sub.check.need; + z->state->mode = DICT0; + return Z_NEED_DICT; + case DICT0: + z->state->mode = BAD; + z->msg = (char*)"need dictionary"; + z->state->sub.marker = 0; /* can try inflateSync */ + return Z_STREAM_ERROR; + case BLOCKS: + r = inflate_blocks(z->state->blocks, z, r); + if (r == Z_DATA_ERROR) + { + z->state->mode = BAD; + z->state->sub.marker = 0; /* can try inflateSync */ + break; + } + if (r == Z_OK) + r = f; + if (r != Z_STREAM_END) + return r; + r = f; + inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was); + if (z->state->nowrap) + { + z->state->mode = DONE; + break; + } + z->state->mode = CHECK4; + case CHECK4: + NEEDBYTE + z->state->sub.check.need = (uLong)NEXTBYTE << 24; + z->state->mode = CHECK3; + case CHECK3: + NEEDBYTE + z->state->sub.check.need += (uLong)NEXTBYTE << 16; + z->state->mode = CHECK2; + case CHECK2: + NEEDBYTE + z->state->sub.check.need += (uLong)NEXTBYTE << 8; + z->state->mode = CHECK1; + case CHECK1: + NEEDBYTE + z->state->sub.check.need += (uLong)NEXTBYTE; + + if (z->state->sub.check.was != z->state->sub.check.need) + { + z->state->mode = BAD; + z->msg = (char*)"incorrect data check"; + z->state->sub.marker = 5; /* can't try inflateSync */ + break; + } + Tracev((stderr, "inflate: zlib check ok\n")); + z->state->mode = DONE; + case DONE: + return Z_STREAM_END; + case BAD: + return Z_DATA_ERROR; + default: + return Z_STREAM_ERROR; + } +#ifdef NEED_DUMMY_RETURN + return Z_STREAM_ERROR; /* Some dumb compilers complain without this */ +#endif +} + + +int ZEXPORT inflateSetDictionary(z, dictionary, dictLength) +z_streamp z; +const Bytef *dictionary; +uInt dictLength; +{ + uInt length = dictLength; + + if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0) + return Z_STREAM_ERROR; + + if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR; + z->adler = 1L; + + if (length >= ((uInt)1<state->wbits)) + { + length = (1<state->wbits)-1; + dictionary += dictLength - length; + } + inflate_set_dictionary(z->state->blocks, dictionary, length); + z->state->mode = BLOCKS; + return Z_OK; +} + + +int ZEXPORT inflateSync(z) +z_streamp z; +{ + uInt n; /* number of bytes to look at */ + Bytef *p; /* pointer to bytes */ + uInt m; /* number of marker bytes found in a row */ + uLong r, w; /* temporaries to save total_in and total_out */ + + /* set up */ + if (z == Z_NULL || z->state == Z_NULL) + return Z_STREAM_ERROR; + if (z->state->mode != BAD) + { + z->state->mode = BAD; + z->state->sub.marker = 0; + } + if ((n = z->avail_in) == 0) + return Z_BUF_ERROR; + p = z->next_in; + m = z->state->sub.marker; + + /* search */ + while (n && m < 4) + { + static const Byte mark[4] = {0, 0, 0xff, 0xff}; + if (*p == mark[m]) + m++; + else if (*p) + m = 0; + else + m = 4 - m; + p++, n--; + } + + /* restore */ + z->total_in += p - z->next_in; + z->next_in = p; + z->avail_in = n; + z->state->sub.marker = m; + + /* return no joy or set up to restart on a new block */ + if (m != 4) + return Z_DATA_ERROR; + r = z->total_in; w = z->total_out; + inflateReset(z); + z->total_in = r; z->total_out = w; + z->state->mode = BLOCKS; + return Z_OK; +} + + +/* Returns true if inflate is currently at the end of a block generated + * by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP + * implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH + * but removes the length bytes of the resulting empty stored block. When + * decompressing, PPP checks that at the end of input packet, inflate is + * waiting for these length bytes. + */ +int ZEXPORT inflateSyncPoint(z) +z_streamp z; +{ + if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL) + return Z_STREAM_ERROR; + return inflate_blocks_sync_point(z->state->blocks); +} diff --git a/fceumm/src-fceumm/zlib/inftrees.c b/fceumm/src-fceumm/zlib/inftrees.c new file mode 100644 index 0000000..4c32ca3 --- /dev/null +++ b/fceumm/src-fceumm/zlib/inftrees.c @@ -0,0 +1,454 @@ +/* inftrees.c -- generate Huffman trees for efficient decoding + * Copyright (C) 1995-2002 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "zutil.h" +#include "inftrees.h" + +#if !defined(BUILDFIXED) && !defined(STDC) +# define BUILDFIXED /* non ANSI compilers may not accept inffixed.h */ +#endif + +const char inflate_copyright[] = + " inflate 1.1.4 Copyright 1995-2002 Mark Adler "; +/* + If you use the zlib library in a product, an acknowledgment is welcome + in the documentation of your product. If for some reason you cannot + include such an acknowledgment, I would appreciate that you keep this + copyright string in the executable of your product. + */ +struct internal_state {int dummy;}; /* for buggy compilers */ + +/* simplify the use of the inflate_huft type with some defines */ +#define exop word.what.Exop +#define bits word.what.Bits + + +local int huft_build OF(( + uIntf *, /* code lengths in bits */ + uInt, /* number of codes */ + uInt, /* number of "simple" codes */ + const uIntf *, /* list of base values for non-simple codes */ + const uIntf *, /* list of extra bits for non-simple codes */ + inflate_huft * FAR*,/* result: starting table */ + uIntf *, /* maximum lookup bits (returns actual) */ + inflate_huft *, /* space for trees */ + uInt *, /* hufts used in space */ + uIntf * )); /* space for values */ + +/* Tables for deflate from PKZIP's appnote.txt. */ +local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */ + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, + 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; + /* see note #13 above about 258 */ +local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */ + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, + 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */ +local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */ + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, + 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, + 8193, 12289, 16385, 24577}; +local const uInt cpdext[30] = { /* Extra bits for distance codes */ + 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, + 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, + 12, 12, 13, 13}; + +/* + Huffman code decoding is performed using a multi-level table lookup. + The fastest way to decode is to simply build a lookup table whose + size is determined by the longest code. However, the time it takes + to build this table can also be a factor if the data being decoded + is not very long. The most common codes are necessarily the + shortest codes, so those codes dominate the decoding time, and hence + the speed. The idea is you can have a shorter table that decodes the + shorter, more probable codes, and then point to subsidiary tables for + the longer codes. The time it costs to decode the longer codes is + then traded against the time it takes to make longer tables. + + This results of this trade are in the variables lbits and dbits + below. lbits is the number of bits the first level table for literal/ + length codes can decode in one step, and dbits is the same thing for + the distance codes. Subsequent tables are also less than or equal to + those sizes. These values may be adjusted either when all of the + codes are shorter than that, in which case the longest code length in + bits is used, or when the shortest code is *longer* than the requested + table size, in which case the length of the shortest code in bits is + used. + + There are two different values for the two tables, since they code a + different number of possibilities each. The literal/length table + codes 286 possible values, or in a flat code, a little over eight + bits. The distance table codes 30 possible values, or a little less + than five bits, flat. The optimum values for speed end up being + about one bit more than those, so lbits is 8+1 and dbits is 5+1. + The optimum values may differ though from machine to machine, and + possibly even between compilers. Your mileage may vary. + */ + + +/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */ +#define BMAX 15 /* maximum bit length of any code */ + +local int huft_build(b, n, s, d, e, t, m, hp, hn, v) +uIntf *b; /* code lengths in bits (all assumed <= BMAX) */ +uInt n; /* number of codes (assumed <= 288) */ +uInt s; /* number of simple-valued codes (0..s-1) */ +const uIntf *d; /* list of base values for non-simple codes */ +const uIntf *e; /* list of extra bits for non-simple codes */ +inflate_huft * FAR *t; /* result: starting table */ +uIntf *m; /* maximum lookup bits, returns actual */ +inflate_huft *hp; /* space for trees */ +uInt *hn; /* hufts used in space */ +uIntf *v; /* working area: values in order of bit length */ +/* Given a list of code lengths and a maximum table size, make a set of + tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR + if the given code set is incomplete (the tables are still built in this + case), or Z_DATA_ERROR if the input is invalid. */ +{ + + uInt a; /* counter for codes of length k */ + uInt c[BMAX+1]; /* bit length count table */ + uInt f; /* i repeats in table every f entries */ + int g; /* maximum code length */ + int h; /* table level */ + register uInt i; /* counter, current code */ + register uInt j; /* counter */ + register int k; /* number of bits in current code */ + int l; /* bits per table (returned in m) */ + uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */ + register uIntf *p; /* pointer into c[], b[], or v[] */ + inflate_huft *q; /* points to current table */ + struct inflate_huft_s r; /* table entry for structure assignment */ + inflate_huft *u[BMAX]; /* table stack */ + register int w; /* bits before this table == (l * h) */ + uInt x[BMAX+1]; /* bit offsets, then code stack */ + uIntf *xp; /* pointer into x */ + int y; /* number of dummy codes added */ + uInt z; /* number of entries in current table */ + + + /* Generate counts for each bit length */ + p = c; +#define C0 *p++ = 0; +#define C2 C0 C0 C0 C0 +#define C4 C2 C2 C2 C2 + C4 /* clear c[]--assume BMAX+1 is 16 */ + p = b; i = n; + do { + c[*p++]++; /* assume all entries <= BMAX */ + } while (--i); + if (c[0] == n) /* null input--all zero length codes */ + { + *t = (inflate_huft *)Z_NULL; + *m = 0; + return Z_OK; + } + + + /* Find minimum and maximum length, bound *m by those */ + l = *m; + for (j = 1; j <= BMAX; j++) + if (c[j]) + break; + k = j; /* minimum code length */ + if ((uInt)l < j) + l = j; + for (i = BMAX; i; i--) + if (c[i]) + break; + g = i; /* maximum code length */ + if ((uInt)l > i) + l = i; + *m = l; + + + /* Adjust last length count to fill out codes, if needed */ + for (y = 1 << j; j < i; j++, y <<= 1) + if ((y -= c[j]) < 0) + return Z_DATA_ERROR; + if ((y -= c[i]) < 0) + return Z_DATA_ERROR; + c[i] += y; + + + /* Generate starting offsets into the value table for each length */ + x[1] = j = 0; + p = c + 1; xp = x + 2; + while (--i) { /* note that i == g from above */ + *xp++ = (j += *p++); + } + + + /* Make a table of values in order of bit lengths */ + p = b; i = 0; + do { + if ((j = *p++) != 0) + v[x[j]++] = i; + } while (++i < n); + n = x[g]; /* set n to length of v */ + + + /* Generate the Huffman codes and for each, make the table entries */ + x[0] = i = 0; /* first Huffman code is zero */ + p = v; /* grab values in bit order */ + h = -1; /* no tables yet--level -1 */ + w = -l; /* bits decoded == (l * h) */ + u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */ + q = (inflate_huft *)Z_NULL; /* ditto */ + z = 0; /* ditto */ + + /* go through the bit lengths (k already is bits in shortest code) */ + for (; k <= g; k++) + { + a = c[k]; + while (a--) + { + /* here i is the Huffman code of length k bits for value *p */ + /* make tables up to required level */ + while (k > w + l) + { + h++; + w += l; /* previous table always l bits */ + + /* compute minimum size table less than or equal to l bits */ + z = g - w; + z = z > (uInt)l ? l : z; /* table size upper limit */ + if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */ + { /* too few codes for k-w bit table */ + f -= a + 1; /* deduct codes from patterns left */ + xp = c + k; + if (j < z) + while (++j < z) /* try smaller tables up to z bits */ + { + if ((f <<= 1) <= *++xp) + break; /* enough codes to use up j bits */ + f -= *xp; /* else deduct codes from patterns */ + } + } + z = 1 << j; /* table entries for j-bit table */ + + /* allocate new table */ + if (*hn + z > MANY) /* (note: doesn't matter for fixed) */ + return Z_DATA_ERROR; /* overflow of MANY */ + u[h] = q = hp + *hn; + *hn += z; + + /* connect to last table, if there is one */ + if (h) + { + x[h] = i; /* save pattern for backing up */ + r.bits = (Byte)l; /* bits to dump before this table */ + r.exop = (Byte)j; /* bits in this table */ + j = i >> (w - l); + r.base = (uInt)(q - u[h-1] - j); /* offset to this table */ + u[h-1][j] = r; /* connect to last table */ + } + else + *t = q; /* first table is returned result */ + } + + /* set up table entry in r */ + r.bits = (Byte)(k - w); + if (p >= v + n) + r.exop = 128 + 64; /* out of values--invalid code */ + else if (*p < s) + { + r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */ + r.base = *p++; /* simple code is just the value */ + } + else + { + r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */ + r.base = d[*p++ - s]; + } + + /* fill code-like entries with r */ + f = 1 << (k - w); + for (j = i >> w; j < z; j += f) + q[j] = r; + + /* backwards increment the k-bit code i */ + for (j = 1 << (k - 1); i & j; j >>= 1) + i ^= j; + i ^= j; + + /* backup over finished tables */ + mask = (1 << w) - 1; /* needed on HP, cc -O bug */ + while ((i & mask) != x[h]) + { + h--; /* don't need to update q */ + w -= l; + mask = (1 << w) - 1; + } + } + } + + + /* Return Z_BUF_ERROR if we were given an incomplete table */ + return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK; +} + + +int inflate_trees_bits(c, bb, tb, hp, z) +uIntf *c; /* 19 code lengths */ +uIntf *bb; /* bits tree desired/actual depth */ +inflate_huft * FAR *tb; /* bits tree result */ +inflate_huft *hp; /* space for trees */ +z_streamp z; /* for messages */ +{ + int r; + uInt hn = 0; /* hufts used in space */ + uIntf *v; /* work area for huft_build */ + + if ((v = (uIntf*)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL) + return Z_MEM_ERROR; + r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL, + tb, bb, hp, &hn, v); + if (r == Z_DATA_ERROR) + z->msg = (char*)"oversubscribed dynamic bit lengths tree"; + else if (r == Z_BUF_ERROR || *bb == 0) + { + z->msg = (char*)"incomplete dynamic bit lengths tree"; + r = Z_DATA_ERROR; + } + ZFREE(z, v); + return r; +} + + +int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z) +uInt nl; /* number of literal/length codes */ +uInt nd; /* number of distance codes */ +uIntf *c; /* that many (total) code lengths */ +uIntf *bl; /* literal desired/actual bit depth */ +uIntf *bd; /* distance desired/actual bit depth */ +inflate_huft * FAR *tl; /* literal/length tree result */ +inflate_huft * FAR *td; /* distance tree result */ +inflate_huft *hp; /* space for trees */ +z_streamp z; /* for messages */ +{ + int r; + uInt hn = 0; /* hufts used in space */ + uIntf *v; /* work area for huft_build */ + + /* allocate work area */ + if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL) + return Z_MEM_ERROR; + + /* build literal/length tree */ + r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v); + if (r != Z_OK || *bl == 0) + { + if (r == Z_DATA_ERROR) + z->msg = (char*)"oversubscribed literal/length tree"; + else if (r != Z_MEM_ERROR) + { + z->msg = (char*)"incomplete literal/length tree"; + r = Z_DATA_ERROR; + } + ZFREE(z, v); + return r; + } + + /* build distance tree */ + r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v); + if (r != Z_OK || (*bd == 0 && nl > 257)) + { + if (r == Z_DATA_ERROR) + z->msg = (char*)"oversubscribed distance tree"; + else if (r == Z_BUF_ERROR) { +#ifdef PKZIP_BUG_WORKAROUND + r = Z_OK; + } +#else + z->msg = (char*)"incomplete distance tree"; + r = Z_DATA_ERROR; + } + else if (r != Z_MEM_ERROR) + { + z->msg = (char*)"empty distance tree with lengths"; + r = Z_DATA_ERROR; + } + ZFREE(z, v); + return r; +#endif + } + + /* done */ + ZFREE(z, v); + return Z_OK; +} + + +/* build fixed tables only once--keep them here */ +#ifdef BUILDFIXED +local int fixed_built = 0; +#define FIXEDH 544 /* number of hufts used by fixed tables */ +local inflate_huft fixed_mem[FIXEDH]; +local uInt fixed_bl; +local uInt fixed_bd; +local inflate_huft *fixed_tl; +local inflate_huft *fixed_td; +#else +#include "inffixed.h" +#endif + + +int inflate_trees_fixed(bl, bd, tl, td, z) +uIntf *bl; /* literal desired/actual bit depth */ +uIntf *bd; /* distance desired/actual bit depth */ +inflate_huft * FAR *tl; /* literal/length tree result */ +inflate_huft * FAR *td; /* distance tree result */ +z_streamp z; /* for memory allocation */ +{ +#ifdef BUILDFIXED + /* build fixed tables if not already */ + if (!fixed_built) + { + int k; /* temporary variable */ + uInt f = 0; /* number of hufts used in fixed_mem */ + uIntf *c; /* length list for huft_build */ + uIntf *v; /* work area for huft_build */ + + /* allocate memory */ + if ((c = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL) + return Z_MEM_ERROR; + if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL) + { + ZFREE(z, c); + return Z_MEM_ERROR; + } + + /* literal table */ + for (k = 0; k < 144; k++) + c[k] = 8; + for (; k < 256; k++) + c[k] = 9; + for (; k < 280; k++) + c[k] = 7; + for (; k < 288; k++) + c[k] = 8; + fixed_bl = 9; + huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl, + fixed_mem, &f, v); + + /* distance table */ + for (k = 0; k < 30; k++) + c[k] = 5; + fixed_bd = 5; + huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd, + fixed_mem, &f, v); + + /* done */ + ZFREE(z, v); + ZFREE(z, c); + fixed_built = 1; + } +#endif + *bl = fixed_bl; + *bd = fixed_bd; + *tl = fixed_tl; + *td = fixed_td; + return Z_OK; +} diff --git a/fceumm/src-fceumm/zlib/inftrees.h b/fceumm/src-fceumm/zlib/inftrees.h new file mode 100644 index 0000000..04b73b7 --- /dev/null +++ b/fceumm/src-fceumm/zlib/inftrees.h @@ -0,0 +1,58 @@ +/* inftrees.h -- header to use inftrees.c + * Copyright (C) 1995-2002 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* Huffman code lookup table entry--this entry is four bytes for machines + that have 16-bit pointers (e.g. PC's in the small or medium model). */ + +typedef struct inflate_huft_s FAR inflate_huft; + +struct inflate_huft_s { + union { + struct { + Byte Exop; /* number of extra bits or operation */ + Byte Bits; /* number of bits in this code or subcode */ + } what; + uInt pad; /* pad structure to a power of 2 (4 bytes for */ + } word; /* 16-bit, 8 bytes for 32-bit int's) */ + uInt base; /* literal, length base, distance base, + or table offset */ +}; + +/* Maximum size of dynamic tree. The maximum found in a long but non- + exhaustive search was 1004 huft structures (850 for length/literals + and 154 for distances, the latter actually the result of an + exhaustive search). The actual maximum is not known, but the + value below is more than safe. */ +#define MANY 1440 + +extern int inflate_trees_bits OF(( + uIntf *, /* 19 code lengths */ + uIntf *, /* bits tree desired/actual depth */ + inflate_huft * FAR *, /* bits tree result */ + inflate_huft *, /* space for trees */ + z_streamp)); /* for messages */ + +extern int inflate_trees_dynamic OF(( + uInt, /* number of literal/length codes */ + uInt, /* number of distance codes */ + uIntf *, /* that many (total) code lengths */ + uIntf *, /* literal desired/actual bit depth */ + uIntf *, /* distance desired/actual bit depth */ + inflate_huft * FAR *, /* literal/length tree result */ + inflate_huft * FAR *, /* distance tree result */ + inflate_huft *, /* space for trees */ + z_streamp)); /* for messages */ + +extern int inflate_trees_fixed OF(( + uIntf *, /* literal desired/actual bit depth */ + uIntf *, /* distance desired/actual bit depth */ + inflate_huft * FAR *, /* literal/length tree result */ + inflate_huft * FAR *, /* distance tree result */ + z_streamp)); /* for memory allocation */ diff --git a/fceumm/src-fceumm/zlib/infutil.c b/fceumm/src-fceumm/zlib/infutil.c new file mode 100644 index 0000000..9a07622 --- /dev/null +++ b/fceumm/src-fceumm/zlib/infutil.c @@ -0,0 +1,87 @@ +/* inflate_util.c -- data and routines common to blocks and codes + * Copyright (C) 1995-2002 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "zutil.h" +#include "infblock.h" +#include "inftrees.h" +#include "infcodes.h" +#include "infutil.h" + +struct inflate_codes_state {int dummy;}; /* for buggy compilers */ + +/* And'ing with mask[n] masks the lower n bits */ +uInt inflate_mask[17] = { + 0x0000, + 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, + 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff +}; + + +/* copy as much as possible from the sliding window to the output area */ +int inflate_flush(s, z, r) +inflate_blocks_statef *s; +z_streamp z; +int r; +{ + uInt n; + Bytef *p; + Bytef *q; + + /* local copies of source and destination pointers */ + p = z->next_out; + q = s->read; + + /* compute number of bytes to copy as far as end of window */ + n = (uInt)((q <= s->write ? s->write : s->end) - q); + if (n > z->avail_out) n = z->avail_out; + if (n && r == Z_BUF_ERROR) r = Z_OK; + + /* update counters */ + z->avail_out -= n; + z->total_out += n; + + /* update check information */ + if (s->checkfn != Z_NULL) + z->adler = s->check = (*s->checkfn)(s->check, q, n); + + /* copy as far as end of window */ + zmemcpy(p, q, n); + p += n; + q += n; + + /* see if more to copy at beginning of window */ + if (q == s->end) + { + /* wrap pointers */ + q = s->window; + if (s->write == s->end) + s->write = s->window; + + /* compute bytes to copy */ + n = (uInt)(s->write - q); + if (n > z->avail_out) n = z->avail_out; + if (n && r == Z_BUF_ERROR) r = Z_OK; + + /* update counters */ + z->avail_out -= n; + z->total_out += n; + + /* update check information */ + if (s->checkfn != Z_NULL) + z->adler = s->check = (*s->checkfn)(s->check, q, n); + + /* copy */ + zmemcpy(p, q, n); + p += n; + q += n; + } + + /* update pointers */ + z->next_out = p; + s->read = q; + + /* done */ + return r; +} diff --git a/fceumm/src-fceumm/zlib/infutil.h b/fceumm/src-fceumm/zlib/infutil.h new file mode 100644 index 0000000..4401df8 --- /dev/null +++ b/fceumm/src-fceumm/zlib/infutil.h @@ -0,0 +1,98 @@ +/* infutil.h -- types and macros common to blocks and codes + * Copyright (C) 1995-2002 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +#ifndef _INFUTIL_H +#define _INFUTIL_H + +typedef enum { + TYPE, /* get type bits (3, including end bit) */ + LENS, /* get lengths for stored */ + STORED, /* processing stored block */ + TABLE, /* get table lengths */ + BTREE, /* get bit lengths tree for a dynamic block */ + DTREE, /* get length, distance trees for a dynamic block */ + CODES, /* processing fixed or dynamic block */ + DRY, /* output remaining window bytes */ + DONE, /* finished last block, done */ + BAD} /* got a data error--stuck here */ +inflate_block_mode; + +/* inflate blocks semi-private state */ +struct inflate_blocks_state { + + /* mode */ + inflate_block_mode mode; /* current inflate_block mode */ + + /* mode dependent information */ + union { + uInt left; /* if STORED, bytes left to copy */ + struct { + uInt table; /* table lengths (14 bits) */ + uInt index; /* index into blens (or border) */ + uIntf *blens; /* bit lengths of codes */ + uInt bb; /* bit length tree depth */ + inflate_huft *tb; /* bit length decoding tree */ + } trees; /* if DTREE, decoding info for trees */ + struct { + inflate_codes_statef + *codes; + } decode; /* if CODES, current state */ + } sub; /* submode */ + uInt last; /* true if this block is the last block */ + + /* mode independent information */ + uInt bitk; /* bits in bit buffer */ + uLong bitb; /* bit buffer */ + inflate_huft *hufts; /* single malloc for tree space */ + Bytef *window; /* sliding window */ + Bytef *end; /* one byte after sliding window */ + Bytef *read; /* window read pointer */ + Bytef *write; /* window write pointer */ + check_func checkfn; /* check function */ + uLong check; /* check on output */ + +}; + + +/* defines for inflate input/output */ +/* update pointers and return */ +#define UPDBITS {s->bitb=b;s->bitk=k;} +#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;} +#define UPDOUT {s->write=q;} +#define UPDATE {UPDBITS UPDIN UPDOUT} +#define LEAVE {UPDATE return inflate_flush(s,z,r);} +/* get bytes and bits */ +#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;} +#define NEEDBYTE {if(n)r=Z_OK;else LEAVE} +#define NEXTBYTE (n--,*p++) +#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<>=(j);k-=(j);} +/* output bytes */ +#define WAVAIL (uInt)(qread?s->read-q-1:s->end-q) +#define LOADOUT {q=s->write;m=(uInt)WAVAIL;} +#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}} +#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT} +#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;} +#define OUTBYTE(a) {*q++=(Byte)(a);m--;} +/* load local pointers */ +#define LOAD {LOADIN LOADOUT} + +/* masks for lower bits (size given to avoid silly warnings with Visual C++) */ +extern uInt inflate_mask[17]; + +/* copy as much as possible from the sliding window to the output area */ +extern int inflate_flush OF(( + inflate_blocks_statef *, + z_streamp , + int)); + +struct internal_state {int dummy;}; /* for buggy compilers */ + +#endif diff --git a/fceumm/src-fceumm/zlib/trees.c b/fceumm/src-fceumm/zlib/trees.c new file mode 100644 index 0000000..c98b000 --- /dev/null +++ b/fceumm/src-fceumm/zlib/trees.c @@ -0,0 +1,1214 @@ +/* trees.c -- output deflated data using Huffman coding + * Copyright (C) 1995-2002 Jean-loup Gailly + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + * ALGORITHM + * + * The "deflation" process uses several Huffman trees. The more + * common source values are represented by shorter bit sequences. + * + * Each code tree is stored in a compressed form which is itself + * a Huffman encoding of the lengths of all the code strings (in + * ascending order by source values). The actual code strings are + * reconstructed from the lengths in the inflate process, as described + * in the deflate specification. + * + * REFERENCES + * + * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". + * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc + * + * Storer, James A. + * Data Compression: Methods and Theory, pp. 49-50. + * Computer Science Press, 1988. ISBN 0-7167-8156-5. + * + * Sedgewick, R. + * Algorithms, p290. + * Addison-Wesley, 1983. ISBN 0-201-06672-6. + */ + +/* @(#) $Id: trees.c,v 1.2 2002/03/13 17:45:56 xodnizel Exp $ */ + +/* #define GEN_TREES_H */ + +#include "deflate.h" + +#ifdef DEBUG +# include +#endif + +/* =========================================================================== + * Constants + */ + +#define MAX_BL_BITS 7 +/* Bit length codes must not exceed MAX_BL_BITS bits */ + +#define END_BLOCK 256 +/* end of block literal code */ + +#define REP_3_6 16 +/* repeat previous bit length 3-6 times (2 bits of repeat count) */ + +#define REPZ_3_10 17 +/* repeat a zero length 3-10 times (3 bits of repeat count) */ + +#define REPZ_11_138 18 +/* repeat a zero length 11-138 times (7 bits of repeat count) */ + +local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ + = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; + +local const int extra_dbits[D_CODES] /* extra bits for each distance code */ + = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; + +local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */ + = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; + +local const uch bl_order[BL_CODES] + = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; +/* The lengths of the bit length codes are sent in order of decreasing + * probability, to avoid transmitting the lengths for unused bit length codes. + */ + +#define Buf_size (8 * 2*sizeof(char)) +/* Number of bits used within bi_buf. (bi_buf might be implemented on + * more than 16 bits on some systems.) + */ + +/* =========================================================================== + * Local data. These are initialized only once. + */ + +#define DIST_CODE_LEN 512 /* see definition of array dist_code below */ + +#if defined(GEN_TREES_H) || !defined(STDC) +/* non ANSI compilers may not accept trees.h */ + +local ct_data static_ltree[L_CODES+2]; +/* The static literal tree. Since the bit lengths are imposed, there is no + * need for the L_CODES extra codes used during heap construction. However + * The codes 286 and 287 are needed to build a canonical tree (see _tr_init + * below). + */ + +local ct_data static_dtree[D_CODES]; +/* The static distance tree. (Actually a trivial tree since all codes use + * 5 bits.) + */ + +uch _dist_code[DIST_CODE_LEN]; +/* Distance codes. The first 256 values correspond to the distances + * 3 .. 258, the last 256 values correspond to the top 8 bits of + * the 15 bit distances. + */ + +uch _length_code[MAX_MATCH-MIN_MATCH+1]; +/* length code for each normalized match length (0 == MIN_MATCH) */ + +local int base_length[LENGTH_CODES]; +/* First normalized length for each code (0 = MIN_MATCH) */ + +local int base_dist[D_CODES]; +/* First normalized distance for each code (0 = distance of 1) */ + +#else +# include "trees.h" +#endif /* GEN_TREES_H */ + +struct static_tree_desc_s { + const ct_data *static_tree; /* static tree or NULL */ + const intf *extra_bits; /* extra bits for each code or NULL */ + int extra_base; /* base index for extra_bits */ + int elems; /* max number of elements in the tree */ + int max_length; /* max bit length for the codes */ +}; + +local static_tree_desc static_l_desc = +{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; + +local static_tree_desc static_d_desc = +{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; + +local static_tree_desc static_bl_desc = +{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; + +/* =========================================================================== + * Local (static) routines in this file. + */ + +local void tr_static_init OF((void)); +local void init_block OF((deflate_state *s)); +local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); +local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); +local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); +local void build_tree OF((deflate_state *s, tree_desc *desc)); +local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); +local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); +local int build_bl_tree OF((deflate_state *s)); +local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, + int blcodes)); +local void compress_block OF((deflate_state *s, ct_data *ltree, + ct_data *dtree)); +local void set_data_type OF((deflate_state *s)); +local unsigned bi_reverse OF((unsigned value, int length)); +local void bi_windup OF((deflate_state *s)); +local void bi_flush OF((deflate_state *s)); +local void copy_block OF((deflate_state *s, charf *buf, unsigned len, + int header)); + +#ifdef GEN_TREES_H +local void gen_trees_header OF((void)); +#endif + +#ifndef DEBUG +# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) + /* Send a code of the given tree. c and tree must not have side effects */ + +#else /* DEBUG */ +# define send_code(s, c, tree) \ + { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ + send_bits(s, tree[c].Code, tree[c].Len); } +#endif + +/* =========================================================================== + * Output a short LSB first on the stream. + * IN assertion: there is enough room in pendingBuf. + */ +#define put_short(s, w) { \ + put_byte(s, (uch)((w) & 0xff)); \ + put_byte(s, (uch)((ush)(w) >> 8)); \ +} + +/* =========================================================================== + * Send a value on a given number of bits. + * IN assertion: length <= 16 and value fits in length bits. + */ +#ifdef DEBUG +local void send_bits OF((deflate_state *s, int value, int length)); + +local void send_bits(s, value, length) + deflate_state *s; + int value; /* value to send */ + int length; /* number of bits */ +{ + Tracevv((stderr," l %2d v %4x ", length, value)); + Assert(length > 0 && length <= 15, "invalid length"); + s->bits_sent += (ulg)length; + + /* If not enough room in bi_buf, use (valid) bits from bi_buf and + * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid)) + * unused bits in value. + */ + if (s->bi_valid > (int)Buf_size - length) { + s->bi_buf |= (value << s->bi_valid); + put_short(s, s->bi_buf); + s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); + s->bi_valid += length - Buf_size; + } else { + s->bi_buf |= value << s->bi_valid; + s->bi_valid += length; + } +} +#else /* !DEBUG */ + +#define send_bits(s, value, length) \ +{ int len = length;\ + if (s->bi_valid > (int)Buf_size - len) {\ + int val = value;\ + s->bi_buf |= (val << s->bi_valid);\ + put_short(s, s->bi_buf);\ + s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ + s->bi_valid += len - Buf_size;\ + } else {\ + s->bi_buf |= (value) << s->bi_valid;\ + s->bi_valid += len;\ + }\ +} +#endif /* DEBUG */ + + +#define MAX(a,b) (a >= b ? a : b) +/* the arguments must not have side effects */ + +/* =========================================================================== + * Initialize the various 'constant' tables. + */ +local void tr_static_init() +{ +#if defined(GEN_TREES_H) || !defined(STDC) + static int static_init_done = 0; + int n; /* iterates over tree elements */ + int bits; /* bit counter */ + int length; /* length value */ + int code; /* code value */ + int dist; /* distance index */ + ush bl_count[MAX_BITS+1]; + /* number of codes at each bit length for an optimal tree */ + + if (static_init_done) return; + + /* For some embedded targets, global variables are not initialized: */ + static_l_desc.static_tree = static_ltree; + static_l_desc.extra_bits = extra_lbits; + static_d_desc.static_tree = static_dtree; + static_d_desc.extra_bits = extra_dbits; + static_bl_desc.extra_bits = extra_blbits; + + /* Initialize the mapping length (0..255) -> length code (0..28) */ + length = 0; + for (code = 0; code < LENGTH_CODES-1; code++) { + base_length[code] = length; + for (n = 0; n < (1< dist code (0..29) */ + dist = 0; + for (code = 0 ; code < 16; code++) { + base_dist[code] = dist; + for (n = 0; n < (1<>= 7; /* from now on, all distances are divided by 128 */ + for ( ; code < D_CODES; code++) { + base_dist[code] = dist << 7; + for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { + _dist_code[256 + dist++] = (uch)code; + } + } + Assert (dist == 256, "tr_static_init: 256+dist != 512"); + + /* Construct the codes of the static literal tree */ + for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; + n = 0; + while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++; + while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++; + while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++; + while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++; + /* Codes 286 and 287 do not exist, but we must include them in the + * tree construction to get a canonical Huffman tree (longest code + * all ones) + */ + gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count); + + /* The static distance tree is trivial: */ + for (n = 0; n < D_CODES; n++) { + static_dtree[n].Len = 5; + static_dtree[n].Code = bi_reverse((unsigned)n, 5); + } + static_init_done = 1; + +# ifdef GEN_TREES_H + gen_trees_header(); +# endif +#endif /* defined(GEN_TREES_H) || !defined(STDC) */ +} + +/* =========================================================================== + * Genererate the file trees.h describing the static trees. + */ +#ifdef GEN_TREES_H +# ifndef DEBUG +# include +# endif + +# define SEPARATOR(i, last, width) \ + ((i) == (last)? "\n};\n\n" : \ + ((i) % (width) == (width)-1 ? ",\n" : ", ")) + +void gen_trees_header() +{ + FILE *header = fopen("trees.h", "w"); + int i; + + Assert (header != NULL, "Can't open trees.h"); + fprintf(header, + "/* header created automatically with -DGEN_TREES_H */\n\n"); + + fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); + for (i = 0; i < L_CODES+2; i++) { + fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, + static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); + } + + fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); + for (i = 0; i < D_CODES; i++) { + fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, + static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); + } + + fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n"); + for (i = 0; i < DIST_CODE_LEN; i++) { + fprintf(header, "%2u%s", _dist_code[i], + SEPARATOR(i, DIST_CODE_LEN-1, 20)); + } + + fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); + for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { + fprintf(header, "%2u%s", _length_code[i], + SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); + } + + fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); + for (i = 0; i < LENGTH_CODES; i++) { + fprintf(header, "%1u%s", base_length[i], + SEPARATOR(i, LENGTH_CODES-1, 20)); + } + + fprintf(header, "local const int base_dist[D_CODES] = {\n"); + for (i = 0; i < D_CODES; i++) { + fprintf(header, "%5u%s", base_dist[i], + SEPARATOR(i, D_CODES-1, 10)); + } + + fclose(header); +} +#endif /* GEN_TREES_H */ + +/* =========================================================================== + * Initialize the tree data structures for a new zlib stream. + */ +void _tr_init(s) + deflate_state *s; +{ + tr_static_init(); + + s->l_desc.dyn_tree = s->dyn_ltree; + s->l_desc.stat_desc = &static_l_desc; + + s->d_desc.dyn_tree = s->dyn_dtree; + s->d_desc.stat_desc = &static_d_desc; + + s->bl_desc.dyn_tree = s->bl_tree; + s->bl_desc.stat_desc = &static_bl_desc; + + s->bi_buf = 0; + s->bi_valid = 0; + s->last_eob_len = 8; /* enough lookahead for inflate */ +#ifdef DEBUG + s->compressed_len = 0L; + s->bits_sent = 0L; +#endif + + /* Initialize the first block of the first file: */ + init_block(s); +} + +/* =========================================================================== + * Initialize a new block. + */ +local void init_block(s) + deflate_state *s; +{ + int n; /* iterates over tree elements */ + + /* Initialize the trees. */ + for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; + for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; + for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; + + s->dyn_ltree[END_BLOCK].Freq = 1; + s->opt_len = s->static_len = 0L; + s->last_lit = s->matches = 0; +} + +#define SMALLEST 1 +/* Index within the heap array of least frequent node in the Huffman tree */ + + +/* =========================================================================== + * Remove the smallest element from the heap and recreate the heap with + * one less element. Updates heap and heap_len. + */ +#define pqremove(s, tree, top) \ +{\ + top = s->heap[SMALLEST]; \ + s->heap[SMALLEST] = s->heap[s->heap_len--]; \ + pqdownheap(s, tree, SMALLEST); \ +} + +/* =========================================================================== + * Compares to subtrees, using the tree depth as tie breaker when + * the subtrees have equal frequency. This minimizes the worst case length. + */ +#define smaller(tree, n, m, depth) \ + (tree[n].Freq < tree[m].Freq || \ + (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) + +/* =========================================================================== + * Restore the heap property by moving down the tree starting at node k, + * exchanging a node with the smallest of its two sons if necessary, stopping + * when the heap property is re-established (each father smaller than its + * two sons). + */ +local void pqdownheap(s, tree, k) + deflate_state *s; + ct_data *tree; /* the tree to restore */ + int k; /* node to move down */ +{ + int v = s->heap[k]; + int j = k << 1; /* left son of k */ + while (j <= s->heap_len) { + /* Set j to the smallest of the two sons: */ + if (j < s->heap_len && + smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { + j++; + } + /* Exit if v is smaller than both sons */ + if (smaller(tree, v, s->heap[j], s->depth)) break; + + /* Exchange v with the smallest son */ + s->heap[k] = s->heap[j]; k = j; + + /* And continue down the tree, setting j to the left son of k */ + j <<= 1; + } + s->heap[k] = v; +} + +/* =========================================================================== + * Compute the optimal bit lengths for a tree and update the total bit length + * for the current block. + * IN assertion: the fields freq and dad are set, heap[heap_max] and + * above are the tree nodes sorted by increasing frequency. + * OUT assertions: the field len is set to the optimal bit length, the + * array bl_count contains the frequencies for each bit length. + * The length opt_len is updated; static_len is also updated if stree is + * not null. + */ +local void gen_bitlen(s, desc) + deflate_state *s; + tree_desc *desc; /* the tree descriptor */ +{ + ct_data *tree = desc->dyn_tree; + int max_code = desc->max_code; + const ct_data *stree = desc->stat_desc->static_tree; + const intf *extra = desc->stat_desc->extra_bits; + int base = desc->stat_desc->extra_base; + int max_length = desc->stat_desc->max_length; + int h; /* heap index */ + int n, m; /* iterate over the tree elements */ + int bits; /* bit length */ + int xbits; /* extra bits */ + ush f; /* frequency */ + int overflow = 0; /* number of elements with bit length too large */ + + for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; + + /* In a first pass, compute the optimal bit lengths (which may + * overflow in the case of the bit length tree). + */ + tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ + + for (h = s->heap_max+1; h < HEAP_SIZE; h++) { + n = s->heap[h]; + bits = tree[tree[n].Dad].Len + 1; + if (bits > max_length) bits = max_length, overflow++; + tree[n].Len = (ush)bits; + /* We overwrite tree[n].Dad which is no longer needed */ + + if (n > max_code) continue; /* not a leaf node */ + + s->bl_count[bits]++; + xbits = 0; + if (n >= base) xbits = extra[n-base]; + f = tree[n].Freq; + s->opt_len += (ulg)f * (bits + xbits); + if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); + } + if (overflow == 0) return; + + Trace((stderr,"\nbit length overflow\n")); + /* This happens for example on obj2 and pic of the Calgary corpus */ + + /* Find the first bit length which could increase: */ + do { + bits = max_length-1; + while (s->bl_count[bits] == 0) bits--; + s->bl_count[bits]--; /* move one leaf down the tree */ + s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ + s->bl_count[max_length]--; + /* The brother of the overflow item also moves one step up, + * but this does not affect bl_count[max_length] + */ + overflow -= 2; + } while (overflow > 0); + + /* Now recompute all bit lengths, scanning in increasing frequency. + * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all + * lengths instead of fixing only the wrong ones. This idea is taken + * from 'ar' written by Haruhiko Okumura.) + */ + for (bits = max_length; bits != 0; bits--) { + n = s->bl_count[bits]; + while (n != 0) { + m = s->heap[--h]; + if (m > max_code) continue; + if (tree[m].Len != (unsigned) bits) { + Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); + s->opt_len += ((long)bits - (long)tree[m].Len) + *(long)tree[m].Freq; + tree[m].Len = (ush)bits; + } + n--; + } + } +} + +/* =========================================================================== + * Generate the codes for a given tree and bit counts (which need not be + * optimal). + * IN assertion: the array bl_count contains the bit length statistics for + * the given tree and the field len is set for all tree elements. + * OUT assertion: the field code is set for all tree elements of non + * zero code length. + */ +local void gen_codes (tree, max_code, bl_count) + ct_data *tree; /* the tree to decorate */ + int max_code; /* largest code with non zero frequency */ + ushf *bl_count; /* number of codes at each bit length */ +{ + ush next_code[MAX_BITS+1]; /* next code value for each bit length */ + ush code = 0; /* running code value */ + int bits; /* bit index */ + int n; /* code index */ + + /* The distribution counts are first used to generate the code values + * without bit reversal. + */ + for (bits = 1; bits <= MAX_BITS; bits++) { + next_code[bits] = code = (code + bl_count[bits-1]) << 1; + } + /* Check that the bit counts in bl_count are consistent. The last code + * must be all ones. + */ + Assert (code + bl_count[MAX_BITS]-1 == (1<dyn_tree; + const ct_data *stree = desc->stat_desc->static_tree; + int elems = desc->stat_desc->elems; + int n, m; /* iterate over heap elements */ + int max_code = -1; /* largest code with non zero frequency */ + int node; /* new node being created */ + + /* Construct the initial heap, with least frequent element in + * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. + * heap[0] is not used. + */ + s->heap_len = 0, s->heap_max = HEAP_SIZE; + + for (n = 0; n < elems; n++) { + if (tree[n].Freq != 0) { + s->heap[++(s->heap_len)] = max_code = n; + s->depth[n] = 0; + } else { + tree[n].Len = 0; + } + } + + /* The pkzip format requires that at least one distance code exists, + * and that at least one bit should be sent even if there is only one + * possible code. So to avoid special checks later on we force at least + * two codes of non zero frequency. + */ + while (s->heap_len < 2) { + node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); + tree[node].Freq = 1; + s->depth[node] = 0; + s->opt_len--; if (stree) s->static_len -= stree[node].Len; + /* node is 0 or 1 so it does not have extra bits */ + } + desc->max_code = max_code; + + /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, + * establish sub-heaps of increasing lengths: + */ + for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); + + /* Construct the Huffman tree by repeatedly combining the least two + * frequent nodes. + */ + node = elems; /* next internal node of the tree */ + do { + pqremove(s, tree, n); /* n = node of least frequency */ + m = s->heap[SMALLEST]; /* m = node of next least frequency */ + + s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */ + s->heap[--(s->heap_max)] = m; + + /* Create a new node father of n and m */ + tree[node].Freq = tree[n].Freq + tree[m].Freq; + s->depth[node] = (uch) (MAX(s->depth[n], s->depth[m]) + 1); + tree[n].Dad = tree[m].Dad = (ush)node; +#ifdef DUMP_BL_TREE + if (tree == s->bl_tree) { + fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", + node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); + } +#endif + /* and insert the new node in the heap */ + s->heap[SMALLEST] = node++; + pqdownheap(s, tree, SMALLEST); + + } while (s->heap_len >= 2); + + s->heap[--(s->heap_max)] = s->heap[SMALLEST]; + + /* At this point, the fields freq and dad are set. We can now + * generate the bit lengths. + */ + gen_bitlen(s, (tree_desc *)desc); + + /* The field len is now set, we can generate the bit codes */ + gen_codes ((ct_data *)tree, max_code, s->bl_count); +} + +/* =========================================================================== + * Scan a literal or distance tree to determine the frequencies of the codes + * in the bit length tree. + */ +local void scan_tree (s, tree, max_code) + deflate_state *s; + ct_data *tree; /* the tree to be scanned */ + int max_code; /* and its largest code of non zero frequency */ +{ + int n; /* iterates over all tree elements */ + int prevlen = -1; /* last emitted length */ + int curlen; /* length of current code */ + int nextlen = tree[0].Len; /* length of next code */ + int count = 0; /* repeat count of the current code */ + int max_count = 7; /* max repeat count */ + int min_count = 4; /* min repeat count */ + + if (nextlen == 0) max_count = 138, min_count = 3; + tree[max_code+1].Len = (ush)0xffff; /* guard */ + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; nextlen = tree[n+1].Len; + if (++count < max_count && curlen == nextlen) { + continue; + } else if (count < min_count) { + s->bl_tree[curlen].Freq += count; + } else if (curlen != 0) { + if (curlen != prevlen) s->bl_tree[curlen].Freq++; + s->bl_tree[REP_3_6].Freq++; + } else if (count <= 10) { + s->bl_tree[REPZ_3_10].Freq++; + } else { + s->bl_tree[REPZ_11_138].Freq++; + } + count = 0; prevlen = curlen; + if (nextlen == 0) { + max_count = 138, min_count = 3; + } else if (curlen == nextlen) { + max_count = 6, min_count = 3; + } else { + max_count = 7, min_count = 4; + } + } +} + +/* =========================================================================== + * Send a literal or distance tree in compressed form, using the codes in + * bl_tree. + */ +local void send_tree (s, tree, max_code) + deflate_state *s; + ct_data *tree; /* the tree to be scanned */ + int max_code; /* and its largest code of non zero frequency */ +{ + int n; /* iterates over all tree elements */ + int prevlen = -1; /* last emitted length */ + int curlen; /* length of current code */ + int nextlen = tree[0].Len; /* length of next code */ + int count = 0; /* repeat count of the current code */ + int max_count = 7; /* max repeat count */ + int min_count = 4; /* min repeat count */ + + /* tree[max_code+1].Len = -1; */ /* guard already set */ + if (nextlen == 0) max_count = 138, min_count = 3; + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; nextlen = tree[n+1].Len; + if (++count < max_count && curlen == nextlen) { + continue; + } else if (count < min_count) { + do { send_code(s, curlen, s->bl_tree); } while (--count != 0); + + } else if (curlen != 0) { + if (curlen != prevlen) { + send_code(s, curlen, s->bl_tree); count--; + } + Assert(count >= 3 && count <= 6, " 3_6?"); + send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); + + } else if (count <= 10) { + send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3); + + } else { + send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7); + } + count = 0; prevlen = curlen; + if (nextlen == 0) { + max_count = 138, min_count = 3; + } else if (curlen == nextlen) { + max_count = 6, min_count = 3; + } else { + max_count = 7, min_count = 4; + } + } +} + +/* =========================================================================== + * Construct the Huffman tree for the bit lengths and return the index in + * bl_order of the last bit length code to send. + */ +local int build_bl_tree(s) + deflate_state *s; +{ + int max_blindex; /* index of last bit length code of non zero freq */ + + /* Determine the bit length frequencies for literal and distance trees */ + scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code); + scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code); + + /* Build the bit length tree: */ + build_tree(s, (tree_desc *)(&(s->bl_desc))); + /* opt_len now includes the length of the tree representations, except + * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. + */ + + /* Determine the number of bit length codes to send. The pkzip format + * requires that at least 4 bit length codes be sent. (appnote.txt says + * 3 but the actual value used is 4.) + */ + for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { + if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; + } + /* Update opt_len to include the bit length tree and counts */ + s->opt_len += 3*(max_blindex+1) + 5+5+4; + Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", + s->opt_len, s->static_len)); + + return max_blindex; +} + +/* =========================================================================== + * Send the header for a block using dynamic Huffman trees: the counts, the + * lengths of the bit length codes, the literal tree and the distance tree. + * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. + */ +local void send_all_trees(s, lcodes, dcodes, blcodes) + deflate_state *s; + int lcodes, dcodes, blcodes; /* number of codes for each tree */ +{ + int rank; /* index in bl_order */ + + Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); + Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, + "too many codes"); + Tracev((stderr, "\nbl counts: ")); + send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ + send_bits(s, dcodes-1, 5); + send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ + for (rank = 0; rank < blcodes; rank++) { + Tracev((stderr, "\nbl code %2d ", bl_order[rank])); + send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); + } + Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); + + send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ + Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); + + send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ + Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); +} + +/* =========================================================================== + * Send a stored block + */ +void _tr_stored_block(s, buf, stored_len, eof) + deflate_state *s; + charf *buf; /* input block */ + ulg stored_len; /* length of input block */ + int eof; /* true if this is the last block for a file */ +{ + send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */ +#ifdef DEBUG + s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; + s->compressed_len += (stored_len + 4) << 3; +#endif + copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ +} + +/* =========================================================================== + * Send one empty static block to give enough lookahead for inflate. + * This takes 10 bits, of which 7 may remain in the bit buffer. + * The current inflate code requires 9 bits of lookahead. If the + * last two codes for the previous block (real code plus EOB) were coded + * on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode + * the last real code. In this case we send two empty static blocks instead + * of one. (There are no problems if the previous block is stored or fixed.) + * To simplify the code, we assume the worst case of last real code encoded + * on one bit only. + */ +void _tr_align(s) + deflate_state *s; +{ + send_bits(s, STATIC_TREES<<1, 3); + send_code(s, END_BLOCK, static_ltree); +#ifdef DEBUG + s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ +#endif + bi_flush(s); + /* Of the 10 bits for the empty block, we have already sent + * (10 - bi_valid) bits. The lookahead for the last real code (before + * the EOB of the previous block) was thus at least one plus the length + * of the EOB plus what we have just sent of the empty static block. + */ + if (1 + s->last_eob_len + 10 - s->bi_valid < 9) { + send_bits(s, STATIC_TREES<<1, 3); + send_code(s, END_BLOCK, static_ltree); +#ifdef DEBUG + s->compressed_len += 10L; +#endif + bi_flush(s); + } + s->last_eob_len = 7; +} + +/* =========================================================================== + * Determine the best encoding for the current block: dynamic trees, static + * trees or store, and output the encoded block to the zip file. + */ +void _tr_flush_block(s, buf, stored_len, eof) + deflate_state *s; + charf *buf; /* input block, or NULL if too old */ + ulg stored_len; /* length of input block */ + int eof; /* true if this is the last block for a file */ +{ + ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ + int max_blindex = 0; /* index of last bit length code of non zero freq */ + + /* Build the Huffman trees unless a stored block is forced */ + if (s->level > 0) { + + /* Check if the file is ascii or binary */ + if (s->data_type == Z_UNKNOWN) set_data_type(s); + + /* Construct the literal and distance trees */ + build_tree(s, (tree_desc *)(&(s->l_desc))); + Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, + s->static_len)); + + build_tree(s, (tree_desc *)(&(s->d_desc))); + Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, + s->static_len)); + /* At this point, opt_len and static_len are the total bit lengths of + * the compressed block data, excluding the tree representations. + */ + + /* Build the bit length tree for the above two trees, and get the index + * in bl_order of the last bit length code to send. + */ + max_blindex = build_bl_tree(s); + + /* Determine the best encoding. Compute first the block length in bytes*/ + opt_lenb = (s->opt_len+3+7)>>3; + static_lenb = (s->static_len+3+7)>>3; + + Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", + opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, + s->last_lit)); + + if (static_lenb <= opt_lenb) opt_lenb = static_lenb; + + } else { + Assert(buf != (char*)0, "lost buf"); + opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ + } + +#ifdef FORCE_STORED + if (buf != (char*)0) { /* force stored block */ +#else + if (stored_len+4 <= opt_lenb && buf != (char*)0) { + /* 4: two words for the lengths */ +#endif + /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. + * Otherwise we can't have processed more than WSIZE input bytes since + * the last block flush, because compression would have been + * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to + * transform a block into a stored block. + */ + _tr_stored_block(s, buf, stored_len, eof); + +#ifdef FORCE_STATIC + } else if (static_lenb >= 0) { /* force static trees */ +#else + } else if (static_lenb == opt_lenb) { +#endif + send_bits(s, (STATIC_TREES<<1)+eof, 3); + compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); +#ifdef DEBUG + s->compressed_len += 3 + s->static_len; +#endif + } else { + send_bits(s, (DYN_TREES<<1)+eof, 3); + send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, + max_blindex+1); + compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree); +#ifdef DEBUG + s->compressed_len += 3 + s->opt_len; +#endif + } + Assert (s->compressed_len == s->bits_sent, "bad compressed size"); + /* The above check is made mod 2^32, for files larger than 512 MB + * and uLong implemented on 32 bits. + */ + init_block(s); + + if (eof) { + bi_windup(s); +#ifdef DEBUG + s->compressed_len += 7; /* align on byte boundary */ +#endif + } + Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, + s->compressed_len-7*eof)); +} + +/* =========================================================================== + * Save the match info and tally the frequency counts. Return true if + * the current block must be flushed. + */ +int _tr_tally (s, dist, lc) + deflate_state *s; + unsigned dist; /* distance of matched string */ + unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ +{ + s->d_buf[s->last_lit] = (ush)dist; + s->l_buf[s->last_lit++] = (uch)lc; + if (dist == 0) { + /* lc is the unmatched char */ + s->dyn_ltree[lc].Freq++; + } else { + s->matches++; + /* Here, lc is the match length - MIN_MATCH */ + dist--; /* dist = match distance - 1 */ + Assert((ush)dist < (ush)MAX_DIST(s) && + (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && + (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); + + s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; + s->dyn_dtree[d_code(dist)].Freq++; + } + +#ifdef TRUNCATE_BLOCK + /* Try to guess if it is profitable to stop the current block here */ + if ((s->last_lit & 0x1fff) == 0 && s->level > 2) { + /* Compute an upper bound for the compressed length */ + ulg out_length = (ulg)s->last_lit*8L; + ulg in_length = (ulg)((long)s->strstart - s->block_start); + int dcode; + for (dcode = 0; dcode < D_CODES; dcode++) { + out_length += (ulg)s->dyn_dtree[dcode].Freq * + (5L+extra_dbits[dcode]); + } + out_length >>= 3; + Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", + s->last_lit, in_length, out_length, + 100L - out_length*100L/in_length)); + if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1; + } +#endif + return (s->last_lit == s->lit_bufsize-1); + /* We avoid equality with lit_bufsize because of wraparound at 64K + * on 16 bit machines and because stored blocks are restricted to + * 64K-1 bytes. + */ +} + +/* =========================================================================== + * Send the block data compressed using the given Huffman trees + */ +local void compress_block(s, ltree, dtree) + deflate_state *s; + ct_data *ltree; /* literal tree */ + ct_data *dtree; /* distance tree */ +{ + unsigned dist; /* distance of matched string */ + int lc; /* match length or unmatched char (if dist == 0) */ + unsigned lx = 0; /* running index in l_buf */ + unsigned code; /* the code to send */ + int extra; /* number of extra bits to send */ + + if (s->last_lit != 0) do { + dist = s->d_buf[lx]; + lc = s->l_buf[lx++]; + if (dist == 0) { + send_code(s, lc, ltree); /* send a literal byte */ + Tracecv(isgraph(lc), (stderr," '%c' ", lc)); + } else { + /* Here, lc is the match length - MIN_MATCH */ + code = _length_code[lc]; + send_code(s, code+LITERALS+1, ltree); /* send the length code */ + extra = extra_lbits[code]; + if (extra != 0) { + lc -= base_length[code]; + send_bits(s, lc, extra); /* send the extra length bits */ + } + dist--; /* dist is now the match distance - 1 */ + code = d_code(dist); + Assert (code < D_CODES, "bad d_code"); + + send_code(s, code, dtree); /* send the distance code */ + extra = extra_dbits[code]; + if (extra != 0) { + dist -= base_dist[code]; + send_bits(s, dist, extra); /* send the extra distance bits */ + } + } /* literal or match pair ? */ + + /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ + Assert(s->pending < s->lit_bufsize + 2*lx, "pendingBuf overflow"); + + } while (lx < s->last_lit); + + send_code(s, END_BLOCK, ltree); + s->last_eob_len = ltree[END_BLOCK].Len; +} + +/* =========================================================================== + * Set the data type to ASCII or BINARY, using a crude approximation: + * binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise. + * IN assertion: the fields freq of dyn_ltree are set and the total of all + * frequencies does not exceed 64K (to fit in an int on 16 bit machines). + */ +local void set_data_type(s) + deflate_state *s; +{ + int n = 0; + unsigned ascii_freq = 0; + unsigned bin_freq = 0; + while (n < 7) bin_freq += s->dyn_ltree[n++].Freq; + while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq; + while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq; + s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII); +} + +/* =========================================================================== + * Reverse the first len bits of a code, using straightforward code (a faster + * method would use a table) + * IN assertion: 1 <= len <= 15 + */ +local unsigned bi_reverse(code, len) + unsigned code; /* the value to invert */ + int len; /* its bit length */ +{ + register unsigned res = 0; + do { + res |= code & 1; + code >>= 1, res <<= 1; + } while (--len > 0); + return res >> 1; +} + +/* =========================================================================== + * Flush the bit buffer, keeping at most 7 bits in it. + */ +local void bi_flush(s) + deflate_state *s; +{ + if (s->bi_valid == 16) { + put_short(s, s->bi_buf); + s->bi_buf = 0; + s->bi_valid = 0; + } else if (s->bi_valid >= 8) { + put_byte(s, (Byte)s->bi_buf); + s->bi_buf >>= 8; + s->bi_valid -= 8; + } +} + +/* =========================================================================== + * Flush the bit buffer and align the output on a byte boundary + */ +local void bi_windup(s) + deflate_state *s; +{ + if (s->bi_valid > 8) { + put_short(s, s->bi_buf); + } else if (s->bi_valid > 0) { + put_byte(s, (Byte)s->bi_buf); + } + s->bi_buf = 0; + s->bi_valid = 0; +#ifdef DEBUG + s->bits_sent = (s->bits_sent+7) & ~7; +#endif +} + +/* =========================================================================== + * Copy a stored block, storing first the length and its + * one's complement if requested. + */ +local void copy_block(s, buf, len, header) + deflate_state *s; + charf *buf; /* the input data */ + unsigned len; /* its length */ + int header; /* true if block header must be written */ +{ + bi_windup(s); /* align on byte boundary */ + s->last_eob_len = 8; /* enough lookahead for inflate */ + + if (header) { + put_short(s, (ush)len); + put_short(s, (ush)~len); +#ifdef DEBUG + s->bits_sent += 2*16; +#endif + } +#ifdef DEBUG + s->bits_sent += (ulg)len<<3; +#endif + while (len--) { + put_byte(s, *buf++); + } +} diff --git a/fceumm/src-fceumm/zlib/trees.h b/fceumm/src-fceumm/zlib/trees.h new file mode 100644 index 0000000..72facf9 --- /dev/null +++ b/fceumm/src-fceumm/zlib/trees.h @@ -0,0 +1,128 @@ +/* header created automatically with -DGEN_TREES_H */ + +local const ct_data static_ltree[L_CODES+2] = { +{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, +{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, +{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, +{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, +{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, +{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, +{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, +{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, +{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, +{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, +{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, +{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, +{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, +{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, +{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, +{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, +{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, +{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, +{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, +{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, +{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, +{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, +{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, +{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, +{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, +{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, +{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, +{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, +{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, +{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, +{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, +{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, +{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, +{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, +{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, +{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, +{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, +{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, +{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, +{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, +{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, +{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, +{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, +{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, +{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, +{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, +{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, +{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, +{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, +{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, +{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, +{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, +{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, +{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, +{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, +{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, +{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, +{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} +}; + +local const ct_data static_dtree[D_CODES] = { +{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, +{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, +{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, +{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, +{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, +{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} +}; + +const uch _dist_code[DIST_CODE_LEN] = { + 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, + 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, +10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, +11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, +12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, +13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, +13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, +18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, +23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, +24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, +27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, +27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, +28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, +28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, +28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 +}; + +const uch _length_code[MAX_MATCH-MIN_MATCH+1]= { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, +13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, +17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, +19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, +21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, +22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, +23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, +24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, +25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, +25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, +26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, +27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 +}; + +local const int base_length[LENGTH_CODES] = { +0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, +64, 80, 96, 112, 128, 160, 192, 224, 0 +}; + +local const int base_dist[D_CODES] = { + 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, + 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, + 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 +}; + diff --git a/fceumm/src-fceumm/zlib/uncompr.c b/fceumm/src-fceumm/zlib/uncompr.c new file mode 100644 index 0000000..3a71259 --- /dev/null +++ b/fceumm/src-fceumm/zlib/uncompr.c @@ -0,0 +1,58 @@ +/* uncompr.c -- decompress a memory buffer + * Copyright (C) 1995-2002 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: uncompr.c,v 1.2 2002/03/13 17:45:56 xodnizel Exp $ */ + +#include "zlib.h" + +/* =========================================================================== + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total + size of the destination buffer, which must be large enough to hold the + entire uncompressed data. (The size of the uncompressed data must have + been saved previously by the compressor and transmitted to the decompressor + by some mechanism outside the scope of this compression library.) + Upon exit, destLen is the actual size of the compressed buffer. + This function can be used to decompress a whole file at once if the + input file is mmap'ed. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted. +*/ +int ZEXPORT uncompress (dest, destLen, source, sourceLen) + Bytef *dest; + uLongf *destLen; + const Bytef *source; + uLong sourceLen; +{ + z_stream stream; + int err; + + stream.next_in = (Bytef*)source; + stream.avail_in = (uInt)sourceLen; + /* Check for source > 64K on 16-bit machine: */ + if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; + + stream.next_out = dest; + stream.avail_out = (uInt)*destLen; + if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; + + stream.zalloc = (alloc_func)0; + stream.zfree = (free_func)0; + + err = inflateInit(&stream); + if (err != Z_OK) return err; + + err = inflate(&stream, Z_FINISH); + if (err != Z_STREAM_END) { + inflateEnd(&stream); + return err == Z_OK ? Z_BUF_ERROR : err; + } + *destLen = stream.total_out; + + err = inflateEnd(&stream); + return err; +} diff --git a/fceumm/src-fceumm/zlib/unzip.c b/fceumm/src-fceumm/zlib/unzip.c new file mode 100644 index 0000000..d156fae --- /dev/null +++ b/fceumm/src-fceumm/zlib/unzip.c @@ -0,0 +1,1301 @@ +/* unzip.c -- IO on .zip files using zlib + Version 0.15 beta, Mar 19th, 1998, + + Read unzip.h for more info +*/ + + +#include +#include +#include +#include "zlib.h" +#include "unzip.h" + +#ifdef STDC +# include +# include +# include +#endif +#ifdef NO_ERRNO_H + extern int errno; +#else +# include +#endif + + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + + + +#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \ + !defined(CASESENSITIVITYDEFAULT_NO) +#define CASESENSITIVITYDEFAULT_NO +#endif + + +#ifndef UNZ_BUFSIZE +#define UNZ_BUFSIZE (16384) +#endif + +#ifndef UNZ_MAXFILENAMEINZIP +#define UNZ_MAXFILENAMEINZIP (256) +#endif + +#ifndef ALLOC +# define ALLOC(size) (malloc(size)) +#endif +#ifndef TRYFREE +# define TRYFREE(p) {if (p) free(p);} +#endif + +#define SIZECENTRALDIRITEM (0x2e) +#define SIZEZIPLOCALHEADER (0x1e) + + +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +const char unz_copyright[] = + " unzip 0.15 Copyright 1998 Gilles Vollant "; + +/* unz_file_info_interntal contain internal info about a file in zipfile*/ +typedef struct unz_file_info_internal_s +{ + uLong offset_curfile;/* relative offset of local header 4 bytes */ +} unz_file_info_internal; + + +/* file_in_zip_read_info_s contain internal information about a file in zipfile, + when reading and decompress it */ +typedef struct +{ + char *read_buffer; /* internal buffer for compressed data */ + z_stream stream; /* zLib stream structure for inflate */ + + uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ + uLong stream_initialised; /* flag set if stream structure is initialised*/ + + uLong offset_local_extrafield;/* offset of the local extra field */ + uInt size_local_extrafield;/* size of the local extra field */ + uLong pos_local_extrafield; /* position in the local extra field in read*/ + + uLong crc32; /* crc32 of all data uncompressed */ + uLong crc32_wait; /* crc32 we must obtain after decompress all */ + uLong rest_read_compressed; /* number of byte to be decompressed */ + uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ + FILE* file; /* io structore of the zipfile */ + uLong compression_method; /* compression method (0==store) */ + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ +} file_in_zip_read_info_s; + + +/* unz_s contain internal information about the zipfile +*/ +typedef struct +{ + FILE* file; /* io structore of the zipfile */ + unz_global_info gi; /* public global information */ + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ + uLong num_file; /* number of the current file in the zipfile*/ + uLong pos_in_central_dir; /* pos of the current file in the central dir*/ + uLong current_file_ok; /* flag about the usability of the current file*/ + uLong central_pos; /* position of the beginning of the central dir*/ + + uLong size_central_dir; /* size of the central directory */ + uLong offset_central_dir; /* offset of start of central directory with + respect to the starting disk number */ + + unz_file_info cur_file_info; /* public info about the current file in zip*/ + unz_file_info_internal cur_file_info_internal; /* private info about it*/ + file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current + file if we are decompressing it */ +} unz_s; + + +/* =========================================================================== + Read a byte from a gz_stream; update next_in and avail_in. Return EOF + for end of file. + IN assertion: the stream s has been sucessfully opened for reading. +*/ + + +local int unzlocal_getByte(fin,pi) + FILE *fin; + int *pi; +{ + unsigned char c; + int err = fread(&c, 1, 1, fin); + if (err==1) + { + *pi = (int)c; + return UNZ_OK; + } + else + { + if (ferror(fin)) + return UNZ_ERRNO; + else + return UNZ_EOF; + } +} + + +/* =========================================================================== + Reads a long in LSB order from the given gz_stream. Sets +*/ +local int unzlocal_getShort (fin,pX) + FILE* fin; + uLong *pX; +{ + uLong x ; + int i; + int err; + + err = unzlocal_getByte(fin,&i); + x = (uLong)i; + + if (err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<8; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + +local int unzlocal_getLong (fin,pX) + FILE* fin; + uLong *pX; +{ + uLong x ; + int i; + int err; + + err = unzlocal_getByte(fin,&i); + x = (uLong)i; + + if (err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<8; + + if (err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<16; + + if (err==UNZ_OK) + err = unzlocal_getByte(fin,&i); + x += ((uLong)i)<<24; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + + +/* My own strcmpi / strcasecmp */ +local int strcmpcasenosensitive_internal (fileName1,fileName2) + const char* fileName1; + const char* fileName2; +{ + for (;;) + { + char c1=*(fileName1++); + char c2=*(fileName2++); + if ((c1>='a') && (c1<='z')) + c1 -= 0x20; + if ((c2>='a') && (c2<='z')) + c2 -= 0x20; + if (c1=='\0') + return ((c2=='\0') ? 0 : -1); + if (c2=='\0') + return 1; + if (c1c2) + return 1; + } +} + + +#ifdef CASESENSITIVITYDEFAULT_NO +#define CASESENSITIVITYDEFAULTVALUE 2 +#else +#define CASESENSITIVITYDEFAULTVALUE 1 +#endif + +#ifndef STRCMPCASENOSENTIVEFUNCTION +#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal +#endif + +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) + +*/ +extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) + const char* fileName1; + const char* fileName2; + int iCaseSensitivity; +{ + if (iCaseSensitivity==0) + iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; + + if (iCaseSensitivity==1) + return strcmp(fileName1,fileName2); + + return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); +} + +#define BUFREADCOMMENT (0x400) + +/* + Locate the Central directory of a zipfile (at the end, just before + the global comment) +*/ +local uLong unzlocal_SearchCentralDir(fin) + FILE *fin; +{ + unsigned char* buf; + uLong uSizeFile; + uLong uBackRead; + uLong uMaxBack=0xffff; /* maximum size of global comment */ + uLong uPosFound=0; + + if (fseek(fin,0,SEEK_END) != 0) + return 0; + + + uSizeFile = ftell( fin ); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); + if (fseek(fin,uReadPos,SEEK_SET)!=0) + break; + + if (fread(buf,(uInt)uReadSize,1,fin)!=1) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) + { + uPosFound = uReadPos+i; + break; + } + + if (uPosFound!=0) + break; + } + TRYFREE(buf); + return uPosFound; +} + +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer + "zlib/zlib109.zip". + If the zipfile cannot be opened (file don't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. +*/ +extern unzFile ZEXPORT unzOpen (path) + const char *path; +{ + unz_s us; + unz_s *s; + uLong central_pos,uL; + FILE * fin ; + + uLong number_disk; /* number of the current dist, used for + spaning ZIP, unsupported, always 0*/ + uLong number_disk_with_CD; /* number the the disk with central dir, used + for spaning ZIP, unsupported, always 0*/ + uLong number_entry_CD; /* total number of entries in + the central dir + (same than number_entry on nospan) */ + + int err=UNZ_OK; + + if (unz_copyright[0]!=' ') + return NULL; + + fin=fopen(path,"rb"); + if (fin==NULL) + return NULL; + + central_pos = unzlocal_SearchCentralDir(fin); + if (central_pos==0) + err=UNZ_ERRNO; + + if (fseek(fin,central_pos,SEEK_SET)!=0) + err=UNZ_ERRNO; + + /* the signature, already checked */ + if (unzlocal_getLong(fin,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of this disk */ + if (unzlocal_getShort(fin,&number_disk)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of the disk with the start of the central directory */ + if (unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central dir on this disk */ + if (unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central dir */ + if (unzlocal_getShort(fin,&number_entry_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + if ((number_entry_CD!=us.gi.number_entry) || + (number_disk_with_CD!=0) || + (number_disk!=0)) + err=UNZ_BADZIPFILE; + + /* size of the central directory */ + if (unzlocal_getLong(fin,&us.size_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + /* offset of start of central directory with respect to the + starting disk number */ + if (unzlocal_getLong(fin,&us.offset_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + /* zipfile comment length */ + if (unzlocal_getShort(fin,&us.gi.size_comment)!=UNZ_OK) + err=UNZ_ERRNO; + + if ((central_pospfile_in_zip_read!=NULL) + unzCloseCurrentFile(file); + + fclose(s->file); + TRYFREE(s); + return UNZ_OK; +} + + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ +extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info) + unzFile file; + unz_global_info *pglobal_info; +{ + unz_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + *pglobal_info=s->gi; + return UNZ_OK; +} + + +/* + Translate date/time from Dos format to tm_unz (readable more easilty) +*/ +local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) + uLong ulDosDate; + tm_unz* ptm; +{ + uLong uDate; + uDate = (uLong)(ulDosDate>>16); + ptm->tm_mday = (uInt)(uDate&0x1f) ; + ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; + ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; + + ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); + ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; + ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; +} + +/* + Get Info about the current file in the zipfile, with internal only info +*/ +local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, + unz_file_info *pfile_info, + unz_file_info_internal + *pfile_info_internal, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); + +local int unzlocal_GetCurrentFileInfoInternal (file, + pfile_info, + pfile_info_internal, + szFileName, fileNameBufferSize, + extraField, extraFieldBufferSize, + szComment, commentBufferSize) + unzFile file; + unz_file_info *pfile_info; + unz_file_info_internal *pfile_info_internal; + char *szFileName; + uLong fileNameBufferSize; + void *extraField; + uLong extraFieldBufferSize; + char *szComment; + uLong commentBufferSize; +{ + unz_s* s; + unz_file_info file_info; + unz_file_info_internal file_info_internal; + int err=UNZ_OK; + uLong uMagic; + long lSeek=0; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0) + err=UNZ_ERRNO; + + + /* we check the magic */ + if (err==UNZ_OK) + { + if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if (uMagic!=0x02014b50) + err=UNZ_BADZIPFILE; + } + + if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.version_needed) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.flag) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.compression_method) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info.dosDate) != UNZ_OK) + err=UNZ_ERRNO; + + unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); + + if (unzlocal_getLong(s->file,&file_info.crc) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info.compressed_size) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info.uncompressed_size) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.size_filename) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.size_file_extra) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.size_file_comment) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.disk_num_start) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&file_info.internal_fa) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info.external_fa) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&file_info_internal.offset_curfile) != UNZ_OK) + err=UNZ_ERRNO; + + lSeek+=file_info.size_filename; + if ((err==UNZ_OK) && (szFileName!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_filename0) && (fileNameBufferSize>0)) + if (fread(szFileName,(uInt)uSizeRead,1,s->file)!=1) + err=UNZ_ERRNO; + lSeek -= uSizeRead; + } + + + if ((err==UNZ_OK) && (extraField!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_file_extrafile,lSeek,SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) + if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1) + err=UNZ_ERRNO; + lSeek += file_info.size_file_extra - uSizeRead; + } + else + lSeek+=file_info.size_file_extra; + + + if ((err==UNZ_OK) && (szComment!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_file_commentfile,lSeek,SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + if ((file_info.size_file_comment>0) && (commentBufferSize>0)) + if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1) + err=UNZ_ERRNO; + lSeek+=file_info.size_file_comment - uSizeRead; + } + else + lSeek+=file_info.size_file_comment; + + if ((err==UNZ_OK) && (pfile_info!=NULL)) + *pfile_info=file_info; + + if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) + *pfile_info_internal=file_info_internal; + + return err; +} + + + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. +*/ +extern int ZEXPORT unzGetCurrentFileInfo (file, + pfile_info, + szFileName, fileNameBufferSize, + extraField, extraFieldBufferSize, + szComment, commentBufferSize) + unzFile file; + unz_file_info *pfile_info; + char *szFileName; + uLong fileNameBufferSize; + void *extraField; + uLong extraFieldBufferSize; + char *szComment; + uLong commentBufferSize; +{ + return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, + szFileName,fileNameBufferSize, + extraField,extraFieldBufferSize, + szComment,commentBufferSize); +} + +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ +extern int ZEXPORT unzGoToFirstFile (file) + unzFile file; +{ + int err=UNZ_OK; + unz_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + s->pos_in_central_dir=s->offset_central_dir; + s->num_file=0; + err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + + +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ +extern int ZEXPORT unzGoToNextFile (file) + unzFile file; +{ + unz_s* s; + int err; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + if (s->num_file+1==s->gi.number_entry) + return UNZ_END_OF_LIST_OF_FILE; + + s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + + s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; + s->num_file++; + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + + +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzipStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ +extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) + unzFile file; + const char *szFileName; + int iCaseSensitivity; +{ + unz_s* s; + int err; + + + uLong num_fileSaved; + uLong pos_in_central_dirSaved; + + + if (file==NULL) + return UNZ_PARAMERROR; + + if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) + return UNZ_PARAMERROR; + + s=(unz_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + + num_fileSaved = s->num_file; + pos_in_central_dirSaved = s->pos_in_central_dir; + + err = unzGoToFirstFile(file); + + while (err == UNZ_OK) + { + char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; + unzGetCurrentFileInfo(file,NULL, + szCurrentFileName,sizeof(szCurrentFileName)-1, + NULL,0,NULL,0); + if (unzStringFileNameCompare(szCurrentFileName, + szFileName,iCaseSensitivity)==0) + return UNZ_OK; + err = unzGoToNextFile(file); + } + + s->num_file = num_fileSaved ; + s->pos_in_central_dir = pos_in_central_dirSaved ; + return err; +} + + +/* + Read the local header of the current zipfile + Check the coherency of the local header and info in the end of central + directory about this file + store in *piSizeVar the size of extra info in local header + (filename and size of extra field data) +*/ +local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, + poffset_local_extrafield, + psize_local_extrafield) + unz_s* s; + uInt* piSizeVar; + uLong *poffset_local_extrafield; + uInt *psize_local_extrafield; +{ + uLong uMagic,uData,uFlags; + uLong size_filename; + uLong size_extra_field; + int err=UNZ_OK; + + *piSizeVar = 0; + *poffset_local_extrafield = 0; + *psize_local_extrafield = 0; + + if (fseek(s->file,s->cur_file_info_internal.offset_curfile + + s->byte_before_the_zipfile,SEEK_SET)!=0) + return UNZ_ERRNO; + + + if (err==UNZ_OK) + { + if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if (uMagic!=0x04034b50) + err=UNZ_BADZIPFILE; + } + + if (unzlocal_getShort(s->file,&uData) != UNZ_OK) + err=UNZ_ERRNO; +/* + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) + err=UNZ_BADZIPFILE; +*/ + if (unzlocal_getShort(s->file,&uFlags) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(s->file,&uData) != UNZ_OK) + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) + err=UNZ_BADZIPFILE; + + if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && + (s->cur_file_info.compression_method!=Z_DEFLATED)) + err=UNZ_BADZIPFILE; + + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* date/time */ + err=UNZ_ERRNO; + + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* crc */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size compr */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size uncompr */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + + if (unzlocal_getShort(s->file,&size_filename) != UNZ_OK) + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) + err=UNZ_BADZIPFILE; + + *piSizeVar += (uInt)size_filename; + + if (unzlocal_getShort(s->file,&size_extra_field) != UNZ_OK) + err=UNZ_ERRNO; + *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + + SIZEZIPLOCALHEADER + size_filename; + *psize_local_extrafield = (uInt)size_extra_field; + + *piSizeVar += (uInt)size_extra_field; + + return err; +} + +/* + Open for reading data the current file in the zipfile. + If there is no error and the file is opened, the return value is UNZ_OK. +*/ +extern int ZEXPORT unzOpenCurrentFile (file) + unzFile file; +{ + int err=UNZ_OK; + int Store; + uInt iSizeVar; + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + uLong offset_local_extrafield; /* offset of the local extra field */ + uInt size_local_extrafield; /* size of the local extra field */ + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (!s->current_file_ok) + return UNZ_PARAMERROR; + + if (s->pfile_in_zip_read != NULL) + unzCloseCurrentFile(file); + + if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, + &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) + return UNZ_BADZIPFILE; + + pfile_in_zip_read_info = (file_in_zip_read_info_s*) + ALLOC(sizeof(file_in_zip_read_info_s)); + if (pfile_in_zip_read_info==NULL) + return UNZ_INTERNALERROR; + + pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); + pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; + pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; + pfile_in_zip_read_info->pos_local_extrafield=0; + + if (pfile_in_zip_read_info->read_buffer==NULL) + { + TRYFREE(pfile_in_zip_read_info); + return UNZ_INTERNALERROR; + } + + pfile_in_zip_read_info->stream_initialised=0; + + if ((s->cur_file_info.compression_method!=0) && + (s->cur_file_info.compression_method!=Z_DEFLATED)) + err=UNZ_BADZIPFILE; + Store = s->cur_file_info.compression_method==0; + + pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; + pfile_in_zip_read_info->crc32=0; + pfile_in_zip_read_info->compression_method = + s->cur_file_info.compression_method; + pfile_in_zip_read_info->file=s->file; + pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; + + pfile_in_zip_read_info->stream.total_out = 0; + + if (!Store) + { + pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; + pfile_in_zip_read_info->stream.zfree = (free_func)0; + pfile_in_zip_read_info->stream.opaque = (voidpf)0; + + err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); + if (err == Z_OK) + pfile_in_zip_read_info->stream_initialised=1; + /* windowBits is passed < 0 to tell that there is no zlib header. + * Note that in this case inflate *requires* an extra "dummy" byte + * after the compressed stream in order to complete decompression and + * return Z_STREAM_END. + * In unzip, i don't wait absolutely Z_STREAM_END because I known the + * size of both compressed and uncompressed data + */ + } + pfile_in_zip_read_info->rest_read_compressed = + s->cur_file_info.compressed_size ; + pfile_in_zip_read_info->rest_read_uncompressed = + s->cur_file_info.uncompressed_size ; + + + pfile_in_zip_read_info->pos_in_zipfile = + s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + + iSizeVar; + + pfile_in_zip_read_info->stream.avail_in = (uInt)0; + + + s->pfile_in_zip_read = pfile_in_zip_read_info; + return UNZ_OK; +} + + +/* + Read bytes from the current file. + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ +extern int ZEXPORT unzReadCurrentFile (file, buf, len) + unzFile file; + voidp buf; + unsigned len; +{ + int err=UNZ_OK; + uInt iRead = 0; + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + + if ((pfile_in_zip_read_info->read_buffer == NULL)) + return UNZ_END_OF_LIST_OF_FILE; + if (len==0) + return 0; + + pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; + + pfile_in_zip_read_info->stream.avail_out = (uInt)len; + + if (len>pfile_in_zip_read_info->rest_read_uncompressed) + pfile_in_zip_read_info->stream.avail_out = + (uInt)pfile_in_zip_read_info->rest_read_uncompressed; + + while (pfile_in_zip_read_info->stream.avail_out>0) + { + if ((pfile_in_zip_read_info->stream.avail_in==0) && + (pfile_in_zip_read_info->rest_read_compressed>0)) + { + uInt uReadThis = UNZ_BUFSIZE; + if (pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; + if (uReadThis == 0) + return UNZ_EOF; + if (fseek(pfile_in_zip_read_info->file, + pfile_in_zip_read_info->pos_in_zipfile + + pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0) + return UNZ_ERRNO; + if (fread(pfile_in_zip_read_info->read_buffer,uReadThis,1, + pfile_in_zip_read_info->file)!=1) + return UNZ_ERRNO; + pfile_in_zip_read_info->pos_in_zipfile += uReadThis; + + pfile_in_zip_read_info->rest_read_compressed-=uReadThis; + + pfile_in_zip_read_info->stream.next_in = + (Bytef*)pfile_in_zip_read_info->read_buffer; + pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; + } + + if (pfile_in_zip_read_info->compression_method==0) + { + uInt uDoCopy,i ; + if (pfile_in_zip_read_info->stream.avail_out < + pfile_in_zip_read_info->stream.avail_in) + uDoCopy = pfile_in_zip_read_info->stream.avail_out ; + else + uDoCopy = pfile_in_zip_read_info->stream.avail_in ; + + for (i=0;istream.next_out+i) = + *(pfile_in_zip_read_info->stream.next_in+i); + + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, + pfile_in_zip_read_info->stream.next_out, + uDoCopy); + pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; + pfile_in_zip_read_info->stream.avail_in -= uDoCopy; + pfile_in_zip_read_info->stream.avail_out -= uDoCopy; + pfile_in_zip_read_info->stream.next_out += uDoCopy; + pfile_in_zip_read_info->stream.next_in += uDoCopy; + pfile_in_zip_read_info->stream.total_out += uDoCopy; + iRead += uDoCopy; + } + else + { + uLong uTotalOutBefore,uTotalOutAfter; + const Bytef *bufBefore; + uLong uOutThis; + int flush=Z_SYNC_FLUSH; + + uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; + bufBefore = pfile_in_zip_read_info->stream.next_out; + + /* + if ((pfile_in_zip_read_info->rest_read_uncompressed == + pfile_in_zip_read_info->stream.avail_out) && + (pfile_in_zip_read_info->rest_read_compressed == 0)) + flush = Z_FINISH; + */ + err=inflate(&pfile_in_zip_read_info->stream,flush); + + uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; + uOutThis = uTotalOutAfter-uTotalOutBefore; + + pfile_in_zip_read_info->crc32 = + crc32(pfile_in_zip_read_info->crc32,bufBefore, + (uInt)(uOutThis)); + + pfile_in_zip_read_info->rest_read_uncompressed -= + uOutThis; + + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); + + if (err==Z_STREAM_END) + return (iRead==0) ? UNZ_EOF : iRead; + if (err!=Z_OK) + break; + } + } + + if (err==Z_OK) + return iRead; + return err; +} + + +/* + Give the current position in uncompressed data +*/ +extern z_off_t ZEXPORT unztell (file) + unzFile file; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + return (z_off_t)pfile_in_zip_read_info->stream.total_out; +} + + +/* + return 1 if the end of file was reached, 0 elsewhere +*/ +extern int ZEXPORT unzeof (file) + unzFile file; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + if (pfile_in_zip_read_info->rest_read_uncompressed == 0) + return 1; + else + return 0; +} + + + +/* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field that can be read + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ +extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) + unzFile file; + voidp buf; + unsigned len; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + uInt read_now; + uLong size_to_read; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + size_to_read = (pfile_in_zip_read_info->size_local_extrafield - + pfile_in_zip_read_info->pos_local_extrafield); + + if (buf==NULL) + return (int)size_to_read; + + if (len>size_to_read) + read_now = (uInt)size_to_read; + else + read_now = (uInt)len ; + + if (read_now==0) + return 0; + + if (fseek(pfile_in_zip_read_info->file, + pfile_in_zip_read_info->offset_local_extrafield + + pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0) + return UNZ_ERRNO; + + if (fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1) + return UNZ_ERRNO; + + return (int)read_now; +} + +/* + Close the file in zip opened with unzipOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ +extern int ZEXPORT unzCloseCurrentFile (file) + unzFile file; +{ + int err=UNZ_OK; + + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + + if (pfile_in_zip_read_info->rest_read_uncompressed == 0) + { + if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) + err=UNZ_CRCERROR; + } + + + TRYFREE(pfile_in_zip_read_info->read_buffer); + pfile_in_zip_read_info->read_buffer = NULL; + if (pfile_in_zip_read_info->stream_initialised) + inflateEnd(&pfile_in_zip_read_info->stream); + + pfile_in_zip_read_info->stream_initialised = 0; + TRYFREE(pfile_in_zip_read_info); + + s->pfile_in_zip_read=NULL; + + return err; +} + + +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ +extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) + unzFile file; + char *szComment; + uLong uSizeBuf; +{ + unz_s* s; + uLong uReadThis ; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + + uReadThis = uSizeBuf; + if (uReadThis>s->gi.size_comment) + uReadThis = s->gi.size_comment; + + if (fseek(s->file,s->central_pos+22,SEEK_SET)!=0) + return UNZ_ERRNO; + + if (uReadThis>0) + { + *szComment='\0'; + if (fread(szComment,(uInt)uReadThis,1,s->file)!=1) + return UNZ_ERRNO; + } + + if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) + *(szComment+s->gi.size_comment)='\0'; + return (int)uReadThis; +} diff --git a/fceumm/src-fceumm/zlib/unzip.h b/fceumm/src-fceumm/zlib/unzip.h new file mode 100644 index 0000000..76692cb --- /dev/null +++ b/fceumm/src-fceumm/zlib/unzip.h @@ -0,0 +1,275 @@ +/* unzip.h -- IO for uncompress .zip files using zlib + Version 0.15 beta, Mar 19th, 1998, + + Copyright (C) 1998 Gilles Vollant + + This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g + WinZip, InfoZip tools and compatible. + Encryption and multi volume ZipFile (span) are not supported. + Old compressions used by old PKZip 1.x are not supported + + THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE + CAN CHANGE IN FUTURE VERSION !! + I WAIT FEEDBACK at mail info@winimage.com + Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution + + Condition of use and distribution are the same than zlib : + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + +*/ +/* for more info about .ZIP format, see + ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip + PkWare has also a specification at : + ftp://ftp.pkware.com/probdesc.zip */ + +#ifndef _unz_H +#define _unz_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) +/* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ +typedef struct TagunzFile__ { int unused; } unzFile__; +typedef unzFile__ *unzFile; +#else +typedef voidp unzFile; +#endif + + +#define UNZ_OK (0) +#define UNZ_END_OF_LIST_OF_FILE (-100) +#define UNZ_ERRNO (Z_ERRNO) +#define UNZ_EOF (0) +#define UNZ_PARAMERROR (-102) +#define UNZ_BADZIPFILE (-103) +#define UNZ_INTERNALERROR (-104) +#define UNZ_CRCERROR (-105) + +/* tm_unz contain date/time info */ +typedef struct tm_unz_s +{ + uInt tm_sec; /* seconds after the minute - [0,59] */ + uInt tm_min; /* minutes after the hour - [0,59] */ + uInt tm_hour; /* hours since midnight - [0,23] */ + uInt tm_mday; /* day of the month - [1,31] */ + uInt tm_mon; /* months since January - [0,11] */ + uInt tm_year; /* years - [1980..2044] */ +} tm_unz; + +/* unz_global_info structure contain global data about the ZIPfile + These data comes from the end of central dir */ +typedef struct unz_global_info_s +{ + uLong number_entry; /* total number of entries in + the central dir on this disk */ + uLong size_comment; /* size of the global comment of the zipfile */ +} unz_global_info; + + +/* unz_file_info contain information about a file in the zipfile */ +typedef struct unz_file_info_s +{ + uLong version; /* version made by 2 bytes */ + uLong version_needed; /* version needed to extract 2 bytes */ + uLong flag; /* general purpose bit flag 2 bytes */ + uLong compression_method; /* compression method 2 bytes */ + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ + uLong crc; /* crc-32 4 bytes */ + uLong compressed_size; /* compressed size 4 bytes */ + uLong uncompressed_size; /* uncompressed size 4 bytes */ + uLong size_filename; /* filename length 2 bytes */ + uLong size_file_extra; /* extra field length 2 bytes */ + uLong size_file_comment; /* file comment length 2 bytes */ + + uLong disk_num_start; /* disk number start 2 bytes */ + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ + + tm_unz tmu_date; +} unz_file_info; + +extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, + const char* fileName2, + int iCaseSensitivity)); +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) +*/ + + +extern unzFile ZEXPORT unzOpen OF((const char *path)); +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer + "zlib/zlib111.zip". + If the zipfile cannot be opened (file don't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. +*/ + +extern int ZEXPORT unzClose OF((unzFile file)); +/* + Close a ZipFile opened with unzipOpen. + If there is files inside the .Zip opened with unzOpenCurrentFile (see later), + these files MUST be closed with unzipCloseCurrentFile before call unzipClose. + return UNZ_OK if there is no problem. */ + +extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, + unz_global_info *pglobal_info)); +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ + + +extern int ZEXPORT unzGetGlobalComment OF((unzFile file, + char *szComment, + uLong uSizeBuf)); +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ + + +/***************************************************************************/ +/* Unzip package allow you browse the directory of the zipfile */ + +extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ + +extern int ZEXPORT unzGoToNextFile OF((unzFile file)); +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ + +extern int ZEXPORT unzLocateFile OF((unzFile file, + const char *szFileName, + int iCaseSensitivity)); +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ + + +extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, + unz_file_info *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); +/* + Get Info about the current file + if pfile_info!=NULL, the *pfile_info structure will contain somes info about + the current file + if szFileName!=NULL, the filemane string will be copied in szFileName + (fileNameBufferSize is the size of the buffer) + if extraField!=NULL, the extra field information will be copied in extraField + (extraFieldBufferSize is the size of the buffer). + This is the Central-header version of the extra field + if szComment!=NULL, the comment string of the file will be copied in szComment + (commentBufferSize is the size of the buffer) +*/ + +/***************************************************************************/ +/* for reading the content of the current zipfile, you can open it, read data + from it, and close it (you can close it before reading all the file) + */ + +extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); +/* + Open for reading data the current file in the zipfile. + If there is no error, the return value is UNZ_OK. +*/ + +extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); +/* + Close the file in zip opened with unzOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ + + +extern int ZEXPORT unzReadCurrentFile OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read bytes from the current file (opened by unzOpenCurrentFile) + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ + +extern z_off_t ZEXPORT unztell OF((unzFile file)); +/* + Give the current position in uncompressed data +*/ + +extern int ZEXPORT unzeof OF((unzFile file)); +/* + return 1 if the end of file was reached, 0 elsewhere +*/ + +extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ + +#ifdef __cplusplus +} +#endif + +#endif /* _unz_H */ diff --git a/fceumm/src-fceumm/zlib/zconf.h b/fceumm/src-fceumm/zlib/zconf.h new file mode 100644 index 0000000..68a9f9c --- /dev/null +++ b/fceumm/src-fceumm/zlib/zconf.h @@ -0,0 +1,279 @@ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2002 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: zconf.h,v 1.2 2002/03/13 17:45:56 xodnizel Exp $ */ + +#ifndef _ZCONF_H +#define _ZCONF_H + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + */ +#ifdef Z_PREFIX +# define deflateInit_ z_deflateInit_ +# define deflate z_deflate +# define deflateEnd z_deflateEnd +# define inflateInit_ z_inflateInit_ +# define inflate z_inflate +# define inflateEnd z_inflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateSetDictionary z_deflateSetDictionary +# define deflateCopy z_deflateCopy +# define deflateReset z_deflateReset +# define deflateParams z_deflateParams +# define inflateInit2_ z_inflateInit2_ +# define inflateSetDictionary z_inflateSetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateReset z_inflateReset +# define compress z_compress +# define compress2 z_compress2 +# define uncompress z_uncompress +# define adler32 z_adler32 +# define crc32 z_crc32 +# define get_crc_table z_get_crc_table + +# define Byte z_Byte +# define uInt z_uInt +# define uLong z_uLong +# define Bytef z_Bytef +# define charf z_charf +# define intf z_intf +# define uIntf z_uIntf +# define uLongf z_uLongf +# define voidpf z_voidpf +# define voidp z_voidp +#endif + +#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) +# define WIN32 +#endif +#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386) +# ifndef __32BIT__ +# define __32BIT__ +# endif +#endif +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#if defined(MSDOS) && !defined(__32BIT__) +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC) +# define STDC +#endif +#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__) +# ifndef STDC +# define STDC +# endif +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const +# endif +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Old Borland C incorrectly complains about missing returns: */ +#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500) +# define NEED_DUMMY_RETURN +#endif + + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +#endif +#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__)) +# ifndef __32BIT__ +# define SMALL_MEDIUM +# define FAR _far +# endif +#endif + +/* Compile with -DZLIB_DLL for Windows DLL support */ +#if defined(ZLIB_DLL) +# if defined(_WINDOWS) || defined(WINDOWS) +# ifdef FAR +# undef FAR +# endif +# include +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR _cdecl _export +# endif +# endif +# if defined (__BORLANDC__) +# if (__BORLANDC__ >= 0x0500) && defined (WIN32) +# include +# define ZEXPORT __declspec(dllexport) WINAPI +# define ZEXPORTRVA __declspec(dllexport) WINAPIV +# else +# if defined (_Windows) && defined (__DLL__) +# define ZEXPORT _export +# define ZEXPORTVA _export +# endif +# endif +# endif +#endif + +#if defined (__BEOS__) +# if defined (ZLIB_DLL) +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +#endif + +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif +#ifndef ZEXTERN +# define ZEXTERN extern +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(MACOS) && !defined(TARGET_OS_MAC) +typedef unsigned char Byte; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + +#ifdef HAVE_UNISTD_H +# include /* for off_t */ +# include /* for SEEK_* and off_t */ +# define z_off_t off_t +#endif +#ifndef SEEK_SET +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif +#ifndef z_off_t +# define z_off_t long +#endif + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) +# pragma map(deflateInit_,"DEIN") +# pragma map(deflateInit2_,"DEIN2") +# pragma map(deflateEnd,"DEEND") +# pragma map(inflateInit_,"ININ") +# pragma map(inflateInit2_,"ININ2") +# pragma map(inflateEnd,"INEND") +# pragma map(inflateSync,"INSY") +# pragma map(inflateSetDictionary,"INSEDI") +# pragma map(inflate_blocks,"INBL") +# pragma map(inflate_blocks_new,"INBLNE") +# pragma map(inflate_blocks_free,"INBLFR") +# pragma map(inflate_blocks_reset,"INBLRE") +# pragma map(inflate_codes_free,"INCOFR") +# pragma map(inflate_codes,"INCO") +# pragma map(inflate_fast,"INFA") +# pragma map(inflate_flush,"INFLU") +# pragma map(inflate_mask,"INMA") +# pragma map(inflate_set_dictionary,"INSEDI2") +# pragma map(inflate_copyright,"INCOPY") +# pragma map(inflate_trees_bits,"INTRBI") +# pragma map(inflate_trees_dynamic,"INTRDY") +# pragma map(inflate_trees_fixed,"INTRFI") +# pragma map(inflate_trees_free,"INTRFR") +#endif + +#endif /* _ZCONF_H */ diff --git a/fceumm/src-fceumm/zlib/zlib.h b/fceumm/src-fceumm/zlib/zlib.h new file mode 100644 index 0000000..52cb529 --- /dev/null +++ b/fceumm/src-fceumm/zlib/zlib.h @@ -0,0 +1,893 @@ +/* zlib.h -- interface of the 'zlib' general purpose compression library + version 1.1.4, March 11th, 2002 + + Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + + + The data format used by the zlib library is described by RFCs (Request for + Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt + (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). +*/ + +#ifndef _ZLIB_H +#define _ZLIB_H + +#include "zconf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ZLIB_VERSION "1.1.4" + +/* + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed + data. This version of the library supports only one compression method + (deflation) but other algorithms will be added later and will have the same + stream interface. + + Compression can be done in a single step if the buffers are large + enough (for example if an input file is mmap'ed), or can be done by + repeated calls of the compression function. In the latter case, the + application must provide more input and/or consume the output + (providing more output space) before each call. + + The library also supports reading and writing files in gzip (.gz) format + with an interface similar to that of stdio. + + The library does not install any signal handler. The decoder checks + the consistency of the compressed data, so the library should never + crash even in case of corrupted input. +*/ + +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); +typedef void (*free_func) OF((voidpf opaque, voidpf address)); + +struct internal_state; + +typedef struct z_stream_s { + Bytef *next_in; /* next input byte */ + uInt avail_in; /* number of bytes available at next_in */ + uLong total_in; /* total nb of input bytes read so far */ + + Bytef *next_out; /* next output byte should be put there */ + uInt avail_out; /* remaining free space at next_out */ + uLong total_out; /* total nb of bytes output so far */ + + char *msg; /* last error message, NULL if no error */ + struct internal_state FAR *state; /* not visible by applications */ + + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + voidpf opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: ascii or binary */ + uLong adler; /* adler32 value of the uncompressed data */ + uLong reserved; /* reserved for future use */ +} z_stream; + +typedef z_stream FAR *z_streamp; + +/* + The application must update next_in and avail_in when avail_in has + dropped to zero. It must update next_out and avail_out when avail_out + has dropped to zero. The application must initialize zalloc, zfree and + opaque before calling the init function. All other fields are set by the + compression library and must not be updated by the application. + + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the + opaque value. + + zalloc must return Z_NULL if there is not enough memory for the object. + If zlib is used in a multi-threaded application, zalloc and zfree must be + thread safe. + + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this + if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, + pointers returned by zalloc for objects of exactly 65536 bytes *must* + have their offset normalized to zero. The default allocation function + provided by this library ensures this (see zutil.c). To reduce memory + requirements and avoid any allocation of 64K objects, at the expense of + compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). + + The fields total_in and total_out can be used for statistics or + progress reports. After compression, total_in holds the total size of + the uncompressed data and may be saved for use in the decompressor + (particularly if the decompressor wants to decompress everything in + a single step). +*/ + + /* constants */ + +#define Z_NO_FLUSH 0 +#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ +#define Z_SYNC_FLUSH 2 +#define Z_FULL_FLUSH 3 +#define Z_FINISH 4 +/* Allowed flush values; see deflate() below for details */ + +#define Z_OK 0 +#define Z_STREAM_END 1 +#define Z_NEED_DICT 2 +#define Z_ERRNO (-1) +#define Z_STREAM_ERROR (-2) +#define Z_DATA_ERROR (-3) +#define Z_MEM_ERROR (-4) +#define Z_BUF_ERROR (-5) +#define Z_VERSION_ERROR (-6) +/* Return codes for the compression/decompression functions. Negative + * values are errors, positive values are used for special but normal events. + */ + +#define Z_NO_COMPRESSION 0 +#define Z_BEST_SPEED 1 +#define Z_BEST_COMPRESSION 9 +#define Z_DEFAULT_COMPRESSION (-1) +/* compression levels */ + +#define Z_FILTERED 1 +#define Z_HUFFMAN_ONLY 2 +#define Z_DEFAULT_STRATEGY 0 +/* compression strategy; see deflateInit2() below for details */ + +#define Z_BINARY 0 +#define Z_ASCII 1 +#define Z_UNKNOWN 2 +/* Possible values of the data_type field */ + +#define Z_DEFLATED 8 +/* The deflate compression method (the only one supported in this version) */ + +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ + +#define zlib_version zlibVersion() +/* for compatibility with versions < 1.0.2 */ + + /* basic functions */ + +ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. + If the first character differs, the library code actually used is + not compatible with the zlib.h header file used by the application. + This check is automatically made by deflateInit and inflateInit. + */ + +/* +ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); + + Initializes the internal stream state for compression. The fields + zalloc, zfree and opaque must be initialized before by the caller. + If zalloc and zfree are set to Z_NULL, deflateInit updates them to + use default allocation functions. + + The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: + 1 gives best speed, 9 gives best compression, 0 gives no compression at + all (the input data is simply copied a block at a time). + Z_DEFAULT_COMPRESSION requests a default compromise between speed and + compression (currently equivalent to level 6). + + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if level is not a valid compression level, + Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible + with the version assumed by the caller (ZLIB_VERSION). + msg is set to null if there is no error message. deflateInit does not + perform any compression: this will be done by deflate(). +*/ + + +ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +/* + deflate compresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce some + output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. deflate performs one or both of the + following actions: + + - Compress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in and avail_in are updated and + processing will resume at this point for the next call of deflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. This action is forced if the parameter flush is non zero. + Forcing flush frequently degrades the compression ratio, so this parameter + should be set only when necessary (in interactive applications). + Some output may be provided even if flush is not set. + + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming + more output, and updating avail_in or avail_out accordingly; avail_out + should never be zero before the call. The application can consume the + compressed output when it wants, for example when the output buffer is full + (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK + and with zero avail_out, it must be called again after making room in the + output buffer because there might be more output pending. + + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is + flushed to the output buffer and the output is aligned on a byte boundary, so + that the decompressor can get all input data available so far. (In particular + avail_in is zero after the call if enough output space has been provided + before the call.) Flushing may degrade compression for some compression + algorithms and so it should be used only when necessary. + + If flush is set to Z_FULL_FLUSH, all output is flushed as with + Z_SYNC_FLUSH, and the compression state is reset so that decompression can + restart from this point if previous compressed data has been damaged or if + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade + the compression. + + If deflate returns with avail_out == 0, this function must be called again + with the same value of the flush parameter and more output space (updated + avail_out), until the flush is complete (deflate returns with non-zero + avail_out). + + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there + was enough output space; if deflate returns with Z_OK, this function must be + called again with Z_FINISH and more output space (updated avail_out) but no + more input data, until it returns with Z_STREAM_END or an error. After + deflate has returned Z_STREAM_END, the only possible operations on the + stream are deflateReset or deflateEnd. + + Z_FINISH can be used immediately after deflateInit if all the compression + is to be done in a single step. In this case, avail_out must be at least + 0.1% larger than avail_in plus 12 bytes. If deflate does not return + Z_STREAM_END, then it must be called again as described above. + + deflate() sets strm->adler to the adler32 checksum of all input read + so far (that is, total_in bytes). + + deflate() may update data_type if it can make a good guess about + the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered + binary. This field is only for information purposes and does not affect + the compression algorithm in any manner. + + deflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if all input has been + consumed and all output has been produced (only when flush is set to + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example + if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible + (for example avail_in or avail_out was zero). +*/ + + +ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any + pending output. + + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the + stream state was inconsistent, Z_DATA_ERROR if the stream was freed + prematurely (some input or output was discarded). In the error case, + msg may be set but then points to a static string (which must not be + deallocated). +*/ + + +/* +ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); + + Initializes the internal stream state for decompression. The fields + next_in, avail_in, zalloc, zfree and opaque must be initialized before by + the caller. If next_in is not Z_NULL and avail_in is large enough (the exact + value depends on the compression method), inflateInit determines the + compression method from the zlib header and allocates all data structures + accordingly; otherwise the allocation will be deferred to the first call of + inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to + use default allocation functions. + + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller. msg is set to null if there is no error + message. inflateInit does not perform any decompression apart from reading + the zlib header if present: this will be done by inflate(). (So next_in and + avail_in may be modified, but next_out and avail_out are unchanged.) +*/ + + +ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +/* + inflate decompresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may some + introduce some output latency (reading input without producing any output) + except when forced to flush. + + The detailed semantics are as follows. inflate performs one or both of the + following actions: + + - Decompress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in is updated and processing + will resume at this point for the next call of inflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. inflate() provides as much output as possible, until there + is no more input data or no more space in the output buffer (see below + about the flush parameter). + + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming + more output, and updating the next_* and avail_* values accordingly. + The application can consume the uncompressed output when it wants, for + example when the output buffer is full (avail_out == 0), or after each + call of inflate(). If inflate returns Z_OK and with zero avail_out, it + must be called again after making room in the output buffer because there + might be more output pending. + + If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much + output as possible to the output buffer. The flushing behavior of inflate is + not specified for values of the flush parameter other than Z_SYNC_FLUSH + and Z_FINISH, but the current implementation actually flushes as much output + as possible anyway. + + inflate() should normally be called until it returns Z_STREAM_END or an + error. However if all decompression is to be performed in a single step + (a single call of inflate), the parameter flush should be set to + Z_FINISH. In this case all pending input is processed and all pending + output is flushed; avail_out must be large enough to hold all the + uncompressed data. (The size of the uncompressed data may have been saved + by the compressor for this purpose.) The next operation on this stream must + be inflateEnd to deallocate the decompression state. The use of Z_FINISH + is never required, but can be used to inform inflate that a faster routine + may be used for the single inflate() call. + + If a preset dictionary is needed at this point (see inflateSetDictionary + below), inflate sets strm-adler to the adler32 checksum of the + dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise + it sets strm->adler to the adler32 checksum of all output produced + so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or + an error code as described below. At the end of the stream, inflate() + checks that its computed adler32 checksum is equal to that saved by the + compressor and returns Z_STREAM_END only if the checksum is correct. + + inflate() returns Z_OK if some progress has been made (more input processed + or more output produced), Z_STREAM_END if the end of the compressed data has + been reached and all uncompressed output has been produced, Z_NEED_DICT if a + preset dictionary is needed at this point, Z_DATA_ERROR if the input data was + corrupted (input stream not conforming to the zlib format or incorrect + adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent + (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if no progress is possible or if there was not + enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR + case, the application may then call inflateSync to look for a good + compression block. +*/ + + +ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any + pending output. + + inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state + was inconsistent. In the error case, msg may be set but then points to a + static string (which must not be deallocated). +*/ + + /* Advanced functions */ + +/* + The following functions are needed only in some special applications. +*/ + +/* +ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy)); + + This is another version of deflateInit with more compression options. The + fields next_in, zalloc, zfree and opaque must be initialized before by + the caller. + + The method parameter is the compression method. It must be Z_DEFLATED in + this version of the library. + + The windowBits parameter is the base two logarithm of the window size + (the size of the history buffer). It should be in the range 8..15 for this + version of the library. Larger values of this parameter result in better + compression at the expense of memory usage. The default value is 15 if + deflateInit is used instead. + + The memLevel parameter specifies how much memory should be allocated + for the internal compression state. memLevel=1 uses minimum memory but + is slow and reduces compression ratio; memLevel=9 uses maximum memory + for optimal speed. The default value is 8. See zconf.h for total memory + usage as a function of windowBits and memLevel. + + The strategy parameter is used to tune the compression algorithm. Use the + value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a + filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no + string match). Filtered data consists mostly of small values with a + somewhat random distribution. In this case, the compression algorithm is + tuned to compress them better. The effect of Z_FILTERED is to force more + Huffman coding and less string matching; it is somewhat intermediate + between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects + the compression ratio but not the correctness of the compressed output even + if it is not set appropriately. + + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid + method). msg is set to null if there is no error message. deflateInit2 does + not perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the compression dictionary from the given byte sequence + without producing any compressed output. This function must be called + immediately after deflateInit, deflateInit2 or deflateReset, before any + call of deflate. The compressor and decompressor must use exactly the same + dictionary (see inflateSetDictionary). + + The dictionary should consist of strings (byte sequences) that are likely + to be encountered later in the data to be compressed, with the most commonly + used strings preferably put towards the end of the dictionary. Using a + dictionary is most useful when the data to be compressed is short and can be + predicted with good accuracy; the data can then be compressed better than + with the default empty dictionary. + + Depending on the size of the compression data structures selected by + deflateInit or deflateInit2, a part of the dictionary may in effect be + discarded, for example if the dictionary is larger than the window size in + deflate or deflate2. Thus the strings most likely to be useful should be + put at the end of the dictionary, not at the front. + + Upon return of this function, strm->adler is set to the Adler32 value + of the dictionary; the decompressor may later use this value to determine + which dictionary has been used by the compressor. (The Adler32 value + applies to the whole dictionary even if only a subset of the dictionary is + actually used by the compressor.) + + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a + parameter is invalid (such as NULL dictionary) or the stream state is + inconsistent (for example if deflate has already been called for this stream + or if the compression method is bsort). deflateSetDictionary does not + perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when several compression strategies will be + tried, for example when there are several ways of pre-processing the input + data with a filter. The streams that will be discarded should then be freed + by calling deflateEnd. Note that deflateCopy duplicates the internal + compression state which can be quite large, so this strategy is slow and + can consume lots of memory. + + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +/* + This function is equivalent to deflateEnd followed by deflateInit, + but does not free and reallocate all the internal compression state. + The stream will keep the same compression level and any other attributes + that may have been set by deflateInit2. + + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being NULL). +*/ + +ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, + int level, + int strategy)); +/* + Dynamically update the compression level and compression strategy. The + interpretation of level and strategy is as in deflateInit2. This can be + used to switch between compression and straight copy of the input data, or + to switch to a different kind of input data requiring a different + strategy. If the compression level is changed, the input available so far + is compressed with the old level (and may be flushed); the new level will + take effect only at the next call of deflate(). + + Before the call of deflateParams, the stream state must be set as for + a call of deflate(), since the currently available input may have to + be compressed and flushed. In particular, strm->avail_out must be non-zero. + + deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source + stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR + if strm->avail_out was zero. +*/ + +/* +ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, + int windowBits)); + + This is another version of inflateInit with an extra parameter. The + fields next_in, avail_in, zalloc, zfree and opaque must be initialized + before by the caller. + + The windowBits parameter is the base two logarithm of the maximum window + size (the size of the history buffer). It should be in the range 8..15 for + this version of the library. The default value is 15 if inflateInit is used + instead. If a compressed stream with a larger window size is given as + input, inflate() will return with the error code Z_DATA_ERROR instead of + trying to allocate a larger window. + + inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative + memLevel). msg is set to null if there is no error message. inflateInit2 + does not perform any decompression apart from reading the zlib header if + present: this will be done by inflate(). (So next_in and avail_in may be + modified, but next_out and avail_out are unchanged.) +*/ + +ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the decompression dictionary from the given uncompressed byte + sequence. This function must be called immediately after a call of inflate + if this call returned Z_NEED_DICT. The dictionary chosen by the compressor + can be determined from the Adler32 value returned by this call of + inflate. The compressor and decompressor must use exactly the same + dictionary (see deflateSetDictionary). + + inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a + parameter is invalid (such as NULL dictionary) or the stream state is + inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the + expected one (incorrect Adler32 value). inflateSetDictionary does not + perform any decompression: this will be done by subsequent calls of + inflate(). +*/ + +ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +/* + Skips invalid compressed data until a full flush point (see above the + description of deflate with Z_FULL_FLUSH) can be found, or until all + available input is skipped. No output is provided. + + inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR + if no more input was provided, Z_DATA_ERROR if no flush point has been found, + or Z_STREAM_ERROR if the stream structure was inconsistent. In the success + case, the application may save the current current value of total_in which + indicates where valid compressed data was found. In the error case, the + application may repeatedly call inflateSync, providing more input each time, + until success or end of the input data. +*/ + +ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +/* + This function is equivalent to inflateEnd followed by inflateInit, + but does not free and reallocate all the internal decompression state. + The stream will keep attributes that may have been set by inflateInit2. + + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being NULL). +*/ + + + /* utility functions */ + +/* + The following utility functions are implemented on top of the + basic stream-oriented functions. To simplify the interface, some + default options are assumed (compression level and memory usage, + standard memory allocation functions). The source code of these + utility functions can easily be modified if you need special options. +*/ + +ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Compresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total + size of the destination buffer, which must be at least 0.1% larger than + sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the + compressed buffer. + This function can be used to compress a whole file at once if the + input file is mmap'ed. + compress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer. +*/ + +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, + int level)); +/* + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least 0.1% larger than sourceLen plus + 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ + +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total + size of the destination buffer, which must be large enough to hold the + entire uncompressed data. (The size of the uncompressed data must have + been saved previously by the compressor and transmitted to the decompressor + by some mechanism outside the scope of this compression library.) + Upon exit, destLen is the actual size of the compressed buffer. + This function can be used to decompress a whole file at once if the + input file is mmap'ed. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted. +*/ + + +typedef voidp gzFile; + +ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); +/* + Opens a gzip (.gz) file for reading or writing. The mode parameter + is as in fopen ("rb" or "wb") but can also include a compression level + ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for + Huffman only compression as in "wb1h". (See the description + of deflateInit2 for more information about the strategy parameter.) + + gzopen can be used to read a file which is not in gzip format; in this + case gzread will directly read from the file without decompression. + + gzopen returns NULL if the file could not be opened or if there was + insufficient memory to allocate the (de)compression state; errno + can be checked to distinguish the two cases (if errno is zero, the + zlib error is Z_MEM_ERROR). */ + +ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +/* + gzdopen() associates a gzFile with the file descriptor fd. File + descriptors are obtained from calls like open, dup, creat, pipe or + fileno (in the file has been previously opened with fopen). + The mode parameter is as in gzopen. + The next call of gzclose on the returned gzFile will also close the + file descriptor fd, just like fclose(fdopen(fd), mode) closes the file + descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). + gzdopen returns NULL if there was insufficient memory to allocate + the (de)compression state. +*/ + +ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +/* + Dynamically update the compression level or strategy. See the description + of deflateInit2 for the meaning of these parameters. + gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not + opened for writing. +*/ + +ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +/* + Reads the given number of uncompressed bytes from the compressed file. + If the input file was not in gzip format, gzread copies the given number + of bytes into the buffer. + gzread returns the number of uncompressed bytes actually read (0 for + end of file, -1 for error). */ + +ZEXTERN int ZEXPORT gzwrite OF((gzFile file, + const voidp buf, unsigned len)); +/* + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of uncompressed bytes actually written + (0 in case of error). +*/ + +ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); +/* + Converts, formats, and writes the args to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written (0 in case of error). +*/ + +ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +/* + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + gzputs returns the number of characters written, or -1 in case of error. +*/ + +ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +/* + Reads bytes from the compressed file until len-1 characters are read, or + a newline character is read and transferred to buf, or an end-of-file + condition is encountered. The string is then terminated with a null + character. + gzgets returns buf, or Z_NULL in case of error. +*/ + +ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +/* + Writes c, converted to an unsigned char, into the compressed file. + gzputc returns the value that was written, or -1 in case of error. +*/ + +ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +/* + Reads one byte from the compressed file. gzgetc returns this byte + or -1 in case of end of file or error. +*/ + +ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +/* + Flushes all pending output into the compressed file. The parameter + flush is as in the deflate() function. The return value is the zlib + error number (see function gzerror below). gzflush returns Z_OK if + the flush parameter is Z_FINISH and all output could be flushed. + gzflush should be called only when strictly necessary because it can + degrade compression. +*/ + +ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, + z_off_t offset, int whence)); +/* + Sets the starting position for the next gzread or gzwrite on the + given compressed file. The offset represents a number of bytes in the + uncompressed data stream. The whence parameter is defined as in lseek(2); + the value SEEK_END is not supported. + If the file is opened for reading, this function is emulated but can be + extremely slow. If the file is opened for writing, only forward seeks are + supported; gzseek then compresses a sequence of zeroes up to the new + starting position. + + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error, in + particular if the file is opened for writing and the new starting position + would be before the current position. +*/ + +ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +/* + Rewinds the given file. This function is supported only for reading. + + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) +*/ + +ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); +/* + Returns the starting position for the next gzread or gzwrite on the + given compressed file. This position represents a number of bytes in the + uncompressed data stream. + + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) +*/ + +ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +/* + Returns 1 when EOF has previously been detected reading the given + input stream, otherwise zero. +*/ + +ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +/* + Flushes all pending output if necessary, closes the compressed file + and deallocates all the (de)compression state. The return value is the zlib + error number (see function gzerror below). +*/ + +ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +/* + Returns the error message for the last error which occurred on the + given compressed file. errnum is set to zlib error number. If an + error occurred in the file system and not in the compression library, + errnum is set to Z_ERRNO and the application may consult errno + to get the exact error code. +*/ + + /* checksum functions */ + +/* + These functions are not related to compression but are exported + anyway because they might be useful in applications using the + compression library. +*/ + +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); + +/* + Update a running Adler-32 checksum with the bytes buf[0..len-1] and + return the updated checksum. If buf is NULL, this function returns + the required initial value for the checksum. + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed + much faster. Usage example: + + uLong adler = adler32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + adler = adler32(adler, buffer, length); + } + if (adler != original_adler) error(); +*/ + +ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +/* + Update a running crc with the bytes buf[0..len-1] and return the updated + crc. If buf is NULL, this function returns the required initial value + for the crc. Pre- and post-conditioning (one's complement) is performed + within this function so it shouldn't be done by the application. + Usage example: + + uLong crc = crc32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + crc = crc32(crc, buffer, length); + } + if (crc != original_crc) error(); +*/ + + + /* various hacks, don't look :) */ + +/* deflateInit and inflateInit are macros to allow checking the zlib version + * and the compiler's view of z_stream: + */ +ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size)); +ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, + const char *version, int stream_size)); +#define deflateInit(strm, level) \ + deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) +#define inflateInit(strm) \ + inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) +#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ + (strategy), ZLIB_VERSION, sizeof(z_stream)) +#define inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) + + +#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) + struct internal_state {int dummy;}; /* hack for buggy compilers */ +#endif + +ZEXTERN const char * ZEXPORT zError OF((int err)); +ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); +ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); + +#ifdef __cplusplus +} +#endif + +#endif /* _ZLIB_H */ diff --git a/fceumm/src-fceumm/zlib/zutil.c b/fceumm/src-fceumm/zlib/zutil.c new file mode 100644 index 0000000..08166c0 --- /dev/null +++ b/fceumm/src-fceumm/zlib/zutil.c @@ -0,0 +1,225 @@ +/* zutil.c -- target dependent utility functions for the compression library + * Copyright (C) 1995-2002 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id: zutil.c,v 1.2 2002/03/13 17:45:56 xodnizel Exp $ */ + +#include "zutil.h" + +struct internal_state {int dummy;}; /* for buggy compilers */ + +#ifndef STDC +extern void exit OF((int)); +#endif + +const char *z_errmsg[10] = { +"need dictionary", /* Z_NEED_DICT 2 */ +"stream end", /* Z_STREAM_END 1 */ +"", /* Z_OK 0 */ +"file error", /* Z_ERRNO (-1) */ +"stream error", /* Z_STREAM_ERROR (-2) */ +"data error", /* Z_DATA_ERROR (-3) */ +"insufficient memory", /* Z_MEM_ERROR (-4) */ +"buffer error", /* Z_BUF_ERROR (-5) */ +"incompatible version",/* Z_VERSION_ERROR (-6) */ +""}; + + +const char * ZEXPORT zlibVersion() +{ + return ZLIB_VERSION; +} + +#ifdef DEBUG + +# ifndef verbose +# define verbose 0 +# endif +int z_verbose = verbose; + +void z_error (m) + char *m; +{ + fprintf(stderr, "%s\n", m); + exit(1); +} +#endif + +/* exported to allow conversion of error code to string for compress() and + * uncompress() + */ +const char * ZEXPORT zError(err) + int err; +{ + return ERR_MSG(err); +} + + +#ifndef HAVE_MEMCPY + +void zmemcpy(dest, source, len) + Bytef* dest; + const Bytef* source; + uInt len; +{ + if (len == 0) return; + do { + *dest++ = *source++; /* ??? to be unrolled */ + } while (--len != 0); +} + +int zmemcmp(s1, s2, len) + const Bytef* s1; + const Bytef* s2; + uInt len; +{ + uInt j; + + for (j = 0; j < len; j++) { + if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; + } + return 0; +} + +void zmemzero(dest, len) + Bytef* dest; + uInt len; +{ + if (len == 0) return; + do { + *dest++ = 0; /* ??? to be unrolled */ + } while (--len != 0); +} +#endif + +#ifdef __TURBOC__ +#if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__) +/* Small and medium model in Turbo C are for now limited to near allocation + * with reduced MAX_WBITS and MAX_MEM_LEVEL + */ +# define MY_ZCALLOC + +/* Turbo C malloc() does not allow dynamic allocation of 64K bytes + * and farmalloc(64K) returns a pointer with an offset of 8, so we + * must fix the pointer. Warning: the pointer must be put back to its + * original form in order to free it, use zcfree(). + */ + +#define MAX_PTR 10 +/* 10*64K = 640K */ + +local int next_ptr = 0; + +typedef struct ptr_table_s { + voidpf org_ptr; + voidpf new_ptr; +} ptr_table; + +local ptr_table table[MAX_PTR]; +/* This table is used to remember the original form of pointers + * to large buffers (64K). Such pointers are normalized with a zero offset. + * Since MSDOS is not a preemptive multitasking OS, this table is not + * protected from concurrent access. This hack doesn't work anyway on + * a protected system like OS/2. Use Microsoft C instead. + */ + +voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) +{ + voidpf buf = opaque; /* just to make some compilers happy */ + ulg bsize = (ulg)items*size; + + /* If we allocate less than 65520 bytes, we assume that farmalloc + * will return a usable pointer which doesn't have to be normalized. + */ + if (bsize < 65520L) { + buf = farmalloc(bsize); + if (*(ush*)&buf != 0) return buf; + } else { + buf = farmalloc(bsize + 16L); + } + if (buf == NULL || next_ptr >= MAX_PTR) return NULL; + table[next_ptr].org_ptr = buf; + + /* Normalize the pointer to seg:0 */ + *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; + *(ush*)&buf = 0; + table[next_ptr++].new_ptr = buf; + return buf; +} + +void zcfree (voidpf opaque, voidpf ptr) +{ + int n; + if (*(ush*)&ptr != 0) { /* object < 64K */ + farfree(ptr); + return; + } + /* Find the original pointer */ + for (n = 0; n < next_ptr; n++) { + if (ptr != table[n].new_ptr) continue; + + farfree(table[n].org_ptr); + while (++n < next_ptr) { + table[n-1] = table[n]; + } + next_ptr--; + return; + } + ptr = opaque; /* just to make some compilers happy */ + Assert(0, "zcfree: ptr not found"); +} +#endif +#endif /* __TURBOC__ */ + + +#if defined(M_I86) && !defined(__32BIT__) +/* Microsoft C in 16-bit mode */ + +# define MY_ZCALLOC + +#if (!defined(_MSC_VER) || (_MSC_VER <= 600)) +# define _halloc halloc +# define _hfree hfree +#endif + +voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) +{ + if (opaque) opaque = 0; /* to make compiler happy */ + return _halloc((long)items, size); +} + +void zcfree (voidpf opaque, voidpf ptr) +{ + if (opaque) opaque = 0; /* to make compiler happy */ + _hfree(ptr); +} + +#endif /* MSC */ + + +#ifndef MY_ZCALLOC /* Any system without a special alloc function */ + +#ifndef STDC +extern voidp calloc OF((uInt items, uInt size)); +extern void free OF((voidpf ptr)); +#endif + +voidpf zcalloc (opaque, items, size) + voidpf opaque; + unsigned items; + unsigned size; +{ + if (opaque) items += size - size; /* make compiler happy */ + return (voidpf)calloc(items, size); +} + +void zcfree (opaque, ptr) + voidpf opaque; + voidpf ptr; +{ + free(ptr); + if (opaque) return; /* make compiler happy */ +} + +#endif /* MY_ZCALLOC */ diff --git a/fceumm/src-fceumm/zlib/zutil.h b/fceumm/src-fceumm/zlib/zutil.h new file mode 100644 index 0000000..507cab9 --- /dev/null +++ b/fceumm/src-fceumm/zlib/zutil.h @@ -0,0 +1,220 @@ +/* zutil.h -- internal interface and configuration of the compression library + * Copyright (C) 1995-2002 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* @(#) $Id: zutil.h,v 1.2 2002/03/13 17:45:56 xodnizel Exp $ */ + +#ifndef _Z_UTIL_H +#define _Z_UTIL_H + +#include "zlib.h" + +#ifdef STDC +# include +# include +# include +#endif +#ifdef NO_ERRNO_H + extern int errno; +#else +# include +#endif + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + +typedef unsigned char uch; +typedef uch FAR uchf; +typedef unsigned short ush; +typedef ush FAR ushf; +typedef unsigned long ulg; + +extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ +/* (size given to avoid silly warnings with Visual C++) */ + +#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] + +#define ERR_RETURN(strm,err) \ + return (strm->msg = (char*)ERR_MSG(err), (err)) +/* To be used only when the state is known to be valid */ + + /* common constants */ + +#ifndef DEF_WBITS +# define DEF_WBITS MAX_WBITS +#endif +/* default windowBits for decompression. MAX_WBITS is for compression only */ + +#if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +#else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +#endif +/* default memLevel */ + +#define STORED_BLOCK 0 +#define STATIC_TREES 1 +#define DYN_TREES 2 +/* The three kinds of block type */ + +#define MIN_MATCH 3 +#define MAX_MATCH 258 +/* The minimum and maximum match lengths */ + +#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ + + /* target dependencies */ + +#ifdef MSDOS +# define OS_CODE 0x00 +# if defined(__TURBOC__) || defined(__BORLANDC__) +# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) + /* Allow compilation with ANSI keywords only enabled */ + void _Cdecl farfree( void *block ); + void *_Cdecl farmalloc( unsigned long nbytes ); +# else +# include +# endif +# else /* MSC or DJGPP */ +# include +# endif +#endif + +#ifdef OS2 +# define OS_CODE 0x06 +#endif + +#ifdef WIN32 /* Window 95 & Windows NT */ +# define OS_CODE 0x0b +#endif + +#if defined(VAXC) || defined(VMS) +# define OS_CODE 0x02 +# define F_OPEN(name, mode) \ + fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") +#endif + +#ifdef AMIGA +# define OS_CODE 0x01 +#endif + +#if defined(ATARI) || defined(atarist) +# define OS_CODE 0x05 +#endif + +#if defined(MACOS) || defined(TARGET_OS_MAC) +# define OS_CODE 0x07 +# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os +# include /* for fdopen */ +# else +# ifndef fdopen +# define fdopen(fd,mode) NULL /* No fdopen() */ +# endif +# endif +#endif + +#ifdef __50SERIES /* Prime/PRIMOS */ +# define OS_CODE 0x0F +#endif + +#ifdef TOPS20 +# define OS_CODE 0x0a +#endif + +#if defined(_BEOS_) || defined(RISCOS) +# define fdopen(fd,mode) NULL /* No fdopen() */ +#endif + +#if (defined(_MSC_VER) && (_MSC_VER > 600)) +# define fdopen(fd,type) _fdopen(fd,type) +#endif + + + /* Common defaults */ + +#ifndef OS_CODE +# define OS_CODE 0x03 /* assume Unix */ +#endif + +#ifndef F_OPEN +# define F_OPEN(name, mode) fopen((name), (mode)) +#endif + + /* functions */ + +#ifdef HAVE_STRERROR + extern char *strerror OF((int)); +# define zstrerror(errnum) strerror(errnum) +#else +# define zstrerror(errnum) "" +#endif + +#if defined(pyr) +# define NO_MEMCPY +#endif +#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) + /* Use our own functions for small and medium model with MSC <= 5.0. + * You may have to use the same strategy for Borland C (untested). + * The __SC__ check is for Symantec. + */ +# define NO_MEMCPY +#endif +#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) +# define HAVE_MEMCPY +#endif +#ifdef HAVE_MEMCPY +# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ +# define zmemcpy _fmemcpy +# define zmemcmp _fmemcmp +# define zmemzero(dest, len) _fmemset(dest, 0, len) +# else +# define zmemcpy memcpy +# define zmemcmp memcmp +# define zmemzero(dest, len) memset(dest, 0, len) +# endif +#else + extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); + extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); + extern void zmemzero OF((Bytef* dest, uInt len)); +#endif + +/* Diagnostic functions */ +#ifdef DEBUG +# include + extern int z_verbose; + extern void z_error OF((char *m)); +# define Assert(cond,msg) {if(!(cond)) z_error(msg);} +# define Trace(x) {if (z_verbose>=0) fprintf x ;} +# define Tracev(x) {if (z_verbose>0) fprintf x ;} +# define Tracevv(x) {if (z_verbose>1) fprintf x ;} +# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} +# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} +#else +# define Assert(cond,msg) +# define Trace(x) +# define Tracev(x) +# define Tracevv(x) +# define Tracec(c,x) +# define Tracecv(c,x) +#endif + + +typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf, + uInt len)); +voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); +void zcfree OF((voidpf opaque, voidpf ptr)); + +#define ZALLOC(strm, items, size) \ + (*((strm)->zalloc))((strm)->opaque, (items), (size)) +#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) +#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} + +#endif /* _Z_UTIL_H */ diff --git a/fceumm/utils/unzip/crypt.h b/fceumm/utils/unzip/crypt.h new file mode 100644 index 0000000..f14a628 --- /dev/null +++ b/fceumm/utils/unzip/crypt.h @@ -0,0 +1,132 @@ +/* crypt.h -- base code for crypt/uncrypt ZIPfile + + + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant + + This code is a modified version of crypting code in Infozip distribution + + The encryption/decryption parts of this source code (as opposed to the + non-echoing password parts) were originally written in Europe. The + whole source package can be freely distributed, including from the USA. + (Prior to January 2000, re-export from the US was a violation of US law.) + + This encryption code is a direct transcription of the algorithm from + Roger Schlafly, described by Phil Katz in the file appnote.txt. This + file (appnote.txt) is distributed with the PKZIP program (even in the + version without encryption capabilities). + + If you don't need crypting in your application, just define symbols + NOCRYPT and NOUNCRYPT. + + This code support the "Traditional PKWARE Encryption". + + The new AES encryption added on Zip format by Winzip (see the page + http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong + Encryption is not supported. +*/ + +#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) + +/*********************************************************************** + * Return the next byte in the pseudo-random sequence + */ +static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) +{ + unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an + * unpredictable manner on 16-bit systems; not a problem + * with any known compiler so far, though */ + + temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; + return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); +} + +/*********************************************************************** + * Update the encryption keys with the next byte of plain text + */ +static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) +{ + (*(pkeys+0)) = CRC32((*(pkeys+0)), c); + (*(pkeys+1)) += (*(pkeys+0)) & 0xff; + (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; + { + register int keyshift = (int)((*(pkeys+1)) >> 24); + (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); + } + return c; +} + + +/*********************************************************************** + * Initialize the encryption keys and the random header according to + * the given password. + */ +static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) +{ + *(pkeys+0) = 305419896L; + *(pkeys+1) = 591751049L; + *(pkeys+2) = 878082192L; + while (*passwd != '\0') { + update_keys(pkeys,pcrc_32_tab,(int)*passwd); + passwd++; + } +} + +#define zdecode(pkeys,pcrc_32_tab,c) \ + (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) + +#define zencode(pkeys,pcrc_32_tab,c,t) \ + (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) + +#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED + +#define RAND_HEAD_LEN 12 + /* "last resort" source for second part of crypt seed pattern */ +# ifndef ZCR_SEED2 +# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ +# endif + +static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) + const char *passwd; /* password string */ + unsigned char *buf; /* where to write header */ + int bufSize; + unsigned long* pkeys; + const unsigned long* pcrc_32_tab; + unsigned long crcForCrypting; +{ + int n; /* index in random header */ + int t; /* temporary */ + int c; /* random byte */ + unsigned char header[RAND_HEAD_LEN-2]; /* random header */ + static unsigned calls = 0; /* ensure different random header each time */ + + if (bufSize> 7) & 0xff; + header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); + } + /* Encrypt random header (last two bytes is high word of crc) */ + init_keys(passwd, pkeys, pcrc_32_tab); + for (n = 0; n < RAND_HEAD_LEN-2; n++) + { + buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); + } + buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); + buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); + return n; +} + +#endif diff --git a/fceumm/utils/unzip/ioapi.c b/fceumm/utils/unzip/ioapi.c new file mode 100644 index 0000000..7f20c18 --- /dev/null +++ b/fceumm/utils/unzip/ioapi.c @@ -0,0 +1,177 @@ +/* ioapi.c -- IO base function header for compress/uncompress .zip + files using zlib + zip or unzip API + + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant +*/ + +#include +#include +#include + +#include "zlib.h" +#include "ioapi.h" + + + +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +voidpf ZCALLBACK fopen_file_func OF(( + voidpf opaque, + const char* filename, + int mode)); + +uLong ZCALLBACK fread_file_func OF(( + voidpf opaque, + voidpf stream, + void* buf, + uLong size)); + +uLong ZCALLBACK fwrite_file_func OF(( + voidpf opaque, + voidpf stream, + const void* buf, + uLong size)); + +long ZCALLBACK ftell_file_func OF(( + voidpf opaque, + voidpf stream)); + +long ZCALLBACK fseek_file_func OF(( + voidpf opaque, + voidpf stream, + uLong offset, + int origin)); + +int ZCALLBACK fclose_file_func OF(( + voidpf opaque, + voidpf stream)); + +int ZCALLBACK ferror_file_func OF(( + voidpf opaque, + voidpf stream)); + + +voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) + voidpf opaque; + const char* filename; + int mode; +{ + FILE* file = NULL; + const char* mode_fopen = NULL; + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) + mode_fopen = "rb"; + else + if (mode & ZLIB_FILEFUNC_MODE_EXISTING) + mode_fopen = "r+b"; + else + if (mode & ZLIB_FILEFUNC_MODE_CREATE) + mode_fopen = "wb"; + + if ((filename!=NULL) && (mode_fopen != NULL)) + file = fopen(filename, mode_fopen); + return file; +} + + +uLong ZCALLBACK fread_file_func (opaque, stream, buf, size) + voidpf opaque; + voidpf stream; + void* buf; + uLong size; +{ + uLong ret; + ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); + return ret; +} + + +uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size) + voidpf opaque; + voidpf stream; + const void* buf; + uLong size; +{ + uLong ret; + ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); + return ret; +} + +long ZCALLBACK ftell_file_func (opaque, stream) + voidpf opaque; + voidpf stream; +{ + long ret; + ret = ftell((FILE *)stream); + return ret; +} + +long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) + voidpf opaque; + voidpf stream; + uLong offset; + int origin; +{ + int fseek_origin=0; + long ret; + switch (origin) + { + case ZLIB_FILEFUNC_SEEK_CUR : + fseek_origin = SEEK_CUR; + break; + case ZLIB_FILEFUNC_SEEK_END : + fseek_origin = SEEK_END; + break; + case ZLIB_FILEFUNC_SEEK_SET : + fseek_origin = SEEK_SET; + break; + default: return -1; + } + ret = 0; + fseek((FILE *)stream, offset, fseek_origin); + return ret; +} + +int ZCALLBACK fclose_file_func (opaque, stream) + voidpf opaque; + voidpf stream; +{ + int ret; + ret = fclose((FILE *)stream); + return ret; +} + +int ZCALLBACK ferror_file_func (opaque, stream) + voidpf opaque; + voidpf stream; +{ + int ret; + ret = ferror((FILE *)stream); + return ret; +} + +void fill_fopen_filefunc (pzlib_filefunc_def) + zlib_filefunc_def* pzlib_filefunc_def; +{ + pzlib_filefunc_def->zopen_file = fopen_file_func; + pzlib_filefunc_def->zread_file = fread_file_func; + pzlib_filefunc_def->zwrite_file = fwrite_file_func; + pzlib_filefunc_def->ztell_file = ftell_file_func; + pzlib_filefunc_def->zseek_file = fseek_file_func; + pzlib_filefunc_def->zclose_file = fclose_file_func; + pzlib_filefunc_def->zerror_file = ferror_file_func; + pzlib_filefunc_def->opaque = NULL; +} diff --git a/fceumm/utils/unzip/ioapi.h b/fceumm/utils/unzip/ioapi.h new file mode 100644 index 0000000..e73a3b2 --- /dev/null +++ b/fceumm/utils/unzip/ioapi.h @@ -0,0 +1,75 @@ +/* ioapi.h -- IO base function header for compress/uncompress .zip + files using zlib + zip or unzip API + + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant +*/ + +#ifndef _ZLIBIOAPI_H +#define _ZLIBIOAPI_H + + +#define ZLIB_FILEFUNC_SEEK_CUR (1) +#define ZLIB_FILEFUNC_SEEK_END (2) +#define ZLIB_FILEFUNC_SEEK_SET (0) + +#define ZLIB_FILEFUNC_MODE_READ (1) +#define ZLIB_FILEFUNC_MODE_WRITE (2) +#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) + +#define ZLIB_FILEFUNC_MODE_EXISTING (4) +#define ZLIB_FILEFUNC_MODE_CREATE (8) + + +#ifndef ZCALLBACK + +#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) +#define ZCALLBACK CALLBACK +#else +#define ZCALLBACK +#endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); +typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); +typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); +typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); +typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); +typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); +typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); + +typedef struct zlib_filefunc_def_s +{ + open_file_func zopen_file; + read_file_func zread_file; + write_file_func zwrite_file; + tell_file_func ztell_file; + seek_file_func zseek_file; + close_file_func zclose_file; + testerror_file_func zerror_file; + voidpf opaque; +} zlib_filefunc_def; + + + +void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); + +#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) +#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) +#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) +#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) +#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) +#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) + + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/fceumm/utils/unzip/iowin32.h b/fceumm/utils/unzip/iowin32.h new file mode 100644 index 0000000..e9c5f8b --- /dev/null +++ b/fceumm/utils/unzip/iowin32.h @@ -0,0 +1,21 @@ +/* iowin32.h -- IO base function header for compress/uncompress .zip + files using zlib + zip or unzip API + This IO API version uses the Win32 API (for Microsoft Windows) + + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant +*/ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); + +#ifdef __cplusplus +} +#endif diff --git a/fceumm/utils/unzip/mztools.c b/fceumm/utils/unzip/mztools.c new file mode 100644 index 0000000..bc5c798 --- /dev/null +++ b/fceumm/utils/unzip/mztools.c @@ -0,0 +1,281 @@ +/* + Additional tools for Minizip + Code: Xavier Roche '2004 + License: Same as ZLIB (www.gzip.org) +*/ + +/* Code */ +#include +#include +#include +#include "zlib.h" +#include "unzip.h" + +#define READ_8(adr) ((unsigned char)*(adr)) +#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) +#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) + +#define WRITE_8(buff, n) do { \ + *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ +} while(0) +#define WRITE_16(buff, n) do { \ + WRITE_8((unsigned char*)(buff), n); \ + WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ +} while(0) +#define WRITE_32(buff, n) do { \ + WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ + WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ +} while(0) + +extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) +const char* file; +const char* fileOut; +const char* fileOutTmp; +uLong* nRecovered; +uLong* bytesRecovered; +{ + int err = Z_OK; + FILE* fpZip = fopen(file, "rb"); + FILE* fpOut = fopen(fileOut, "wb"); + FILE* fpOutCD = fopen(fileOutTmp, "wb"); + if (fpZip != NULL && fpOut != NULL) { + int entries = 0; + uLong totalBytes = 0; + char header[30]; + char filename[256]; + char extra[1024]; + int offset = 0; + int offsetCD = 0; + while ( fread(header, 1, 30, fpZip) == 30 ) { + int currentOffset = offset; + + /* File entry */ + if (READ_32(header) == 0x04034b50) { + unsigned int version = READ_16(header + 4); + unsigned int gpflag = READ_16(header + 6); + unsigned int method = READ_16(header + 8); + unsigned int filetime = READ_16(header + 10); + unsigned int filedate = READ_16(header + 12); + unsigned int crc = READ_32(header + 14); /* crc */ + unsigned int cpsize = READ_32(header + 18); /* compressed size */ + unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ + unsigned int fnsize = READ_16(header + 26); /* file name length */ + unsigned int extsize = READ_16(header + 28); /* extra field length */ + filename[0] = extra[0] = '\0'; + + /* Header */ + if (fwrite(header, 1, 30, fpOut) == 30) { + offset += 30; + } else { + err = Z_ERRNO; + break; + } + + /* Filename */ + if (fnsize > 0) { + if (fread(filename, 1, fnsize, fpZip) == fnsize) { + if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { + offset += fnsize; + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_STREAM_ERROR; + break; + } + + /* Extra field */ + if (extsize > 0) { + if (fread(extra, 1, extsize, fpZip) == extsize) { + if (fwrite(extra, 1, extsize, fpOut) == extsize) { + offset += extsize; + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_ERRNO; + break; + } + } + + /* Data */ + { + int dataSize = cpsize; + if (dataSize == 0) { + dataSize = uncpsize; + } + if (dataSize > 0) { + char* data = malloc(dataSize); + if (data != NULL) { + if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { + if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { + offset += dataSize; + totalBytes += dataSize; + } else { + err = Z_ERRNO; + } + } else { + err = Z_ERRNO; + } + free(data); + if (err != Z_OK) { + break; + } + } else { + err = Z_MEM_ERROR; + break; + } + } + } + + /* Central directory entry */ + { + char header[46]; + char* comment = ""; + int comsize = (int) strlen(comment); + WRITE_32(header, 0x02014b50); + WRITE_16(header + 4, version); + WRITE_16(header + 6, version); + WRITE_16(header + 8, gpflag); + WRITE_16(header + 10, method); + WRITE_16(header + 12, filetime); + WRITE_16(header + 14, filedate); + WRITE_32(header + 16, crc); + WRITE_32(header + 20, cpsize); + WRITE_32(header + 24, uncpsize); + WRITE_16(header + 28, fnsize); + WRITE_16(header + 30, extsize); + WRITE_16(header + 32, comsize); + WRITE_16(header + 34, 0); /* disk # */ + WRITE_16(header + 36, 0); /* int attrb */ + WRITE_32(header + 38, 0); /* ext attrb */ + WRITE_32(header + 42, currentOffset); + /* Header */ + if (fwrite(header, 1, 46, fpOutCD) == 46) { + offsetCD += 46; + + /* Filename */ + if (fnsize > 0) { + if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { + offsetCD += fnsize; + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_STREAM_ERROR; + break; + } + + /* Extra field */ + if (extsize > 0) { + if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { + offsetCD += extsize; + } else { + err = Z_ERRNO; + break; + } + } + + /* Comment field */ + if (comsize > 0) { + if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { + offsetCD += comsize; + } else { + err = Z_ERRNO; + break; + } + } + + + } else { + err = Z_ERRNO; + break; + } + } + + /* Success */ + entries++; + + } else { + break; + } + } + + /* Final central directory */ + { + int entriesZip = entries; + char header[22]; + char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; + int comsize = (int) strlen(comment); + if (entriesZip > 0xffff) { + entriesZip = 0xffff; + } + WRITE_32(header, 0x06054b50); + WRITE_16(header + 4, 0); /* disk # */ + WRITE_16(header + 6, 0); /* disk # */ + WRITE_16(header + 8, entriesZip); /* hack */ + WRITE_16(header + 10, entriesZip); /* hack */ + WRITE_32(header + 12, offsetCD); /* size of CD */ + WRITE_32(header + 16, offset); /* offset to CD */ + WRITE_16(header + 20, comsize); /* comment */ + + /* Header */ + if (fwrite(header, 1, 22, fpOutCD) == 22) { + + /* Comment field */ + if (comsize > 0) { + if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { + err = Z_ERRNO; + } + } + + } else { + err = Z_ERRNO; + } + } + + /* Final merge (file + central directory) */ + fclose(fpOutCD); + if (err == Z_OK) { + fpOutCD = fopen(fileOutTmp, "rb"); + if (fpOutCD != NULL) { + int nRead; + char buffer[8192]; + while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { + if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { + err = Z_ERRNO; + break; + } + } + fclose(fpOutCD); + } + } + + /* Close */ + fclose(fpZip); + fclose(fpOut); + + /* Wipe temporary file */ + (void)remove(fileOutTmp); + + /* Number of recovered entries */ + if (err == Z_OK) { + if (nRecovered != NULL) { + *nRecovered = entries; + } + if (bytesRecovered != NULL) { + *bytesRecovered = totalBytes; + } + } + } else { + err = Z_STREAM_ERROR; + } + return err; +} diff --git a/fceumm/utils/unzip/mztools.h b/fceumm/utils/unzip/mztools.h new file mode 100644 index 0000000..82d1597 --- /dev/null +++ b/fceumm/utils/unzip/mztools.h @@ -0,0 +1,31 @@ +/* + Additional tools for Minizip + Code: Xavier Roche '2004 + License: Same as ZLIB (www.gzip.org) +*/ + +#ifndef _zip_tools_H +#define _zip_tools_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#include "unzip.h" + +/* Repair a ZIP file (missing central directory) + file: file to recover + fileOut: output file after recovery + fileOutTmp: temporary file name used for recovery +*/ +extern int ZEXPORT unzRepair(const char* file, + const char* fileOut, + const char* fileOutTmp, + uLong* nRecovered, + uLong* bytesRecovered); + +#endif diff --git a/fceumm/utils/unzip/unzip.c b/fceumm/utils/unzip/unzip.c new file mode 100644 index 0000000..ef4304a --- /dev/null +++ b/fceumm/utils/unzip/unzip.c @@ -0,0 +1,1608 @@ +/* unzip.c -- IO for uncompress .zip files using zlib + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant + + Read unzip.h for more info +*/ + +/* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of +compatibility with older software. The following is from the original crypt.c. Code +woven in by Terry Thorsen 1/2003. +*/ +/* + Copyright (c) 1990-2000 Info-ZIP. All rights reserved. + + See the accompanying file LICENSE, version 2000-Apr-09 or later + (the contents of which are also included in zip.h) for terms of use. + If, for some reason, all these files are missing, the Info-ZIP license + also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html +*/ +/* + crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h] + + The encryption/decryption parts of this source code (as opposed to the + non-echoing password parts) were originally written in Europe. The + whole source package can be freely distributed, including from the USA. + (Prior to January 2000, re-export from the US was a violation of US law.) + */ + +/* + This encryption code is a direct transcription of the algorithm from + Roger Schlafly, described by Phil Katz in the file appnote.txt. This + file (appnote.txt) is distributed with the PKZIP program (even in the + version without encryption capabilities). + */ + + +#include +#include +#include +#include "zlib.h" +#include "unzip.h" + +#ifdef STDC +# include +# include +# include +#endif +#ifdef NO_ERRNO_H + extern int errno; +#else +# include +#endif + + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + + +#ifndef CASESENSITIVITYDEFAULT_NO +# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) +# define CASESENSITIVITYDEFAULT_NO +# endif +#endif + + +#ifndef UNZ_BUFSIZE +#define UNZ_BUFSIZE (16384) +#endif + +#ifndef UNZ_MAXFILENAMEINZIP +#define UNZ_MAXFILENAMEINZIP (256) +#endif + +#ifndef ALLOC +# define ALLOC(size) (malloc(size)) +#endif +#ifndef TRYFREE +# define TRYFREE(p) {if (p) free(p);} +#endif + +#define SIZECENTRALDIRITEM (0x2e) +#define SIZEZIPLOCALHEADER (0x1e) + + + + +const char unz_copyright[] = + " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; + +/* unz_file_info_interntal contain internal info about a file in zipfile*/ +typedef struct unz_file_info_internal_s +{ + uLong offset_curfile;/* relative offset of local header 4 bytes */ +} unz_file_info_internal; + + +/* file_in_zip_read_info_s contain internal information about a file in zipfile, + when reading and decompress it */ +typedef struct +{ + char *read_buffer; /* internal buffer for compressed data */ + z_stream stream; /* zLib stream structure for inflate */ + + uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ + uLong stream_initialised; /* flag set if stream structure is initialised*/ + + uLong offset_local_extrafield;/* offset of the local extra field */ + uInt size_local_extrafield;/* size of the local extra field */ + uLong pos_local_extrafield; /* position in the local extra field in read*/ + + uLong crc32; /* crc32 of all data uncompressed */ + uLong crc32_wait; /* crc32 we must obtain after decompress all */ + uLong rest_read_compressed; /* number of byte to be decompressed */ + uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ + zlib_filefunc_def z_filefunc; + voidpf filestream; /* io structore of the zipfile */ + uLong compression_method; /* compression method (0==store) */ + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ + int raw; +} file_in_zip_read_info_s; + + +/* unz_s contain internal information about the zipfile +*/ +typedef struct +{ + zlib_filefunc_def z_filefunc; + voidpf filestream; /* io structore of the zipfile */ + unz_global_info gi; /* public global information */ + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ + uLong num_file; /* number of the current file in the zipfile*/ + uLong pos_in_central_dir; /* pos of the current file in the central dir*/ + uLong current_file_ok; /* flag about the usability of the current file*/ + uLong central_pos; /* position of the beginning of the central dir*/ + + uLong size_central_dir; /* size of the central directory */ + uLong offset_central_dir; /* offset of start of central directory with + respect to the starting disk number */ + + unz_file_info cur_file_info; /* public info about the current file in zip*/ + unz_file_info_internal cur_file_info_internal; /* private info about it*/ + file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current + file if we are decompressing it */ + int encrypted; +# ifndef NOUNCRYPT + unsigned long keys[3]; /* keys defining the pseudo-random sequence */ + const unsigned long* pcrc_32_tab; +# endif +} unz_s; + + +#ifndef NOUNCRYPT +#include "crypt.h" +#endif + +/* =========================================================================== + Read a byte from a gz_stream; update next_in and avail_in. Return EOF + for end of file. + IN assertion: the stream s has been sucessfully opened for reading. +*/ + + +local int unzlocal_getByte OF(( + const zlib_filefunc_def* pzlib_filefunc_def, + voidpf filestream, + int *pi)); + +local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi) + const zlib_filefunc_def* pzlib_filefunc_def; + voidpf filestream; + int *pi; +{ + unsigned char c; + int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); + if (err==1) + { + *pi = (int)c; + return UNZ_OK; + } + else + { + if (ZERROR(*pzlib_filefunc_def,filestream)) + return UNZ_ERRNO; + else + return UNZ_EOF; + } +} + + +/* =========================================================================== + Reads a long in LSB order from the given gz_stream. Sets +*/ +local int unzlocal_getShort OF(( + const zlib_filefunc_def* pzlib_filefunc_def, + voidpf filestream, + uLong *pX)); + +local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX) + const zlib_filefunc_def* pzlib_filefunc_def; + voidpf filestream; + uLong *pX; +{ + uLong x ; + int i = 0; + int err; + + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); + x = (uLong)i; + + if (err==UNZ_OK) + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<8; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + +local int unzlocal_getLong OF(( + const zlib_filefunc_def* pzlib_filefunc_def, + voidpf filestream, + uLong *pX)); + +local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX) + const zlib_filefunc_def* pzlib_filefunc_def; + voidpf filestream; + uLong *pX; +{ + uLong x ; + int i = 0; + int err; + + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); + x = (uLong)i; + + if (err==UNZ_OK) + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<8; + + if (err==UNZ_OK) + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<16; + + if (err==UNZ_OK) + err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<24; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + + +/* My own strcmpi / strcasecmp */ +local int strcmpcasenosensitive_internal (fileName1,fileName2) + const char* fileName1; + const char* fileName2; +{ + for (;;) + { + char c1=*(fileName1++); + char c2=*(fileName2++); + if ((c1>='a') && (c1<='z')) + c1 -= 0x20; + if ((c2>='a') && (c2<='z')) + c2 -= 0x20; + if (c1=='\0') + return ((c2=='\0') ? 0 : -1); + if (c2=='\0') + return 1; + if (c1c2) + return 1; + } +} + + +#ifdef CASESENSITIVITYDEFAULT_NO +#define CASESENSITIVITYDEFAULTVALUE 2 +#else +#define CASESENSITIVITYDEFAULTVALUE 1 +#endif + +#ifndef STRCMPCASENOSENTIVEFUNCTION +#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal +#endif + +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) + +*/ +extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) + const char* fileName1; + const char* fileName2; + int iCaseSensitivity; +{ + if (iCaseSensitivity==0) + iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; + + if (iCaseSensitivity==1) + return strcmp(fileName1,fileName2); + + return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); +} + +#ifndef BUFREADCOMMENT +#define BUFREADCOMMENT (0x400) +#endif + +/* + Locate the Central directory of a zipfile (at the end, just before + the global comment) +*/ +local uLong unzlocal_SearchCentralDir OF(( + const zlib_filefunc_def* pzlib_filefunc_def, + voidpf filestream)); + +local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream) + const zlib_filefunc_def* pzlib_filefunc_def; + voidpf filestream; +{ + unsigned char* buf; + uLong uSizeFile; + uLong uBackRead; + uLong uMaxBack=0xffff; /* maximum size of global comment */ + uLong uPosFound=0; + + if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) + return 0; + + + uSizeFile = ZTELL(*pzlib_filefunc_def,filestream); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); + if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) + break; + + if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) + { + uPosFound = uReadPos+i; + break; + } + + if (uPosFound!=0) + break; + } + TRYFREE(buf); + return uPosFound; +} + +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer + "zlib/zlib114.zip". + If the zipfile cannot be opened (file doesn't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. +*/ +extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) + const char *path; + zlib_filefunc_def* pzlib_filefunc_def; +{ + unz_s us; + unz_s *s; + uLong central_pos,uL; + + uLong number_disk; /* number of the current dist, used for + spaning ZIP, unsupported, always 0*/ + uLong number_disk_with_CD; /* number the the disk with central dir, used + for spaning ZIP, unsupported, always 0*/ + uLong number_entry_CD; /* total number of entries in + the central dir + (same than number_entry on nospan) */ + + int err=UNZ_OK; + + if (unz_copyright[0]!=' ') + return NULL; + + if (pzlib_filefunc_def==NULL) + fill_fopen_filefunc(&us.z_filefunc); + else + us.z_filefunc = *pzlib_filefunc_def; + + us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque, + path, + ZLIB_FILEFUNC_MODE_READ | + ZLIB_FILEFUNC_MODE_EXISTING); + if (us.filestream==NULL) + return NULL; + + central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream); + if (central_pos==0) + err=UNZ_ERRNO; + + if (ZSEEK(us.z_filefunc, us.filestream, + central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) + err=UNZ_ERRNO; + + /* the signature, already checked */ + if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of this disk */ + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of the disk with the start of the central directory */ + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central dir on this disk */ + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central dir */ + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + if ((number_entry_CD!=us.gi.number_entry) || + (number_disk_with_CD!=0) || + (number_disk!=0)) + err=UNZ_BADZIPFILE; + + /* size of the central directory */ + if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + /* offset of start of central directory with respect to the + starting disk number */ + if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + /* zipfile comment length */ + if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) + err=UNZ_ERRNO; + + if ((central_pospfile_in_zip_read!=NULL) + unzCloseCurrentFile(file); + + ZCLOSE(s->z_filefunc, s->filestream); + TRYFREE(s); + return UNZ_OK; +} + + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ +extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info) + unzFile file; + unz_global_info *pglobal_info; +{ + unz_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + *pglobal_info=s->gi; + return UNZ_OK; +} + + +/* + Translate date/time from Dos format to tm_unz (readable more easilty) +*/ +local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) + uLong ulDosDate; + tm_unz* ptm; +{ + uLong uDate; + uDate = (uLong)(ulDosDate>>16); + ptm->tm_mday = (uInt)(uDate&0x1f) ; + ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; + ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; + + ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); + ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; + ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; +} + +/* + Get Info about the current file in the zipfile, with internal only info +*/ +local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, + unz_file_info *pfile_info, + unz_file_info_internal + *pfile_info_internal, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); + +local int unzlocal_GetCurrentFileInfoInternal (file, + pfile_info, + pfile_info_internal, + szFileName, fileNameBufferSize, + extraField, extraFieldBufferSize, + szComment, commentBufferSize) + unzFile file; + unz_file_info *pfile_info; + unz_file_info_internal *pfile_info_internal; + char *szFileName; + uLong fileNameBufferSize; + void *extraField; + uLong extraFieldBufferSize; + char *szComment; + uLong commentBufferSize; +{ + unz_s* s; + unz_file_info file_info; + unz_file_info_internal file_info_internal; + int err=UNZ_OK; + uLong uMagic; + long lSeek=0; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (ZSEEK(s->z_filefunc, s->filestream, + s->pos_in_central_dir+s->byte_before_the_zipfile, + ZLIB_FILEFUNC_SEEK_SET)!=0) + err=UNZ_ERRNO; + + + /* we check the magic */ + if (err==UNZ_OK) + { + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if (uMagic!=0x02014b50) + err=UNZ_BADZIPFILE; + } + + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) + err=UNZ_ERRNO; + + unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); + + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) + err=UNZ_ERRNO; + + lSeek+=file_info.size_filename; + if ((err==UNZ_OK) && (szFileName!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_filename0) && (fileNameBufferSize>0)) + if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) + err=UNZ_ERRNO; + lSeek -= uSizeRead; + } + + + if ((err==UNZ_OK) && (extraField!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_file_extraz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + + if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) + if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead) + err=UNZ_ERRNO; + lSeek += file_info.size_file_extra - uSizeRead; + } + else + lSeek+=file_info.size_file_extra; + + + if ((err==UNZ_OK) && (szComment!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_file_commentz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + + if ((file_info.size_file_comment>0) && (commentBufferSize>0)) + if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) + err=UNZ_ERRNO; + lSeek+=file_info.size_file_comment - uSizeRead; + } + else + lSeek+=file_info.size_file_comment; + + if ((err==UNZ_OK) && (pfile_info!=NULL)) + *pfile_info=file_info; + + if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) + *pfile_info_internal=file_info_internal; + + return err; +} + + + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. +*/ +extern int ZEXPORT unzGetCurrentFileInfo (file, + pfile_info, + szFileName, fileNameBufferSize, + extraField, extraFieldBufferSize, + szComment, commentBufferSize) + unzFile file; + unz_file_info *pfile_info; + char *szFileName; + uLong fileNameBufferSize; + void *extraField; + uLong extraFieldBufferSize; + char *szComment; + uLong commentBufferSize; +{ + return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, + szFileName,fileNameBufferSize, + extraField,extraFieldBufferSize, + szComment,commentBufferSize); +} + +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ +extern int ZEXPORT unzGoToFirstFile (file) + unzFile file; +{ + int err=UNZ_OK; + unz_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + s->pos_in_central_dir=s->offset_central_dir; + s->num_file=0; + err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ +extern int ZEXPORT unzGoToNextFile (file) + unzFile file; +{ + unz_s* s; + int err; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ + if (s->num_file+1==s->gi.number_entry) + return UNZ_END_OF_LIST_OF_FILE; + + s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + + s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; + s->num_file++; + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + + +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzipStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ +extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) + unzFile file; + const char *szFileName; + int iCaseSensitivity; +{ + unz_s* s; + int err; + + /* We remember the 'current' position in the file so that we can jump + * back there if we fail. + */ + unz_file_info cur_file_infoSaved; + unz_file_info_internal cur_file_info_internalSaved; + uLong num_fileSaved; + uLong pos_in_central_dirSaved; + + + if (file==NULL) + return UNZ_PARAMERROR; + + if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) + return UNZ_PARAMERROR; + + s=(unz_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + + /* Save the current state */ + num_fileSaved = s->num_file; + pos_in_central_dirSaved = s->pos_in_central_dir; + cur_file_infoSaved = s->cur_file_info; + cur_file_info_internalSaved = s->cur_file_info_internal; + + err = unzGoToFirstFile(file); + + while (err == UNZ_OK) + { + char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; + err = unzGetCurrentFileInfo(file,NULL, + szCurrentFileName,sizeof(szCurrentFileName)-1, + NULL,0,NULL,0); + if (err == UNZ_OK) + { + if (unzStringFileNameCompare(szCurrentFileName, + szFileName,iCaseSensitivity)==0) + return UNZ_OK; + err = unzGoToNextFile(file); + } + } + + /* We failed, so restore the state of the 'current file' to where we + * were. + */ + s->num_file = num_fileSaved ; + s->pos_in_central_dir = pos_in_central_dirSaved ; + s->cur_file_info = cur_file_infoSaved; + s->cur_file_info_internal = cur_file_info_internalSaved; + return err; +} + + +/* +/////////////////////////////////////////// +// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net) +// I need random access +// +// Further optimization could be realized by adding an ability +// to cache the directory in memory. The goal being a single +// comprehensive file read to put the file I need in a memory. +*/ + +/* +typedef struct unz_file_pos_s +{ + uLong pos_in_zip_directory; // offset in file + uLong num_of_file; // # of file +} unz_file_pos; +*/ + +extern int ZEXPORT unzGetFilePos(file, file_pos) + unzFile file; + unz_file_pos* file_pos; +{ + unz_s* s; + + if (file==NULL || file_pos==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + + file_pos->pos_in_zip_directory = s->pos_in_central_dir; + file_pos->num_of_file = s->num_file; + + return UNZ_OK; +} + +extern int ZEXPORT unzGoToFilePos(file, file_pos) + unzFile file; + unz_file_pos* file_pos; +{ + unz_s* s; + int err; + + if (file==NULL || file_pos==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + + /* jump to the right spot */ + s->pos_in_central_dir = file_pos->pos_in_zip_directory; + s->num_file = file_pos->num_of_file; + + /* set the current file */ + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + /* return results */ + s->current_file_ok = (err == UNZ_OK); + return err; +} + +/* +// Unzip Helper Functions - should be here? +/////////////////////////////////////////// +*/ + +/* + Read the local header of the current zipfile + Check the coherency of the local header and info in the end of central + directory about this file + store in *piSizeVar the size of extra info in local header + (filename and size of extra field data) +*/ +local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, + poffset_local_extrafield, + psize_local_extrafield) + unz_s* s; + uInt* piSizeVar; + uLong *poffset_local_extrafield; + uInt *psize_local_extrafield; +{ + uLong uMagic,uData,uFlags; + uLong size_filename; + uLong size_extra_field; + int err=UNZ_OK; + + *piSizeVar = 0; + *poffset_local_extrafield = 0; + *psize_local_extrafield = 0; + + if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + + s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) + return UNZ_ERRNO; + + + if (err==UNZ_OK) + { + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if (uMagic!=0x04034b50) + err=UNZ_BADZIPFILE; + } + + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) + err=UNZ_ERRNO; +/* + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) + err=UNZ_BADZIPFILE; +*/ + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) + err=UNZ_ERRNO; + + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) + err=UNZ_BADZIPFILE; + + if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && + (s->cur_file_info.compression_method!=Z_DEFLATED)) + err=UNZ_BADZIPFILE; + + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ + err=UNZ_ERRNO; + + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && + ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK) + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) + err=UNZ_BADZIPFILE; + + *piSizeVar += (uInt)size_filename; + + if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) + err=UNZ_ERRNO; + *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + + SIZEZIPLOCALHEADER + size_filename; + *psize_local_extrafield = (uInt)size_extra_field; + + *piSizeVar += (uInt)size_extra_field; + + return err; +} + +/* + Open for reading data the current file in the zipfile. + If there is no error and the file is opened, the return value is UNZ_OK. +*/ +extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password) + unzFile file; + int* method; + int* level; + int raw; + const char* password; +{ + int err=UNZ_OK; + uInt iSizeVar; + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + uLong offset_local_extrafield; /* offset of the local extra field */ + uInt size_local_extrafield; /* size of the local extra field */ +# ifndef NOUNCRYPT + char source[12]; +# else + if (password != NULL) + return UNZ_PARAMERROR; +# endif + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (!s->current_file_ok) + return UNZ_PARAMERROR; + + if (s->pfile_in_zip_read != NULL) + unzCloseCurrentFile(file); + + if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, + &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) + return UNZ_BADZIPFILE; + + pfile_in_zip_read_info = (file_in_zip_read_info_s*) + ALLOC(sizeof(file_in_zip_read_info_s)); + if (pfile_in_zip_read_info==NULL) + return UNZ_INTERNALERROR; + + pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); + pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; + pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; + pfile_in_zip_read_info->pos_local_extrafield=0; + pfile_in_zip_read_info->raw=raw; + + if (pfile_in_zip_read_info->read_buffer==NULL) + { + TRYFREE(pfile_in_zip_read_info); + return UNZ_INTERNALERROR; + } + + pfile_in_zip_read_info->stream_initialised=0; + + if (method!=NULL) + *method = (int)s->cur_file_info.compression_method; + + if (level!=NULL) + { + *level = 6; + switch (s->cur_file_info.flag & 0x06) + { + case 6 : *level = 1; break; + case 4 : *level = 2; break; + case 2 : *level = 9; break; + } + } + + if ((s->cur_file_info.compression_method!=0) && + (s->cur_file_info.compression_method!=Z_DEFLATED)) + err=UNZ_BADZIPFILE; + + pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; + pfile_in_zip_read_info->crc32=0; + pfile_in_zip_read_info->compression_method = + s->cur_file_info.compression_method; + pfile_in_zip_read_info->filestream=s->filestream; + pfile_in_zip_read_info->z_filefunc=s->z_filefunc; + pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; + + pfile_in_zip_read_info->stream.total_out = 0; + + if ((s->cur_file_info.compression_method==Z_DEFLATED) && + (!raw)) + { + pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; + pfile_in_zip_read_info->stream.zfree = (free_func)0; + pfile_in_zip_read_info->stream.opaque = (voidpf)0; + pfile_in_zip_read_info->stream.next_in = (voidpf)0; + pfile_in_zip_read_info->stream.avail_in = 0; + + err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); + if (err == Z_OK) + pfile_in_zip_read_info->stream_initialised=1; + else + { + TRYFREE(pfile_in_zip_read_info); + return err; + } + /* windowBits is passed < 0 to tell that there is no zlib header. + * Note that in this case inflate *requires* an extra "dummy" byte + * after the compressed stream in order to complete decompression and + * return Z_STREAM_END. + * In unzip, i don't wait absolutely Z_STREAM_END because I known the + * size of both compressed and uncompressed data + */ + } + pfile_in_zip_read_info->rest_read_compressed = + s->cur_file_info.compressed_size ; + pfile_in_zip_read_info->rest_read_uncompressed = + s->cur_file_info.uncompressed_size ; + + + pfile_in_zip_read_info->pos_in_zipfile = + s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + + iSizeVar; + + pfile_in_zip_read_info->stream.avail_in = (uInt)0; + + s->pfile_in_zip_read = pfile_in_zip_read_info; + +# ifndef NOUNCRYPT + if (password != NULL) + { + int i; + s->pcrc_32_tab = get_crc_table(); + init_keys(password,s->keys,s->pcrc_32_tab); + if (ZSEEK(s->z_filefunc, s->filestream, + s->pfile_in_zip_read->pos_in_zipfile + + s->pfile_in_zip_read->byte_before_the_zipfile, + SEEK_SET)!=0) + return UNZ_INTERNALERROR; + if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12) + return UNZ_INTERNALERROR; + + for (i = 0; i<12; i++) + zdecode(s->keys,s->pcrc_32_tab,source[i]); + + s->pfile_in_zip_read->pos_in_zipfile+=12; + s->encrypted=1; + } +# endif + + + return UNZ_OK; +} + +extern int ZEXPORT unzOpenCurrentFile (file) + unzFile file; +{ + return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); +} + +extern int ZEXPORT unzOpenCurrentFilePassword (file, password) + unzFile file; + const char* password; +{ + return unzOpenCurrentFile3(file, NULL, NULL, 0, password); +} + +extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw) + unzFile file; + int* method; + int* level; + int raw; +{ + return unzOpenCurrentFile3(file, method, level, raw, NULL); +} + +/* + Read bytes from the current file. + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ +extern int ZEXPORT unzReadCurrentFile (file, buf, len) + unzFile file; + voidp buf; + unsigned len; +{ + int err=UNZ_OK; + uInt iRead = 0; + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + + if ((pfile_in_zip_read_info->read_buffer == NULL)) + return UNZ_END_OF_LIST_OF_FILE; + if (len==0) + return 0; + + pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; + + pfile_in_zip_read_info->stream.avail_out = (uInt)len; + + if ((len>pfile_in_zip_read_info->rest_read_uncompressed) && + (!(pfile_in_zip_read_info->raw))) + pfile_in_zip_read_info->stream.avail_out = + (uInt)pfile_in_zip_read_info->rest_read_uncompressed; + + if ((len>pfile_in_zip_read_info->rest_read_compressed+ + pfile_in_zip_read_info->stream.avail_in) && + (pfile_in_zip_read_info->raw)) + pfile_in_zip_read_info->stream.avail_out = + (uInt)pfile_in_zip_read_info->rest_read_compressed+ + pfile_in_zip_read_info->stream.avail_in; + + while (pfile_in_zip_read_info->stream.avail_out>0) + { + if ((pfile_in_zip_read_info->stream.avail_in==0) && + (pfile_in_zip_read_info->rest_read_compressed>0)) + { + uInt uReadThis = UNZ_BUFSIZE; + if (pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; + if (uReadThis == 0) + return UNZ_EOF; + if (ZSEEK(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, + pfile_in_zip_read_info->pos_in_zipfile + + pfile_in_zip_read_info->byte_before_the_zipfile, + ZLIB_FILEFUNC_SEEK_SET)!=0) + return UNZ_ERRNO; + if (ZREAD(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, + pfile_in_zip_read_info->read_buffer, + uReadThis)!=uReadThis) + return UNZ_ERRNO; + + +# ifndef NOUNCRYPT + if(s->encrypted) + { + uInt i; + for(i=0;iread_buffer[i] = + zdecode(s->keys,s->pcrc_32_tab, + pfile_in_zip_read_info->read_buffer[i]); + } +# endif + + + pfile_in_zip_read_info->pos_in_zipfile += uReadThis; + + pfile_in_zip_read_info->rest_read_compressed-=uReadThis; + + pfile_in_zip_read_info->stream.next_in = + (Bytef*)pfile_in_zip_read_info->read_buffer; + pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; + } + + if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) + { + uInt uDoCopy,i ; + + if ((pfile_in_zip_read_info->stream.avail_in == 0) && + (pfile_in_zip_read_info->rest_read_compressed == 0)) + return (iRead==0) ? UNZ_EOF : iRead; + + if (pfile_in_zip_read_info->stream.avail_out < + pfile_in_zip_read_info->stream.avail_in) + uDoCopy = pfile_in_zip_read_info->stream.avail_out ; + else + uDoCopy = pfile_in_zip_read_info->stream.avail_in ; + + for (i=0;istream.next_out+i) = + *(pfile_in_zip_read_info->stream.next_in+i); + + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, + pfile_in_zip_read_info->stream.next_out, + uDoCopy); + pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; + pfile_in_zip_read_info->stream.avail_in -= uDoCopy; + pfile_in_zip_read_info->stream.avail_out -= uDoCopy; + pfile_in_zip_read_info->stream.next_out += uDoCopy; + pfile_in_zip_read_info->stream.next_in += uDoCopy; + pfile_in_zip_read_info->stream.total_out += uDoCopy; + iRead += uDoCopy; + } + else + { + uLong uTotalOutBefore,uTotalOutAfter; + const Bytef *bufBefore; + uLong uOutThis; + int flush=Z_SYNC_FLUSH; + + uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; + bufBefore = pfile_in_zip_read_info->stream.next_out; + + /* + if ((pfile_in_zip_read_info->rest_read_uncompressed == + pfile_in_zip_read_info->stream.avail_out) && + (pfile_in_zip_read_info->rest_read_compressed == 0)) + flush = Z_FINISH; + */ + err=inflate(&pfile_in_zip_read_info->stream,flush); + + if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL)) + err = Z_DATA_ERROR; + + uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; + uOutThis = uTotalOutAfter-uTotalOutBefore; + + pfile_in_zip_read_info->crc32 = + crc32(pfile_in_zip_read_info->crc32,bufBefore, + (uInt)(uOutThis)); + + pfile_in_zip_read_info->rest_read_uncompressed -= + uOutThis; + + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); + + if (err==Z_STREAM_END) + return (iRead==0) ? UNZ_EOF : iRead; + if (err!=Z_OK) + break; + } + } + + if (err==Z_OK) + return iRead; + return err; +} + + +/* + Give the current position in uncompressed data +*/ +extern z_off_t ZEXPORT unztell (file) + unzFile file; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + return (z_off_t)pfile_in_zip_read_info->stream.total_out; +} + + +/* + return 1 if the end of file was reached, 0 elsewhere +*/ +extern int ZEXPORT unzeof (file) + unzFile file; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + if (pfile_in_zip_read_info->rest_read_uncompressed == 0) + return 1; + else + return 0; +} + + + +/* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field that can be read + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ +extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) + unzFile file; + voidp buf; + unsigned len; +{ + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + uInt read_now; + uLong size_to_read; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + size_to_read = (pfile_in_zip_read_info->size_local_extrafield - + pfile_in_zip_read_info->pos_local_extrafield); + + if (buf==NULL) + return (int)size_to_read; + + if (len>size_to_read) + read_now = (uInt)size_to_read; + else + read_now = (uInt)len ; + + if (read_now==0) + return 0; + + if (ZSEEK(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, + pfile_in_zip_read_info->offset_local_extrafield + + pfile_in_zip_read_info->pos_local_extrafield, + ZLIB_FILEFUNC_SEEK_SET)!=0) + return UNZ_ERRNO; + + if (ZREAD(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, + buf,read_now)!=read_now) + return UNZ_ERRNO; + + return (int)read_now; +} + +/* + Close the file in zip opened with unzipOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ +extern int ZEXPORT unzCloseCurrentFile (file) + unzFile file; +{ + int err=UNZ_OK; + + unz_s* s; + file_in_zip_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + + if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && + (!pfile_in_zip_read_info->raw)) + { + if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) + err=UNZ_CRCERROR; + } + + + TRYFREE(pfile_in_zip_read_info->read_buffer); + pfile_in_zip_read_info->read_buffer = NULL; + if (pfile_in_zip_read_info->stream_initialised) + inflateEnd(&pfile_in_zip_read_info->stream); + + pfile_in_zip_read_info->stream_initialised = 0; + TRYFREE(pfile_in_zip_read_info); + + s->pfile_in_zip_read=NULL; + + return err; +} + + +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ +extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) + unzFile file; + char *szComment; + uLong uSizeBuf; +{ + /* int err=UNZ_OK; */ + unz_s* s; + uLong uReadThis ; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + + uReadThis = uSizeBuf; + if (uReadThis>s->gi.size_comment) + uReadThis = s->gi.size_comment; + + if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) + return UNZ_ERRNO; + + if (uReadThis>0) + { + *szComment='\0'; + if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) + return UNZ_ERRNO; + } + + if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) + *(szComment+s->gi.size_comment)='\0'; + return (int)uReadThis; +} + +/* Additions by RX '2004 */ +extern uLong ZEXPORT unzGetOffset (file) + unzFile file; +{ + unz_s* s; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + if (!s->current_file_ok) + return 0; + if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) + if (s->num_file==s->gi.number_entry) + return 0; + return s->pos_in_central_dir; +} + +extern int ZEXPORT unzSetOffset (file, pos) + unzFile file; + uLong pos; +{ + unz_s* s; + int err; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz_s*)file; + + s->pos_in_central_dir = pos; + s->num_file = s->gi.number_entry; /* hack */ + err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} diff --git a/fceumm/utils/unzip/unzip.h b/fceumm/utils/unzip/unzip.h new file mode 100644 index 0000000..c3206a0 --- /dev/null +++ b/fceumm/utils/unzip/unzip.h @@ -0,0 +1,354 @@ +/* unzip.h -- IO for uncompress .zip files using zlib + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant + + This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g + WinZip, InfoZip tools and compatible. + + Multi volume ZipFile (span) are not supported. + Encryption compatible with pkzip 2.04g only supported + Old compressions used by old PKZip 1.x are not supported + + + I WAIT FEEDBACK at mail info@winimage.com + Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution + + Condition of use and distribution are the same than zlib : + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + +*/ + +/* for more info about .ZIP format, see + http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip + http://www.info-zip.org/pub/infozip/doc/ + PkWare has also a specification at : + ftp://ftp.pkware.com/probdesc.zip +*/ + +#ifndef _unz_H +#define _unz_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#ifndef _ZLIBIOAPI_H +#include "ioapi.h" +#endif + +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) +/* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ +typedef struct TagunzFile__ { int unused; } unzFile__; +typedef unzFile__ *unzFile; +#else +typedef voidp unzFile; +#endif + + +#define UNZ_OK (0) +#define UNZ_END_OF_LIST_OF_FILE (-100) +#define UNZ_ERRNO (Z_ERRNO) +#define UNZ_EOF (0) +#define UNZ_PARAMERROR (-102) +#define UNZ_BADZIPFILE (-103) +#define UNZ_INTERNALERROR (-104) +#define UNZ_CRCERROR (-105) + +/* tm_unz contain date/time info */ +typedef struct tm_unz_s +{ + uInt tm_sec; /* seconds after the minute - [0,59] */ + uInt tm_min; /* minutes after the hour - [0,59] */ + uInt tm_hour; /* hours since midnight - [0,23] */ + uInt tm_mday; /* day of the month - [1,31] */ + uInt tm_mon; /* months since January - [0,11] */ + uInt tm_year; /* years - [1980..2044] */ +} tm_unz; + +/* unz_global_info structure contain global data about the ZIPfile + These data comes from the end of central dir */ +typedef struct unz_global_info_s +{ + uLong number_entry; /* total number of entries in + the central dir on this disk */ + uLong size_comment; /* size of the global comment of the zipfile */ +} unz_global_info; + + +/* unz_file_info contain information about a file in the zipfile */ +typedef struct unz_file_info_s +{ + uLong version; /* version made by 2 bytes */ + uLong version_needed; /* version needed to extract 2 bytes */ + uLong flag; /* general purpose bit flag 2 bytes */ + uLong compression_method; /* compression method 2 bytes */ + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ + uLong crc; /* crc-32 4 bytes */ + uLong compressed_size; /* compressed size 4 bytes */ + uLong uncompressed_size; /* uncompressed size 4 bytes */ + uLong size_filename; /* filename length 2 bytes */ + uLong size_file_extra; /* extra field length 2 bytes */ + uLong size_file_comment; /* file comment length 2 bytes */ + + uLong disk_num_start; /* disk number start 2 bytes */ + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ + + tm_unz tmu_date; +} unz_file_info; + +extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, + const char* fileName2, + int iCaseSensitivity)); +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) +*/ + + +extern unzFile ZEXPORT unzOpen OF((const char *path)); +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer + "zlib/zlib113.zip". + If the zipfile cannot be opened (file don't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. +*/ + +extern unzFile ZEXPORT unzOpen2 OF((const char *path, + zlib_filefunc_def* pzlib_filefunc_def)); +/* + Open a Zip file, like unzOpen, but provide a set of file low level API + for read/write the zip file (see ioapi.h) +*/ + +extern int ZEXPORT unzClose OF((unzFile file)); +/* + Close a ZipFile opened with unzipOpen. + If there is files inside the .Zip opened with unzOpenCurrentFile (see later), + these files MUST be closed with unzipCloseCurrentFile before call unzipClose. + return UNZ_OK if there is no problem. */ + +extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, + unz_global_info *pglobal_info)); +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ + + +extern int ZEXPORT unzGetGlobalComment OF((unzFile file, + char *szComment, + uLong uSizeBuf)); +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ + + +/***************************************************************************/ +/* Unzip package allow you browse the directory of the zipfile */ + +extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ + +extern int ZEXPORT unzGoToNextFile OF((unzFile file)); +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ + +extern int ZEXPORT unzLocateFile OF((unzFile file, + const char *szFileName, + int iCaseSensitivity)); +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ + + +/* ****************************************** */ +/* Ryan supplied functions */ +/* unz_file_info contain information about a file in the zipfile */ +typedef struct unz_file_pos_s +{ + uLong pos_in_zip_directory; /* offset in zip file directory */ + uLong num_of_file; /* # of file */ +} unz_file_pos; + +extern int ZEXPORT unzGetFilePos( + unzFile file, + unz_file_pos* file_pos); + +extern int ZEXPORT unzGoToFilePos( + unzFile file, + unz_file_pos* file_pos); + +/* ****************************************** */ + +extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, + unz_file_info *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); +/* + Get Info about the current file + if pfile_info!=NULL, the *pfile_info structure will contain somes info about + the current file + if szFileName!=NULL, the filemane string will be copied in szFileName + (fileNameBufferSize is the size of the buffer) + if extraField!=NULL, the extra field information will be copied in extraField + (extraFieldBufferSize is the size of the buffer). + This is the Central-header version of the extra field + if szComment!=NULL, the comment string of the file will be copied in szComment + (commentBufferSize is the size of the buffer) +*/ + +/***************************************************************************/ +/* for reading the content of the current zipfile, you can open it, read data + from it, and close it (you can close it before reading all the file) + */ + +extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); +/* + Open for reading data the current file in the zipfile. + If there is no error, the return value is UNZ_OK. +*/ + +extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, + const char* password)); +/* + Open for reading data the current file in the zipfile. + password is a crypting password + If there is no error, the return value is UNZ_OK. +*/ + +extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, + int* method, + int* level, + int raw)); +/* + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) + if raw==1 + *method will receive method of compression, *level will receive level of + compression + note : you can set level parameter as NULL (if you did not want known level, + but you CANNOT set method parameter as NULL +*/ + +extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, + int* method, + int* level, + int raw, + const char* password)); +/* + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) + if raw==1 + *method will receive method of compression, *level will receive level of + compression + note : you can set level parameter as NULL (if you did not want known level, + but you CANNOT set method parameter as NULL +*/ + + +extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); +/* + Close the file in zip opened with unzOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ + +extern int ZEXPORT unzReadCurrentFile OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read bytes from the current file (opened by unzOpenCurrentFile) + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ + +extern z_off_t ZEXPORT unztell OF((unzFile file)); +/* + Give the current position in uncompressed data +*/ + +extern int ZEXPORT unzeof OF((unzFile file)); +/* + return 1 if the end of file was reached, 0 elsewhere +*/ + +extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ + +/***************************************************************************/ + +/* Get the current file offset */ +extern uLong ZEXPORT unzGetOffset (unzFile file); + +/* Set the current file offset */ +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); + + + +#ifdef __cplusplus +} +#endif + +#endif /* _unz_H */ diff --git a/fceumm/utils/unzip/zconf.h b/fceumm/utils/unzip/zconf.h new file mode 100644 index 0000000..02ce56c --- /dev/null +++ b/fceumm/utils/unzip/zconf.h @@ -0,0 +1,428 @@ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2010 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#ifndef ZCONF_H +#define ZCONF_H + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + * Even better than compiling with -DZ_PREFIX would be to use configure to set + * this permanently in zconf.h using "./configure --zprefix". + */ +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ + +/* all linked symbols */ +# define _dist_code z__dist_code +# define _length_code z__length_code +# define _tr_align z__tr_align +# define _tr_flush_block z__tr_flush_block +# define _tr_init z__tr_init +# define _tr_stored_block z__tr_stored_block +# define _tr_tally z__tr_tally +# define adler32 z_adler32 +# define adler32_combine z_adler32_combine +# define adler32_combine64 z_adler32_combine64 +# define compress z_compress +# define compress2 z_compress2 +# define compressBound z_compressBound +# define crc32 z_crc32 +# define crc32_combine z_crc32_combine +# define crc32_combine64 z_crc32_combine64 +# define deflate z_deflate +# define deflateBound z_deflateBound +# define deflateCopy z_deflateCopy +# define deflateEnd z_deflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateInit_ z_deflateInit_ +# define deflateParams z_deflateParams +# define deflatePrime z_deflatePrime +# define deflateReset z_deflateReset +# define deflateSetDictionary z_deflateSetDictionary +# define deflateSetHeader z_deflateSetHeader +# define deflateTune z_deflateTune +# define deflate_copyright z_deflate_copyright +# define get_crc_table z_get_crc_table +# define gz_error z_gz_error +# define gz_intmax z_gz_intmax +# define gz_strwinerror z_gz_strwinerror +# define gzbuffer z_gzbuffer +# define gzclearerr z_gzclearerr +# define gzclose z_gzclose +# define gzclose_r z_gzclose_r +# define gzclose_w z_gzclose_w +# define gzdirect z_gzdirect +# define gzdopen z_gzdopen +# define gzeof z_gzeof +# define gzerror z_gzerror +# define gzflush z_gzflush +# define gzgetc z_gzgetc +# define gzgets z_gzgets +# define gzoffset z_gzoffset +# define gzoffset64 z_gzoffset64 +# define gzopen z_gzopen +# define gzopen64 z_gzopen64 +# define gzprintf z_gzprintf +# define gzputc z_gzputc +# define gzputs z_gzputs +# define gzread z_gzread +# define gzrewind z_gzrewind +# define gzseek z_gzseek +# define gzseek64 z_gzseek64 +# define gzsetparams z_gzsetparams +# define gztell z_gztell +# define gztell64 z_gztell64 +# define gzungetc z_gzungetc +# define gzwrite z_gzwrite +# define inflate z_inflate +# define inflateBack z_inflateBack +# define inflateBackEnd z_inflateBackEnd +# define inflateBackInit_ z_inflateBackInit_ +# define inflateCopy z_inflateCopy +# define inflateEnd z_inflateEnd +# define inflateGetHeader z_inflateGetHeader +# define inflateInit2_ z_inflateInit2_ +# define inflateInit_ z_inflateInit_ +# define inflateMark z_inflateMark +# define inflatePrime z_inflatePrime +# define inflateReset z_inflateReset +# define inflateReset2 z_inflateReset2 +# define inflateSetDictionary z_inflateSetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateUndermine z_inflateUndermine +# define inflate_copyright z_inflate_copyright +# define inflate_fast z_inflate_fast +# define inflate_table z_inflate_table +# define uncompress z_uncompress +# define zError z_zError +# define zcalloc z_zcalloc +# define zcfree z_zcfree +# define zlibCompileFlags z_zlibCompileFlags +# define zlibVersion z_zlibVersion + +/* all zlib typedefs in zlib.h and zconf.h */ +# define Byte z_Byte +# define Bytef z_Bytef +# define alloc_func z_alloc_func +# define charf z_charf +# define free_func z_free_func +# define gzFile z_gzFile +# define gz_header z_gz_header +# define gz_headerp z_gz_headerp +# define in_func z_in_func +# define intf z_intf +# define out_func z_out_func +# define uInt z_uInt +# define uIntf z_uIntf +# define uLong z_uLong +# define uLongf z_uLongf +# define voidp z_voidp +# define voidpc z_voidpc +# define voidpf z_voidpf + +/* all zlib structs in zlib.h and zconf.h */ +# define gz_header_s z_gz_header_s +# define internal_state z_internal_state + +#endif + +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) +# define OS2 +#endif +#if defined(_WINDOWS) && !defined(WINDOWS) +# define WINDOWS +#endif +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) +# ifndef WIN32 +# define WIN32 +# endif +#endif +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) +# ifndef SYS16BIT +# define SYS16BIT +# endif +# endif +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#ifdef SYS16BIT +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) +# define STDC +#endif +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) +# define STDC +#endif +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) +# define STDC +#endif +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) +# define STDC +#endif + +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ +# define STDC +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const /* note: need a more gentle solution here */ +# endif +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#ifdef SYS16BIT +# if defined(M_I86SM) || defined(M_I86MM) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +# endif +# if (defined(__SMALL__) || defined(__MEDIUM__)) + /* Turbo C small or medium model */ +# define SMALL_MEDIUM +# ifdef __BORLANDC__ +# define FAR _far +# else +# define FAR far +# endif +# endif +#endif + +#if defined(WINDOWS) || defined(WIN32) + /* If building or using zlib as a DLL, define ZLIB_DLL. + * This is not mandatory, but it offers a little performance increase. + */ +# ifdef ZLIB_DLL +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +# endif +# endif /* ZLIB_DLL */ + /* If building or using zlib with the WINAPI/WINAPIV calling convention, + * define ZLIB_WINAPI. + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. + */ +# ifdef ZLIB_WINAPI +# ifdef FAR +# undef FAR +# endif +# include + /* No need for _export, use ZLIB.DEF instead. */ + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR CDECL +# endif +# endif +#endif + +#if defined (__BEOS__) +# ifdef ZLIB_DLL +# ifdef ZLIB_INTERNAL +# define ZEXPORT __declspec(dllexport) +# define ZEXPORTVA __declspec(dllexport) +# else +# define ZEXPORT __declspec(dllimport) +# define ZEXPORTVA __declspec(dllimport) +# endif +# endif +#endif + +#ifndef ZEXTERN +# define ZEXTERN extern +#endif +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(__MACTYPES__) +typedef unsigned char Byte; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void const *voidpc; + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte const *voidpc; + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + +#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_UNISTD_H +#endif + +#ifdef STDC +# include /* for off_t */ +#endif + +/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and + * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even + * though the former does not conform to the LFS document), but considering + * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as + * equivalently requesting no 64-bit operations + */ +#if -_LARGEFILE64_SOURCE - -1 == 1 +# undef _LARGEFILE64_SOURCE +#endif + +#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) +# include /* for SEEK_* and off_t */ +# ifdef VMS +# include /* for off_t */ +# endif +# ifndef z_off_t +# define z_off_t off_t +# endif +#endif + +#ifndef SEEK_SET +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif + +#ifndef z_off_t +# define z_off_t long +#endif + +#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 +# define z_off64_t off64_t +#else +# define z_off64_t z_off_t +#endif + +#if defined(__OS400__) +# define NO_vsnprintf +#endif + +#if defined(__MVS__) +# define NO_vsnprintf +#endif + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) + #pragma map(deflateInit_,"DEIN") + #pragma map(deflateInit2_,"DEIN2") + #pragma map(deflateEnd,"DEEND") + #pragma map(deflateBound,"DEBND") + #pragma map(inflateInit_,"ININ") + #pragma map(inflateInit2_,"ININ2") + #pragma map(inflateEnd,"INEND") + #pragma map(inflateSync,"INSY") + #pragma map(inflateSetDictionary,"INSEDI") + #pragma map(compressBound,"CMBND") + #pragma map(inflate_table,"INTABL") + #pragma map(inflate_fast,"INFA") + #pragma map(inflate_copyright,"INCOPY") +#endif + +#endif /* ZCONF_H */ diff --git a/fceumm/utils/unzip/zip.c b/fceumm/utils/unzip/zip.c new file mode 100644 index 0000000..fef25f2 --- /dev/null +++ b/fceumm/utils/unzip/zip.c @@ -0,0 +1,1220 @@ +/* zip.c -- IO on .zip files using zlib + Version 1.01e, February 12th, 2005 + + 27 Dec 2004 Rolf Kalbermatter + Modification to zipOpen2 to support globalComment retrieval. + + Copyright (C) 1998-2005 Gilles Vollant + + Read zip.h for more info +*/ + + +#include +#include +#include +#include +#include "zlib.h" +#include "zip.h" + +#ifdef STDC +# include +# include +# include +#endif +#ifdef NO_ERRNO_H + extern int errno; +#else +# include +#endif + + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + +#ifndef VERSIONMADEBY +# define VERSIONMADEBY (0x0) /* platform depedent */ +#endif + +#ifndef Z_BUFSIZE +#define Z_BUFSIZE (16384) +#endif + +#ifndef Z_MAXFILENAMEINZIP +#define Z_MAXFILENAMEINZIP (256) +#endif + +#ifndef ALLOC +# define ALLOC(size) (malloc(size)) +#endif +#ifndef TRYFREE +# define TRYFREE(p) {if (p) free(p);} +#endif + +/* +#define SIZECENTRALDIRITEM (0x2e) +#define SIZEZIPLOCALHEADER (0x1e) +*/ + +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +#ifndef DEF_MEM_LEVEL +#if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +#else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +#endif +#endif +const char zip_copyright[] = + " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; + + +#define SIZEDATA_INDATABLOCK (4096-(4*4)) + +#define LOCALHEADERMAGIC (0x04034b50) +#define CENTRALHEADERMAGIC (0x02014b50) +#define ENDHEADERMAGIC (0x06054b50) + +#define FLAG_LOCALHEADER_OFFSET (0x06) +#define CRC_LOCALHEADER_OFFSET (0x0e) + +#define SIZECENTRALHEADER (0x2e) /* 46 */ + +typedef struct linkedlist_datablock_internal_s +{ + struct linkedlist_datablock_internal_s* next_datablock; + uLong avail_in_this_block; + uLong filled_in_this_block; + uLong unused; /* for future use and alignement */ + unsigned char data[SIZEDATA_INDATABLOCK]; +} linkedlist_datablock_internal; + +typedef struct linkedlist_data_s +{ + linkedlist_datablock_internal* first_block; + linkedlist_datablock_internal* last_block; +} linkedlist_data; + + +typedef struct +{ + z_stream stream; /* zLib stream structure for inflate */ + int stream_initialised; /* 1 is stream is initialised */ + uInt pos_in_buffered_data; /* last written byte in buffered_data */ + + uLong pos_local_header; /* offset of the local header of the file + currenty writing */ + char* central_header; /* central header data for the current file */ + uLong size_centralheader; /* size of the central header for cur file */ + uLong flag; /* flag of the file currently writing */ + + int method; /* compression method of file currenty wr.*/ + int raw; /* 1 for directly writing raw data */ + Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/ + uLong dosDate; + uLong crc32; + int encrypt; +#ifndef NOCRYPT + unsigned long keys[3]; /* keys defining the pseudo-random sequence */ + const unsigned long* pcrc_32_tab; + int crypt_header_size; +#endif +} curfile_info; + +typedef struct +{ + zlib_filefunc_def z_filefunc; + voidpf filestream; /* io structore of the zipfile */ + linkedlist_data central_dir;/* datablock with central dir in construction*/ + int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ + curfile_info ci; /* info on the file curretly writing */ + + uLong begin_pos; /* position of the beginning of the zipfile */ + uLong add_position_when_writting_offset; + uLong number_entry; +#ifndef NO_ADDFILEINEXISTINGZIP + char *globalcomment; +#endif +} zip_internal; + + + +#ifndef NOCRYPT +#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED +#include "crypt.h" +#endif + +local linkedlist_datablock_internal* allocate_new_datablock() +{ + linkedlist_datablock_internal* ldi; + ldi = (linkedlist_datablock_internal*) + ALLOC(sizeof(linkedlist_datablock_internal)); + if (ldi!=NULL) + { + ldi->next_datablock = NULL ; + ldi->filled_in_this_block = 0 ; + ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ; + } + return ldi; +} + +local void free_datablock(ldi) + linkedlist_datablock_internal* ldi; +{ + while (ldi!=NULL) + { + linkedlist_datablock_internal* ldinext = ldi->next_datablock; + TRYFREE(ldi); + ldi = ldinext; + } +} + +local void init_linkedlist(ll) + linkedlist_data* ll; +{ + ll->first_block = ll->last_block = NULL; +} + +/* Unused +local void free_linkedlist(ll) + linkedlist_data* ll; +{ + free_datablock(ll->first_block); + ll->first_block = ll->last_block = NULL; +} +*/ + +local int add_data_in_datablock(ll,buf,len) + linkedlist_data* ll; + const void* buf; + uLong len; +{ + linkedlist_datablock_internal* ldi; + const unsigned char* from_copy; + + if (ll==NULL) + return ZIP_INTERNALERROR; + + if (ll->last_block == NULL) + { + ll->first_block = ll->last_block = allocate_new_datablock(); + if (ll->first_block == NULL) + return ZIP_INTERNALERROR; + } + + ldi = ll->last_block; + from_copy = (unsigned char*)buf; + + while (len>0) + { + uInt copy_this; + uInt i; + unsigned char* to_copy; + + if (ldi->avail_in_this_block==0) + { + ldi->next_datablock = allocate_new_datablock(); + if (ldi->next_datablock == NULL) + return ZIP_INTERNALERROR; + ldi = ldi->next_datablock ; + ll->last_block = ldi; + } + + if (ldi->avail_in_this_block < len) + copy_this = (uInt)ldi->avail_in_this_block; + else + copy_this = (uInt)len; + + to_copy = &(ldi->data[ldi->filled_in_this_block]); + + for (i=0;ifilled_in_this_block += copy_this; + ldi->avail_in_this_block -= copy_this; + from_copy += copy_this ; + len -= copy_this; + } + return ZIP_OK; +} + + + +/****************************************************************************/ + +#ifndef NO_ADDFILEINEXISTINGZIP +/* =========================================================================== + Inputs a long in LSB order to the given file + nbByte == 1, 2 or 4 (byte, short or long) +*/ + +local int ziplocal_putValue OF((const zlib_filefunc_def* pzlib_filefunc_def, + voidpf filestream, uLong x, int nbByte)); +local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte) + const zlib_filefunc_def* pzlib_filefunc_def; + voidpf filestream; + uLong x; + int nbByte; +{ + unsigned char buf[4]; + int n; + for (n = 0; n < nbByte; n++) + { + buf[n] = (unsigned char)(x & 0xff); + x >>= 8; + } + if (x != 0) + { /* data overflow - hack for ZIP64 (X Roche) */ + for (n = 0; n < nbByte; n++) + { + buf[n] = 0xff; + } + } + + if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) + return ZIP_ERRNO; + else + return ZIP_OK; +} + +local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte)); +local void ziplocal_putValue_inmemory (dest, x, nbByte) + void* dest; + uLong x; + int nbByte; +{ + unsigned char* buf=(unsigned char*)dest; + int n; + for (n = 0; n < nbByte; n++) { + buf[n] = (unsigned char)(x & 0xff); + x >>= 8; + } + + if (x != 0) + { /* data overflow - hack for ZIP64 */ + for (n = 0; n < nbByte; n++) + { + buf[n] = 0xff; + } + } +} + +/****************************************************************************/ + + +local uLong ziplocal_TmzDateToDosDate(ptm,dosDate) + const tm_zip* ptm; + uLong dosDate; +{ + uLong year = (uLong)ptm->tm_year; + if (year>1980) + year-=1980; + else if (year>80) + year-=80; + return + (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) | + ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour)); +} + + +/****************************************************************************/ + +local int ziplocal_getByte OF(( + const zlib_filefunc_def* pzlib_filefunc_def, + voidpf filestream, + int *pi)); + +local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi) + const zlib_filefunc_def* pzlib_filefunc_def; + voidpf filestream; + int *pi; +{ + unsigned char c; + int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); + if (err==1) + { + *pi = (int)c; + return ZIP_OK; + } + else + { + if (ZERROR(*pzlib_filefunc_def,filestream)) + return ZIP_ERRNO; + else + return ZIP_EOF; + } +} + + +/* =========================================================================== + Reads a long in LSB order from the given gz_stream. Sets +*/ +local int ziplocal_getShort OF(( + const zlib_filefunc_def* pzlib_filefunc_def, + voidpf filestream, + uLong *pX)); + +local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX) + const zlib_filefunc_def* pzlib_filefunc_def; + voidpf filestream; + uLong *pX; +{ + uLong x ; + int i = 0; + int err; + + err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); + x = (uLong)i; + + if (err==ZIP_OK) + err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<8; + + if (err==ZIP_OK) + *pX = x; + else + *pX = 0; + return err; +} + +local int ziplocal_getLong OF(( + const zlib_filefunc_def* pzlib_filefunc_def, + voidpf filestream, + uLong *pX)); + +local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX) + const zlib_filefunc_def* pzlib_filefunc_def; + voidpf filestream; + uLong *pX; +{ + uLong x ; + int i = 0; + int err; + + err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); + x = (uLong)i; + + if (err==ZIP_OK) + err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<8; + + if (err==ZIP_OK) + err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<16; + + if (err==ZIP_OK) + err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<24; + + if (err==ZIP_OK) + *pX = x; + else + *pX = 0; + return err; +} + +#ifndef BUFREADCOMMENT +#define BUFREADCOMMENT (0x400) +#endif +/* + Locate the Central directory of a zipfile (at the end, just before + the global comment) +*/ +local uLong ziplocal_SearchCentralDir OF(( + const zlib_filefunc_def* pzlib_filefunc_def, + voidpf filestream)); + +local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream) + const zlib_filefunc_def* pzlib_filefunc_def; + voidpf filestream; +{ + unsigned char* buf; + uLong uSizeFile; + uLong uBackRead; + uLong uMaxBack=0xffff; /* maximum size of global comment */ + uLong uPosFound=0; + + if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) + return 0; + + + uSizeFile = ZTELL(*pzlib_filefunc_def,filestream); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); + if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) + break; + + if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) + { + uPosFound = uReadPos+i; + break; + } + + if (uPosFound!=0) + break; + } + TRYFREE(buf); + return uPosFound; +} +#endif /* !NO_ADDFILEINEXISTINGZIP*/ + +/************************************************************/ +extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc_def) + const char *pathname; + int append; + zipcharpc* globalcomment; + zlib_filefunc_def* pzlib_filefunc_def; +{ + zip_internal ziinit; + zip_internal* zi; + int err=ZIP_OK; + + + if (pzlib_filefunc_def==NULL) + fill_fopen_filefunc(&ziinit.z_filefunc); + else + ziinit.z_filefunc = *pzlib_filefunc_def; + + ziinit.filestream = (*(ziinit.z_filefunc.zopen_file)) + (ziinit.z_filefunc.opaque, + pathname, + (append == APPEND_STATUS_CREATE) ? + (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) : + (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING)); + + if (ziinit.filestream == NULL) + return NULL; + ziinit.begin_pos = ZTELL(ziinit.z_filefunc,ziinit.filestream); + ziinit.in_opened_file_inzip = 0; + ziinit.ci.stream_initialised = 0; + ziinit.number_entry = 0; + ziinit.add_position_when_writting_offset = 0; + init_linkedlist(&(ziinit.central_dir)); + + + zi = (zip_internal*)ALLOC(sizeof(zip_internal)); + if (zi==NULL) + { + ZCLOSE(ziinit.z_filefunc,ziinit.filestream); + return NULL; + } + + /* now we add file in a zipfile */ +# ifndef NO_ADDFILEINEXISTINGZIP + ziinit.globalcomment = NULL; + if (append == APPEND_STATUS_ADDINZIP) + { + uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ + + uLong size_central_dir; /* size of the central directory */ + uLong offset_central_dir; /* offset of start of central directory */ + uLong central_pos,uL; + + uLong number_disk; /* number of the current dist, used for + spaning ZIP, unsupported, always 0*/ + uLong number_disk_with_CD; /* number the the disk with central dir, used + for spaning ZIP, unsupported, always 0*/ + uLong number_entry; + uLong number_entry_CD; /* total number of entries in + the central dir + (same than number_entry on nospan) */ + uLong size_comment; + + central_pos = ziplocal_SearchCentralDir(&ziinit.z_filefunc,ziinit.filestream); + if (central_pos==0) + err=ZIP_ERRNO; + + if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, + central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) + err=ZIP_ERRNO; + + /* the signature, already checked */ + if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&uL)!=ZIP_OK) + err=ZIP_ERRNO; + + /* number of this disk */ + if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk)!=ZIP_OK) + err=ZIP_ERRNO; + + /* number of the disk with the start of the central directory */ + if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk_with_CD)!=ZIP_OK) + err=ZIP_ERRNO; + + /* total number of entries in the central dir on this disk */ + if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry)!=ZIP_OK) + err=ZIP_ERRNO; + + /* total number of entries in the central dir */ + if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry_CD)!=ZIP_OK) + err=ZIP_ERRNO; + + if ((number_entry_CD!=number_entry) || + (number_disk_with_CD!=0) || + (number_disk!=0)) + err=ZIP_BADZIPFILE; + + /* size of the central directory */ + if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&size_central_dir)!=ZIP_OK) + err=ZIP_ERRNO; + + /* offset of start of central directory with respect to the + starting disk number */ + if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&offset_central_dir)!=ZIP_OK) + err=ZIP_ERRNO; + + /* zipfile global comment length */ + if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&size_comment)!=ZIP_OK) + err=ZIP_ERRNO; + + if ((central_pos0) + { + ziinit.globalcomment = ALLOC(size_comment+1); + if (ziinit.globalcomment) + { + size_comment = ZREAD(ziinit.z_filefunc, ziinit.filestream,ziinit.globalcomment,size_comment); + ziinit.globalcomment[size_comment]=0; + } + } + + byte_before_the_zipfile = central_pos - + (offset_central_dir+size_central_dir); + ziinit.add_position_when_writting_offset = byte_before_the_zipfile; + + { + uLong size_central_dir_to_read = size_central_dir; + size_t buf_size = SIZEDATA_INDATABLOCK; + void* buf_read = (void*)ALLOC(buf_size); + if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, + offset_central_dir + byte_before_the_zipfile, + ZLIB_FILEFUNC_SEEK_SET) != 0) + err=ZIP_ERRNO; + + while ((size_central_dir_to_read>0) && (err==ZIP_OK)) + { + uLong read_this = SIZEDATA_INDATABLOCK; + if (read_this > size_central_dir_to_read) + read_this = size_central_dir_to_read; + if (ZREAD(ziinit.z_filefunc, ziinit.filestream,buf_read,read_this) != read_this) + err=ZIP_ERRNO; + + if (err==ZIP_OK) + err = add_data_in_datablock(&ziinit.central_dir,buf_read, + (uLong)read_this); + size_central_dir_to_read-=read_this; + } + TRYFREE(buf_read); + } + ziinit.begin_pos = byte_before_the_zipfile; + ziinit.number_entry = number_entry_CD; + + if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, + offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) + err=ZIP_ERRNO; + } + + if (globalcomment) + { + *globalcomment = ziinit.globalcomment; + } +# endif /* !NO_ADDFILEINEXISTINGZIP*/ + + if (err != ZIP_OK) + { +# ifndef NO_ADDFILEINEXISTINGZIP + TRYFREE(ziinit.globalcomment); +# endif /* !NO_ADDFILEINEXISTINGZIP*/ + TRYFREE(zi); + return NULL; + } + else + { + *zi = ziinit; + return (zipFile)zi; + } +} + +extern zipFile ZEXPORT zipOpen (pathname, append) + const char *pathname; + int append; +{ + return zipOpen2(pathname,append,NULL,NULL); +} + +extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + windowBits, memLevel, strategy, + password, crcForCrypting) + zipFile file; + const char* filename; + const zip_fileinfo* zipfi; + const void* extrafield_local; + uInt size_extrafield_local; + const void* extrafield_global; + uInt size_extrafield_global; + const char* comment; + int method; + int level; + int raw; + int windowBits; + int memLevel; + int strategy; + const char* password; + uLong crcForCrypting; +{ + zip_internal* zi; + uInt size_filename; + uInt size_comment; + uInt i; + int err = ZIP_OK; + +# ifdef NOCRYPT + if (password != NULL) + return ZIP_PARAMERROR; +# endif + + if (file == NULL) + return ZIP_PARAMERROR; + if ((method!=0) && (method!=Z_DEFLATED)) + return ZIP_PARAMERROR; + + zi = (zip_internal*)file; + + if (zi->in_opened_file_inzip == 1) + { + err = zipCloseFileInZip (file); + if (err != ZIP_OK) + return err; + } + + + if (filename==NULL) + filename="-"; + + if (comment==NULL) + size_comment = 0; + else + size_comment = (uInt)strlen(comment); + + size_filename = (uInt)strlen(filename); + + if (zipfi == NULL) + zi->ci.dosDate = 0; + else + { + if (zipfi->dosDate != 0) + zi->ci.dosDate = zipfi->dosDate; + else zi->ci.dosDate = ziplocal_TmzDateToDosDate(&zipfi->tmz_date,zipfi->dosDate); + } + + zi->ci.flag = 0; + if ((level==8) || (level==9)) + zi->ci.flag |= 2; + if ((level==2)) + zi->ci.flag |= 4; + if ((level==1)) + zi->ci.flag |= 6; + if (password != NULL) + zi->ci.flag |= 1; + + zi->ci.crc32 = 0; + zi->ci.method = method; + zi->ci.encrypt = 0; + zi->ci.stream_initialised = 0; + zi->ci.pos_in_buffered_data = 0; + zi->ci.raw = raw; + zi->ci.pos_local_header = ZTELL(zi->z_filefunc,zi->filestream) ; + zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + + size_extrafield_global + size_comment; + zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader); + + ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4); + /* version info */ + ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2); + ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2); + ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2); + ziplocal_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2); + ziplocal_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4); + ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/ + ziplocal_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/ + ziplocal_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/ + ziplocal_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2); + ziplocal_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2); + ziplocal_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2); + ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/ + + if (zipfi==NULL) + ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2); + else + ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2); + + if (zipfi==NULL) + ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4); + else + ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); + + ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header- zi->add_position_when_writting_offset,4); + + for (i=0;ici.central_header+SIZECENTRALHEADER+i) = *(filename+i); + + for (i=0;ici.central_header+SIZECENTRALHEADER+size_filename+i) = + *(((const char*)extrafield_global)+i); + + for (i=0;ici.central_header+SIZECENTRALHEADER+size_filename+ + size_extrafield_global+i) = *(comment+i); + if (zi->ci.central_header == NULL) + return ZIP_INTERNALERROR; + + /* write the local header */ + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC,4); + + if (err==ZIP_OK) + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */ + if (err==ZIP_OK) + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2); + + if (err==ZIP_OK) + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2); + + if (err==ZIP_OK) + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4); + + if (err==ZIP_OK) + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */ + if (err==ZIP_OK) + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */ + if (err==ZIP_OK) + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */ + + if (err==ZIP_OK) + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2); + + if (err==ZIP_OK) + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield_local,2); + + if ((err==ZIP_OK) && (size_filename>0)) + if (ZWRITE(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename) + err = ZIP_ERRNO; + + if ((err==ZIP_OK) && (size_extrafield_local>0)) + if (ZWRITE(zi->z_filefunc,zi->filestream,extrafield_local,size_extrafield_local) + !=size_extrafield_local) + err = ZIP_ERRNO; + + zi->ci.stream.avail_in = (uInt)0; + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.stream.next_out = zi->ci.buffered_data; + zi->ci.stream.total_in = 0; + zi->ci.stream.total_out = 0; + + if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) + { + zi->ci.stream.zalloc = (alloc_func)0; + zi->ci.stream.zfree = (free_func)0; + zi->ci.stream.opaque = (voidpf)0; + + if (windowBits>0) + windowBits = -windowBits; + + err = deflateInit2(&zi->ci.stream, level, + Z_DEFLATED, windowBits, memLevel, strategy); + + if (err==Z_OK) + zi->ci.stream_initialised = 1; + } +# ifndef NOCRYPT + zi->ci.crypt_header_size = 0; + if ((err==Z_OK) && (password != NULL)) + { + unsigned char bufHead[RAND_HEAD_LEN]; + unsigned int sizeHead; + zi->ci.encrypt = 1; + zi->ci.pcrc_32_tab = get_crc_table(); + /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/ + + sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting); + zi->ci.crypt_header_size = sizeHead; + + if (ZWRITE(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead) + err = ZIP_ERRNO; + } +# endif + + if (err==Z_OK) + zi->in_opened_file_inzip = 1; + return err; +} + +extern int ZEXPORT zipOpenNewFileInZip2(file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw) + zipFile file; + const char* filename; + const zip_fileinfo* zipfi; + const void* extrafield_local; + uInt size_extrafield_local; + const void* extrafield_global; + uInt size_extrafield_global; + const char* comment; + int method; + int level; + int raw; +{ + return zipOpenNewFileInZip3 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, + NULL, 0); +} + +extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level) + zipFile file; + const char* filename; + const zip_fileinfo* zipfi; + const void* extrafield_local; + uInt size_extrafield_local; + const void* extrafield_global; + uInt size_extrafield_global; + const char* comment; + int method; + int level; +{ + return zipOpenNewFileInZip2 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, 0); +} + +local int zipFlushWriteBuffer(zi) + zip_internal* zi; +{ + int err=ZIP_OK; + + if (zi->ci.encrypt != 0) + { +#ifndef NOCRYPT + uInt i; + int t; + for (i=0;ici.pos_in_buffered_data;i++) + zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, + zi->ci.buffered_data[i],t); +#endif + } + if (ZWRITE(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) + !=zi->ci.pos_in_buffered_data) + err = ZIP_ERRNO; + zi->ci.pos_in_buffered_data = 0; + return err; +} + +extern int ZEXPORT zipWriteInFileInZip (file, buf, len) + zipFile file; + const void* buf; + unsigned len; +{ + zip_internal* zi; + int err=ZIP_OK; + + if (file == NULL) + return ZIP_PARAMERROR; + zi = (zip_internal*)file; + + if (zi->in_opened_file_inzip == 0) + return ZIP_PARAMERROR; + + zi->ci.stream.next_in = (void*)buf; + zi->ci.stream.avail_in = len; + zi->ci.crc32 = crc32(zi->ci.crc32,buf,len); + + while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) + { + if (zi->ci.stream.avail_out == 0) + { + if (zipFlushWriteBuffer(zi) == ZIP_ERRNO) + err = ZIP_ERRNO; + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.stream.next_out = zi->ci.buffered_data; + } + + + if(err != ZIP_OK) + break; + + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) + { + uLong uTotalOutBefore = zi->ci.stream.total_out; + err=deflate(&zi->ci.stream, Z_NO_FLUSH); + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; + + } + else + { + uInt copy_this,i; + if (zi->ci.stream.avail_in < zi->ci.stream.avail_out) + copy_this = zi->ci.stream.avail_in; + else + copy_this = zi->ci.stream.avail_out; + for (i=0;ici.stream.next_out)+i) = + *(((const char*)zi->ci.stream.next_in)+i); + { + zi->ci.stream.avail_in -= copy_this; + zi->ci.stream.avail_out-= copy_this; + zi->ci.stream.next_in+= copy_this; + zi->ci.stream.next_out+= copy_this; + zi->ci.stream.total_in+= copy_this; + zi->ci.stream.total_out+= copy_this; + zi->ci.pos_in_buffered_data += copy_this; + } + } + } + + return err; +} + +extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32) + zipFile file; + uLong uncompressed_size; + uLong crc32; +{ + zip_internal* zi; + uLong compressed_size; + int err=ZIP_OK; + + if (file == NULL) + return ZIP_PARAMERROR; + zi = (zip_internal*)file; + + if (zi->in_opened_file_inzip == 0) + return ZIP_PARAMERROR; + zi->ci.stream.avail_in = 0; + + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) + while (err==ZIP_OK) + { + uLong uTotalOutBefore; + if (zi->ci.stream.avail_out == 0) + { + if (zipFlushWriteBuffer(zi) == ZIP_ERRNO) + err = ZIP_ERRNO; + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.stream.next_out = zi->ci.buffered_data; + } + uTotalOutBefore = zi->ci.stream.total_out; + err=deflate(&zi->ci.stream, Z_FINISH); + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; + } + + if (err==Z_STREAM_END) + err=ZIP_OK; /* this is normal */ + + if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK)) + if (zipFlushWriteBuffer(zi)==ZIP_ERRNO) + err = ZIP_ERRNO; + + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) + { + err=deflateEnd(&zi->ci.stream); + zi->ci.stream_initialised = 0; + } + + if (!zi->ci.raw) + { + crc32 = (uLong)zi->ci.crc32; + uncompressed_size = (uLong)zi->ci.stream.total_in; + } + compressed_size = (uLong)zi->ci.stream.total_out; +# ifndef NOCRYPT + compressed_size += zi->ci.crypt_header_size; +# endif + + ziplocal_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/ + ziplocal_putValue_inmemory(zi->ci.central_header+20, + compressed_size,4); /*compr size*/ + if (zi->ci.stream.data_type == Z_ASCII) + ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2); + ziplocal_putValue_inmemory(zi->ci.central_header+24, + uncompressed_size,4); /*uncompr size*/ + + if (err==ZIP_OK) + err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header, + (uLong)zi->ci.size_centralheader); + free(zi->ci.central_header); + + if (err==ZIP_OK) + { + long cur_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream); + if (ZSEEK(zi->z_filefunc,zi->filestream, + zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0) + err = ZIP_ERRNO; + + if (err==ZIP_OK) + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */ + + if (err==ZIP_OK) /* compressed size, unknown */ + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4); + + if (err==ZIP_OK) /* uncompressed size, unknown */ + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4); + + if (ZSEEK(zi->z_filefunc,zi->filestream, + cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0) + err = ZIP_ERRNO; + } + + zi->number_entry ++; + zi->in_opened_file_inzip = 0; + + return err; +} + +extern int ZEXPORT zipCloseFileInZip (file) + zipFile file; +{ + return zipCloseFileInZipRaw (file,0,0); +} + +extern int ZEXPORT zipClose (file, global_comment) + zipFile file; + const char* global_comment; +{ + zip_internal* zi; + int err = 0; + uLong size_centraldir = 0; + uLong centraldir_pos_inzip; + uInt size_global_comment; + if (file == NULL) + return ZIP_PARAMERROR; + zi = (zip_internal*)file; + + if (zi->in_opened_file_inzip == 1) + { + err = zipCloseFileInZip (file); + } + +#ifndef NO_ADDFILEINEXISTINGZIP + if (global_comment==NULL) + global_comment = zi->globalcomment; +#endif + if (global_comment==NULL) + size_global_comment = 0; + else + size_global_comment = (uInt)strlen(global_comment); + + centraldir_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream); + if (err==ZIP_OK) + { + linkedlist_datablock_internal* ldi = zi->central_dir.first_block ; + while (ldi!=NULL) + { + if ((err==ZIP_OK) && (ldi->filled_in_this_block>0)) + if (ZWRITE(zi->z_filefunc,zi->filestream, + ldi->data,ldi->filled_in_this_block) + !=ldi->filled_in_this_block ) + err = ZIP_ERRNO; + + size_centraldir += ldi->filled_in_this_block; + ldi = ldi->next_datablock; + } + } + free_datablock(zi->central_dir.first_block); + + if (err==ZIP_OK) /* Magic End */ + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4); + + if (err==ZIP_OK) /* number of this disk */ + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); + + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); + + if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); + + if (err==ZIP_OK) /* total number of entries in the central dir */ + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); + + if (err==ZIP_OK) /* size of the central directory */ + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4); + + if (err==ZIP_OK) /* offset of start of central directory with respect to the + starting disk number */ + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream, + (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4); + + if (err==ZIP_OK) /* zipfile comment length */ + err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2); + + if ((err==ZIP_OK) && (size_global_comment>0)) + if (ZWRITE(zi->z_filefunc,zi->filestream, + global_comment,size_global_comment) != size_global_comment) + err = ZIP_ERRNO; + + if (ZCLOSE(zi->z_filefunc,zi->filestream) != 0) + if (err == ZIP_OK) + err = ZIP_ERRNO; + +#ifndef NO_ADDFILEINEXISTINGZIP + TRYFREE(zi->globalcomment); +#endif + TRYFREE(zi); + + return err; +} diff --git a/fceumm/utils/unzip/zip.h b/fceumm/utils/unzip/zip.h new file mode 100644 index 0000000..cd38b67 --- /dev/null +++ b/fceumm/utils/unzip/zip.h @@ -0,0 +1,235 @@ +/* zip.h -- IO for compress .zip files using zlib + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant + + This unzip package allow creates .ZIP file, compatible with PKZip 2.04g + WinZip, InfoZip tools and compatible. + Multi volume ZipFile (span) are not supported. + Encryption compatible with pkzip 2.04g only supported + Old compressions used by old PKZip 1.x are not supported + + For uncompress .zip file, look at unzip.h + + + I WAIT FEEDBACK at mail info@winimage.com + Visit also http://www.winimage.com/zLibDll/unzip.html for evolution + + Condition of use and distribution are the same than zlib : + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + +*/ + +/* for more info about .ZIP format, see + http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip + http://www.info-zip.org/pub/infozip/doc/ + PkWare has also a specification at : + ftp://ftp.pkware.com/probdesc.zip +*/ + +#ifndef _zip_H +#define _zip_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#ifndef _ZLIBIOAPI_H +#include "ioapi.h" +#endif + +#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) +/* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ +typedef struct TagzipFile__ { int unused; } zipFile__; +typedef zipFile__ *zipFile; +#else +typedef voidp zipFile; +#endif + +#define ZIP_OK (0) +#define ZIP_EOF (0) +#define ZIP_ERRNO (Z_ERRNO) +#define ZIP_PARAMERROR (-102) +#define ZIP_BADZIPFILE (-103) +#define ZIP_INTERNALERROR (-104) + +#ifndef DEF_MEM_LEVEL +# if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +# else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +# endif +#endif +/* default memLevel */ + +/* tm_zip contain date/time info */ +typedef struct tm_zip_s +{ + uInt tm_sec; /* seconds after the minute - [0,59] */ + uInt tm_min; /* minutes after the hour - [0,59] */ + uInt tm_hour; /* hours since midnight - [0,23] */ + uInt tm_mday; /* day of the month - [1,31] */ + uInt tm_mon; /* months since January - [0,11] */ + uInt tm_year; /* years - [1980..2044] */ +} tm_zip; + +typedef struct +{ + tm_zip tmz_date; /* date in understandable format */ + uLong dosDate; /* if dos_date == 0, tmu_date is used */ +/* uLong flag; */ /* general purpose bit flag 2 bytes */ + + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ +} zip_fileinfo; + +typedef const char* zipcharpc; + + +#define APPEND_STATUS_CREATE (0) +#define APPEND_STATUS_CREATEAFTER (1) +#define APPEND_STATUS_ADDINZIP (2) + +extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); +/* + Create a zipfile. + pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on + an Unix computer "zlib/zlib113.zip". + if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip + will be created at the end of the file. + (useful if the file contain a self extractor code) + if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will + add files in existing zip (be sure you don't add file that doesn't exist) + If the zipfile cannot be opened, the return value is NULL. + Else, the return value is a zipFile Handle, usable with other function + of this zip package. +*/ + +/* Note : there is no delete function into a zipfile. + If you want delete file into a zipfile, you must open a zipfile, and create another + Of couse, you can use RAW reading and writing to copy the file you did not want delte +*/ + +extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, + int append, + zipcharpc* globalcomment, + zlib_filefunc_def* pzlib_filefunc_def)); + +extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level)); +/* + Open a file in the ZIP for writing. + filename : the filename in zip (if NULL, '-' without quote will be used + *zipfi contain supplemental information + if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local + contains the extrafield data the the local header + if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global + contains the extrafield data the the local header + if comment != NULL, comment contain the comment string + method contain the compression method (0 for store, Z_DEFLATED for deflate) + level contain the level of compression (can be Z_DEFAULT_COMPRESSION) +*/ + + +extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw)); + +/* + Same than zipOpenNewFileInZip, except if raw=1, we write raw file + */ + +extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCtypting)); + +/* + Same than zipOpenNewFileInZip2, except + windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 + password : crypting password (NULL for no crypting) + crcForCtypting : crc of file to compress (needed for crypting) + */ + + +extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, + const void* buf, + unsigned len)); +/* + Write data in the zipfile +*/ + +extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); +/* + Close the current file in the zipfile +*/ + +extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, + uLong uncompressed_size, + uLong crc32)); +/* + Close the current file in the zipfile, for fiel opened with + parameter raw=1 in zipOpenNewFileInZip2 + uncompressed_size and crc32 are value for the uncompressed size +*/ + +extern int ZEXPORT zipClose OF((zipFile file, + const char* global_comment)); +/* + Close the zipfile +*/ + +#ifdef __cplusplus +} +#endif + +#endif /* _zip_H */ diff --git a/fceumm/utils/unzip/zlib.h b/fceumm/utils/unzip/zlib.h new file mode 100644 index 0000000..bfbba83 --- /dev/null +++ b/fceumm/utils/unzip/zlib.h @@ -0,0 +1,1613 @@ +/* zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.5, April 19th, 2010 + + Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + + + The data format used by the zlib library is described by RFCs (Request for + Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt + (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). +*/ + +#ifndef ZLIB_H +#define ZLIB_H + +#include "zconf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ZLIB_VERSION "1.2.5" +#define ZLIB_VERNUM 0x1250 +#define ZLIB_VER_MAJOR 1 +#define ZLIB_VER_MINOR 2 +#define ZLIB_VER_REVISION 5 +#define ZLIB_VER_SUBREVISION 0 + +/* + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed data. + This version of the library supports only one compression method (deflation) + but other algorithms will be added later and will have the same stream + interface. + + Compression can be done in a single step if the buffers are large enough, + or can be done by repeated calls of the compression function. In the latter + case, the application must provide more input and/or consume the output + (providing more output space) before each call. + + The compressed data format used by default by the in-memory functions is + the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped + around a deflate stream, which is itself documented in RFC 1951. + + The library also supports reading and writing files in gzip (.gz) format + with an interface similar to that of stdio using the functions that start + with "gz". The gzip format is different from the zlib format. gzip is a + gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. + + This library can optionally read and write gzip streams in memory as well. + + The zlib format was designed to be compact and fast for use in memory + and on communications channels. The gzip format was designed for single- + file compression on file systems, has a larger header than zlib to maintain + directory information, and uses a different, slower check method than zlib. + + The library does not install any signal handler. The decoder checks + the consistency of the compressed data, so the library should never crash + even in case of corrupted input. +*/ + +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); +typedef void (*free_func) OF((voidpf opaque, voidpf address)); + +struct internal_state; + +typedef struct z_stream_s { + Bytef *next_in; /* next input byte */ + uInt avail_in; /* number of bytes available at next_in */ + uLong total_in; /* total nb of input bytes read so far */ + + Bytef *next_out; /* next output byte should be put there */ + uInt avail_out; /* remaining free space at next_out */ + uLong total_out; /* total nb of bytes output so far */ + + char *msg; /* last error message, NULL if no error */ + struct internal_state FAR *state; /* not visible by applications */ + + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + voidpf opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: binary or text */ + uLong adler; /* adler32 value of the uncompressed data */ + uLong reserved; /* reserved for future use */ +} z_stream; + +typedef z_stream FAR *z_streamp; + +/* + gzip header information passed to and from zlib routines. See RFC 1952 + for more details on the meanings of these fields. +*/ +typedef struct gz_header_s { + int text; /* true if compressed data believed to be text */ + uLong time; /* modification time */ + int xflags; /* extra flags (not used when writing a gzip file) */ + int os; /* operating system */ + Bytef *extra; /* pointer to extra field or Z_NULL if none */ + uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ + uInt extra_max; /* space at extra (only when reading header) */ + Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ + uInt name_max; /* space at name (only when reading header) */ + Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ + uInt comm_max; /* space at comment (only when reading header) */ + int hcrc; /* true if there was or will be a header crc */ + int done; /* true when done reading gzip header (not used + when writing a gzip file) */ +} gz_header; + +typedef gz_header FAR *gz_headerp; + +/* + The application must update next_in and avail_in when avail_in has dropped + to zero. It must update next_out and avail_out when avail_out has dropped + to zero. The application must initialize zalloc, zfree and opaque before + calling the init function. All other fields are set by the compression + library and must not be updated by the application. + + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the + opaque value. + + zalloc must return Z_NULL if there is not enough memory for the object. + If zlib is used in a multi-threaded application, zalloc and zfree must be + thread safe. + + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this if + the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers + returned by zalloc for objects of exactly 65536 bytes *must* have their + offset normalized to zero. The default allocation function provided by this + library ensures this (see zutil.c). To reduce memory requirements and avoid + any allocation of 64K objects, at the expense of compression ratio, compile + the library with -DMAX_WBITS=14 (see zconf.h). + + The fields total_in and total_out can be used for statistics or progress + reports. After compression, total_in holds the total size of the + uncompressed data and may be saved for use in the decompressor (particularly + if the decompressor wants to decompress everything in a single step). +*/ + + /* constants */ + +#define Z_NO_FLUSH 0 +#define Z_PARTIAL_FLUSH 1 +#define Z_SYNC_FLUSH 2 +#define Z_FULL_FLUSH 3 +#define Z_FINISH 4 +#define Z_BLOCK 5 +#define Z_TREES 6 +/* Allowed flush values; see deflate() and inflate() below for details */ + +#define Z_OK 0 +#define Z_STREAM_END 1 +#define Z_NEED_DICT 2 +#define Z_ERRNO (-1) +#define Z_STREAM_ERROR (-2) +#define Z_DATA_ERROR (-3) +#define Z_MEM_ERROR (-4) +#define Z_BUF_ERROR (-5) +#define Z_VERSION_ERROR (-6) +/* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ + +#define Z_NO_COMPRESSION 0 +#define Z_BEST_SPEED 1 +#define Z_BEST_COMPRESSION 9 +#define Z_DEFAULT_COMPRESSION (-1) +/* compression levels */ + +#define Z_FILTERED 1 +#define Z_HUFFMAN_ONLY 2 +#define Z_RLE 3 +#define Z_FIXED 4 +#define Z_DEFAULT_STRATEGY 0 +/* compression strategy; see deflateInit2() below for details */ + +#define Z_BINARY 0 +#define Z_TEXT 1 +#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ +#define Z_UNKNOWN 2 +/* Possible values of the data_type field (though see inflate()) */ + +#define Z_DEFLATED 8 +/* The deflate compression method (the only one supported in this version) */ + +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ + +#define zlib_version zlibVersion() +/* for compatibility with versions < 1.0.2 */ + + + /* basic functions */ + +ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. + If the first character differs, the library code actually used is not + compatible with the zlib.h header file used by the application. This check + is automatically made by deflateInit and inflateInit. + */ + +/* +ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); + + Initializes the internal stream state for compression. The fields + zalloc, zfree and opaque must be initialized before by the caller. If + zalloc and zfree are set to Z_NULL, deflateInit updates them to use default + allocation functions. + + The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: + 1 gives best speed, 9 gives best compression, 0 gives no compression at all + (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION + requests a default compromise between speed and compression (currently + equivalent to level 6). + + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if level is not a valid compression level, or + Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible + with the version assumed by the caller (ZLIB_VERSION). msg is set to null + if there is no error message. deflateInit does not perform any compression: + this will be done by deflate(). +*/ + + +ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +/* + deflate compresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. deflate performs one or both of the + following actions: + + - Compress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in and avail_in are updated and + processing will resume at this point for the next call of deflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. This action is forced if the parameter flush is non zero. + Forcing flush frequently degrades the compression ratio, so this parameter + should be set only when necessary (in interactive applications). Some + output may be provided even if flush is not set. + + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating avail_in or avail_out accordingly; avail_out should + never be zero before the call. The application can consume the compressed + output when it wants, for example when the output buffer is full (avail_out + == 0), or after each call of deflate(). If deflate returns Z_OK and with + zero avail_out, it must be called again after making room in the output + buffer because there might be more output pending. + + Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to + decide how much data to accumulate before producing output, in order to + maximize compression. + + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is + flushed to the output buffer and the output is aligned on a byte boundary, so + that the decompressor can get all input data available so far. (In + particular avail_in is zero after the call if enough output space has been + provided before the call.) Flushing may degrade compression for some + compression algorithms and so it should be used only when necessary. This + completes the current deflate block and follows it with an empty stored block + that is three bits plus filler bits to the next byte, followed by four bytes + (00 00 ff ff). + + If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the + output buffer, but the output is not aligned to a byte boundary. All of the + input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. + This completes the current deflate block and follows it with an empty fixed + codes block that is 10 bits long. This assures that enough bytes are output + in order for the decompressor to finish the block before the empty fixed code + block. + + If flush is set to Z_BLOCK, a deflate block is completed and emitted, as + for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to + seven bits of the current block are held to be written as the next byte after + the next deflate block is completed. In this case, the decompressor may not + be provided enough bits at this point in order to complete decompression of + the data provided so far to the compressor. It may need to wait for the next + block to be emitted. This is for advanced applications that need to control + the emission of deflate blocks. + + If flush is set to Z_FULL_FLUSH, all output is flushed as with + Z_SYNC_FLUSH, and the compression state is reset so that decompression can + restart from this point if previous compressed data has been damaged or if + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade + compression. + + If deflate returns with avail_out == 0, this function must be called again + with the same value of the flush parameter and more output space (updated + avail_out), until the flush is complete (deflate returns with non-zero + avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that + avail_out is greater than six to avoid repeated flush markers due to + avail_out == 0 on return. + + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there was + enough output space; if deflate returns with Z_OK, this function must be + called again with Z_FINISH and more output space (updated avail_out) but no + more input data, until it returns with Z_STREAM_END or an error. After + deflate has returned Z_STREAM_END, the only possible operations on the stream + are deflateReset or deflateEnd. + + Z_FINISH can be used immediately after deflateInit if all the compression + is to be done in a single step. In this case, avail_out must be at least the + value returned by deflateBound (see below). If deflate does not return + Z_STREAM_END, then it must be called again as described above. + + deflate() sets strm->adler to the adler32 checksum of all input read + so far (that is, total_in bytes). + + deflate() may update strm->data_type if it can make a good guess about + the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered + binary. This field is only for information purposes and does not affect the + compression algorithm in any manner. + + deflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if all input has been + consumed and all output has been produced (only when flush is set to + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example + if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible + (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not + fatal, and deflate() can be called again with more input and more output + space to continue compressing. +*/ + + +ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the + stream state was inconsistent, Z_DATA_ERROR if the stream was freed + prematurely (some input or output was discarded). In the error case, msg + may be set but then points to a static string (which must not be + deallocated). +*/ + + +/* +ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); + + Initializes the internal stream state for decompression. The fields + next_in, avail_in, zalloc, zfree and opaque must be initialized before by + the caller. If next_in is not Z_NULL and avail_in is large enough (the + exact value depends on the compression method), inflateInit determines the + compression method from the zlib header and allocates all data structures + accordingly; otherwise the allocation will be deferred to the first call of + inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to + use default allocation functions. + + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit() does not process any header information -- that is deferred + until inflate() is called. +*/ + + +ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +/* + inflate decompresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. inflate performs one or both of the + following actions: + + - Decompress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in is updated and processing will + resume at this point for the next call of inflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. inflate() provides as much output as possible, until there is + no more input data or no more space in the output buffer (see below about + the flush parameter). + + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating the next_* and avail_* values accordingly. The + application can consume the uncompressed output when it wants, for example + when the output buffer is full (avail_out == 0), or after each call of + inflate(). If inflate returns Z_OK and with zero avail_out, it must be + called again after making room in the output buffer because there might be + more output pending. + + The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, + Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much + output as possible to the output buffer. Z_BLOCK requests that inflate() + stop if and when it gets to the next deflate block boundary. When decoding + the zlib or gzip format, this will cause inflate() to return immediately + after the header and before the first block. When doing a raw inflate, + inflate() will go ahead and process the first block, and will return when it + gets to the end of that block, or when it runs out of data. + + The Z_BLOCK option assists in appending to or combining deflate streams. + Also to assist in this, on return inflate() will set strm->data_type to the + number of unused bits in the last byte taken from strm->next_in, plus 64 if + inflate() is currently decoding the last block in the deflate stream, plus + 128 if inflate() returned immediately after decoding an end-of-block code or + decoding the complete header up to just before the first byte of the deflate + stream. The end-of-block will not be indicated until all of the uncompressed + data from that block has been written to strm->next_out. The number of + unused bits may in general be greater than seven, except when bit 7 of + data_type is set, in which case the number of unused bits will be less than + eight. data_type is set as noted here every time inflate() returns for all + flush options, and so can be used to determine the amount of currently + consumed input in bits. + + The Z_TREES option behaves as Z_BLOCK does, but it also returns when the + end of each deflate block header is reached, before any actual data in that + block is decoded. This allows the caller to determine the length of the + deflate block header for later use in random access within a deflate block. + 256 is added to the value of strm->data_type when inflate() returns + immediately after reaching the end of the deflate block header. + + inflate() should normally be called until it returns Z_STREAM_END or an + error. However if all decompression is to be performed in a single step (a + single call of inflate), the parameter flush should be set to Z_FINISH. In + this case all pending input is processed and all pending output is flushed; + avail_out must be large enough to hold all the uncompressed data. (The size + of the uncompressed data may have been saved by the compressor for this + purpose.) The next operation on this stream must be inflateEnd to deallocate + the decompression state. The use of Z_FINISH is never required, but can be + used to inform inflate that a faster approach may be used for the single + inflate() call. + + In this implementation, inflate() always flushes as much output as + possible to the output buffer, and always uses the faster approach on the + first call. So the only effect of the flush parameter in this implementation + is on the return value of inflate(), as noted below, or when it returns early + because Z_BLOCK or Z_TREES is used. + + If a preset dictionary is needed after this call (see inflateSetDictionary + below), inflate sets strm->adler to the adler32 checksum of the dictionary + chosen by the compressor and returns Z_NEED_DICT; otherwise it sets + strm->adler to the adler32 checksum of all output produced so far (that is, + total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described + below. At the end of the stream, inflate() checks that its computed adler32 + checksum is equal to that saved by the compressor and returns Z_STREAM_END + only if the checksum is correct. + + inflate() can decompress and check either zlib-wrapped or gzip-wrapped + deflate data. The header type is detected automatically, if requested when + initializing with inflateInit2(). Any information contained in the gzip + header is not retained, so applications that need that information should + instead use raw inflate, see inflateInit2() below, or inflateBack() and + perform their own processing of the gzip header and trailer. + + inflate() returns Z_OK if some progress has been made (more input processed + or more output produced), Z_STREAM_END if the end of the compressed data has + been reached and all uncompressed output has been produced, Z_NEED_DICT if a + preset dictionary is needed at this point, Z_DATA_ERROR if the input data was + corrupted (input stream not conforming to the zlib format or incorrect check + value), Z_STREAM_ERROR if the stream structure was inconsistent (for example + next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, + Z_BUF_ERROR if no progress is possible or if there was not enough room in the + output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and + inflate() can be called again with more input and more output space to + continue decompressing. If Z_DATA_ERROR is returned, the application may + then call inflateSync() to look for a good compression block if a partial + recovery of the data is desired. +*/ + + +ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state + was inconsistent. In the error case, msg may be set but then points to a + static string (which must not be deallocated). +*/ + + + /* Advanced functions */ + +/* + The following functions are needed only in some special applications. +*/ + +/* +ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy)); + + This is another version of deflateInit with more compression options. The + fields next_in, zalloc, zfree and opaque must be initialized before by the + caller. + + The method parameter is the compression method. It must be Z_DEFLATED in + this version of the library. + + The windowBits parameter is the base two logarithm of the window size + (the size of the history buffer). It should be in the range 8..15 for this + version of the library. Larger values of this parameter result in better + compression at the expense of memory usage. The default value is 15 if + deflateInit is used instead. + + windowBits can also be -8..-15 for raw deflate. In this case, -windowBits + determines the window size. deflate() will then generate raw deflate data + with no zlib header or trailer, and will not compute an adler32 check value. + + windowBits can also be greater than 15 for optional gzip encoding. Add + 16 to windowBits to write a simple gzip header and trailer around the + compressed data instead of a zlib wrapper. The gzip header will have no + file name, no extra data, no comment, no modification time (set to zero), no + header crc, and the operating system will be set to 255 (unknown). If a + gzip stream is being written, strm->adler is a crc32 instead of an adler32. + + The memLevel parameter specifies how much memory should be allocated + for the internal compression state. memLevel=1 uses minimum memory but is + slow and reduces compression ratio; memLevel=9 uses maximum memory for + optimal speed. The default value is 8. See zconf.h for total memory usage + as a function of windowBits and memLevel. + + The strategy parameter is used to tune the compression algorithm. Use the + value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a + filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no + string match), or Z_RLE to limit match distances to one (run-length + encoding). Filtered data consists mostly of small values with a somewhat + random distribution. In this case, the compression algorithm is tuned to + compress them better. The effect of Z_FILTERED is to force more Huffman + coding and less string matching; it is somewhat intermediate between + Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as + fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The + strategy parameter only affects the compression ratio but not the + correctness of the compressed output even if it is not set appropriately. + Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler + decoder for special applications. + + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid + method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is + incompatible with the version assumed by the caller (ZLIB_VERSION). msg is + set to null if there is no error message. deflateInit2 does not perform any + compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the compression dictionary from the given byte sequence + without producing any compressed output. This function must be called + immediately after deflateInit, deflateInit2 or deflateReset, before any call + of deflate. The compressor and decompressor must use exactly the same + dictionary (see inflateSetDictionary). + + The dictionary should consist of strings (byte sequences) that are likely + to be encountered later in the data to be compressed, with the most commonly + used strings preferably put towards the end of the dictionary. Using a + dictionary is most useful when the data to be compressed is short and can be + predicted with good accuracy; the data can then be compressed better than + with the default empty dictionary. + + Depending on the size of the compression data structures selected by + deflateInit or deflateInit2, a part of the dictionary may in effect be + discarded, for example if the dictionary is larger than the window size + provided in deflateInit or deflateInit2. Thus the strings most likely to be + useful should be put at the end of the dictionary, not at the front. In + addition, the current implementation of deflate will use at most the window + size minus 262 bytes of the provided dictionary. + + Upon return of this function, strm->adler is set to the adler32 value + of the dictionary; the decompressor may later use this value to determine + which dictionary has been used by the compressor. (The adler32 value + applies to the whole dictionary even if only a subset of the dictionary is + actually used by the compressor.) If a raw deflate was requested, then the + adler32 value is not computed and strm->adler is not set. + + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent (for example if deflate has already been called for this stream + or if the compression method is bsort). deflateSetDictionary does not + perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when several compression strategies will be + tried, for example when there are several ways of pre-processing the input + data with a filter. The streams that will be discarded should then be freed + by calling deflateEnd. Note that deflateCopy duplicates the internal + compression state which can be quite large, so this strategy is slow and can + consume lots of memory. + + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +/* + This function is equivalent to deflateEnd followed by deflateInit, + but does not free and reallocate all the internal compression state. The + stream will keep the same compression level and any other attributes that + may have been set by deflateInit2. + + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, + int level, + int strategy)); +/* + Dynamically update the compression level and compression strategy. The + interpretation of level and strategy is as in deflateInit2. This can be + used to switch between compression and straight copy of the input data, or + to switch to a different kind of input data requiring a different strategy. + If the compression level is changed, the input available so far is + compressed with the old level (and may be flushed); the new level will take + effect only at the next call of deflate(). + + Before the call of deflateParams, the stream state must be set as for + a call of deflate(), since the currently available input may have to be + compressed and flushed. In particular, strm->avail_out must be non-zero. + + deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source + stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if + strm->avail_out was zero. +*/ + +ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, + int good_length, + int max_lazy, + int nice_length, + int max_chain)); +/* + Fine tune deflate's internal compression parameters. This should only be + used by someone who understands the algorithm used by zlib's deflate for + searching for the best matching string, and even then only by the most + fanatic optimizer trying to squeeze out the last compressed bit for their + specific input data. Read the deflate.c source code for the meaning of the + max_lazy, good_length, nice_length, and max_chain parameters. + + deflateTune() can be called after deflateInit() or deflateInit2(), and + returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. + */ + +ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, + uLong sourceLen)); +/* + deflateBound() returns an upper bound on the compressed size after + deflation of sourceLen bytes. It must be called after deflateInit() or + deflateInit2(), and after deflateSetHeader(), if used. This would be used + to allocate an output buffer for deflation in a single pass, and so would be + called before deflate(). +*/ + +ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + deflatePrime() inserts bits in the deflate output stream. The intent + is that this function is used to start off the deflate output with the bits + leftover from a previous deflate stream when appending to it. As such, this + function can only be used for raw deflate, and must be used before the first + deflate() call after a deflateInit2() or deflateReset(). bits must be less + than or equal to 16, and that many of the least significant bits of value + will be inserted in the output. + + deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, + gz_headerp head)); +/* + deflateSetHeader() provides gzip header information for when a gzip + stream is requested by deflateInit2(). deflateSetHeader() may be called + after deflateInit2() or deflateReset() and before the first call of + deflate(). The text, time, os, extra field, name, and comment information + in the provided gz_header structure are written to the gzip header (xflag is + ignored -- the extra flags are set according to the compression level). The + caller must assure that, if not Z_NULL, name and comment are terminated with + a zero byte, and that if extra is not Z_NULL, that extra_len bytes are + available there. If hcrc is true, a gzip header crc is included. Note that + the current versions of the command-line version of gzip (up through version + 1.3.x) do not support header crc's, and will report that it is a "multi-part + gzip file" and give up. + + If deflateSetHeader is not used, the default gzip header has text false, + the time set to zero, and os set to 255, with no extra, name, or comment + fields. The gzip header is returned to the default state by deflateReset(). + + deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, + int windowBits)); + + This is another version of inflateInit with an extra parameter. The + fields next_in, avail_in, zalloc, zfree and opaque must be initialized + before by the caller. + + The windowBits parameter is the base two logarithm of the maximum window + size (the size of the history buffer). It should be in the range 8..15 for + this version of the library. The default value is 15 if inflateInit is used + instead. windowBits must be greater than or equal to the windowBits value + provided to deflateInit2() while compressing, or it must be equal to 15 if + deflateInit2() was not used. If a compressed stream with a larger window + size is given as input, inflate() will return with the error code + Z_DATA_ERROR instead of trying to allocate a larger window. + + windowBits can also be zero to request that inflate use the window size in + the zlib header of the compressed stream. + + windowBits can also be -8..-15 for raw inflate. In this case, -windowBits + determines the window size. inflate() will then process raw deflate data, + not looking for a zlib or gzip header, not generating a check value, and not + looking for any check values for comparison at the end of the stream. This + is for use with other formats that use the deflate compressed data format + such as zip. Those formats provide their own check values. If a custom + format is developed using the raw deflate format for compressed data, it is + recommended that a check value such as an adler32 or a crc32 be applied to + the uncompressed data as is done in the zlib, gzip, and zip formats. For + most applications, the zlib format should be used as is. Note that comments + above on the use in deflateInit2() applies to the magnitude of windowBits. + + windowBits can also be greater than 15 for optional gzip decoding. Add + 32 to windowBits to enable zlib and gzip decoding with automatic header + detection, or add 16 to decode only the gzip format (the zlib format will + return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a + crc32 instead of an adler32. + + inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit2 does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit2() does not process any header information -- that is + deferred until inflate() is called. +*/ + +ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the decompression dictionary from the given uncompressed byte + sequence. This function must be called immediately after a call of inflate, + if that call returned Z_NEED_DICT. The dictionary chosen by the compressor + can be determined from the adler32 value returned by that call of inflate. + The compressor and decompressor must use exactly the same dictionary (see + deflateSetDictionary). For raw inflate, this function can be called + immediately after inflateInit2() or inflateReset() and before any call of + inflate() to set the dictionary. The application must insure that the + dictionary that was used for compression is provided. + + inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the + expected one (incorrect adler32 value). inflateSetDictionary does not + perform any decompression: this will be done by subsequent calls of + inflate(). +*/ + +ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +/* + Skips invalid compressed data until a full flush point (see above the + description of deflate with Z_FULL_FLUSH) can be found, or until all + available input is skipped. No output is provided. + + inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR + if no more input was provided, Z_DATA_ERROR if no flush point has been + found, or Z_STREAM_ERROR if the stream structure was inconsistent. In the + success case, the application may save the current current value of total_in + which indicates where valid compressed data was found. In the error case, + the application may repeatedly call inflateSync, providing more input each + time, until success or end of the input data. +*/ + +ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when randomly accessing a large stream. The + first pass through the stream can periodically record the inflate state, + allowing restarting inflate at those points when randomly accessing the + stream. + + inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +/* + This function is equivalent to inflateEnd followed by inflateInit, + but does not free and reallocate all the internal decompression state. The + stream will keep attributes that may have been set by inflateInit2. + + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, + int windowBits)); +/* + This function is the same as inflateReset, but it also permits changing + the wrap and window size requests. The windowBits parameter is interpreted + the same as it is for inflateInit2. + + inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL), or if + the windowBits parameter is invalid. +*/ + +ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + This function inserts bits in the inflate input stream. The intent is + that this function is used to start inflating at a bit position in the + middle of a byte. The provided bits will be used before any bytes are used + from next_in. This function should only be used with raw inflate, and + should be used before the first inflate() call after inflateInit2() or + inflateReset(). bits must be less than or equal to 16, and that many of the + least significant bits of value will be inserted in the input. + + If bits is negative, then the input stream bit buffer is emptied. Then + inflatePrime() can be called again to put bits in the buffer. This is used + to clear out bits leftover after feeding inflate a block description prior + to feeding inflate codes. + + inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); +/* + This function returns two values, one in the lower 16 bits of the return + value, and the other in the remaining upper bits, obtained by shifting the + return value down 16 bits. If the upper value is -1 and the lower value is + zero, then inflate() is currently decoding information outside of a block. + If the upper value is -1 and the lower value is non-zero, then inflate is in + the middle of a stored block, with the lower value equaling the number of + bytes from the input remaining to copy. If the upper value is not -1, then + it is the number of bits back from the current bit position in the input of + the code (literal or length/distance pair) currently being processed. In + that case the lower value is the number of bytes already emitted for that + code. + + A code is being processed if inflate is waiting for more input to complete + decoding of the code, or if it has completed decoding but is waiting for + more output space to write the literal or match data. + + inflateMark() is used to mark locations in the input data for random + access, which may be at bit positions, and to note those cases where the + output of a code may span boundaries of random access blocks. The current + location in the input stream can be determined from avail_in and data_type + as noted in the description for the Z_BLOCK flush parameter for inflate. + + inflateMark returns the value noted above or -1 << 16 if the provided + source stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, + gz_headerp head)); +/* + inflateGetHeader() requests that gzip header information be stored in the + provided gz_header structure. inflateGetHeader() may be called after + inflateInit2() or inflateReset(), and before the first call of inflate(). + As inflate() processes the gzip stream, head->done is zero until the header + is completed, at which time head->done is set to one. If a zlib stream is + being decoded, then head->done is set to -1 to indicate that there will be + no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be + used to force inflate() to return immediately after header processing is + complete and before any actual data is decompressed. + + The text, time, xflags, and os fields are filled in with the gzip header + contents. hcrc is set to true if there is a header CRC. (The header CRC + was valid if done is set to one.) If extra is not Z_NULL, then extra_max + contains the maximum number of bytes to write to extra. Once done is true, + extra_len contains the actual extra field length, and extra contains the + extra field, or that field truncated if extra_max is less than extra_len. + If name is not Z_NULL, then up to name_max characters are written there, + terminated with a zero unless the length is greater than name_max. If + comment is not Z_NULL, then up to comm_max characters are written there, + terminated with a zero unless the length is greater than comm_max. When any + of extra, name, or comment are not Z_NULL and the respective field is not + present in the header, then that field is set to Z_NULL to signal its + absence. This allows the use of deflateSetHeader() with the returned + structure to duplicate the header. However if those fields are set to + allocated memory, then the application will need to save those pointers + elsewhere so that they can be eventually freed. + + If inflateGetHeader is not used, then the header information is simply + discarded. The header is always checked for validity, including the header + CRC if present. inflateReset() will reset the process to discard the header + information. The application would need to call inflateGetHeader() again to + retrieve the header from the next gzip stream. + + inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, + unsigned char FAR *window)); + + Initialize the internal stream state for decompression using inflateBack() + calls. The fields zalloc, zfree and opaque in strm must be initialized + before the call. If zalloc and zfree are Z_NULL, then the default library- + derived memory allocation routines are used. windowBits is the base two + logarithm of the window size, in the range 8..15. window is a caller + supplied buffer of that size. Except for special applications where it is + assured that deflate was used with small window sizes, windowBits must be 15 + and a 32K byte window must be supplied to be able to decompress general + deflate streams. + + See inflateBack() for the usage of these routines. + + inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of + the paramaters are invalid, Z_MEM_ERROR if the internal state could not be + allocated, or Z_VERSION_ERROR if the version of the library does not match + the version of the header file. +*/ + +typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); +typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); + +ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, + in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc)); +/* + inflateBack() does a raw inflate with a single call using a call-back + interface for input and output. This is more efficient than inflate() for + file i/o applications in that it avoids copying between the output and the + sliding window by simply making the window itself the output buffer. This + function trusts the application to not change the output buffer passed by + the output function, at least until inflateBack() returns. + + inflateBackInit() must be called first to allocate the internal state + and to initialize the state with the user-provided window buffer. + inflateBack() may then be used multiple times to inflate a complete, raw + deflate stream with each call. inflateBackEnd() is then called to free the + allocated state. + + A raw deflate stream is one with no zlib or gzip header or trailer. + This routine would normally be used in a utility that reads zip or gzip + files and writes out uncompressed files. The utility would decode the + header and process the trailer on its own, hence this routine expects only + the raw deflate stream to decompress. This is different from the normal + behavior of inflate(), which expects either a zlib or gzip header and + trailer around the deflate stream. + + inflateBack() uses two subroutines supplied by the caller that are then + called by inflateBack() for input and output. inflateBack() calls those + routines until it reads a complete deflate stream and writes out all of the + uncompressed data, or until it encounters an error. The function's + parameters and return types are defined above in the in_func and out_func + typedefs. inflateBack() will call in(in_desc, &buf) which should return the + number of bytes of provided input, and a pointer to that input in buf. If + there is no input available, in() must return zero--buf is ignored in that + case--and inflateBack() will return a buffer error. inflateBack() will call + out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() + should return zero on success, or non-zero on failure. If out() returns + non-zero, inflateBack() will return with an error. Neither in() nor out() + are permitted to change the contents of the window provided to + inflateBackInit(), which is also the buffer that out() uses to write from. + The length written by out() will be at most the window size. Any non-zero + amount of input may be provided by in(). + + For convenience, inflateBack() can be provided input on the first call by + setting strm->next_in and strm->avail_in. If that input is exhausted, then + in() will be called. Therefore strm->next_in must be initialized before + calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called + immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in + must also be initialized, and then if strm->avail_in is not zero, input will + initially be taken from strm->next_in[0 .. strm->avail_in - 1]. + + The in_desc and out_desc parameters of inflateBack() is passed as the + first parameter of in() and out() respectively when they are called. These + descriptors can be optionally used to pass any information that the caller- + supplied in() and out() functions need to do their job. + + On return, inflateBack() will set strm->next_in and strm->avail_in to + pass back any unused input that was provided by the last in() call. The + return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR + if in() or out() returned an error, Z_DATA_ERROR if there was a format error + in the deflate stream (in which case strm->msg is set to indicate the nature + of the error), or Z_STREAM_ERROR if the stream was not properly initialized. + In the case of Z_BUF_ERROR, an input or output error can be distinguished + using strm->next_in which will be Z_NULL only if in() returned an error. If + strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning + non-zero. (in() will always be called before out(), so strm->next_in is + assured to be defined if out() returns non-zero.) Note that inflateBack() + cannot return Z_OK. +*/ + +ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +/* + All memory allocated by inflateBackInit() is freed. + + inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream + state was inconsistent. +*/ + +ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +/* Return flags indicating compile-time options. + + Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: + 1.0: size of uInt + 3.2: size of uLong + 5.4: size of voidpf (pointer) + 7.6: size of z_off_t + + Compiler, assembler, and debug options: + 8: DEBUG + 9: ASMV or ASMINF -- use ASM code + 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention + 11: 0 (reserved) + + One-time table building (smaller code, but not thread-safe if true): + 12: BUILDFIXED -- build static block decoding tables when needed + 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed + 14,15: 0 (reserved) + + Library content (indicates missing functionality): + 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking + deflate code when not needed) + 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect + and decode gzip streams (to avoid linking crc code) + 18-19: 0 (reserved) + + Operation variations (changes in library functionality): + 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate + 21: FASTEST -- deflate algorithm with only one, lowest compression level + 22,23: 0 (reserved) + + The sprintf variant used by gzprintf (zero is best): + 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format + 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! + 26: 0 = returns value, 1 = void -- 1 means inferred string length returned + + Remainder: + 27-31: 0 (reserved) + */ + + + /* utility functions */ + +/* + The following utility functions are implemented on top of the basic + stream-oriented functions. To simplify the interface, some default options + are assumed (compression level and memory usage, standard memory allocation + functions). The source code of these utility functions can be modified if + you need special options. +*/ + +ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Compresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer. +*/ + +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, + int level)); +/* + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ + +ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +/* + compressBound() returns an upper bound on the compressed size after + compress() or compress2() on sourceLen bytes. It would be used before a + compress() or compress2() call to allocate the destination buffer. +*/ + +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be large enough to hold the entire + uncompressed data. (The size of the uncompressed data must have been saved + previously by the compressor and transmitted to the decompressor by some + mechanism outside the scope of this compression library.) Upon exit, destLen + is the actual size of the uncompressed buffer. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. +*/ + + + /* gzip file access functions */ + +/* + This library supports reading and writing files in gzip (.gz) format with + an interface similar to that of stdio, using the functions that start with + "gz". The gzip format is different from the zlib format. gzip is a gzip + wrapper, documented in RFC 1952, wrapped around a deflate stream. +*/ + +typedef voidp gzFile; /* opaque gzip file descriptor */ + +/* +ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); + + Opens a gzip (.gz) file for reading or writing. The mode parameter is as + in fopen ("rb" or "wb") but can also include a compression level ("wb9") or + a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only + compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' + for fixed code compression as in "wb9F". (See the description of + deflateInit2 for more information about the strategy parameter.) Also "a" + can be used instead of "w" to request that the gzip stream that will be + written be appended to the file. "+" will result in an error, since reading + and writing to the same gzip file is not supported. + + gzopen can be used to read a file which is not in gzip format; in this + case gzread will directly read from the file without decompression. + + gzopen returns NULL if the file could not be opened, if there was + insufficient memory to allocate the gzFile state, or if an invalid mode was + specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). + errno can be checked to determine if the reason gzopen failed was that the + file could not be opened. +*/ + +ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +/* + gzdopen associates a gzFile with the file descriptor fd. File descriptors + are obtained from calls like open, dup, creat, pipe or fileno (if the file + has been previously opened with fopen). The mode parameter is as in gzopen. + + The next call of gzclose on the returned gzFile will also close the file + descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor + fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, + mode);. The duplicated descriptor should be saved to avoid a leak, since + gzdopen does not close fd if it fails. + + gzdopen returns NULL if there was insufficient memory to allocate the + gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not + provided, or '+' was provided), or if fd is -1. The file descriptor is not + used until the next gz* read, write, seek, or close operation, so gzdopen + will not detect if fd is invalid (unless fd is -1). +*/ + +ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); +/* + Set the internal buffer size used by this library's functions. The + default buffer size is 8192 bytes. This function must be called after + gzopen() or gzdopen(), and before any other calls that read or write the + file. The buffer memory allocation is always deferred to the first read or + write. Two buffers are allocated, either both of the specified size when + writing, or one of the specified size and the other twice that size when + reading. A larger buffer size of, for example, 64K or 128K bytes will + noticeably increase the speed of decompression (reading). + + The new buffer size also affects the maximum length for gzprintf(). + + gzbuffer() returns 0 on success, or -1 on failure, such as being called + too late. +*/ + +ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +/* + Dynamically update the compression level or strategy. See the description + of deflateInit2 for the meaning of these parameters. + + gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not + opened for writing. +*/ + +ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +/* + Reads the given number of uncompressed bytes from the compressed file. If + the input file was not in gzip format, gzread copies the given number of + bytes into the buffer. + + After reaching the end of a gzip stream in the input, gzread will continue + to read, looking for another gzip stream, or failing that, reading the rest + of the input file directly without decompression. The entire input file + will be read if gzread is called until it returns less than the requested + len. + + gzread returns the number of uncompressed bytes actually read, less than + len for end of file, or -1 for error. +*/ + +ZEXTERN int ZEXPORT gzwrite OF((gzFile file, + voidpc buf, unsigned len)); +/* + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of uncompressed bytes written or 0 in case of + error. +*/ + +ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); +/* + Converts, formats, and writes the arguments to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written, or 0 in case of error. The number of + uncompressed bytes written is limited to 8191, or one less than the buffer + size given to gzbuffer(). The caller should assure that this limit is not + exceeded. If it is exceeded, then gzprintf() will return an error (0) with + nothing written. In this case, there may also be a buffer overflow with + unpredictable consequences, which is possible only if zlib was compiled with + the insecure functions sprintf() or vsprintf() because the secure snprintf() + or vsnprintf() functions were not available. This can be determined using + zlibCompileFlags(). +*/ + +ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +/* + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + + gzputs returns the number of characters written, or -1 in case of error. +*/ + +ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +/* + Reads bytes from the compressed file until len-1 characters are read, or a + newline character is read and transferred to buf, or an end-of-file + condition is encountered. If any characters are read or if len == 1, the + string is terminated with a null character. If no characters are read due + to an end-of-file or len < 1, then the buffer is left untouched. + + gzgets returns buf which is a null-terminated string, or it returns NULL + for end-of-file or in case of error. If there was an error, the contents at + buf are indeterminate. +*/ + +ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +/* + Writes c, converted to an unsigned char, into the compressed file. gzputc + returns the value that was written, or -1 in case of error. +*/ + +ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +/* + Reads one byte from the compressed file. gzgetc returns this byte or -1 + in case of end of file or error. +*/ + +ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +/* + Push one character back onto the stream to be read as the first character + on the next read. At least one character of push-back is allowed. + gzungetc() returns the character pushed, or -1 on failure. gzungetc() will + fail if c is -1, and may fail if a character has been pushed but not read + yet. If gzungetc is used immediately after gzopen or gzdopen, at least the + output buffer size of pushed characters is allowed. (See gzbuffer above.) + The pushed character will be discarded if the stream is repositioned with + gzseek() or gzrewind(). +*/ + +ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +/* + Flushes all pending output into the compressed file. The parameter flush + is as in the deflate() function. The return value is the zlib error number + (see function gzerror below). gzflush is only permitted when writing. + + If the flush parameter is Z_FINISH, the remaining data is written and the + gzip stream is completed in the output. If gzwrite() is called again, a new + gzip stream will be started in the output. gzread() is able to read such + concatented gzip streams. + + gzflush should be called only when strictly necessary because it will + degrade compression if called too often. +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, + z_off_t offset, int whence)); + + Sets the starting position for the next gzread or gzwrite on the given + compressed file. The offset represents a number of bytes in the + uncompressed data stream. The whence parameter is defined as in lseek(2); + the value SEEK_END is not supported. + + If the file is opened for reading, this function is emulated but can be + extremely slow. If the file is opened for writing, only forward seeks are + supported; gzseek then compresses a sequence of zeroes up to the new + starting position. + + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error, in + particular if the file is opened for writing and the new starting position + would be before the current position. +*/ + +ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +/* + Rewinds the given file. This function is supported only for reading. + + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); + + Returns the starting position for the next gzread or gzwrite on the given + compressed file. This position represents a number of bytes in the + uncompressed data stream, and is zero when starting, even if appending or + reading a gzip stream from the middle of a file using gzdopen(). + + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); + + Returns the current offset in the file being read or written. This offset + includes the count of bytes that precede the gzip stream, for example when + appending or when using gzdopen() for reading. When reading, the offset + does not include as yet unused buffered input. This information can be used + for a progress indicator. On error, gzoffset() returns -1. +*/ + +ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +/* + Returns true (1) if the end-of-file indicator has been set while reading, + false (0) otherwise. Note that the end-of-file indicator is set only if the + read tried to go past the end of the input, but came up short. Therefore, + just like feof(), gzeof() may return false even if there is no more data to + read, in the event that the last read request was for the exact number of + bytes remaining in the input file. This will happen if the input file size + is an exact multiple of the buffer size. + + If gzeof() returns true, then the read functions will return no more data, + unless the end-of-file indicator is reset by gzclearerr() and the input file + has grown since the previous end of file was detected. +*/ + +ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +/* + Returns true (1) if file is being copied directly while reading, or false + (0) if file is a gzip stream being decompressed. This state can change from + false to true while reading the input file if the end of a gzip stream is + reached, but is followed by data that is not another gzip stream. + + If the input file is empty, gzdirect() will return true, since the input + does not contain a gzip stream. + + If gzdirect() is used immediately after gzopen() or gzdopen() it will + cause buffers to be allocated to allow reading the file to determine if it + is a gzip file. Therefore if gzbuffer() is used, it should be called before + gzdirect(). +*/ + +ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +/* + Flushes all pending output if necessary, closes the compressed file and + deallocates the (de)compression state. Note that once file is closed, you + cannot call gzerror with file, since its structures have been deallocated. + gzclose must not be called more than once on the same file, just as free + must not be called more than once on the same allocation. + + gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a + file operation error, or Z_OK on success. +*/ + +ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); +/* + Same as gzclose(), but gzclose_r() is only for use when reading, and + gzclose_w() is only for use when writing or appending. The advantage to + using these instead of gzclose() is that they avoid linking in zlib + compression or decompression code that is not used when only reading or only + writing respectively. If gzclose() is used, then both compression and + decompression code will be included the application when linking to a static + zlib library. +*/ + +ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +/* + Returns the error message for the last error which occurred on the given + compressed file. errnum is set to zlib error number. If an error occurred + in the file system and not in the compression library, errnum is set to + Z_ERRNO and the application may consult errno to get the exact error code. + + The application must not modify the returned string. Future calls to + this function may invalidate the previously returned string. If file is + closed, then the string previously returned by gzerror will no longer be + available. + + gzerror() should be used to distinguish errors from end-of-file for those + functions above that do not distinguish those cases in their return values. +*/ + +ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +/* + Clears the error and end-of-file flags for file. This is analogous to the + clearerr() function in stdio. This is useful for continuing to read a gzip + file that is being written concurrently. +*/ + + + /* checksum functions */ + +/* + These functions are not related to compression but are exported + anyway because they might be useful in applications using the compression + library. +*/ + +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +/* + Update a running Adler-32 checksum with the bytes buf[0..len-1] and + return the updated checksum. If buf is Z_NULL, this function returns the + required initial value for the checksum. + + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed + much faster. + + Usage example: + + uLong adler = adler32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + adler = adler32(adler, buffer, length); + } + if (adler != original_adler) error(); +*/ + +/* +ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, + z_off_t len2)); + + Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 + and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for + each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of + seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. +*/ + +ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +/* + Update a running CRC-32 with the bytes buf[0..len-1] and return the + updated CRC-32. If buf is Z_NULL, this function returns the required + initial value for the for the crc. Pre- and post-conditioning (one's + complement) is performed within this function so it shouldn't be done by the + application. + + Usage example: + + uLong crc = crc32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + crc = crc32(crc, buffer, length); + } + if (crc != original_crc) error(); +*/ + +/* +ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); + + Combine two CRC-32 check values into one. For two sequences of bytes, + seq1 and seq2 with lengths len1 and len2, CRC-32 check values were + calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 + check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and + len2. +*/ + + + /* various hacks, don't look :) */ + +/* deflateInit and inflateInit are macros to allow checking the zlib version + * and the compiler's view of z_stream: + */ +ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size)); +ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, + unsigned char FAR *window, + const char *version, + int stream_size)); +#define deflateInit(strm, level) \ + deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) +#define inflateInit(strm) \ + inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) +#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ + (strategy), ZLIB_VERSION, sizeof(z_stream)) +#define inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) +#define inflateBackInit(strm, windowBits, window) \ + inflateBackInit_((strm), (windowBits), (window), \ + ZLIB_VERSION, sizeof(z_stream)) + +/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or + * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if + * both are true, the application gets the *64 functions, and the regular + * functions are changed to 64 bits) -- in case these are set on systems + * without large file support, _LFS64_LARGEFILE must also be true + */ +#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); + ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); +#endif + +#if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS-0 == 64 && _LFS64_LARGEFILE-0 +# define gzopen gzopen64 +# define gzseek gzseek64 +# define gztell gztell64 +# define gzoffset gzoffset64 +# define adler32_combine adler32_combine64 +# define crc32_combine crc32_combine64 +# ifdef _LARGEFILE64_SOURCE + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); +# endif +#else + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); +#endif + +/* hack for buggy compilers */ +#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) + struct internal_state {int dummy;}; +#endif + +/* undocumented functions */ +ZEXTERN const char * ZEXPORT zError OF((int)); +ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); +ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); +ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); + +#ifdef __cplusplus +} +#endif + +#endif /* ZLIB_H */ diff --git a/fceumm/utils/zlib/adler32.c b/fceumm/utils/zlib/adler32.c new file mode 100644 index 0000000..65ad6a5 --- /dev/null +++ b/fceumm/utils/zlib/adler32.c @@ -0,0 +1,169 @@ +/* adler32.c -- compute the Adler-32 checksum of a data stream + * Copyright (C) 1995-2007 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#include "zutil.h" + +#define local static + +local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2); + +#define BASE 65521UL /* largest prime smaller than 65536 */ +#define NMAX 5552 +/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ + +#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} +#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); +#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); +#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); +#define DO16(buf) DO8(buf,0); DO8(buf,8); + +/* use NO_DIVIDE if your processor does not do division in hardware */ +#ifdef NO_DIVIDE +# define MOD(a) \ + do { \ + if (a >= (BASE << 16)) a -= (BASE << 16); \ + if (a >= (BASE << 15)) a -= (BASE << 15); \ + if (a >= (BASE << 14)) a -= (BASE << 14); \ + if (a >= (BASE << 13)) a -= (BASE << 13); \ + if (a >= (BASE << 12)) a -= (BASE << 12); \ + if (a >= (BASE << 11)) a -= (BASE << 11); \ + if (a >= (BASE << 10)) a -= (BASE << 10); \ + if (a >= (BASE << 9)) a -= (BASE << 9); \ + if (a >= (BASE << 8)) a -= (BASE << 8); \ + if (a >= (BASE << 7)) a -= (BASE << 7); \ + if (a >= (BASE << 6)) a -= (BASE << 6); \ + if (a >= (BASE << 5)) a -= (BASE << 5); \ + if (a >= (BASE << 4)) a -= (BASE << 4); \ + if (a >= (BASE << 3)) a -= (BASE << 3); \ + if (a >= (BASE << 2)) a -= (BASE << 2); \ + if (a >= (BASE << 1)) a -= (BASE << 1); \ + if (a >= BASE) a -= BASE; \ + } while (0) +# define MOD4(a) \ + do { \ + if (a >= (BASE << 4)) a -= (BASE << 4); \ + if (a >= (BASE << 3)) a -= (BASE << 3); \ + if (a >= (BASE << 2)) a -= (BASE << 2); \ + if (a >= (BASE << 1)) a -= (BASE << 1); \ + if (a >= BASE) a -= BASE; \ + } while (0) +#else +# define MOD(a) a %= BASE +# define MOD4(a) a %= BASE +#endif + +/* ========================================================================= */ +uLong ZEXPORT adler32(adler, buf, len) + uLong adler; + const Bytef *buf; + uInt len; +{ + unsigned long sum2; + unsigned n; + + /* split Adler-32 into component sums */ + sum2 = (adler >> 16) & 0xffff; + adler &= 0xffff; + + /* in case user likes doing a byte at a time, keep it fast */ + if (len == 1) { + adler += buf[0]; + if (adler >= BASE) + adler -= BASE; + sum2 += adler; + if (sum2 >= BASE) + sum2 -= BASE; + return adler | (sum2 << 16); + } + + /* initial Adler-32 value (deferred check for len == 1 speed) */ + if (buf == Z_NULL) + return 1L; + + /* in case short lengths are provided, keep it somewhat fast */ + if (len < 16) { + while (len--) { + adler += *buf++; + sum2 += adler; + } + if (adler >= BASE) + adler -= BASE; + MOD4(sum2); /* only added so many BASE's */ + return adler | (sum2 << 16); + } + + /* do length NMAX blocks -- requires just one modulo operation */ + while (len >= NMAX) { + len -= NMAX; + n = NMAX / 16; /* NMAX is divisible by 16 */ + do { + DO16(buf); /* 16 sums unrolled */ + buf += 16; + } while (--n); + MOD(adler); + MOD(sum2); + } + + /* do remaining bytes (less than NMAX, still just one modulo) */ + if (len) { /* avoid modulos if none remaining */ + while (len >= 16) { + len -= 16; + DO16(buf); + buf += 16; + } + while (len--) { + adler += *buf++; + sum2 += adler; + } + MOD(adler); + MOD(sum2); + } + + /* return recombined sums */ + return adler | (sum2 << 16); +} + +/* ========================================================================= */ +local uLong adler32_combine_(adler1, adler2, len2) + uLong adler1; + uLong adler2; + z_off64_t len2; +{ + unsigned long sum1; + unsigned long sum2; + unsigned rem; + + /* the derivation of this formula is left as an exercise for the reader */ + rem = (unsigned)(len2 % BASE); + sum1 = adler1 & 0xffff; + sum2 = rem * sum1; + MOD(sum2); + sum1 += (adler2 & 0xffff) + BASE - 1; + sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; + if (sum1 >= BASE) sum1 -= BASE; + if (sum1 >= BASE) sum1 -= BASE; + if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); + if (sum2 >= BASE) sum2 -= BASE; + return sum1 | (sum2 << 16); +} + +/* ========================================================================= */ +uLong ZEXPORT adler32_combine(adler1, adler2, len2) + uLong adler1; + uLong adler2; + z_off_t len2; +{ + return adler32_combine_(adler1, adler2, len2); +} + +uLong ZEXPORT adler32_combine64(adler1, adler2, len2) + uLong adler1; + uLong adler2; + z_off64_t len2; +{ + return adler32_combine_(adler1, adler2, len2); +} diff --git a/fceumm/utils/zlib/compress.c b/fceumm/utils/zlib/compress.c new file mode 100644 index 0000000..ea4dfbe --- /dev/null +++ b/fceumm/utils/zlib/compress.c @@ -0,0 +1,80 @@ +/* compress.c -- compress a memory buffer + * Copyright (C) 1995-2005 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#define ZLIB_INTERNAL +#include "zlib.h" + +/* =========================================================================== + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least 0.1% larger than sourceLen plus + 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ +int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) + Bytef *dest; + uLongf *destLen; + const Bytef *source; + uLong sourceLen; + int level; +{ + z_stream stream; + int err; + + stream.next_in = (Bytef*)source; + stream.avail_in = (uInt)sourceLen; +#ifdef MAXSEG_64K + /* Check for source > 64K on 16-bit machine: */ + if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; +#endif + stream.next_out = dest; + stream.avail_out = (uInt)*destLen; + if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; + + stream.zalloc = (alloc_func)0; + stream.zfree = (free_func)0; + stream.opaque = (voidpf)0; + + err = deflateInit(&stream, level); + if (err != Z_OK) return err; + + err = deflate(&stream, Z_FINISH); + if (err != Z_STREAM_END) { + deflateEnd(&stream); + return err == Z_OK ? Z_BUF_ERROR : err; + } + *destLen = stream.total_out; + + err = deflateEnd(&stream); + return err; +} + +/* =========================================================================== + */ +int ZEXPORT compress (dest, destLen, source, sourceLen) + Bytef *dest; + uLongf *destLen; + const Bytef *source; + uLong sourceLen; +{ + return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); +} + +/* =========================================================================== + If the default memLevel or windowBits for deflateInit() is changed, then + this function needs to be updated. + */ +uLong ZEXPORT compressBound (sourceLen) + uLong sourceLen; +{ + return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + + (sourceLen >> 25) + 13; +} diff --git a/fceumm/utils/zlib/contrib/minizip/Makefile b/fceumm/utils/zlib/contrib/minizip/Makefile new file mode 100644 index 0000000..84eaad2 --- /dev/null +++ b/fceumm/utils/zlib/contrib/minizip/Makefile @@ -0,0 +1,25 @@ +CC=cc +CFLAGS=-O -I../.. + +UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a +ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a + +.c.o: + $(CC) -c $(CFLAGS) $*.c + +all: miniunz minizip + +miniunz: $(UNZ_OBJS) + $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS) + +minizip: $(ZIP_OBJS) + $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS) + +test: miniunz minizip + ./minizip test readme.txt + ./miniunz -l test.zip + mv readme.txt readme.old + ./miniunz test.zip + +clean: + /bin/rm -f *.o *~ minizip miniunz diff --git a/fceumm/utils/zlib/contrib/minizip/crypt.h b/fceumm/utils/zlib/contrib/minizip/crypt.h new file mode 100644 index 0000000..a01d08d --- /dev/null +++ b/fceumm/utils/zlib/contrib/minizip/crypt.h @@ -0,0 +1,131 @@ +/* crypt.h -- base code for crypt/uncrypt ZIPfile + + + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant + + This code is a modified version of crypting code in Infozip distribution + + The encryption/decryption parts of this source code (as opposed to the + non-echoing password parts) were originally written in Europe. The + whole source package can be freely distributed, including from the USA. + (Prior to January 2000, re-export from the US was a violation of US law.) + + This encryption code is a direct transcription of the algorithm from + Roger Schlafly, described by Phil Katz in the file appnote.txt. This + file (appnote.txt) is distributed with the PKZIP program (even in the + version without encryption capabilities). + + If you don't need crypting in your application, just define symbols + NOCRYPT and NOUNCRYPT. + + This code support the "Traditional PKWARE Encryption". + + The new AES encryption added on Zip format by Winzip (see the page + http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong + Encryption is not supported. +*/ + +#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) + +/*********************************************************************** + * Return the next byte in the pseudo-random sequence + */ +static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) +{ + unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an + * unpredictable manner on 16-bit systems; not a problem + * with any known compiler so far, though */ + + temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; + return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); +} + +/*********************************************************************** + * Update the encryption keys with the next byte of plain text + */ +static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) +{ + (*(pkeys+0)) = CRC32((*(pkeys+0)), c); + (*(pkeys+1)) += (*(pkeys+0)) & 0xff; + (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; + { + register int keyshift = (int)((*(pkeys+1)) >> 24); + (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); + } + return c; +} + + +/*********************************************************************** + * Initialize the encryption keys and the random header according to + * the given password. + */ +static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) +{ + *(pkeys+0) = 305419896L; + *(pkeys+1) = 591751049L; + *(pkeys+2) = 878082192L; + while (*passwd != '\0') { + update_keys(pkeys,pcrc_32_tab,(int)*passwd); + passwd++; + } +} + +#define zdecode(pkeys,pcrc_32_tab,c) \ + (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) + +#define zencode(pkeys,pcrc_32_tab,c,t) \ + (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) + +#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED + +#define RAND_HEAD_LEN 12 + /* "last resort" source for second part of crypt seed pattern */ +# ifndef ZCR_SEED2 +# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ +# endif + +static int crypthead(const char* passwd, /* password string */ + unsigned char* buf, /* where to write header */ + int bufSize, + unsigned long* pkeys, + const unsigned long* pcrc_32_tab, + unsigned long crcForCrypting) +{ + int n; /* index in random header */ + int t; /* temporary */ + int c; /* random byte */ + unsigned char header[RAND_HEAD_LEN-2]; /* random header */ + static unsigned calls = 0; /* ensure different random header each time */ + + if (bufSize> 7) & 0xff; + header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); + } + /* Encrypt random header (last two bytes is high word of crc) */ + init_keys(passwd, pkeys, pcrc_32_tab); + for (n = 0; n < RAND_HEAD_LEN-2; n++) + { + buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); + } + buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); + buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); + return n; +} + +#endif diff --git a/fceumm/utils/zlib/contrib/minizip/ioapi.c b/fceumm/utils/zlib/contrib/minizip/ioapi.c new file mode 100644 index 0000000..49958f6 --- /dev/null +++ b/fceumm/utils/zlib/contrib/minizip/ioapi.c @@ -0,0 +1,235 @@ +/* ioapi.h -- IO base function header for compress/uncompress .zip + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + +*/ + +#if (defined(_WIN32)) + #define _CRT_SECURE_NO_WARNINGS +#endif + +#include "ioapi.h" + +voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode) +{ + if (pfilefunc->zfile_func64.zopen64_file != NULL) + return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); + else + { + return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode); + } +} + +long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) +{ + if (pfilefunc->zfile_func64.zseek64_file != NULL) + return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); + else + { + uLong offsetTruncated = (uLong)offset; + if (offsetTruncated != offset) + return -1; + else + return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin); + } +} + +ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) +{ + if (pfilefunc->zfile_func64.zseek64_file != NULL) + return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); + else + { + uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream); + if ((tell_uLong) == ((uLong)-1)) + return (ZPOS64_T)-1; + else + return tell_uLong; + } +} + +void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) +{ + p_filefunc64_32->zfile_func64.zopen64_file = NULL; + p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; + p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; + p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; + p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; + p_filefunc64_32->zfile_func64.ztell64_file = NULL; + p_filefunc64_32->zfile_func64.zseek64_file = NULL; + p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; + p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; + p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; + p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; + p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; +} + + + +static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode)); +static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); +static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size)); +static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream)); +static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); +static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream)); +static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream)); + +static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) +{ + FILE* file = NULL; + const char* mode_fopen = NULL; + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) + mode_fopen = "rb"; + else + if (mode & ZLIB_FILEFUNC_MODE_EXISTING) + mode_fopen = "r+b"; + else + if (mode & ZLIB_FILEFUNC_MODE_CREATE) + mode_fopen = "wb"; + + if ((filename!=NULL) && (mode_fopen != NULL)) + file = fopen(filename, mode_fopen); + return file; +} + +static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode) +{ + FILE* file = NULL; + const char* mode_fopen = NULL; + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) + mode_fopen = "rb"; + else + if (mode & ZLIB_FILEFUNC_MODE_EXISTING) + mode_fopen = "r+b"; + else + if (mode & ZLIB_FILEFUNC_MODE_CREATE) + mode_fopen = "wb"; + + if ((filename!=NULL) && (mode_fopen != NULL)) + file = fopen64((const char*)filename, mode_fopen); + return file; +} + + +static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) +{ + uLong ret; + ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); + return ret; +} + +static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) +{ + uLong ret; + ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); + return ret; +} + +static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) +{ + long ret; + ret = ftell((FILE *)stream); + return ret; +} + + +static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) +{ + ZPOS64_T ret; + ret = ftello64((FILE *)stream); + return ret; +} + +static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) +{ + int fseek_origin=0; + long ret; + switch (origin) + { + case ZLIB_FILEFUNC_SEEK_CUR : + fseek_origin = SEEK_CUR; + break; + case ZLIB_FILEFUNC_SEEK_END : + fseek_origin = SEEK_END; + break; + case ZLIB_FILEFUNC_SEEK_SET : + fseek_origin = SEEK_SET; + break; + default: return -1; + } + ret = 0; + if (fseek((FILE *)stream, offset, fseek_origin) != 0) + ret = -1; + return ret; +} + +static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) +{ + int fseek_origin=0; + long ret; + switch (origin) + { + case ZLIB_FILEFUNC_SEEK_CUR : + fseek_origin = SEEK_CUR; + break; + case ZLIB_FILEFUNC_SEEK_END : + fseek_origin = SEEK_END; + break; + case ZLIB_FILEFUNC_SEEK_SET : + fseek_origin = SEEK_SET; + break; + default: return -1; + } + ret = 0; + + if(fseeko64((FILE *)stream, offset, fseek_origin) != 0) + ret = -1; + + return ret; +} + + +static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) +{ + int ret; + ret = fclose((FILE *)stream); + return ret; +} + +static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) +{ + int ret; + ret = ferror((FILE *)stream); + return ret; +} + +void fill_fopen_filefunc (pzlib_filefunc_def) + zlib_filefunc_def* pzlib_filefunc_def; +{ + pzlib_filefunc_def->zopen_file = fopen_file_func; + pzlib_filefunc_def->zread_file = fread_file_func; + pzlib_filefunc_def->zwrite_file = fwrite_file_func; + pzlib_filefunc_def->ztell_file = ftell_file_func; + pzlib_filefunc_def->zseek_file = fseek_file_func; + pzlib_filefunc_def->zclose_file = fclose_file_func; + pzlib_filefunc_def->zerror_file = ferror_file_func; + pzlib_filefunc_def->opaque = NULL; +} + +void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def) +{ + pzlib_filefunc_def->zopen64_file = fopen64_file_func; + pzlib_filefunc_def->zread_file = fread_file_func; + pzlib_filefunc_def->zwrite_file = fwrite_file_func; + pzlib_filefunc_def->ztell64_file = ftell64_file_func; + pzlib_filefunc_def->zseek64_file = fseek64_file_func; + pzlib_filefunc_def->zclose_file = fclose_file_func; + pzlib_filefunc_def->zerror_file = ferror_file_func; + pzlib_filefunc_def->opaque = NULL; +} diff --git a/fceumm/utils/zlib/contrib/minizip/ioapi.h b/fceumm/utils/zlib/contrib/minizip/ioapi.h new file mode 100644 index 0000000..8309c4c --- /dev/null +++ b/fceumm/utils/zlib/contrib/minizip/ioapi.h @@ -0,0 +1,200 @@ +/* ioapi.h -- IO base function header for compress/uncompress .zip + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + Changes + + Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this) + Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux. + More if/def section may be needed to support other platforms + Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows. + (but you should use iowin32.c for windows instead) + +*/ + +#ifndef _ZLIBIOAPI64_H +#define _ZLIBIOAPI64_H + +#if (!defined(_WIN32)) && (!defined(WIN32)) + + // Linux needs this to support file operation on files larger then 4+GB + // But might need better if/def to select just the platforms that needs them. + + #ifndef __USE_FILE_OFFSET64 + #define __USE_FILE_OFFSET64 + #endif + #ifndef __USE_LARGEFILE64 + #define __USE_LARGEFILE64 + #endif + #ifndef _LARGEFILE64_SOURCE + #define _LARGEFILE64_SOURCE + #endif + #ifndef _FILE_OFFSET_BIT + #define _FILE_OFFSET_BIT 64 + #endif +#endif + +#include +#include +#include "zlib.h" + +#if defined(USE_FILE32API) +#define fopen64 fopen +#define ftello64 ftell +#define fseeko64 fseek +#else +#ifdef _MSC_VER + #define fopen64 fopen + #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) + #define ftello64 _ftelli64 + #define fseeko64 _fseeki64 + #else // old MSC + #define ftello64 ftell + #define fseeko64 fseek + #endif +#endif +#endif + +/* +#ifndef ZPOS64_T + #ifdef _WIN32 + #define ZPOS64_T fpos_t + #else + #include + #define ZPOS64_T uint64_t + #endif +#endif +*/ + +#ifdef HAVE_MINIZIP64_CONF_H +#include "mz64conf.h" +#endif + +/* a type choosen by DEFINE */ +#ifdef HAVE_64BIT_INT_CUSTOM +typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; +#else +#ifdef HAS_STDINT_H +#include "stdint.h" +typedef uint64_t ZPOS64_T; +#else + + +#if defined(_MSC_VER) || defined(__BORLANDC__) +typedef unsigned __int64 ZPOS64_T; +#else +typedef unsigned long long int ZPOS64_T; +#endif +#endif +#endif + + + +#ifdef __cplusplus +extern "C" { +#endif + + +#define ZLIB_FILEFUNC_SEEK_CUR (1) +#define ZLIB_FILEFUNC_SEEK_END (2) +#define ZLIB_FILEFUNC_SEEK_SET (0) + +#define ZLIB_FILEFUNC_MODE_READ (1) +#define ZLIB_FILEFUNC_MODE_WRITE (2) +#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) + +#define ZLIB_FILEFUNC_MODE_EXISTING (4) +#define ZLIB_FILEFUNC_MODE_CREATE (8) + + +#ifndef ZCALLBACK + #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) + #define ZCALLBACK CALLBACK + #else + #define ZCALLBACK + #endif +#endif + + + + +typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); +typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); +typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); +typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); +typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); + +typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); +typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); + + +/* here is the "old" 32 bits structure structure */ +typedef struct zlib_filefunc_def_s +{ + open_file_func zopen_file; + read_file_func zread_file; + write_file_func zwrite_file; + tell_file_func ztell_file; + seek_file_func zseek_file; + close_file_func zclose_file; + testerror_file_func zerror_file; + voidpf opaque; +} zlib_filefunc_def; + +typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); +typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); +typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); + +typedef struct zlib_filefunc64_def_s +{ + open64_file_func zopen64_file; + read_file_func zread_file; + write_file_func zwrite_file; + tell64_file_func ztell64_file; + seek64_file_func zseek64_file; + close_file_func zclose_file; + testerror_file_func zerror_file; + voidpf opaque; +} zlib_filefunc64_def; + +void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); +void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); + +/* now internal definition, only for zip.c and unzip.h */ +typedef struct zlib_filefunc64_32_def_s +{ + zlib_filefunc64_def zfile_func64; + open_file_func zopen32_file; + tell_file_func ztell32_file; + seek_file_func zseek32_file; +} zlib_filefunc64_32_def; + + +#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) +#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) +//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) +//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) +#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) +#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) + +voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); +long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); +ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); + +void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); + +#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) +#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) +#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/fceumm/utils/zlib/contrib/minizip/make_vms.com b/fceumm/utils/zlib/contrib/minizip/make_vms.com new file mode 100644 index 0000000..9ac13a9 --- /dev/null +++ b/fceumm/utils/zlib/contrib/minizip/make_vms.com @@ -0,0 +1,25 @@ +$ if f$search("ioapi.h_orig") .eqs. "" then copy ioapi.h ioapi.h_orig +$ open/write zdef vmsdefs.h +$ copy sys$input: zdef +$ deck +#define unix +#define fill_zlib_filefunc64_32_def_from_filefunc32 fillzffunc64from +#define Write_Zip64EndOfCentralDirectoryLocator Write_Zip64EoDLocator +#define Write_Zip64EndOfCentralDirectoryRecord Write_Zip64EoDRecord +#define Write_EndOfCentralDirectoryRecord Write_EoDRecord +$ eod +$ close zdef +$ copy vmsdefs.h,ioapi.h_orig ioapi.h +$ cc/include=[--]/prefix=all ioapi.c +$ cc/include=[--]/prefix=all miniunz.c +$ cc/include=[--]/prefix=all unzip.c +$ cc/include=[--]/prefix=all minizip.c +$ cc/include=[--]/prefix=all zip.c +$ link miniunz,unzip,ioapi,[--]libz.olb/lib +$ link minizip,zip,ioapi,[--]libz.olb/lib +$ mcr []minizip test minizip_info.txt +$ mcr []miniunz -l test.zip +$ rename minizip_info.txt; minizip_info.txt_old +$ mcr []miniunz test.zip +$ delete test.zip;* +$exit diff --git a/fceumm/utils/zlib/contrib/minizip/miniunz.c b/fceumm/utils/zlib/contrib/minizip/miniunz.c new file mode 100644 index 0000000..9ed009f --- /dev/null +++ b/fceumm/utils/zlib/contrib/minizip/miniunz.c @@ -0,0 +1,648 @@ +/* + miniunz.c + Version 1.1, February 14h, 2010 + sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications of Unzip for Zip64 + Copyright (C) 2007-2008 Even Rouault + + Modifications for Zip64 support on both zip and unzip + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) +*/ + +#ifndef _WIN32 + #ifndef __USE_FILE_OFFSET64 + #define __USE_FILE_OFFSET64 + #endif + #ifndef __USE_LARGEFILE64 + #define __USE_LARGEFILE64 + #endif + #ifndef _LARGEFILE64_SOURCE + #define _LARGEFILE64_SOURCE + #endif + #ifndef _FILE_OFFSET_BIT + #define _FILE_OFFSET_BIT 64 + #endif +#endif + +#include +#include +#include +#include +#include +#include + +#ifdef unix +# include +# include +#else +# include +# include +#endif + +#include "unzip.h" + +#define CASESENSITIVITY (0) +#define WRITEBUFFERSIZE (8192) +#define MAXFILENAME (256) + +#ifdef _WIN32 +#define USEWIN32IOAPI +#include "iowin32.h" +#endif +/* + mini unzip, demo of unzip package + + usage : + Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir] + + list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT + if it exists +*/ + + +/* change_file_date : change the date/time of a file + filename : the filename of the file where date/time must be modified + dosdate : the new date at the MSDos format (4 bytes) + tmu_date : the SAME new date at the tm_unz format */ +void change_file_date(filename,dosdate,tmu_date) + const char *filename; + uLong dosdate; + tm_unz tmu_date; +{ +#ifdef _WIN32 + HANDLE hFile; + FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; + + hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE, + 0,NULL,OPEN_EXISTING,0,NULL); + GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); + DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); + LocalFileTimeToFileTime(&ftLocal,&ftm); + SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); + CloseHandle(hFile); +#else +#ifdef unix + struct utimbuf ut; + struct tm newdate; + newdate.tm_sec = tmu_date.tm_sec; + newdate.tm_min=tmu_date.tm_min; + newdate.tm_hour=tmu_date.tm_hour; + newdate.tm_mday=tmu_date.tm_mday; + newdate.tm_mon=tmu_date.tm_mon; + if (tmu_date.tm_year > 1900) + newdate.tm_year=tmu_date.tm_year - 1900; + else + newdate.tm_year=tmu_date.tm_year ; + newdate.tm_isdst=-1; + + ut.actime=ut.modtime=mktime(&newdate); + utime(filename,&ut); +#endif +#endif +} + + +/* mymkdir and change_file_date are not 100 % portable + As I don't know well Unix, I wait feedback for the unix portion */ + +int mymkdir(dirname) + const char* dirname; +{ + int ret=0; +#ifdef _WIN32 + ret = _mkdir(dirname); +#else +#ifdef unix + ret = mkdir (dirname,0775); +#endif +#endif + return ret; +} + +int makedir (newdir) + char *newdir; +{ + char *buffer ; + char *p; + int len = (int)strlen(newdir); + + if (len <= 0) + return 0; + + buffer = (char*)malloc(len+1); + if (buffer==NULL) + { + printf("Error allocating memory\n"); + return UNZ_INTERNALERROR; + } + strcpy(buffer,newdir); + + if (buffer[len-1] == '/') { + buffer[len-1] = '\0'; + } + if (mymkdir(buffer) == 0) + { + free(buffer); + return 1; + } + + p = buffer+1; + while (1) + { + char hold; + + while(*p && *p != '\\' && *p != '/') + p++; + hold = *p; + *p = 0; + if ((mymkdir(buffer) == -1) && (errno == ENOENT)) + { + printf("couldn't create directory %s\n",buffer); + free(buffer); + return 0; + } + if (hold == 0) + break; + *p++ = hold; + } + free(buffer); + return 1; +} + +void do_banner() +{ + printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n"); + printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); +} + +void do_help() +{ + printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \ + " -e Extract without pathname (junk paths)\n" \ + " -x Extract with pathname\n" \ + " -v list files\n" \ + " -l list files\n" \ + " -d directory to extract into\n" \ + " -o overwrite files without prompting\n" \ + " -p extract crypted file using password\n\n"); +} + +void Display64BitsSize(ZPOS64_T n, int size_char) +{ + /* to avoid compatibility problem , we do here the conversion */ + char number[21]; + int offset=19; + int pos_string = 19; + number[20]=0; + for (;;) { + number[offset]=(char)((n%10)+'0'); + if (number[offset] != '0') + pos_string=offset; + n/=10; + if (offset==0) + break; + offset--; + } + { + int size_display_string = 19-pos_string; + while (size_char > size_display_string) + { + size_char--; + printf(" "); + } + } + + printf("%s",&number[pos_string]); +} + +int do_list(uf) + unzFile uf; +{ + uLong i; + unz_global_info64 gi; + int err; + + err = unzGetGlobalInfo64(uf,&gi); + if (err!=UNZ_OK) + printf("error %d with zipfile in unzGetGlobalInfo \n",err); + printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); + printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); + for (i=0;i0) + ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size); + + /* display a '*' if the file is crypted */ + if ((file_info.flag & 1) != 0) + charCrypt='*'; + + if (file_info.compression_method==0) + string_method="Stored"; + else + if (file_info.compression_method==Z_DEFLATED) + { + uInt iLevel=(uInt)((file_info.flag & 0x6)/2); + if (iLevel==0) + string_method="Defl:N"; + else if (iLevel==1) + string_method="Defl:X"; + else if ((iLevel==2) || (iLevel==3)) + string_method="Defl:F"; /* 2:fast , 3 : extra fast*/ + } + else + if (file_info.compression_method==Z_BZIP2ED) + { + string_method="BZip2 "; + } + else + string_method="Unkn. "; + + Display64BitsSize(file_info.uncompressed_size,7); + printf(" %6s%c",string_method,charCrypt); + Display64BitsSize(file_info.compressed_size,7); + printf(" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", + ratio, + (uLong)file_info.tmu_date.tm_mon + 1, + (uLong)file_info.tmu_date.tm_mday, + (uLong)file_info.tmu_date.tm_year % 100, + (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min, + (uLong)file_info.crc,filename_inzip); + if ((i+1)='a') && (rep<='z')) + rep -= 0x20; + } + while ((rep!='Y') && (rep!='N') && (rep!='A')); + } + + if (rep == 'N') + skip = 1; + + if (rep == 'A') + *popt_overwrite=1; + } + + if ((skip==0) && (err==UNZ_OK)) + { + fout=fopen64(write_filename,"wb"); + + /* some zipfile don't contain directory alone before file */ + if ((fout==NULL) && ((*popt_extract_without_path)==0) && + (filename_withoutpath!=(char*)filename_inzip)) + { + char c=*(filename_withoutpath-1); + *(filename_withoutpath-1)='\0'; + makedir(write_filename); + *(filename_withoutpath-1)=c; + fout=fopen64(write_filename,"wb"); + } + + if (fout==NULL) + { + printf("error opening %s\n",write_filename); + } + } + + if (fout!=NULL) + { + printf(" extracting: %s\n",write_filename); + + do + { + err = unzReadCurrentFile(uf,buf,size_buf); + if (err<0) + { + printf("error %d with zipfile in unzReadCurrentFile\n",err); + break; + } + if (err>0) + if (fwrite(buf,err,1,fout)!=1) + { + printf("error in writing extracted file\n"); + err=UNZ_ERRNO; + break; + } + } + while (err>0); + if (fout) + fclose(fout); + + if (err==0) + change_file_date(write_filename,file_info.dosDate, + file_info.tmu_date); + } + + if (err==UNZ_OK) + { + err = unzCloseCurrentFile (uf); + if (err!=UNZ_OK) + { + printf("error %d with zipfile in unzCloseCurrentFile\n",err); + } + } + else + unzCloseCurrentFile(uf); /* don't lose the error */ + } + + free(buf); + return err; +} + + +int do_extract(uf,opt_extract_without_path,opt_overwrite,password) + unzFile uf; + int opt_extract_without_path; + int opt_overwrite; + const char* password; +{ + uLong i; + unz_global_info64 gi; + int err; + FILE* fout=NULL; + + err = unzGetGlobalInfo64(uf,&gi); + if (err!=UNZ_OK) + printf("error %d with zipfile in unzGetGlobalInfo \n",err); + + for (i=0;i +#include +#include +#include "zlib.h" +#include "unzip.h" + +#define READ_8(adr) ((unsigned char)*(adr)) +#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) +#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) + +#define WRITE_8(buff, n) do { \ + *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ +} while(0) +#define WRITE_16(buff, n) do { \ + WRITE_8((unsigned char*)(buff), n); \ + WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ +} while(0) +#define WRITE_32(buff, n) do { \ + WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ + WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ +} while(0) + +extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) +const char* file; +const char* fileOut; +const char* fileOutTmp; +uLong* nRecovered; +uLong* bytesRecovered; +{ + int err = Z_OK; + FILE* fpZip = fopen(file, "rb"); + FILE* fpOut = fopen(fileOut, "wb"); + FILE* fpOutCD = fopen(fileOutTmp, "wb"); + if (fpZip != NULL && fpOut != NULL) { + int entries = 0; + uLong totalBytes = 0; + char header[30]; + char filename[256]; + char extra[1024]; + int offset = 0; + int offsetCD = 0; + while ( fread(header, 1, 30, fpZip) == 30 ) { + int currentOffset = offset; + + /* File entry */ + if (READ_32(header) == 0x04034b50) { + unsigned int version = READ_16(header + 4); + unsigned int gpflag = READ_16(header + 6); + unsigned int method = READ_16(header + 8); + unsigned int filetime = READ_16(header + 10); + unsigned int filedate = READ_16(header + 12); + unsigned int crc = READ_32(header + 14); /* crc */ + unsigned int cpsize = READ_32(header + 18); /* compressed size */ + unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ + unsigned int fnsize = READ_16(header + 26); /* file name length */ + unsigned int extsize = READ_16(header + 28); /* extra field length */ + filename[0] = extra[0] = '\0'; + + /* Header */ + if (fwrite(header, 1, 30, fpOut) == 30) { + offset += 30; + } else { + err = Z_ERRNO; + break; + } + + /* Filename */ + if (fnsize > 0) { + if (fread(filename, 1, fnsize, fpZip) == fnsize) { + if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { + offset += fnsize; + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_STREAM_ERROR; + break; + } + + /* Extra field */ + if (extsize > 0) { + if (fread(extra, 1, extsize, fpZip) == extsize) { + if (fwrite(extra, 1, extsize, fpOut) == extsize) { + offset += extsize; + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_ERRNO; + break; + } + } + + /* Data */ + { + int dataSize = cpsize; + if (dataSize == 0) { + dataSize = uncpsize; + } + if (dataSize > 0) { + char* data = malloc(dataSize); + if (data != NULL) { + if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { + if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { + offset += dataSize; + totalBytes += dataSize; + } else { + err = Z_ERRNO; + } + } else { + err = Z_ERRNO; + } + free(data); + if (err != Z_OK) { + break; + } + } else { + err = Z_MEM_ERROR; + break; + } + } + } + + /* Central directory entry */ + { + char header[46]; + char* comment = ""; + int comsize = (int) strlen(comment); + WRITE_32(header, 0x02014b50); + WRITE_16(header + 4, version); + WRITE_16(header + 6, version); + WRITE_16(header + 8, gpflag); + WRITE_16(header + 10, method); + WRITE_16(header + 12, filetime); + WRITE_16(header + 14, filedate); + WRITE_32(header + 16, crc); + WRITE_32(header + 20, cpsize); + WRITE_32(header + 24, uncpsize); + WRITE_16(header + 28, fnsize); + WRITE_16(header + 30, extsize); + WRITE_16(header + 32, comsize); + WRITE_16(header + 34, 0); /* disk # */ + WRITE_16(header + 36, 0); /* int attrb */ + WRITE_32(header + 38, 0); /* ext attrb */ + WRITE_32(header + 42, currentOffset); + /* Header */ + if (fwrite(header, 1, 46, fpOutCD) == 46) { + offsetCD += 46; + + /* Filename */ + if (fnsize > 0) { + if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { + offsetCD += fnsize; + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_STREAM_ERROR; + break; + } + + /* Extra field */ + if (extsize > 0) { + if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { + offsetCD += extsize; + } else { + err = Z_ERRNO; + break; + } + } + + /* Comment field */ + if (comsize > 0) { + if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { + offsetCD += comsize; + } else { + err = Z_ERRNO; + break; + } + } + + + } else { + err = Z_ERRNO; + break; + } + } + + /* Success */ + entries++; + + } else { + break; + } + } + + /* Final central directory */ + { + int entriesZip = entries; + char header[22]; + char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; + int comsize = (int) strlen(comment); + if (entriesZip > 0xffff) { + entriesZip = 0xffff; + } + WRITE_32(header, 0x06054b50); + WRITE_16(header + 4, 0); /* disk # */ + WRITE_16(header + 6, 0); /* disk # */ + WRITE_16(header + 8, entriesZip); /* hack */ + WRITE_16(header + 10, entriesZip); /* hack */ + WRITE_32(header + 12, offsetCD); /* size of CD */ + WRITE_32(header + 16, offset); /* offset to CD */ + WRITE_16(header + 20, comsize); /* comment */ + + /* Header */ + if (fwrite(header, 1, 22, fpOutCD) == 22) { + + /* Comment field */ + if (comsize > 0) { + if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { + err = Z_ERRNO; + } + } + + } else { + err = Z_ERRNO; + } + } + + /* Final merge (file + central directory) */ + fclose(fpOutCD); + if (err == Z_OK) { + fpOutCD = fopen(fileOutTmp, "rb"); + if (fpOutCD != NULL) { + int nRead; + char buffer[8192]; + while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { + if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { + err = Z_ERRNO; + break; + } + } + fclose(fpOutCD); + } + } + + /* Close */ + fclose(fpZip); + fclose(fpOut); + + /* Wipe temporary file */ + (void)remove(fileOutTmp); + + /* Number of recovered entries */ + if (err == Z_OK) { + if (nRecovered != NULL) { + *nRecovered = entries; + } + if (bytesRecovered != NULL) { + *bytesRecovered = totalBytes; + } + } + } else { + err = Z_STREAM_ERROR; + } + return err; +} diff --git a/fceumm/utils/zlib/contrib/minizip/mztools.h b/fceumm/utils/zlib/contrib/minizip/mztools.h new file mode 100644 index 0000000..88b3459 --- /dev/null +++ b/fceumm/utils/zlib/contrib/minizip/mztools.h @@ -0,0 +1,31 @@ +/* + Additional tools for Minizip + Code: Xavier Roche '2004 + License: Same as ZLIB (www.gzip.org) +*/ + +#ifndef _zip_tools_H +#define _zip_tools_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#include "unzip.h" + +/* Repair a ZIP file (missing central directory) + file: file to recover + fileOut: output file after recovery + fileOutTmp: temporary file name used for recovery +*/ +extern int ZEXPORT unzRepair(const char* file, + const char* fileOut, + const char* fileOutTmp, + uLong* nRecovered, + uLong* bytesRecovered); + +#endif diff --git a/fceumm/utils/zlib/contrib/minizip/unzip.c b/fceumm/utils/zlib/contrib/minizip/unzip.c new file mode 100644 index 0000000..7617f41 --- /dev/null +++ b/fceumm/utils/zlib/contrib/minizip/unzip.c @@ -0,0 +1,2125 @@ +/* unzip.c -- IO for uncompress .zip files using zlib + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications of Unzip for Zip64 + Copyright (C) 2007-2008 Even Rouault + + Modifications for Zip64 support on both zip and unzip + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + + ------------------------------------------------------------------------------------ + Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of + compatibility with older software. The following is from the original crypt.c. + Code woven in by Terry Thorsen 1/2003. + + Copyright (c) 1990-2000 Info-ZIP. All rights reserved. + + See the accompanying file LICENSE, version 2000-Apr-09 or later + (the contents of which are also included in zip.h) for terms of use. + If, for some reason, all these files are missing, the Info-ZIP license + also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html + + crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h] + + The encryption/decryption parts of this source code (as opposed to the + non-echoing password parts) were originally written in Europe. The + whole source package can be freely distributed, including from the USA. + (Prior to January 2000, re-export from the US was a violation of US law.) + + This encryption code is a direct transcription of the algorithm from + Roger Schlafly, described by Phil Katz in the file appnote.txt. This + file (appnote.txt) is distributed with the PKZIP program (even in the + version without encryption capabilities). + + ------------------------------------------------------------------------------------ + + Changes in unzip.c + + 2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos + 2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz* + 2007-2008 - Even Rouault - Remove old C style function prototypes + 2007-2008 - Even Rouault - Add unzip support for ZIP64 + + Copyright (C) 2007-2008 Even Rouault + + + Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again). + Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G + should only read the compressed/uncompressed size from the Zip64 format if + the size from normal header was 0xFFFFFFFF + Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant + Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required) + Patch created by Daniel Borca + + Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer + + Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson + +*/ + + +#include +#include +#include + +#ifndef NOUNCRYPT + #define NOUNCRYPT +#endif + +#include "zlib.h" +#include "unzip.h" + +#ifdef STDC +# include +# include +# include +#endif +#ifdef NO_ERRNO_H + extern int errno; +#else +# include +#endif + + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + + +#ifndef CASESENSITIVITYDEFAULT_NO +# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) +# define CASESENSITIVITYDEFAULT_NO +# endif +#endif + + +#ifndef UNZ_BUFSIZE +#define UNZ_BUFSIZE (16384) +#endif + +#ifndef UNZ_MAXFILENAMEINZIP +#define UNZ_MAXFILENAMEINZIP (256) +#endif + +#ifndef ALLOC +# define ALLOC(size) (malloc(size)) +#endif +#ifndef TRYFREE +# define TRYFREE(p) {if (p) free(p);} +#endif + +#define SIZECENTRALDIRITEM (0x2e) +#define SIZEZIPLOCALHEADER (0x1e) + + +const char unz_copyright[] = + " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; + +/* unz_file_info_interntal contain internal info about a file in zipfile*/ +typedef struct unz_file_info64_internal_s +{ + ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */ +} unz_file_info64_internal; + + +/* file_in_zip_read_info_s contain internal information about a file in zipfile, + when reading and decompress it */ +typedef struct +{ + char *read_buffer; /* internal buffer for compressed data */ + z_stream stream; /* zLib stream structure for inflate */ + +#ifdef HAVE_BZIP2 + bz_stream bstream; /* bzLib stream structure for bziped */ +#endif + + ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ + uLong stream_initialised; /* flag set if stream structure is initialised*/ + + ZPOS64_T offset_local_extrafield;/* offset of the local extra field */ + uInt size_local_extrafield;/* size of the local extra field */ + ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/ + ZPOS64_T total_out_64; + + uLong crc32; /* crc32 of all data uncompressed */ + uLong crc32_wait; /* crc32 we must obtain after decompress all */ + ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */ + ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/ + zlib_filefunc64_32_def z_filefunc; + voidpf filestream; /* io structore of the zipfile */ + uLong compression_method; /* compression method (0==store) */ + ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ + int raw; +} file_in_zip64_read_info_s; + + +/* unz64_s contain internal information about the zipfile +*/ +typedef struct +{ + zlib_filefunc64_32_def z_filefunc; + int is64bitOpenFunction; + voidpf filestream; /* io structore of the zipfile */ + unz_global_info64 gi; /* public global information */ + ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ + ZPOS64_T num_file; /* number of the current file in the zipfile*/ + ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/ + ZPOS64_T current_file_ok; /* flag about the usability of the current file*/ + ZPOS64_T central_pos; /* position of the beginning of the central dir*/ + + ZPOS64_T size_central_dir; /* size of the central directory */ + ZPOS64_T offset_central_dir; /* offset of start of central directory with + respect to the starting disk number */ + + unz_file_info64 cur_file_info; /* public info about the current file in zip*/ + unz_file_info64_internal cur_file_info_internal; /* private info about it*/ + file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current + file if we are decompressing it */ + int encrypted; + + int isZip64; + +# ifndef NOUNCRYPT + unsigned long keys[3]; /* keys defining the pseudo-random sequence */ + const unsigned long* pcrc_32_tab; +# endif +} unz64_s; + + +#ifndef NOUNCRYPT +#include "crypt.h" +#endif + +/* =========================================================================== + Read a byte from a gz_stream; update next_in and avail_in. Return EOF + for end of file. + IN assertion: the stream s has been sucessfully opened for reading. +*/ + + +local int unz64local_getByte OF(( + const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + int *pi)); + +local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi) +{ + unsigned char c; + int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); + if (err==1) + { + *pi = (int)c; + return UNZ_OK; + } + else + { + if (ZERROR64(*pzlib_filefunc_def,filestream)) + return UNZ_ERRNO; + else + return UNZ_EOF; + } +} + + +/* =========================================================================== + Reads a long in LSB order from the given gz_stream. Sets +*/ +local int unz64local_getShort OF(( + const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + uLong *pX)); + +local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + uLong *pX) +{ + uLong x ; + int i = 0; + int err; + + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (uLong)i; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((uLong)i)<<8; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + +local int unz64local_getLong OF(( + const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + uLong *pX)); + +local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + uLong *pX) +{ + uLong x ; + int i = 0; + int err; + + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (uLong)i; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((uLong)i)<<8; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((uLong)i)<<16; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<24; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + +local int unz64local_getLong64 OF(( + const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + ZPOS64_T *pX)); + + +local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + ZPOS64_T *pX) +{ + ZPOS64_T x ; + int i = 0; + int err; + + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (ZPOS64_T)i; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<8; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<16; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<24; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<32; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<40; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<48; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<56; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + +/* My own strcmpi / strcasecmp */ +local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2) +{ + for (;;) + { + char c1=*(fileName1++); + char c2=*(fileName2++); + if ((c1>='a') && (c1<='z')) + c1 -= 0x20; + if ((c2>='a') && (c2<='z')) + c2 -= 0x20; + if (c1=='\0') + return ((c2=='\0') ? 0 : -1); + if (c2=='\0') + return 1; + if (c1c2) + return 1; + } +} + + +#ifdef CASESENSITIVITYDEFAULT_NO +#define CASESENSITIVITYDEFAULTVALUE 2 +#else +#define CASESENSITIVITYDEFAULTVALUE 1 +#endif + +#ifndef STRCMPCASENOSENTIVEFUNCTION +#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal +#endif + +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) + +*/ +extern int ZEXPORT unzStringFileNameCompare (const char* fileName1, + const char* fileName2, + int iCaseSensitivity) + +{ + if (iCaseSensitivity==0) + iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; + + if (iCaseSensitivity==1) + return strcmp(fileName1,fileName2); + + return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); +} + +#ifndef BUFREADCOMMENT +#define BUFREADCOMMENT (0x400) +#endif + +/* + Locate the Central directory of a zipfile (at the end, just before + the global comment) +*/ +local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); +local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) +{ + unsigned char* buf; + ZPOS64_T uSizeFile; + ZPOS64_T uBackRead; + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ + ZPOS64_T uPosFound=0; + + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) + return 0; + + + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); + if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) + break; + + if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) + { + uPosFound = uReadPos+i; + break; + } + + if (uPosFound!=0) + break; + } + TRYFREE(buf); + return uPosFound; +} + + +/* + Locate the Central directory 64 of a zipfile (at the end, just before + the global comment) +*/ +local ZPOS64_T unz64local_SearchCentralDir64 OF(( + const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream)); + +local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream) +{ + unsigned char* buf; + ZPOS64_T uSizeFile; + ZPOS64_T uBackRead; + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ + ZPOS64_T uPosFound=0; + uLong uL; + ZPOS64_T relativeOffset; + + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) + return 0; + + + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); + if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) + break; + + if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && + ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) + { + uPosFound = uReadPos+i; + break; + } + + if (uPosFound!=0) + break; + } + TRYFREE(buf); + if (uPosFound == 0) + return 0; + + /* Zip64 end of central directory locator */ + if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) + return 0; + + /* the signature, already checked */ + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) + return 0; + + /* number of the disk with the start of the zip64 end of central directory */ + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) + return 0; + if (uL != 0) + return 0; + + /* relative offset of the zip64 end of central directory record */ + if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK) + return 0; + + /* total number of disks */ + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) + return 0; + if (uL != 1) + return 0; + + /* Goto end of central directory record */ + if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) + return 0; + + /* the signature */ + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) + return 0; + + if (uL != 0x06064b50) + return 0; + + return relativeOffset; +} + +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer + "zlib/zlib114.zip". + If the zipfile cannot be opened (file doesn't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. +*/ +local unzFile unzOpenInternal (const void *path, + zlib_filefunc64_32_def* pzlib_filefunc64_32_def, + int is64bitOpenFunction) +{ + unz64_s us; + unz64_s *s; + ZPOS64_T central_pos; + uLong uL; + + uLong number_disk; /* number of the current dist, used for + spaning ZIP, unsupported, always 0*/ + uLong number_disk_with_CD; /* number the the disk with central dir, used + for spaning ZIP, unsupported, always 0*/ + ZPOS64_T number_entry_CD; /* total number of entries in + the central dir + (same than number_entry on nospan) */ + + int err=UNZ_OK; + + if (unz_copyright[0]!=' ') + return NULL; + + us.z_filefunc.zseek32_file = NULL; + us.z_filefunc.ztell32_file = NULL; + if (pzlib_filefunc64_32_def==NULL) + fill_fopen64_filefunc(&us.z_filefunc.zfile_func64); + else + us.z_filefunc = *pzlib_filefunc64_32_def; + us.is64bitOpenFunction = is64bitOpenFunction; + + + + us.filestream = ZOPEN64(us.z_filefunc, + path, + ZLIB_FILEFUNC_MODE_READ | + ZLIB_FILEFUNC_MODE_EXISTING); + if (us.filestream==NULL) + return NULL; + + central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream); + if (central_pos) + { + uLong uS; + ZPOS64_T uL64; + + us.isZip64 = 1; + + if (ZSEEK64(us.z_filefunc, us.filestream, + central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) + err=UNZ_ERRNO; + + /* the signature, already checked */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + + /* size of zip64 end of central directory record */ + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK) + err=UNZ_ERRNO; + + /* version made by */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) + err=UNZ_ERRNO; + + /* version needed to extract */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of this disk */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of the disk with the start of the central directory */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central directory on this disk */ + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central directory */ + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + if ((number_entry_CD!=us.gi.number_entry) || + (number_disk_with_CD!=0) || + (number_disk!=0)) + err=UNZ_BADZIPFILE; + + /* size of the central directory */ + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + /* offset of start of central directory with respect to the + starting disk number */ + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + us.gi.size_comment = 0; + } + else + { + central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream); + if (central_pos==0) + err=UNZ_ERRNO; + + us.isZip64 = 0; + + if (ZSEEK64(us.z_filefunc, us.filestream, + central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) + err=UNZ_ERRNO; + + /* the signature, already checked */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of this disk */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of the disk with the start of the central directory */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central dir on this disk */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + us.gi.number_entry = uL; + + /* total number of entries in the central dir */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + number_entry_CD = uL; + + if ((number_entry_CD!=us.gi.number_entry) || + (number_disk_with_CD!=0) || + (number_disk!=0)) + err=UNZ_BADZIPFILE; + + /* size of the central directory */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + us.size_central_dir = uL; + + /* offset of start of central directory with respect to the + starting disk number */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + us.offset_central_dir = uL; + + /* zipfile comment length */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) + err=UNZ_ERRNO; + } + + if ((central_pospfile_in_zip_read!=NULL) + unzCloseCurrentFile(file); + + ZCLOSE64(s->z_filefunc, s->filestream); + TRYFREE(s); + return UNZ_OK; +} + + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ +extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info) +{ + unz64_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + *pglobal_info=s->gi; + return UNZ_OK; +} + +extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32) +{ + unz64_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + /* to do : check if number_entry is not truncated */ + pglobal_info32->number_entry = (uLong)s->gi.number_entry; + pglobal_info32->size_comment = s->gi.size_comment; + return UNZ_OK; +} +/* + Translate date/time from Dos format to tm_unz (readable more easilty) +*/ +local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm) +{ + ZPOS64_T uDate; + uDate = (ZPOS64_T)(ulDosDate>>16); + ptm->tm_mday = (uInt)(uDate&0x1f) ; + ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; + ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; + + ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); + ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; + ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; +} + +/* + Get Info about the current file in the zipfile, with internal only info +*/ +local int unz64local_GetCurrentFileInfoInternal OF((unzFile file, + unz_file_info64 *pfile_info, + unz_file_info64_internal + *pfile_info_internal, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); + +local int unz64local_GetCurrentFileInfoInternal (unzFile file, + unz_file_info64 *pfile_info, + unz_file_info64_internal + *pfile_info_internal, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize) +{ + unz64_s* s; + unz_file_info64 file_info; + unz_file_info64_internal file_info_internal; + int err=UNZ_OK; + uLong uMagic; + long lSeek=0; + uLong uL; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + if (ZSEEK64(s->z_filefunc, s->filestream, + s->pos_in_central_dir+s->byte_before_the_zipfile, + ZLIB_FILEFUNC_SEEK_SET)!=0) + err=UNZ_ERRNO; + + + /* we check the magic */ + if (err==UNZ_OK) + { + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if (uMagic!=0x02014b50) + err=UNZ_BADZIPFILE; + } + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) + err=UNZ_ERRNO; + + unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) + err=UNZ_ERRNO; + file_info.compressed_size = uL; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) + err=UNZ_ERRNO; + file_info.uncompressed_size = uL; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) + err=UNZ_ERRNO; + + // relative offset of local header + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) + err=UNZ_ERRNO; + file_info_internal.offset_curfile = uL; + + lSeek+=file_info.size_filename; + if ((err==UNZ_OK) && (szFileName!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_filename0) && (fileNameBufferSize>0)) + if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) + err=UNZ_ERRNO; + lSeek -= uSizeRead; + } + + // Read extrafield + if ((err==UNZ_OK) && (extraField!=NULL)) + { + ZPOS64_T uSizeRead ; + if (file_info.size_file_extraz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + + if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) + if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead) + err=UNZ_ERRNO; + + lSeek += file_info.size_file_extra - (uLong)uSizeRead; + } + else + lSeek += file_info.size_file_extra; + + + if ((err==UNZ_OK) && (file_info.size_file_extra != 0)) + { + uLong acc = 0; + + // since lSeek now points to after the extra field we need to move back + lSeek -= file_info.size_file_extra; + + if (lSeek!=0) + { + if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + + while(acc < file_info.size_file_extra) + { + uLong headerId; + uLong dataSize; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK) + err=UNZ_ERRNO; + + /* ZIP64 extra fields */ + if (headerId == 0x0001) + { + uLong uL; + + if(file_info.uncompressed_size == (ZPOS64_T)(unsigned long)-1) + { + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) + err=UNZ_ERRNO; + } + + if(file_info.compressed_size == (ZPOS64_T)(unsigned long)-1) + { + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) + err=UNZ_ERRNO; + } + + if(file_info_internal.offset_curfile == (ZPOS64_T)(unsigned long)-1) + { + /* Relative Header offset */ + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) + err=UNZ_ERRNO; + } + + if(file_info.disk_num_start == (unsigned long)-1) + { + /* Disk Start Number */ + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) + err=UNZ_ERRNO; + } + + } + else + { + if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0) + err=UNZ_ERRNO; + } + + acc += 2 + 2 + dataSize; + } + } + + if ((err==UNZ_OK) && (szComment!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_file_commentz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + + if ((file_info.size_file_comment>0) && (commentBufferSize>0)) + if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) + err=UNZ_ERRNO; + lSeek+=file_info.size_file_comment - uSizeRead; + } + else + lSeek+=file_info.size_file_comment; + + + if ((err==UNZ_OK) && (pfile_info!=NULL)) + *pfile_info=file_info; + + if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) + *pfile_info_internal=file_info_internal; + + return err; +} + + + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. +*/ +extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file, + unz_file_info64 * pfile_info, + char * szFileName, uLong fileNameBufferSize, + void *extraField, uLong extraFieldBufferSize, + char* szComment, uLong commentBufferSize) +{ + return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL, + szFileName,fileNameBufferSize, + extraField,extraFieldBufferSize, + szComment,commentBufferSize); +} + +extern int ZEXPORT unzGetCurrentFileInfo (unzFile file, + unz_file_info * pfile_info, + char * szFileName, uLong fileNameBufferSize, + void *extraField, uLong extraFieldBufferSize, + char* szComment, uLong commentBufferSize) +{ + int err; + unz_file_info64 file_info64; + err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL, + szFileName,fileNameBufferSize, + extraField,extraFieldBufferSize, + szComment,commentBufferSize); + if (err==UNZ_OK) + { + pfile_info->version = file_info64.version; + pfile_info->version_needed = file_info64.version_needed; + pfile_info->flag = file_info64.flag; + pfile_info->compression_method = file_info64.compression_method; + pfile_info->dosDate = file_info64.dosDate; + pfile_info->crc = file_info64.crc; + + pfile_info->size_filename = file_info64.size_filename; + pfile_info->size_file_extra = file_info64.size_file_extra; + pfile_info->size_file_comment = file_info64.size_file_comment; + + pfile_info->disk_num_start = file_info64.disk_num_start; + pfile_info->internal_fa = file_info64.internal_fa; + pfile_info->external_fa = file_info64.external_fa; + + pfile_info->tmu_date = file_info64.tmu_date, + + + pfile_info->compressed_size = (uLong)file_info64.compressed_size; + pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size; + + } + return err; +} +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ +extern int ZEXPORT unzGoToFirstFile (unzFile file) +{ + int err=UNZ_OK; + unz64_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + s->pos_in_central_dir=s->offset_central_dir; + s->num_file=0; + err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ +extern int ZEXPORT unzGoToNextFile (unzFile file) +{ + unz64_s* s; + int err; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ + if (s->num_file+1==s->gi.number_entry) + return UNZ_END_OF_LIST_OF_FILE; + + s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + + s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; + s->num_file++; + err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + + +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzipStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ +extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity) +{ + unz64_s* s; + int err; + + /* We remember the 'current' position in the file so that we can jump + * back there if we fail. + */ + unz_file_info64 cur_file_infoSaved; + unz_file_info64_internal cur_file_info_internalSaved; + ZPOS64_T num_fileSaved; + ZPOS64_T pos_in_central_dirSaved; + + + if (file==NULL) + return UNZ_PARAMERROR; + + if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) + return UNZ_PARAMERROR; + + s=(unz64_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + + /* Save the current state */ + num_fileSaved = s->num_file; + pos_in_central_dirSaved = s->pos_in_central_dir; + cur_file_infoSaved = s->cur_file_info; + cur_file_info_internalSaved = s->cur_file_info_internal; + + err = unzGoToFirstFile(file); + + while (err == UNZ_OK) + { + char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; + err = unzGetCurrentFileInfo64(file,NULL, + szCurrentFileName,sizeof(szCurrentFileName)-1, + NULL,0,NULL,0); + if (err == UNZ_OK) + { + if (unzStringFileNameCompare(szCurrentFileName, + szFileName,iCaseSensitivity)==0) + return UNZ_OK; + err = unzGoToNextFile(file); + } + } + + /* We failed, so restore the state of the 'current file' to where we + * were. + */ + s->num_file = num_fileSaved ; + s->pos_in_central_dir = pos_in_central_dirSaved ; + s->cur_file_info = cur_file_infoSaved; + s->cur_file_info_internal = cur_file_info_internalSaved; + return err; +} + + +/* +/////////////////////////////////////////// +// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net) +// I need random access +// +// Further optimization could be realized by adding an ability +// to cache the directory in memory. The goal being a single +// comprehensive file read to put the file I need in a memory. +*/ + +/* +typedef struct unz_file_pos_s +{ + ZPOS64_T pos_in_zip_directory; // offset in file + ZPOS64_T num_of_file; // # of file +} unz_file_pos; +*/ + +extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) +{ + unz64_s* s; + + if (file==NULL || file_pos==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + + file_pos->pos_in_zip_directory = s->pos_in_central_dir; + file_pos->num_of_file = s->num_file; + + return UNZ_OK; +} + +extern int ZEXPORT unzGetFilePos( + unzFile file, + unz_file_pos* file_pos) +{ + unz64_file_pos file_pos64; + int err = unzGetFilePos64(file,&file_pos64); + if (err==UNZ_OK) + { + file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory; + file_pos->num_of_file = (uLong)file_pos64.num_of_file; + } + return err; +} + +extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) +{ + unz64_s* s; + int err; + + if (file==NULL || file_pos==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + + /* jump to the right spot */ + s->pos_in_central_dir = file_pos->pos_in_zip_directory; + s->num_file = file_pos->num_of_file; + + /* set the current file */ + err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + /* return results */ + s->current_file_ok = (err == UNZ_OK); + return err; +} + +extern int ZEXPORT unzGoToFilePos( + unzFile file, + unz_file_pos* file_pos) +{ + unz64_file_pos file_pos64; + if (file_pos == NULL) + return UNZ_PARAMERROR; + + file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory; + file_pos64.num_of_file = file_pos->num_of_file; + return unzGoToFilePos64(file,&file_pos64); +} + +/* +// Unzip Helper Functions - should be here? +/////////////////////////////////////////// +*/ + +/* + Read the local header of the current zipfile + Check the coherency of the local header and info in the end of central + directory about this file + store in *piSizeVar the size of extra info in local header + (filename and size of extra field data) +*/ +local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar, + ZPOS64_T * poffset_local_extrafield, + uInt * psize_local_extrafield) +{ + uLong uMagic,uData,uFlags; + uLong size_filename; + uLong size_extra_field; + int err=UNZ_OK; + + *piSizeVar = 0; + *poffset_local_extrafield = 0; + *psize_local_extrafield = 0; + + if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + + s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) + return UNZ_ERRNO; + + + if (err==UNZ_OK) + { + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if (uMagic!=0x04034b50) + err=UNZ_BADZIPFILE; + } + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) + err=UNZ_ERRNO; +/* + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) + err=UNZ_BADZIPFILE; +*/ + if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) + err=UNZ_BADZIPFILE; + + if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && +/* #ifdef HAVE_BZIP2 */ + (s->cur_file_info.compression_method!=Z_BZIP2ED) && +/* #endif */ + (s->cur_file_info.compression_method!=Z_DEFLATED)) + err=UNZ_BADZIPFILE; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ + err=UNZ_ERRNO; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ + err=UNZ_ERRNO; + else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ + err=UNZ_ERRNO; + else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK) + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) + err=UNZ_BADZIPFILE; + + *piSizeVar += (uInt)size_filename; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) + err=UNZ_ERRNO; + *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + + SIZEZIPLOCALHEADER + size_filename; + *psize_local_extrafield = (uInt)size_extra_field; + + *piSizeVar += (uInt)size_extra_field; + + return err; +} + +/* + Open for reading data the current file in the zipfile. + If there is no error and the file is opened, the return value is UNZ_OK. +*/ +extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, + int* level, int raw, const char* password) +{ + int err=UNZ_OK; + uInt iSizeVar; + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + ZPOS64_T offset_local_extrafield; /* offset of the local extra field */ + uInt size_local_extrafield; /* size of the local extra field */ +# ifndef NOUNCRYPT + char source[12]; +# else + if (password != NULL) + return UNZ_PARAMERROR; +# endif + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + if (!s->current_file_ok) + return UNZ_PARAMERROR; + + if (s->pfile_in_zip_read != NULL) + unzCloseCurrentFile(file); + + if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) + return UNZ_BADZIPFILE; + + pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s)); + if (pfile_in_zip_read_info==NULL) + return UNZ_INTERNALERROR; + + pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); + pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; + pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; + pfile_in_zip_read_info->pos_local_extrafield=0; + pfile_in_zip_read_info->raw=raw; + + if (pfile_in_zip_read_info->read_buffer==NULL) + { + TRYFREE(pfile_in_zip_read_info); + return UNZ_INTERNALERROR; + } + + pfile_in_zip_read_info->stream_initialised=0; + + if (method!=NULL) + *method = (int)s->cur_file_info.compression_method; + + if (level!=NULL) + { + *level = 6; + switch (s->cur_file_info.flag & 0x06) + { + case 6 : *level = 1; break; + case 4 : *level = 2; break; + case 2 : *level = 9; break; + } + } + + if ((s->cur_file_info.compression_method!=0) && +/* #ifdef HAVE_BZIP2 */ + (s->cur_file_info.compression_method!=Z_BZIP2ED) && +/* #endif */ + (s->cur_file_info.compression_method!=Z_DEFLATED)) + + err=UNZ_BADZIPFILE; + + pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; + pfile_in_zip_read_info->crc32=0; + pfile_in_zip_read_info->total_out_64=0; + pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method; + pfile_in_zip_read_info->filestream=s->filestream; + pfile_in_zip_read_info->z_filefunc=s->z_filefunc; + pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; + + pfile_in_zip_read_info->stream.total_out = 0; + + if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw)) + { +#ifdef HAVE_BZIP2 + pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0; + pfile_in_zip_read_info->bstream.bzfree = (free_func)0; + pfile_in_zip_read_info->bstream.opaque = (voidpf)0; + pfile_in_zip_read_info->bstream.state = (voidpf)0; + + pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; + pfile_in_zip_read_info->stream.zfree = (free_func)0; + pfile_in_zip_read_info->stream.opaque = (voidpf)0; + pfile_in_zip_read_info->stream.next_in = (voidpf)0; + pfile_in_zip_read_info->stream.avail_in = 0; + + err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0); + if (err == Z_OK) + pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED; + else + { + TRYFREE(pfile_in_zip_read_info); + return err; + } +#else + pfile_in_zip_read_info->raw=1; +#endif + } + else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw)) + { + pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; + pfile_in_zip_read_info->stream.zfree = (free_func)0; + pfile_in_zip_read_info->stream.opaque = (voidpf)0; + pfile_in_zip_read_info->stream.next_in = 0; + pfile_in_zip_read_info->stream.avail_in = 0; + + err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); + if (err == Z_OK) + pfile_in_zip_read_info->stream_initialised=Z_DEFLATED; + else + { + TRYFREE(pfile_in_zip_read_info); + return err; + } + /* windowBits is passed < 0 to tell that there is no zlib header. + * Note that in this case inflate *requires* an extra "dummy" byte + * after the compressed stream in order to complete decompression and + * return Z_STREAM_END. + * In unzip, i don't wait absolutely Z_STREAM_END because I known the + * size of both compressed and uncompressed data + */ + } + pfile_in_zip_read_info->rest_read_compressed = + s->cur_file_info.compressed_size ; + pfile_in_zip_read_info->rest_read_uncompressed = + s->cur_file_info.uncompressed_size ; + + + pfile_in_zip_read_info->pos_in_zipfile = + s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + + iSizeVar; + + pfile_in_zip_read_info->stream.avail_in = (uInt)0; + + s->pfile_in_zip_read = pfile_in_zip_read_info; + s->encrypted = 0; + +# ifndef NOUNCRYPT + if (password != NULL) + { + int i; + s->pcrc_32_tab = get_crc_table(); + init_keys(password,s->keys,s->pcrc_32_tab); + if (ZSEEK64(s->z_filefunc, s->filestream, + s->pfile_in_zip_read->pos_in_zipfile + + s->pfile_in_zip_read->byte_before_the_zipfile, + SEEK_SET)!=0) + return UNZ_INTERNALERROR; + if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12) + return UNZ_INTERNALERROR; + + for (i = 0; i<12; i++) + zdecode(s->keys,s->pcrc_32_tab,source[i]); + + s->pfile_in_zip_read->pos_in_zipfile+=12; + s->encrypted=1; + } +# endif + + + return UNZ_OK; +} + +extern int ZEXPORT unzOpenCurrentFile (unzFile file) +{ + return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); +} + +extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password) +{ + return unzOpenCurrentFile3(file, NULL, NULL, 0, password); +} + +extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw) +{ + return unzOpenCurrentFile3(file, method, level, raw, NULL); +} + +/** Addition for GDAL : START */ + +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file) +{ + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + s=(unz64_s*)file; + if (file==NULL) + return 0; //UNZ_PARAMERROR; + pfile_in_zip_read_info=s->pfile_in_zip_read; + if (pfile_in_zip_read_info==NULL) + return 0; //UNZ_PARAMERROR; + return pfile_in_zip_read_info->pos_in_zipfile + + pfile_in_zip_read_info->byte_before_the_zipfile; +} + +/** Addition for GDAL : END */ + +/* + Read bytes from the current file. + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ +extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) +{ + int err=UNZ_OK; + uInt iRead = 0; + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + + if ((pfile_in_zip_read_info->read_buffer == NULL)) + return UNZ_END_OF_LIST_OF_FILE; + if (len==0) + return 0; + + pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; + + pfile_in_zip_read_info->stream.avail_out = (uInt)len; + + if ((len>pfile_in_zip_read_info->rest_read_uncompressed) && + (!(pfile_in_zip_read_info->raw))) + pfile_in_zip_read_info->stream.avail_out = + (uInt)pfile_in_zip_read_info->rest_read_uncompressed; + + if ((len>pfile_in_zip_read_info->rest_read_compressed+ + pfile_in_zip_read_info->stream.avail_in) && + (pfile_in_zip_read_info->raw)) + pfile_in_zip_read_info->stream.avail_out = + (uInt)pfile_in_zip_read_info->rest_read_compressed+ + pfile_in_zip_read_info->stream.avail_in; + + while (pfile_in_zip_read_info->stream.avail_out>0) + { + if ((pfile_in_zip_read_info->stream.avail_in==0) && + (pfile_in_zip_read_info->rest_read_compressed>0)) + { + uInt uReadThis = UNZ_BUFSIZE; + if (pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; + if (uReadThis == 0) + return UNZ_EOF; + if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, + pfile_in_zip_read_info->pos_in_zipfile + + pfile_in_zip_read_info->byte_before_the_zipfile, + ZLIB_FILEFUNC_SEEK_SET)!=0) + return UNZ_ERRNO; + if (ZREAD64(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, + pfile_in_zip_read_info->read_buffer, + uReadThis)!=uReadThis) + return UNZ_ERRNO; + + +# ifndef NOUNCRYPT + if(s->encrypted) + { + uInt i; + for(i=0;iread_buffer[i] = + zdecode(s->keys,s->pcrc_32_tab, + pfile_in_zip_read_info->read_buffer[i]); + } +# endif + + + pfile_in_zip_read_info->pos_in_zipfile += uReadThis; + + pfile_in_zip_read_info->rest_read_compressed-=uReadThis; + + pfile_in_zip_read_info->stream.next_in = + (Bytef*)pfile_in_zip_read_info->read_buffer; + pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; + } + + if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) + { + uInt uDoCopy,i ; + + if ((pfile_in_zip_read_info->stream.avail_in == 0) && + (pfile_in_zip_read_info->rest_read_compressed == 0)) + return (iRead==0) ? UNZ_EOF : iRead; + + if (pfile_in_zip_read_info->stream.avail_out < + pfile_in_zip_read_info->stream.avail_in) + uDoCopy = pfile_in_zip_read_info->stream.avail_out ; + else + uDoCopy = pfile_in_zip_read_info->stream.avail_in ; + + for (i=0;istream.next_out+i) = + *(pfile_in_zip_read_info->stream.next_in+i); + + pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy; + + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, + pfile_in_zip_read_info->stream.next_out, + uDoCopy); + pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; + pfile_in_zip_read_info->stream.avail_in -= uDoCopy; + pfile_in_zip_read_info->stream.avail_out -= uDoCopy; + pfile_in_zip_read_info->stream.next_out += uDoCopy; + pfile_in_zip_read_info->stream.next_in += uDoCopy; + pfile_in_zip_read_info->stream.total_out += uDoCopy; + iRead += uDoCopy; + } + else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED) + { +#ifdef HAVE_BZIP2 + uLong uTotalOutBefore,uTotalOutAfter; + const Bytef *bufBefore; + uLong uOutThis; + + pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in; + pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in; + pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in; + pfile_in_zip_read_info->bstream.total_in_hi32 = 0; + pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out; + pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out; + pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out; + pfile_in_zip_read_info->bstream.total_out_hi32 = 0; + + uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32; + bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out; + + err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream); + + uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32; + uOutThis = uTotalOutAfter-uTotalOutBefore; + + pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; + + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis)); + pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis; + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); + + pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in; + pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in; + pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32; + pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out; + pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out; + pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32; + + if (err==BZ_STREAM_END) + return (iRead==0) ? UNZ_EOF : iRead; + if (err!=BZ_OK) + break; +#endif + } // end Z_BZIP2ED + else + { + ZPOS64_T uTotalOutBefore,uTotalOutAfter; + const Bytef *bufBefore; + ZPOS64_T uOutThis; + int flush=Z_SYNC_FLUSH; + + uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; + bufBefore = pfile_in_zip_read_info->stream.next_out; + + /* + if ((pfile_in_zip_read_info->rest_read_uncompressed == + pfile_in_zip_read_info->stream.avail_out) && + (pfile_in_zip_read_info->rest_read_compressed == 0)) + flush = Z_FINISH; + */ + err=inflate(&pfile_in_zip_read_info->stream,flush); + + if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL)) + err = Z_DATA_ERROR; + + uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; + uOutThis = uTotalOutAfter-uTotalOutBefore; + + pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; + + pfile_in_zip_read_info->crc32 = + crc32(pfile_in_zip_read_info->crc32,bufBefore, + (uInt)(uOutThis)); + + pfile_in_zip_read_info->rest_read_uncompressed -= + uOutThis; + + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); + + if (err==Z_STREAM_END) + return (iRead==0) ? UNZ_EOF : iRead; + if (err!=Z_OK) + break; + } + } + + if (err==Z_OK) + return iRead; + return err; +} + + +/* + Give the current position in uncompressed data +*/ +extern z_off_t ZEXPORT unztell (unzFile file) +{ + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + return (z_off_t)pfile_in_zip_read_info->stream.total_out; +} + +extern ZPOS64_T ZEXPORT unztell64 (unzFile file) +{ + + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return (ZPOS64_T)-1; + s=(unz64_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return (ZPOS64_T)-1; + + return pfile_in_zip_read_info->total_out_64; +} + + +/* + return 1 if the end of file was reached, 0 elsewhere +*/ +extern int ZEXPORT unzeof (unzFile file) +{ + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + if (pfile_in_zip_read_info->rest_read_uncompressed == 0) + return 1; + else + return 0; +} + + + +/* +Read extra field from the current file (opened by unzOpenCurrentFile) +This is the local-header version of the extra field (sometimes, there is +more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field that can be read + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ +extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len) +{ + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + uInt read_now; + ZPOS64_T size_to_read; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + size_to_read = (pfile_in_zip_read_info->size_local_extrafield - + pfile_in_zip_read_info->pos_local_extrafield); + + if (buf==NULL) + return (int)size_to_read; + + if (len>size_to_read) + read_now = (uInt)size_to_read; + else + read_now = (uInt)len ; + + if (read_now==0) + return 0; + + if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, + pfile_in_zip_read_info->offset_local_extrafield + + pfile_in_zip_read_info->pos_local_extrafield, + ZLIB_FILEFUNC_SEEK_SET)!=0) + return UNZ_ERRNO; + + if (ZREAD64(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, + buf,read_now)!=read_now) + return UNZ_ERRNO; + + return (int)read_now; +} + +/* + Close the file in zip opened with unzipOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ +extern int ZEXPORT unzCloseCurrentFile (unzFile file) +{ + int err=UNZ_OK; + + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + + if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && + (!pfile_in_zip_read_info->raw)) + { + if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) + err=UNZ_CRCERROR; + } + + + TRYFREE(pfile_in_zip_read_info->read_buffer); + pfile_in_zip_read_info->read_buffer = NULL; + if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED) + inflateEnd(&pfile_in_zip_read_info->stream); +#ifdef HAVE_BZIP2 + else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED) + BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream); +#endif + + + pfile_in_zip_read_info->stream_initialised = 0; + TRYFREE(pfile_in_zip_read_info); + + s->pfile_in_zip_read=NULL; + + return err; +} + + +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ +extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf) +{ + unz64_s* s; + uLong uReadThis ; + if (file==NULL) + return (int)UNZ_PARAMERROR; + s=(unz64_s*)file; + + uReadThis = uSizeBuf; + if (uReadThis>s->gi.size_comment) + uReadThis = s->gi.size_comment; + + if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) + return UNZ_ERRNO; + + if (uReadThis>0) + { + *szComment='\0'; + if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) + return UNZ_ERRNO; + } + + if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) + *(szComment+s->gi.size_comment)='\0'; + return (int)uReadThis; +} + +/* Additions by RX '2004 */ +extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) +{ + unz64_s* s; + + if (file==NULL) + return 0; //UNZ_PARAMERROR; + s=(unz64_s*)file; + if (!s->current_file_ok) + return 0; + if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) + if (s->num_file==s->gi.number_entry) + return 0; + return s->pos_in_central_dir; +} + +extern uLong ZEXPORT unzGetOffset (unzFile file) +{ + ZPOS64_T offset64; + + if (file==NULL) + return 0; //UNZ_PARAMERROR; + offset64 = unzGetOffset64(file); + return (uLong)offset64; +} + +extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) +{ + unz64_s* s; + int err; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + + s->pos_in_central_dir = pos; + s->num_file = s->gi.number_entry; /* hack */ + err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) +{ + return unzSetOffset64(file,pos); +} diff --git a/fceumm/utils/zlib/contrib/minizip/unzip.h b/fceumm/utils/zlib/contrib/minizip/unzip.h new file mode 100644 index 0000000..3183968 --- /dev/null +++ b/fceumm/utils/zlib/contrib/minizip/unzip.h @@ -0,0 +1,437 @@ +/* unzip.h -- IO for uncompress .zip files using zlib + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications of Unzip for Zip64 + Copyright (C) 2007-2008 Even Rouault + + Modifications for Zip64 support on both zip and unzip + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + --------------------------------------------------------------------------------- + + Condition of use and distribution are the same than zlib : + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + --------------------------------------------------------------------------------- + + Changes + + See header of unzip64.c + +*/ + +#ifndef _unz64_H +#define _unz64_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#ifndef _ZLIBIOAPI_H +#include "ioapi.h" +#endif + +#ifdef HAVE_BZIP2 +#include "bzlib.h" +#endif + +#define Z_BZIP2ED 12 + +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) +/* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ +typedef struct TagunzFile__ { int unused; } unzFile__; +typedef unzFile__ *unzFile; +#else +typedef voidp unzFile; +#endif + + +#define UNZ_OK (0) +#define UNZ_END_OF_LIST_OF_FILE (-100) +#define UNZ_ERRNO (Z_ERRNO) +#define UNZ_EOF (0) +#define UNZ_PARAMERROR (-102) +#define UNZ_BADZIPFILE (-103) +#define UNZ_INTERNALERROR (-104) +#define UNZ_CRCERROR (-105) + +/* tm_unz contain date/time info */ +typedef struct tm_unz_s +{ + uInt tm_sec; /* seconds after the minute - [0,59] */ + uInt tm_min; /* minutes after the hour - [0,59] */ + uInt tm_hour; /* hours since midnight - [0,23] */ + uInt tm_mday; /* day of the month - [1,31] */ + uInt tm_mon; /* months since January - [0,11] */ + uInt tm_year; /* years - [1980..2044] */ +} tm_unz; + +/* unz_global_info structure contain global data about the ZIPfile + These data comes from the end of central dir */ +typedef struct unz_global_info64_s +{ + ZPOS64_T number_entry; /* total number of entries in + the central dir on this disk */ + uLong size_comment; /* size of the global comment of the zipfile */ +} unz_global_info64; + +typedef struct unz_global_info_s +{ + uLong number_entry; /* total number of entries in + the central dir on this disk */ + uLong size_comment; /* size of the global comment of the zipfile */ +} unz_global_info; + +/* unz_file_info contain information about a file in the zipfile */ +typedef struct unz_file_info64_s +{ + uLong version; /* version made by 2 bytes */ + uLong version_needed; /* version needed to extract 2 bytes */ + uLong flag; /* general purpose bit flag 2 bytes */ + uLong compression_method; /* compression method 2 bytes */ + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ + uLong crc; /* crc-32 4 bytes */ + ZPOS64_T compressed_size; /* compressed size 8 bytes */ + ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */ + uLong size_filename; /* filename length 2 bytes */ + uLong size_file_extra; /* extra field length 2 bytes */ + uLong size_file_comment; /* file comment length 2 bytes */ + + uLong disk_num_start; /* disk number start 2 bytes */ + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ + + tm_unz tmu_date; +} unz_file_info64; + +typedef struct unz_file_info_s +{ + uLong version; /* version made by 2 bytes */ + uLong version_needed; /* version needed to extract 2 bytes */ + uLong flag; /* general purpose bit flag 2 bytes */ + uLong compression_method; /* compression method 2 bytes */ + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ + uLong crc; /* crc-32 4 bytes */ + uLong compressed_size; /* compressed size 4 bytes */ + uLong uncompressed_size; /* uncompressed size 4 bytes */ + uLong size_filename; /* filename length 2 bytes */ + uLong size_file_extra; /* extra field length 2 bytes */ + uLong size_file_comment; /* file comment length 2 bytes */ + + uLong disk_num_start; /* disk number start 2 bytes */ + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ + + tm_unz tmu_date; +} unz_file_info; + +extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, + const char* fileName2, + int iCaseSensitivity)); +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) +*/ + + +extern unzFile ZEXPORT unzOpen OF((const char *path)); +extern unzFile ZEXPORT unzOpen64 OF((const void *path)); +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer + "zlib/zlib113.zip". + If the zipfile cannot be opened (file don't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. + the "64" function take a const void* pointer, because the path is just the + value passed to the open64_file_func callback. + Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path + is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* + does not describe the reality +*/ + + +extern unzFile ZEXPORT unzOpen2 OF((const char *path, + zlib_filefunc_def* pzlib_filefunc_def)); +/* + Open a Zip file, like unzOpen, but provide a set of file low level API + for read/write the zip file (see ioapi.h) +*/ + +extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, + zlib_filefunc64_def* pzlib_filefunc_def)); +/* + Open a Zip file, like unz64Open, but provide a set of file low level API + for read/write the zip file (see ioapi.h) +*/ + +extern int ZEXPORT unzClose OF((unzFile file)); +/* + Close a ZipFile opened with unzipOpen. + If there is files inside the .Zip opened with unzOpenCurrentFile (see later), + these files MUST be closed with unzipCloseCurrentFile before call unzipClose. + return UNZ_OK if there is no problem. */ + +extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, + unz_global_info *pglobal_info)); + +extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, + unz_global_info64 *pglobal_info)); +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ + + +extern int ZEXPORT unzGetGlobalComment OF((unzFile file, + char *szComment, + uLong uSizeBuf)); +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ + + +/***************************************************************************/ +/* Unzip package allow you browse the directory of the zipfile */ + +extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ + +extern int ZEXPORT unzGoToNextFile OF((unzFile file)); +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ + +extern int ZEXPORT unzLocateFile OF((unzFile file, + const char *szFileName, + int iCaseSensitivity)); +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ + + +/* ****************************************** */ +/* Ryan supplied functions */ +/* unz_file_info contain information about a file in the zipfile */ +typedef struct unz_file_pos_s +{ + uLong pos_in_zip_directory; /* offset in zip file directory */ + uLong num_of_file; /* # of file */ +} unz_file_pos; + +extern int ZEXPORT unzGetFilePos( + unzFile file, + unz_file_pos* file_pos); + +extern int ZEXPORT unzGoToFilePos( + unzFile file, + unz_file_pos* file_pos); + +typedef struct unz64_file_pos_s +{ + ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */ + ZPOS64_T num_of_file; /* # of file */ +} unz64_file_pos; + +extern int ZEXPORT unzGetFilePos64( + unzFile file, + unz64_file_pos* file_pos); + +extern int ZEXPORT unzGoToFilePos64( + unzFile file, + const unz64_file_pos* file_pos); + +/* ****************************************** */ + +extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, + unz_file_info64 *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); + +extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, + unz_file_info *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); +/* + Get Info about the current file + if pfile_info!=NULL, the *pfile_info structure will contain somes info about + the current file + if szFileName!=NULL, the filemane string will be copied in szFileName + (fileNameBufferSize is the size of the buffer) + if extraField!=NULL, the extra field information will be copied in extraField + (extraFieldBufferSize is the size of the buffer). + This is the Central-header version of the extra field + if szComment!=NULL, the comment string of the file will be copied in szComment + (commentBufferSize is the size of the buffer) +*/ + + +/** Addition for GDAL : START */ + +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); + +/** Addition for GDAL : END */ + + +/***************************************************************************/ +/* for reading the content of the current zipfile, you can open it, read data + from it, and close it (you can close it before reading all the file) + */ + +extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); +/* + Open for reading data the current file in the zipfile. + If there is no error, the return value is UNZ_OK. +*/ + +extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, + const char* password)); +/* + Open for reading data the current file in the zipfile. + password is a crypting password + If there is no error, the return value is UNZ_OK. +*/ + +extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, + int* method, + int* level, + int raw)); +/* + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) + if raw==1 + *method will receive method of compression, *level will receive level of + compression + note : you can set level parameter as NULL (if you did not want known level, + but you CANNOT set method parameter as NULL +*/ + +extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, + int* method, + int* level, + int raw, + const char* password)); +/* + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) + if raw==1 + *method will receive method of compression, *level will receive level of + compression + note : you can set level parameter as NULL (if you did not want known level, + but you CANNOT set method parameter as NULL +*/ + + +extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); +/* + Close the file in zip opened with unzOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ + +extern int ZEXPORT unzReadCurrentFile OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read bytes from the current file (opened by unzOpenCurrentFile) + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ + +extern z_off_t ZEXPORT unztell OF((unzFile file)); + +extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); +/* + Give the current position in uncompressed data +*/ + +extern int ZEXPORT unzeof OF((unzFile file)); +/* + return 1 if the end of file was reached, 0 elsewhere +*/ + +extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ + +/***************************************************************************/ + +/* Get the current file offset */ +extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file); +extern uLong ZEXPORT unzGetOffset (unzFile file); + +/* Set the current file offset */ +extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos); +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); + + + +#ifdef __cplusplus +} +#endif + +#endif /* _unz64_H */ diff --git a/fceumm/utils/zlib/contrib/minizip/zconf.h b/fceumm/utils/zlib/contrib/minizip/zconf.h new file mode 100644 index 0000000..02ce56c --- /dev/null +++ b/fceumm/utils/zlib/contrib/minizip/zconf.h @@ -0,0 +1,428 @@ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2010 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#ifndef ZCONF_H +#define ZCONF_H + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + * Even better than compiling with -DZ_PREFIX would be to use configure to set + * this permanently in zconf.h using "./configure --zprefix". + */ +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ + +/* all linked symbols */ +# define _dist_code z__dist_code +# define _length_code z__length_code +# define _tr_align z__tr_align +# define _tr_flush_block z__tr_flush_block +# define _tr_init z__tr_init +# define _tr_stored_block z__tr_stored_block +# define _tr_tally z__tr_tally +# define adler32 z_adler32 +# define adler32_combine z_adler32_combine +# define adler32_combine64 z_adler32_combine64 +# define compress z_compress +# define compress2 z_compress2 +# define compressBound z_compressBound +# define crc32 z_crc32 +# define crc32_combine z_crc32_combine +# define crc32_combine64 z_crc32_combine64 +# define deflate z_deflate +# define deflateBound z_deflateBound +# define deflateCopy z_deflateCopy +# define deflateEnd z_deflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateInit_ z_deflateInit_ +# define deflateParams z_deflateParams +# define deflatePrime z_deflatePrime +# define deflateReset z_deflateReset +# define deflateSetDictionary z_deflateSetDictionary +# define deflateSetHeader z_deflateSetHeader +# define deflateTune z_deflateTune +# define deflate_copyright z_deflate_copyright +# define get_crc_table z_get_crc_table +# define gz_error z_gz_error +# define gz_intmax z_gz_intmax +# define gz_strwinerror z_gz_strwinerror +# define gzbuffer z_gzbuffer +# define gzclearerr z_gzclearerr +# define gzclose z_gzclose +# define gzclose_r z_gzclose_r +# define gzclose_w z_gzclose_w +# define gzdirect z_gzdirect +# define gzdopen z_gzdopen +# define gzeof z_gzeof +# define gzerror z_gzerror +# define gzflush z_gzflush +# define gzgetc z_gzgetc +# define gzgets z_gzgets +# define gzoffset z_gzoffset +# define gzoffset64 z_gzoffset64 +# define gzopen z_gzopen +# define gzopen64 z_gzopen64 +# define gzprintf z_gzprintf +# define gzputc z_gzputc +# define gzputs z_gzputs +# define gzread z_gzread +# define gzrewind z_gzrewind +# define gzseek z_gzseek +# define gzseek64 z_gzseek64 +# define gzsetparams z_gzsetparams +# define gztell z_gztell +# define gztell64 z_gztell64 +# define gzungetc z_gzungetc +# define gzwrite z_gzwrite +# define inflate z_inflate +# define inflateBack z_inflateBack +# define inflateBackEnd z_inflateBackEnd +# define inflateBackInit_ z_inflateBackInit_ +# define inflateCopy z_inflateCopy +# define inflateEnd z_inflateEnd +# define inflateGetHeader z_inflateGetHeader +# define inflateInit2_ z_inflateInit2_ +# define inflateInit_ z_inflateInit_ +# define inflateMark z_inflateMark +# define inflatePrime z_inflatePrime +# define inflateReset z_inflateReset +# define inflateReset2 z_inflateReset2 +# define inflateSetDictionary z_inflateSetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateUndermine z_inflateUndermine +# define inflate_copyright z_inflate_copyright +# define inflate_fast z_inflate_fast +# define inflate_table z_inflate_table +# define uncompress z_uncompress +# define zError z_zError +# define zcalloc z_zcalloc +# define zcfree z_zcfree +# define zlibCompileFlags z_zlibCompileFlags +# define zlibVersion z_zlibVersion + +/* all zlib typedefs in zlib.h and zconf.h */ +# define Byte z_Byte +# define Bytef z_Bytef +# define alloc_func z_alloc_func +# define charf z_charf +# define free_func z_free_func +# define gzFile z_gzFile +# define gz_header z_gz_header +# define gz_headerp z_gz_headerp +# define in_func z_in_func +# define intf z_intf +# define out_func z_out_func +# define uInt z_uInt +# define uIntf z_uIntf +# define uLong z_uLong +# define uLongf z_uLongf +# define voidp z_voidp +# define voidpc z_voidpc +# define voidpf z_voidpf + +/* all zlib structs in zlib.h and zconf.h */ +# define gz_header_s z_gz_header_s +# define internal_state z_internal_state + +#endif + +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) +# define OS2 +#endif +#if defined(_WINDOWS) && !defined(WINDOWS) +# define WINDOWS +#endif +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) +# ifndef WIN32 +# define WIN32 +# endif +#endif +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) +# ifndef SYS16BIT +# define SYS16BIT +# endif +# endif +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#ifdef SYS16BIT +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) +# define STDC +#endif +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) +# define STDC +#endif +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) +# define STDC +#endif +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) +# define STDC +#endif + +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ +# define STDC +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const /* note: need a more gentle solution here */ +# endif +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#ifdef SYS16BIT +# if defined(M_I86SM) || defined(M_I86MM) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +# endif +# if (defined(__SMALL__) || defined(__MEDIUM__)) + /* Turbo C small or medium model */ +# define SMALL_MEDIUM +# ifdef __BORLANDC__ +# define FAR _far +# else +# define FAR far +# endif +# endif +#endif + +#if defined(WINDOWS) || defined(WIN32) + /* If building or using zlib as a DLL, define ZLIB_DLL. + * This is not mandatory, but it offers a little performance increase. + */ +# ifdef ZLIB_DLL +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +# endif +# endif /* ZLIB_DLL */ + /* If building or using zlib with the WINAPI/WINAPIV calling convention, + * define ZLIB_WINAPI. + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. + */ +# ifdef ZLIB_WINAPI +# ifdef FAR +# undef FAR +# endif +# include + /* No need for _export, use ZLIB.DEF instead. */ + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR CDECL +# endif +# endif +#endif + +#if defined (__BEOS__) +# ifdef ZLIB_DLL +# ifdef ZLIB_INTERNAL +# define ZEXPORT __declspec(dllexport) +# define ZEXPORTVA __declspec(dllexport) +# else +# define ZEXPORT __declspec(dllimport) +# define ZEXPORTVA __declspec(dllimport) +# endif +# endif +#endif + +#ifndef ZEXTERN +# define ZEXTERN extern +#endif +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(__MACTYPES__) +typedef unsigned char Byte; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void const *voidpc; + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte const *voidpc; + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + +#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_UNISTD_H +#endif + +#ifdef STDC +# include /* for off_t */ +#endif + +/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and + * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even + * though the former does not conform to the LFS document), but considering + * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as + * equivalently requesting no 64-bit operations + */ +#if -_LARGEFILE64_SOURCE - -1 == 1 +# undef _LARGEFILE64_SOURCE +#endif + +#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) +# include /* for SEEK_* and off_t */ +# ifdef VMS +# include /* for off_t */ +# endif +# ifndef z_off_t +# define z_off_t off_t +# endif +#endif + +#ifndef SEEK_SET +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif + +#ifndef z_off_t +# define z_off_t long +#endif + +#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 +# define z_off64_t off64_t +#else +# define z_off64_t z_off_t +#endif + +#if defined(__OS400__) +# define NO_vsnprintf +#endif + +#if defined(__MVS__) +# define NO_vsnprintf +#endif + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) + #pragma map(deflateInit_,"DEIN") + #pragma map(deflateInit2_,"DEIN2") + #pragma map(deflateEnd,"DEEND") + #pragma map(deflateBound,"DEBND") + #pragma map(inflateInit_,"ININ") + #pragma map(inflateInit2_,"ININ2") + #pragma map(inflateEnd,"INEND") + #pragma map(inflateSync,"INSY") + #pragma map(inflateSetDictionary,"INSEDI") + #pragma map(compressBound,"CMBND") + #pragma map(inflate_table,"INTABL") + #pragma map(inflate_fast,"INFA") + #pragma map(inflate_copyright,"INCOPY") +#endif + +#endif /* ZCONF_H */ diff --git a/fceumm/utils/zlib/contrib/minizip/zip.c b/fceumm/utils/zlib/contrib/minizip/zip.c new file mode 100644 index 0000000..3c34fc8 --- /dev/null +++ b/fceumm/utils/zlib/contrib/minizip/zip.c @@ -0,0 +1,2004 @@ +/* zip.c -- IO on .zip files using zlib + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + Changes + Oct-2009 - Mathias Svensson - Remove old C style function prototypes + Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives + Oct-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions. + Oct-2009 - Mathias Svensson - Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data + It is used when recreting zip archive with RAW when deleting items from a zip. + ZIP64 data is automaticly added to items that needs it, and existing ZIP64 data need to be removed. + Oct-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required) + Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer + +*/ + + +#include +#include +#include +#include +#include "zlib.h" +#include "zip.h" + +#ifdef STDC +# include +# include +# include +#endif +#ifdef NO_ERRNO_H + extern int errno; +#else +# include +#endif + + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + +#ifndef VERSIONMADEBY +# define VERSIONMADEBY (0x0) /* platform depedent */ +#endif + +#ifndef Z_BUFSIZE +#define Z_BUFSIZE (64*1024) //(16384) +#endif + +#ifndef Z_MAXFILENAMEINZIP +#define Z_MAXFILENAMEINZIP (256) +#endif + +#ifndef ALLOC +# define ALLOC(size) (malloc(size)) +#endif +#ifndef TRYFREE +# define TRYFREE(p) {if (p) free(p);} +#endif + +/* +#define SIZECENTRALDIRITEM (0x2e) +#define SIZEZIPLOCALHEADER (0x1e) +*/ + +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ + + +// NOT sure that this work on ALL platform +#define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32)) + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +#ifndef DEF_MEM_LEVEL +#if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +#else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +#endif +#endif +const char zip_copyright[] =" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; + + +#define SIZEDATA_INDATABLOCK (4096-(4*4)) + +#define LOCALHEADERMAGIC (0x04034b50) +#define CENTRALHEADERMAGIC (0x02014b50) +#define ENDHEADERMAGIC (0x06054b50) +#define ZIP64ENDHEADERMAGIC (0x6064b50) +#define ZIP64ENDLOCHEADERMAGIC (0x7064b50) + +#define FLAG_LOCALHEADER_OFFSET (0x06) +#define CRC_LOCALHEADER_OFFSET (0x0e) + +#define SIZECENTRALHEADER (0x2e) /* 46 */ + +typedef struct linkedlist_datablock_internal_s +{ + struct linkedlist_datablock_internal_s* next_datablock; + uLong avail_in_this_block; + uLong filled_in_this_block; + uLong unused; /* for future use and alignement */ + unsigned char data[SIZEDATA_INDATABLOCK]; +} linkedlist_datablock_internal; + +typedef struct linkedlist_data_s +{ + linkedlist_datablock_internal* first_block; + linkedlist_datablock_internal* last_block; +} linkedlist_data; + + +typedef struct +{ + z_stream stream; /* zLib stream structure for inflate */ +#ifdef HAVE_BZIP2 + bz_stream bstream; /* bzLib stream structure for bziped */ +#endif + + int stream_initialised; /* 1 is stream is initialised */ + uInt pos_in_buffered_data; /* last written byte in buffered_data */ + + ZPOS64_T pos_local_header; /* offset of the local header of the file + currenty writing */ + char* central_header; /* central header data for the current file */ + uLong size_centralExtra; + uLong size_centralheader; /* size of the central header for cur file */ + uLong size_centralExtraFree; /* Extra bytes allocated to the centralheader but that are not used */ + uLong flag; /* flag of the file currently writing */ + + int method; /* compression method of file currenty wr.*/ + int raw; /* 1 for directly writing raw data */ + Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/ + uLong dosDate; + uLong crc32; + int encrypt; + int zip64; /* Add ZIP64 extened information in the extra field */ + ZPOS64_T pos_zip64extrainfo; + ZPOS64_T totalCompressedData; + ZPOS64_T totalUncompressedData; +#ifndef NOCRYPT + unsigned long keys[3]; /* keys defining the pseudo-random sequence */ + const unsigned long* pcrc_32_tab; + int crypt_header_size; +#endif +} curfile64_info; + +typedef struct +{ + zlib_filefunc64_32_def z_filefunc; + voidpf filestream; /* io structore of the zipfile */ + linkedlist_data central_dir;/* datablock with central dir in construction*/ + int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ + curfile64_info ci; /* info on the file curretly writing */ + + ZPOS64_T begin_pos; /* position of the beginning of the zipfile */ + ZPOS64_T add_position_when_writting_offset; + ZPOS64_T number_entry; + +#ifndef NO_ADDFILEINEXISTINGZIP + char *globalcomment; +#endif + +} zip64_internal; + + +#ifndef NOCRYPT +#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED +#include "crypt.h" +#endif + +local linkedlist_datablock_internal* allocate_new_datablock() +{ + linkedlist_datablock_internal* ldi; + ldi = (linkedlist_datablock_internal*) + ALLOC(sizeof(linkedlist_datablock_internal)); + if (ldi!=NULL) + { + ldi->next_datablock = NULL ; + ldi->filled_in_this_block = 0 ; + ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ; + } + return ldi; +} + +local void free_datablock(linkedlist_datablock_internal* ldi) +{ + while (ldi!=NULL) + { + linkedlist_datablock_internal* ldinext = ldi->next_datablock; + TRYFREE(ldi); + ldi = ldinext; + } +} + +local void init_linkedlist(linkedlist_data* ll) +{ + ll->first_block = ll->last_block = NULL; +} + +local void free_linkedlist(linkedlist_data* ll) +{ + free_datablock(ll->first_block); + ll->first_block = ll->last_block = NULL; +} + + +local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len) +{ + linkedlist_datablock_internal* ldi; + const unsigned char* from_copy; + + if (ll==NULL) + return ZIP_INTERNALERROR; + + if (ll->last_block == NULL) + { + ll->first_block = ll->last_block = allocate_new_datablock(); + if (ll->first_block == NULL) + return ZIP_INTERNALERROR; + } + + ldi = ll->last_block; + from_copy = (unsigned char*)buf; + + while (len>0) + { + uInt copy_this; + uInt i; + unsigned char* to_copy; + + if (ldi->avail_in_this_block==0) + { + ldi->next_datablock = allocate_new_datablock(); + if (ldi->next_datablock == NULL) + return ZIP_INTERNALERROR; + ldi = ldi->next_datablock ; + ll->last_block = ldi; + } + + if (ldi->avail_in_this_block < len) + copy_this = (uInt)ldi->avail_in_this_block; + else + copy_this = (uInt)len; + + to_copy = &(ldi->data[ldi->filled_in_this_block]); + + for (i=0;ifilled_in_this_block += copy_this; + ldi->avail_in_this_block -= copy_this; + from_copy += copy_this ; + len -= copy_this; + } + return ZIP_OK; +} + + + +/****************************************************************************/ + +#ifndef NO_ADDFILEINEXISTINGZIP +/* =========================================================================== + Inputs a long in LSB order to the given file + nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T) +*/ + +local int zip64local_putValue OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)); +local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte) +{ + unsigned char buf[8]; + int n; + for (n = 0; n < nbByte; n++) + { + buf[n] = (unsigned char)(x & 0xff); + x >>= 8; + } + if (x != 0) + { /* data overflow - hack for ZIP64 (X Roche) */ + for (n = 0; n < nbByte; n++) + { + buf[n] = 0xff; + } + } + + if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) + return ZIP_ERRNO; + else + return ZIP_OK; +} + +local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte)); +local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte) +{ + unsigned char* buf=(unsigned char*)dest; + int n; + for (n = 0; n < nbByte; n++) { + buf[n] = (unsigned char)(x & 0xff); + x >>= 8; + } + + if (x != 0) + { /* data overflow - hack for ZIP64 */ + for (n = 0; n < nbByte; n++) + { + buf[n] = 0xff; + } + } +} + +/****************************************************************************/ + + +local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm) +{ + uLong year = (uLong)ptm->tm_year; + if (year>=1980) + year-=1980; + else if (year>=80) + year-=80; + return + (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) | + ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour)); +} + + +/****************************************************************************/ + +local int zip64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)); + +local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,voidpf filestream,int* pi) +{ + unsigned char c; + int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); + if (err==1) + { + *pi = (int)c; + return ZIP_OK; + } + else + { + if (ZERROR64(*pzlib_filefunc_def,filestream)) + return ZIP_ERRNO; + else + return ZIP_EOF; + } +} + + +/* =========================================================================== + Reads a long in LSB order from the given gz_stream. Sets +*/ +local int zip64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)); + +local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) +{ + uLong x ; + int i = 0; + int err; + + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (uLong)i; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<8; + + if (err==ZIP_OK) + *pX = x; + else + *pX = 0; + return err; +} + +local int zip64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)); + +local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) +{ + uLong x ; + int i = 0; + int err; + + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (uLong)i; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<8; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<16; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<24; + + if (err==ZIP_OK) + *pX = x; + else + *pX = 0; + return err; +} + +local int zip64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)); + + +local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX) +{ + ZPOS64_T x; + int i = 0; + int err; + + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (ZPOS64_T)i; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<8; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<16; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<24; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<32; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<40; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<48; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<56; + + if (err==ZIP_OK) + *pX = x; + else + *pX = 0; + + return err; +} + +#ifndef BUFREADCOMMENT +#define BUFREADCOMMENT (0x400) +#endif +/* + Locate the Central directory of a zipfile (at the end, just before + the global comment) +*/ +local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); + +local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) +{ + unsigned char* buf; + ZPOS64_T uSizeFile; + ZPOS64_T uBackRead; + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ + ZPOS64_T uPosFound=0; + + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) + return 0; + + + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); + if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) + break; + + if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) + { + uPosFound = uReadPos+i; + break; + } + + if (uPosFound!=0) + break; + } + TRYFREE(buf); + return uPosFound; +} + +/* +Locate the End of Zip64 Central directory locator and from there find the CD of a zipfile (at the end, just before +the global comment) +*/ +local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); + +local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) +{ + unsigned char* buf; + ZPOS64_T uSizeFile; + ZPOS64_T uBackRead; + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ + ZPOS64_T uPosFound=0; + uLong uL; + ZPOS64_T relativeOffset; + + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) + return 0; + + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); + if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) + break; + + if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + { + // Signature "0x07064b50" Zip64 end of central directory locater + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) + { + uPosFound = uReadPos+i; + break; + } + } + + if (uPosFound!=0) + break; + } + + TRYFREE(buf); + if (uPosFound == 0) + return 0; + + /* Zip64 end of central directory locator */ + if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) + return 0; + + /* the signature, already checked */ + if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) + return 0; + + /* number of the disk with the start of the zip64 end of central directory */ + if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) + return 0; + if (uL != 0) + return 0; + + /* relative offset of the zip64 end of central directory record */ + if (zip64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=ZIP_OK) + return 0; + + /* total number of disks */ + if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) + return 0; + if (uL != 1) + return 0; + + /* Goto Zip64 end of central directory record */ + if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) + return 0; + + /* the signature */ + if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) + return 0; + + if (uL != 0x06064b50) // signature of 'Zip64 end of central directory' + return 0; + + return relativeOffset; +} + +int LoadCentralDirectoryRecord(zip64_internal* pziinit) +{ + int err=ZIP_OK; + ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ + + ZPOS64_T size_central_dir; /* size of the central directory */ + ZPOS64_T offset_central_dir; /* offset of start of central directory */ + ZPOS64_T central_pos; + uLong uL; + + uLong number_disk; /* number of the current dist, used for + spaning ZIP, unsupported, always 0*/ + uLong number_disk_with_CD; /* number the the disk with central dir, used + for spaning ZIP, unsupported, always 0*/ + ZPOS64_T number_entry; + ZPOS64_T number_entry_CD; /* total number of entries in + the central dir + (same than number_entry on nospan) */ + uLong VersionMadeBy; + uLong VersionNeeded; + uLong size_comment; + + int hasZIP64Record = 0; + + // check first if we find a ZIP64 record + central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream); + if(central_pos > 0) + { + hasZIP64Record = 1; + } + else if(central_pos == 0) + { + central_pos = zip64local_SearchCentralDir(&pziinit->z_filefunc,pziinit->filestream); + } + +/* disable to allow appending to empty ZIP archive + if (central_pos==0) + err=ZIP_ERRNO; +*/ + + if(hasZIP64Record) + { + ZPOS64_T sizeEndOfCentralDirectory; + if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0) + err=ZIP_ERRNO; + + /* the signature, already checked */ + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK) + err=ZIP_ERRNO; + + /* size of zip64 end of central directory record */ + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &sizeEndOfCentralDirectory)!=ZIP_OK) + err=ZIP_ERRNO; + + /* version made by */ + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionMadeBy)!=ZIP_OK) + err=ZIP_ERRNO; + + /* version needed to extract */ + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionNeeded)!=ZIP_OK) + err=ZIP_ERRNO; + + /* number of this disk */ + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK) + err=ZIP_ERRNO; + + /* number of the disk with the start of the central directory */ + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK) + err=ZIP_ERRNO; + + /* total number of entries in the central directory on this disk */ + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &number_entry)!=ZIP_OK) + err=ZIP_ERRNO; + + /* total number of entries in the central directory */ + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&number_entry_CD)!=ZIP_OK) + err=ZIP_ERRNO; + + if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) + err=ZIP_BADZIPFILE; + + /* size of the central directory */ + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&size_central_dir)!=ZIP_OK) + err=ZIP_ERRNO; + + /* offset of start of central directory with respect to the + starting disk number */ + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK) + err=ZIP_ERRNO; + + // TODO.. + // read the comment from the standard central header. + size_comment = 0; + } + else + { + // Read End of central Directory info + if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) + err=ZIP_ERRNO; + + /* the signature, already checked */ + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK) + err=ZIP_ERRNO; + + /* number of this disk */ + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK) + err=ZIP_ERRNO; + + /* number of the disk with the start of the central directory */ + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK) + err=ZIP_ERRNO; + + /* total number of entries in the central dir on this disk */ + number_entry = 0; + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) + err=ZIP_ERRNO; + else + number_entry = uL; + + /* total number of entries in the central dir */ + number_entry_CD = 0; + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) + err=ZIP_ERRNO; + else + number_entry_CD = uL; + + if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) + err=ZIP_BADZIPFILE; + + /* size of the central directory */ + size_central_dir = 0; + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) + err=ZIP_ERRNO; + else + size_central_dir = uL; + + /* offset of start of central directory with respect to the starting disk number */ + offset_central_dir = 0; + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) + err=ZIP_ERRNO; + else + offset_central_dir = uL; + + + /* zipfile global comment length */ + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &size_comment)!=ZIP_OK) + err=ZIP_ERRNO; + } + + if ((central_posz_filefunc, pziinit->filestream); + return ZIP_ERRNO; + } + + if (size_comment>0) + { + pziinit->globalcomment = (char*)ALLOC(size_comment+1); + if (pziinit->globalcomment) + { + size_comment = ZREAD64(pziinit->z_filefunc, pziinit->filestream, pziinit->globalcomment,size_comment); + pziinit->globalcomment[size_comment]=0; + } + } + + byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir); + pziinit->add_position_when_writting_offset = byte_before_the_zipfile; + + { + ZPOS64_T size_central_dir_to_read = size_central_dir; + size_t buf_size = SIZEDATA_INDATABLOCK; + void* buf_read = (void*)ALLOC(buf_size); + if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0) + err=ZIP_ERRNO; + + while ((size_central_dir_to_read>0) && (err==ZIP_OK)) + { + ZPOS64_T read_this = SIZEDATA_INDATABLOCK; + if (read_this > size_central_dir_to_read) + read_this = size_central_dir_to_read; + + if (ZREAD64(pziinit->z_filefunc, pziinit->filestream,buf_read,(uLong)read_this) != read_this) + err=ZIP_ERRNO; + + if (err==ZIP_OK) + err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this); + + size_central_dir_to_read-=read_this; + } + TRYFREE(buf_read); + } + pziinit->begin_pos = byte_before_the_zipfile; + pziinit->number_entry = number_entry_CD; + + if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0) + err=ZIP_ERRNO; + + return err; +} + + +#endif /* !NO_ADDFILEINEXISTINGZIP*/ + + +/************************************************************/ +extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def) +{ + zip64_internal ziinit; + zip64_internal* zi; + int err=ZIP_OK; + + ziinit.z_filefunc.zseek32_file = NULL; + ziinit.z_filefunc.ztell32_file = NULL; + if (pzlib_filefunc64_32_def==NULL) + fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64); + else + ziinit.z_filefunc = *pzlib_filefunc64_32_def; + + ziinit.filestream = ZOPEN64(ziinit.z_filefunc, + pathname, + (append == APPEND_STATUS_CREATE) ? + (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) : + (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING)); + + if (ziinit.filestream == NULL) + return NULL; + + if (append == APPEND_STATUS_CREATEAFTER) + ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END); + + ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream); + ziinit.in_opened_file_inzip = 0; + ziinit.ci.stream_initialised = 0; + ziinit.number_entry = 0; + ziinit.add_position_when_writting_offset = 0; + init_linkedlist(&(ziinit.central_dir)); + + + + zi = (zip64_internal*)ALLOC(sizeof(zip64_internal)); + if (zi==NULL) + { + ZCLOSE64(ziinit.z_filefunc,ziinit.filestream); + return NULL; + } + + /* now we add file in a zipfile */ +# ifndef NO_ADDFILEINEXISTINGZIP + ziinit.globalcomment = NULL; + if (append == APPEND_STATUS_ADDINZIP) + { + // Read and Cache Central Directory Records + err = LoadCentralDirectoryRecord(&ziinit); + } + + if (globalcomment) + { + *globalcomment = ziinit.globalcomment; + } +# endif /* !NO_ADDFILEINEXISTINGZIP*/ + + if (err != ZIP_OK) + { +# ifndef NO_ADDFILEINEXISTINGZIP + TRYFREE(ziinit.globalcomment); +# endif /* !NO_ADDFILEINEXISTINGZIP*/ + TRYFREE(zi); + return NULL; + } + else + { + *zi = ziinit; + return (zipFile)zi; + } +} + +extern zipFile ZEXPORT zipOpen2 (const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def) +{ + if (pzlib_filefunc32_def != NULL) + { + zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; + fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def); + return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill); + } + else + return zipOpen3(pathname, append, globalcomment, NULL); +} + +extern zipFile ZEXPORT zipOpen2_64 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def) +{ + if (pzlib_filefunc_def != NULL) + { + zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; + zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def; + zlib_filefunc64_32_def_fill.ztell32_file = NULL; + zlib_filefunc64_32_def_fill.zseek32_file = NULL; + return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill); + } + else + return zipOpen3(pathname, append, globalcomment, NULL); +} + + + +extern zipFile ZEXPORT zipOpen (const char* pathname, int append) +{ + return zipOpen3((const void*)pathname,append,NULL,NULL); +} + +extern zipFile ZEXPORT zipOpen64 (const void* pathname, int append) +{ + return zipOpen3(pathname,append,NULL,NULL); +} + +int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local) +{ + /* write the local header */ + int err; + uInt size_filename = (uInt)strlen(filename); + uInt size_extrafield = size_extrafield_local; + + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC, 4); + + if (err==ZIP_OK) + { + if(zi->ci.zip64) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */ + else + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */ + } + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2); + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2); + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4); + + // CRC / Compressed size / Uncompressed size will be filled in later and rewritten later + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */ + if (err==ZIP_OK) + { + if(zi->ci.zip64) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* compressed size, unknown */ + else + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */ + } + if (err==ZIP_OK) + { + if(zi->ci.zip64) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* uncompressed size, unknown */ + else + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */ + } + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2); + + if(zi->ci.zip64) + { + size_extrafield += 20; + } + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield,2); + + if ((err==ZIP_OK) && (size_filename > 0)) + { + if (ZWRITE64(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename) + err = ZIP_ERRNO; + } + + if ((err==ZIP_OK) && (size_extrafield_local > 0)) + { + if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local) + err = ZIP_ERRNO; + } + + + if ((err==ZIP_OK) && (zi->ci.zip64)) + { + // write the Zip64 extended info + short HeaderID = 1; + short DataSize = 16; + ZPOS64_T CompressedSize = 0; + ZPOS64_T UncompressedSize = 0; + + // Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file) + zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream); + + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)HeaderID,2); + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)DataSize,2); + + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)UncompressedSize,8); + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)CompressedSize,8); + } + + return err; +} + +/* + NOTE. + When writing RAW the ZIP64 extended information in extrafield_local and extrafield_global needs to be stripped + before calling this function it can be done with zipRemoveExtraInfoBlock + + It is not done here because then we need to realloc a new buffer since parameters are 'const' and I want to minimize + unnecessary allocations. + */ +extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void* extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int raw, + int windowBits,int memLevel, int strategy, + const char* password, uLong crcForCrypting, + uLong versionMadeBy, uLong flagBase, int zip64) +{ + zip64_internal* zi; + uInt size_filename; + uInt size_comment; + uInt i; + int err = ZIP_OK; + +# ifdef NOCRYPT + if (password != NULL) + return ZIP_PARAMERROR; +# endif + + if (file == NULL) + return ZIP_PARAMERROR; + +#ifdef HAVE_BZIP2 + if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED)) + return ZIP_PARAMERROR; +#else + if ((method!=0) && (method!=Z_DEFLATED)) + return ZIP_PARAMERROR; +#endif + + zi = (zip64_internal*)file; + + if (zi->in_opened_file_inzip == 1) + { + err = zipCloseFileInZip (file); + if (err != ZIP_OK) + return err; + } + + if (filename==NULL) + filename="-"; + + if (comment==NULL) + size_comment = 0; + else + size_comment = (uInt)strlen(comment); + + size_filename = (uInt)strlen(filename); + + if (zipfi == NULL) + zi->ci.dosDate = 0; + else + { + if (zipfi->dosDate != 0) + zi->ci.dosDate = zipfi->dosDate; + else + zi->ci.dosDate = zip64local_TmzDateToDosDate(&zipfi->tmz_date); + } + + zi->ci.flag = flagBase; + if ((level==8) || (level==9)) + zi->ci.flag |= 2; + if ((level==2)) + zi->ci.flag |= 4; + if ((level==1)) + zi->ci.flag |= 6; + if (password != NULL) + zi->ci.flag |= 1; + + zi->ci.crc32 = 0; + zi->ci.method = method; + zi->ci.encrypt = 0; + zi->ci.stream_initialised = 0; + zi->ci.pos_in_buffered_data = 0; + zi->ci.raw = raw; + zi->ci.pos_local_header = ZTELL64(zi->z_filefunc,zi->filestream); + + zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment; + zi->ci.size_centralExtraFree = 32; // Extra space we have reserved in case we need to add ZIP64 extra info data + + zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree); + + zi->ci.size_centralExtra = size_extrafield_global; + zip64local_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4); + /* version info */ + zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)versionMadeBy,2); + zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2); + zip64local_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2); + zip64local_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2); + zip64local_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4); + zip64local_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/ + zip64local_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/ + zip64local_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/ + zip64local_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2); + zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2); + zip64local_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2); + zip64local_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/ + + if (zipfi==NULL) + zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2); + else + zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2); + + if (zipfi==NULL) + zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4); + else + zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); + + if(zi->ci.pos_local_header >= 0xffffffff) + zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4); + else + zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header - zi->add_position_when_writting_offset,4); + + for (i=0;ici.central_header+SIZECENTRALHEADER+i) = *(filename+i); + + for (i=0;ici.central_header+SIZECENTRALHEADER+size_filename+i) = + *(((const char*)extrafield_global)+i); + + for (i=0;ici.central_header+SIZECENTRALHEADER+size_filename+ + size_extrafield_global+i) = *(comment+i); + if (zi->ci.central_header == NULL) + return ZIP_INTERNALERROR; + + zi->ci.zip64 = zip64; + zi->ci.totalCompressedData = 0; + zi->ci.totalUncompressedData = 0; + zi->ci.pos_zip64extrainfo = 0; + + err = Write_LocalFileHeader(zi, filename, size_extrafield_local, extrafield_local); + +#ifdef HAVE_BZIP2 + zi->ci.bstream.avail_in = (uInt)0; + zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; + zi->ci.bstream.total_in_hi32 = 0; + zi->ci.bstream.total_in_lo32 = 0; + zi->ci.bstream.total_out_hi32 = 0; + zi->ci.bstream.total_out_lo32 = 0; +#endif + + zi->ci.stream.avail_in = (uInt)0; + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.stream.next_out = zi->ci.buffered_data; + zi->ci.stream.total_in = 0; + zi->ci.stream.total_out = 0; + zi->ci.stream.data_type = Z_BINARY; + +#ifdef HAVE_BZIP2 + if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED || zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) +#else + if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) +#endif + { + if(zi->ci.method == Z_DEFLATED) + { + zi->ci.stream.zalloc = (alloc_func)0; + zi->ci.stream.zfree = (free_func)0; + zi->ci.stream.opaque = (voidpf)0; + + if (windowBits>0) + windowBits = -windowBits; + + err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy); + + if (err==Z_OK) + zi->ci.stream_initialised = Z_DEFLATED; + } + else if(zi->ci.method == Z_BZIP2ED) + { +#ifdef HAVE_BZIP2 + // Init BZip stuff here + zi->ci.bstream.bzalloc = 0; + zi->ci.bstream.bzfree = 0; + zi->ci.bstream.opaque = (voidpf)0; + + err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0,35); + if(err == BZ_OK) + zi->ci.stream_initialised = Z_BZIP2ED; +#endif + } + + } + +# ifndef NOCRYPT + zi->ci.crypt_header_size = 0; + if ((err==Z_OK) && (password != NULL)) + { + unsigned char bufHead[RAND_HEAD_LEN]; + unsigned int sizeHead; + zi->ci.encrypt = 1; + zi->ci.pcrc_32_tab = get_crc_table(); + /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/ + + sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting); + zi->ci.crypt_header_size = sizeHead; + + if (ZWRITE64(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead) + err = ZIP_ERRNO; + } +# endif + + if (err==Z_OK) + zi->in_opened_file_inzip = 1; + return err; +} + +extern int ZEXPORT zipOpenNewFileInZip4 (zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void* extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int raw, + int windowBits,int memLevel, int strategy, + const char* password, uLong crcForCrypting, + uLong versionMadeBy, uLong flagBase) +{ + return zipOpenNewFileInZip4_64 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + windowBits, memLevel, strategy, + password, crcForCrypting, versionMadeBy, flagBase, 0); +} + +extern int ZEXPORT zipOpenNewFileInZip3 (zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void* extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int raw, + int windowBits,int memLevel, int strategy, + const char* password, uLong crcForCrypting) +{ + return zipOpenNewFileInZip4_64 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + windowBits, memLevel, strategy, + password, crcForCrypting, VERSIONMADEBY, 0, 0); +} + +extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void* extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int raw, + int windowBits,int memLevel, int strategy, + const char* password, uLong crcForCrypting, int zip64) +{ + return zipOpenNewFileInZip4_64 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + windowBits, memLevel, strategy, + password, crcForCrypting, VERSIONMADEBY, 0, zip64); +} + +extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void* extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int raw) +{ + return zipOpenNewFileInZip4_64 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, + NULL, 0, VERSIONMADEBY, 0, 0); +} + +extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void* extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int raw, int zip64) +{ + return zipOpenNewFileInZip4_64 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, + NULL, 0, VERSIONMADEBY, 0, zip64); +} + +extern int ZEXPORT zipOpenNewFileInZip64 (zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void*extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int zip64) +{ + return zipOpenNewFileInZip4_64 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, 0, + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, + NULL, 0, VERSIONMADEBY, 0, zip64); +} + +extern int ZEXPORT zipOpenNewFileInZip (zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void*extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level) +{ + return zipOpenNewFileInZip4_64 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, 0, + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, + NULL, 0, VERSIONMADEBY, 0, 0); +} + +local int zip64FlushWriteBuffer(zip64_internal* zi) +{ + int err=ZIP_OK; + + if (zi->ci.encrypt != 0) + { +#ifndef NOCRYPT + uInt i; + int t; + for (i=0;ici.pos_in_buffered_data;i++) + zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i],t); +#endif + } + + if (ZWRITE64(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) != zi->ci.pos_in_buffered_data) + err = ZIP_ERRNO; + + zi->ci.totalCompressedData += zi->ci.pos_in_buffered_data; + +#ifdef HAVE_BZIP2 + if(zi->ci.method == Z_BZIP2ED) + { + zi->ci.totalUncompressedData += zi->ci.bstream.total_in_lo32; + zi->ci.bstream.total_in_lo32 = 0; + zi->ci.bstream.total_in_hi32 = 0; + } + else +#endif + { + zi->ci.totalUncompressedData += zi->ci.stream.total_in; + zi->ci.stream.total_in = 0; + } + + + zi->ci.pos_in_buffered_data = 0; + + return err; +} + +extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned int len) +{ + zip64_internal* zi; + int err=ZIP_OK; + + if (file == NULL) + return ZIP_PARAMERROR; + zi = (zip64_internal*)file; + + if (zi->in_opened_file_inzip == 0) + return ZIP_PARAMERROR; + + zi->ci.crc32 = crc32(zi->ci.crc32,buf,(uInt)len); + +#ifdef HAVE_BZIP2 + if(zi->ci.method == Z_BZIP2ED && (!zi->ci.raw)) + { + zi->ci.bstream.next_in = (void*)buf; + zi->ci.bstream.avail_in = len; + err = BZ_RUN_OK; + + while ((err==BZ_RUN_OK) && (zi->ci.bstream.avail_in>0)) + { + if (zi->ci.bstream.avail_out == 0) + { + if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) + err = ZIP_ERRNO; + zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; + } + + + if(err != BZ_RUN_OK) + break; + + if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) + { + uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32; +// uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32; + err=BZ2_bzCompress(&zi->ci.bstream, BZ_RUN); + + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ; + } + } + + if(err == BZ_RUN_OK) + err = ZIP_OK; + } + else +#endif + { + zi->ci.stream.next_in = (Bytef*)buf; + zi->ci.stream.avail_in = len; + + while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) + { + if (zi->ci.stream.avail_out == 0) + { + if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) + err = ZIP_ERRNO; + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.stream.next_out = zi->ci.buffered_data; + } + + + if(err != ZIP_OK) + break; + + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) + { + uLong uTotalOutBefore = zi->ci.stream.total_out; + err=deflate(&zi->ci.stream, Z_NO_FLUSH); + if(uTotalOutBefore > zi->ci.stream.total_out) + { + int bBreak = 0; + bBreak++; + } + + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; + } + else + { + uInt copy_this,i; + if (zi->ci.stream.avail_in < zi->ci.stream.avail_out) + copy_this = zi->ci.stream.avail_in; + else + copy_this = zi->ci.stream.avail_out; + + for (i = 0; i < copy_this; i++) + *(((char*)zi->ci.stream.next_out)+i) = + *(((const char*)zi->ci.stream.next_in)+i); + { + zi->ci.stream.avail_in -= copy_this; + zi->ci.stream.avail_out-= copy_this; + zi->ci.stream.next_in+= copy_this; + zi->ci.stream.next_out+= copy_this; + zi->ci.stream.total_in+= copy_this; + zi->ci.stream.total_out+= copy_this; + zi->ci.pos_in_buffered_data += copy_this; + } + } + }// while(...) + } + + return err; +} + +extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32) +{ + return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32); +} + +extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32) +{ + zip64_internal* zi; + ZPOS64_T compressed_size; + uLong invalidValue = 0xffffffff; + short datasize = 0; + int err=ZIP_OK; + + if (file == NULL) + return ZIP_PARAMERROR; + zi = (zip64_internal*)file; + + if (zi->in_opened_file_inzip == 0) + return ZIP_PARAMERROR; + zi->ci.stream.avail_in = 0; + + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) + { + while (err==ZIP_OK) + { + uLong uTotalOutBefore; + if (zi->ci.stream.avail_out == 0) + { + if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) + err = ZIP_ERRNO; + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.stream.next_out = zi->ci.buffered_data; + } + uTotalOutBefore = zi->ci.stream.total_out; + err=deflate(&zi->ci.stream, Z_FINISH); + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; + } + } + else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) + { +#ifdef HAVE_BZIP2 + err = BZ_FINISH_OK; + while (err==BZ_FINISH_OK) + { + uLong uTotalOutBefore; + if (zi->ci.bstream.avail_out == 0) + { + if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) + err = ZIP_ERRNO; + zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; + } + uTotalOutBefore = zi->ci.bstream.total_out_lo32; + err=BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH); + if(err == BZ_STREAM_END) + err = Z_STREAM_END; + + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore); + } + + if(err == BZ_FINISH_OK) + err = ZIP_OK; +#endif + } + + if (err==Z_STREAM_END) + err=ZIP_OK; /* this is normal */ + + if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK)) + { + if (zip64FlushWriteBuffer(zi)==ZIP_ERRNO) + err = ZIP_ERRNO; + } + + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) + { + int tmp_err = deflateEnd(&zi->ci.stream); + if (err == ZIP_OK) + err = tmp_err; + zi->ci.stream_initialised = 0; + } +#ifdef HAVE_BZIP2 + else if((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) + { + int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream); + if (err==ZIP_OK) + err = tmperr; + zi->ci.stream_initialised = 0; + } +#endif + + if (!zi->ci.raw) + { + crc32 = (uLong)zi->ci.crc32; + uncompressed_size = zi->ci.totalUncompressedData; + } + compressed_size = zi->ci.totalCompressedData; + +# ifndef NOCRYPT + compressed_size += zi->ci.crypt_header_size; +# endif + + // update Current Item crc and sizes, + if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff) + { + /*version Made by*/ + zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2); + /*version needed*/ + zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2); + + } + + zip64local_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/ + + + if(compressed_size >= 0xffffffff) + zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue,4); /*compr size*/ + else + zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/ + + /// set internal file attributes field + if (zi->ci.stream.data_type == Z_ASCII) + zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2); + + if(uncompressed_size >= 0xffffffff) + zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue,4); /*uncompr size*/ + else + zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/ + + // Add ZIP64 extra info field for uncompressed size + if(uncompressed_size >= 0xffffffff) + datasize += 8; + + // Add ZIP64 extra info field for compressed size + if(compressed_size >= 0xffffffff) + datasize += 8; + + // Add ZIP64 extra info field for relative offset to local file header of current file + if(zi->ci.pos_local_header >= 0xffffffff) + datasize += 8; + + if(datasize > 0) + { + char* p = NULL; + + if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree) + { + // we can not write more data to the buffer that we have room for. + return ZIP_BADZIPFILE; + } + + p = zi->ci.central_header + zi->ci.size_centralheader; + + // Add Extra Information Header for 'ZIP64 information' + zip64local_putValue_inmemory(p, 0x0001, 2); // HeaderID + p += 2; + zip64local_putValue_inmemory(p, datasize, 2); // DataSize + p += 2; + + if(uncompressed_size >= 0xffffffff) + { + zip64local_putValue_inmemory(p, uncompressed_size, 8); + p += 8; + } + + if(compressed_size >= 0xffffffff) + { + zip64local_putValue_inmemory(p, compressed_size, 8); + p += 8; + } + + if(zi->ci.pos_local_header >= 0xffffffff) + { + zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8); + p += 8; + } + + // Update how much extra free space we got in the memory buffer + // and increase the centralheader size so the new ZIP64 fields are included + // ( 4 below is the size of HeaderID and DataSize field ) + zi->ci.size_centralExtraFree -= datasize + 4; + zi->ci.size_centralheader += datasize + 4; + + // Update the extra info size field + zi->ci.size_centralExtra += datasize + 4; + zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2); + } + + if (err==ZIP_OK) + err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader); + + free(zi->ci.central_header); + + if (err==ZIP_OK) + { + // Update the LocalFileHeader with the new values. + + ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream); + + if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0) + err = ZIP_ERRNO; + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */ + + if(uncompressed_size >= 0xffffffff) + { + if(zi->ci.pos_zip64extrainfo > 0) + { + // Update the size in the ZIP64 extended field. + if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo + 4,ZLIB_FILEFUNC_SEEK_SET)!=0) + err = ZIP_ERRNO; + + if (err==ZIP_OK) /* compressed size, unknown */ + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8); + + if (err==ZIP_OK) /* uncompressed size, unknown */ + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8); + } + } + else + { + if (err==ZIP_OK) /* compressed size, unknown */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4); + + if (err==ZIP_OK) /* uncompressed size, unknown */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4); + } + + if (ZSEEK64(zi->z_filefunc,zi->filestream, cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0) + err = ZIP_ERRNO; + } + + zi->number_entry ++; + zi->in_opened_file_inzip = 0; + + return err; +} + +extern int ZEXPORT zipCloseFileInZip (zipFile file) +{ + return zipCloseFileInZipRaw (file,0,0); +} + +int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip) +{ + int err = ZIP_OK; + ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writting_offset; + + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4); + + /*num disks*/ + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); + + /*relative offset*/ + if (err==ZIP_OK) /* Relative offset to the Zip64EndOfCentralDirectory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream, pos,8); + + /*total disks*/ /* Do not support spawning of disk so always say 1 here*/ + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4); + + return err; +} + +int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) +{ + int err = ZIP_OK; + + uLong Zip64DataSize = 44; + + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4); + + if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); // why ZPOS64_T of this ? + + if (err==ZIP_OK) /* version made by */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2); + + if (err==ZIP_OK) /* version needed */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2); + + if (err==ZIP_OK) /* number of this disk */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); + + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); + + if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8); + + if (err==ZIP_OK) /* total number of entries in the central dir */ + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8); + + if (err==ZIP_OK) /* size of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)size_centraldir,8); + + if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */ + { + ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; + err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8); + } + return err; +} +int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) +{ + int err = ZIP_OK; + + /*signature*/ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4); + + if (err==ZIP_OK) /* number of this disk */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); + + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); + + if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ + { + { + if(zi->number_entry >= 0xFFFF) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record + else + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); + } + } + + if (err==ZIP_OK) /* total number of entries in the central dir */ + { + if(zi->number_entry >= 0xFFFF) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record + else + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); + } + + if (err==ZIP_OK) /* size of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4); + + if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */ + { + ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; + if(pos >= 0xffffffff) + { + err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4); + } + else + err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4); + } + + return err; +} + +int Write_GlobalComment(zip64_internal* zi, const char* global_comment) +{ + int err = ZIP_OK; + uInt size_global_comment = 0; + + if(global_comment != NULL) + size_global_comment = (uInt)strlen(global_comment); + + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2); + + if (err == ZIP_OK && size_global_comment > 0) + { + if (ZWRITE64(zi->z_filefunc,zi->filestream, global_comment, size_global_comment) != size_global_comment) + err = ZIP_ERRNO; + } + return err; +} + +extern int ZEXPORT zipClose (zipFile file, const char* global_comment) +{ + zip64_internal* zi; + int err = 0; + uLong size_centraldir = 0; + ZPOS64_T centraldir_pos_inzip; + ZPOS64_T pos; + + if (file == NULL) + return ZIP_PARAMERROR; + + zi = (zip64_internal*)file; + + if (zi->in_opened_file_inzip == 1) + { + err = zipCloseFileInZip (file); + } + +#ifndef NO_ADDFILEINEXISTINGZIP + if (global_comment==NULL) + global_comment = zi->globalcomment; +#endif + + centraldir_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream); + + if (err==ZIP_OK) + { + linkedlist_datablock_internal* ldi = zi->central_dir.first_block; + while (ldi!=NULL) + { + if ((err==ZIP_OK) && (ldi->filled_in_this_block>0)) + { + if (ZWRITE64(zi->z_filefunc,zi->filestream, ldi->data, ldi->filled_in_this_block) != ldi->filled_in_this_block) + err = ZIP_ERRNO; + } + + size_centraldir += ldi->filled_in_this_block; + ldi = ldi->next_datablock; + } + } + free_linkedlist(&(zi->central_dir)); + + pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; + if(pos >= 0xffffffff) + { + ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream); + Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); + + Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos); + } + + if (err==ZIP_OK) + err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); + + if(err == ZIP_OK) + err = Write_GlobalComment(zi, global_comment); + + if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0) + if (err == ZIP_OK) + err = ZIP_ERRNO; + +#ifndef NO_ADDFILEINEXISTINGZIP + TRYFREE(zi->globalcomment); +#endif + TRYFREE(zi); + + return err; +} + +extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHeader) +{ + char* p = pData; + int size = 0; + char* pNewHeader; + char* pTmp; + short header; + short dataSize; + + int retVal = ZIP_OK; + + if(pData == NULL || *dataLen < 4) + return ZIP_PARAMERROR; + + pNewHeader = (char*)ALLOC(*dataLen); + pTmp = pNewHeader; + + while(p < (pData + *dataLen)) + { + header = *(short*)p; + dataSize = *(((short*)p)+1); + + if( header == sHeader ) // Header found. + { + p += dataSize + 4; // skip it. do not copy to temp buffer + } + else + { + // Extra Info block should not be removed, So copy it to the temp buffer. + memcpy(pTmp, p, dataSize + 4); + p += dataSize + 4; + size += dataSize + 4; + } + + } + + if(size < *dataLen) + { + // clean old extra info block. + memset(pData,0, *dataLen); + + // copy the new extra info block over the old + if(size > 0) + memcpy(pData, pNewHeader, size); + + // set the new extra info size + *dataLen = size; + + retVal = ZIP_OK; + } + else + retVal = ZIP_ERRNO; + + TRYFREE(pNewHeader); + + return retVal; +} diff --git a/fceumm/utils/zlib/contrib/minizip/zip.h b/fceumm/utils/zlib/contrib/minizip/zip.h new file mode 100644 index 0000000..8aaebb6 --- /dev/null +++ b/fceumm/utils/zlib/contrib/minizip/zip.h @@ -0,0 +1,362 @@ +/* zip.h -- IO on .zip files using zlib + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + --------------------------------------------------------------------------- + + Condition of use and distribution are the same than zlib : + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + --------------------------------------------------------------------------- + + Changes + + See header of zip.h + +*/ + +#ifndef _zip12_H +#define _zip12_H + +#ifdef __cplusplus +extern "C" { +#endif + +//#define HAVE_BZIP2 + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#ifndef _ZLIBIOAPI_H +#include "ioapi.h" +#endif + +#ifdef HAVE_BZIP2 +#include "bzlib.h" +#endif + +#define Z_BZIP2ED 12 + +#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) +/* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ +typedef struct TagzipFile__ { int unused; } zipFile__; +typedef zipFile__ *zipFile; +#else +typedef voidp zipFile; +#endif + +#define ZIP_OK (0) +#define ZIP_EOF (0) +#define ZIP_ERRNO (Z_ERRNO) +#define ZIP_PARAMERROR (-102) +#define ZIP_BADZIPFILE (-103) +#define ZIP_INTERNALERROR (-104) + +#ifndef DEF_MEM_LEVEL +# if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +# else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +# endif +#endif +/* default memLevel */ + +/* tm_zip contain date/time info */ +typedef struct tm_zip_s +{ + uInt tm_sec; /* seconds after the minute - [0,59] */ + uInt tm_min; /* minutes after the hour - [0,59] */ + uInt tm_hour; /* hours since midnight - [0,23] */ + uInt tm_mday; /* day of the month - [1,31] */ + uInt tm_mon; /* months since January - [0,11] */ + uInt tm_year; /* years - [1980..2044] */ +} tm_zip; + +typedef struct +{ + tm_zip tmz_date; /* date in understandable format */ + uLong dosDate; /* if dos_date == 0, tmu_date is used */ +/* uLong flag; */ /* general purpose bit flag 2 bytes */ + + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ +} zip_fileinfo; + +typedef const char* zipcharpc; + + +#define APPEND_STATUS_CREATE (0) +#define APPEND_STATUS_CREATEAFTER (1) +#define APPEND_STATUS_ADDINZIP (2) + +extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); +extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append)); +/* + Create a zipfile. + pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on + an Unix computer "zlib/zlib113.zip". + if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip + will be created at the end of the file. + (useful if the file contain a self extractor code) + if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will + add files in existing zip (be sure you don't add file that doesn't exist) + If the zipfile cannot be opened, the return value is NULL. + Else, the return value is a zipFile Handle, usable with other function + of this zip package. +*/ + +/* Note : there is no delete function into a zipfile. + If you want delete file into a zipfile, you must open a zipfile, and create another + Of couse, you can use RAW reading and writing to copy the file you did not want delte +*/ + +extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, + int append, + zipcharpc* globalcomment, + zlib_filefunc_def* pzlib_filefunc_def)); + +extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname, + int append, + zipcharpc* globalcomment, + zlib_filefunc64_def* pzlib_filefunc_def)); + +extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level)); + +extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int zip64)); + +/* + Open a file in the ZIP for writing. + filename : the filename in zip (if NULL, '-' without quote will be used + *zipfi contain supplemental information + if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local + contains the extrafield data the the local header + if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global + contains the extrafield data the the local header + if comment != NULL, comment contain the comment string + method contain the compression method (0 for store, Z_DEFLATED for deflate) + level contain the level of compression (can be Z_DEFAULT_COMPRESSION) + zip64 is set to 1 if a zip64 extended information block should be added to the local file header. + this MUST be '1' if the uncompressed size is >= 0xffffffff. + +*/ + + +extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw)); + + +extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int zip64)); +/* + Same than zipOpenNewFileInZip, except if raw=1, we write raw file + */ + +extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCrypting)); + +extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCrypting, + int zip64 + )); + +/* + Same than zipOpenNewFileInZip2, except + windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 + password : crypting password (NULL for no crypting) + crcForCrypting : crc of file to compress (needed for crypting) + */ + +extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCrypting, + uLong versionMadeBy, + uLong flagBase + )); + + +extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCrypting, + uLong versionMadeBy, + uLong flagBase, + int zip64 + )); +/* + Same than zipOpenNewFileInZip4, except + versionMadeBy : value for Version made by field + flag : value for flag field (compression level info will be added) + */ + + +extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, + const void* buf, + unsigned len)); +/* + Write data in the zipfile +*/ + +extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); +/* + Close the current file in the zipfile +*/ + +extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, + uLong uncompressed_size, + uLong crc32)); + +extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file, + ZPOS64_T uncompressed_size, + uLong crc32)); + +/* + Close the current file in the zipfile, for file opened with + parameter raw=1 in zipOpenNewFileInZip2 + uncompressed_size and crc32 are value for the uncompressed size +*/ + +extern int ZEXPORT zipClose OF((zipFile file, + const char* global_comment)); +/* + Close the zipfile +*/ + + +extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader)); +/* + zipRemoveExtraInfoBlock - Added by Mathias Svensson + + Remove extra information block from a extra information data for the local file header or central directory header + + It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode. + + 0x0001 is the signature header for the ZIP64 extra information blocks + + usage. + Remove ZIP64 Extra information from a central director extra field data + zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001); + + Remove ZIP64 Extra information from a Local File Header extra field data + zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001); +*/ + +#ifdef __cplusplus +} +#endif + +#endif /* _zip64_H */ diff --git a/fceumm/utils/zlib/contrib/minizip/zlib.h b/fceumm/utils/zlib/contrib/minizip/zlib.h new file mode 100644 index 0000000..bfbba83 --- /dev/null +++ b/fceumm/utils/zlib/contrib/minizip/zlib.h @@ -0,0 +1,1613 @@ +/* zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.5, April 19th, 2010 + + Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + + + The data format used by the zlib library is described by RFCs (Request for + Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt + (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). +*/ + +#ifndef ZLIB_H +#define ZLIB_H + +#include "zconf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ZLIB_VERSION "1.2.5" +#define ZLIB_VERNUM 0x1250 +#define ZLIB_VER_MAJOR 1 +#define ZLIB_VER_MINOR 2 +#define ZLIB_VER_REVISION 5 +#define ZLIB_VER_SUBREVISION 0 + +/* + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed data. + This version of the library supports only one compression method (deflation) + but other algorithms will be added later and will have the same stream + interface. + + Compression can be done in a single step if the buffers are large enough, + or can be done by repeated calls of the compression function. In the latter + case, the application must provide more input and/or consume the output + (providing more output space) before each call. + + The compressed data format used by default by the in-memory functions is + the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped + around a deflate stream, which is itself documented in RFC 1951. + + The library also supports reading and writing files in gzip (.gz) format + with an interface similar to that of stdio using the functions that start + with "gz". The gzip format is different from the zlib format. gzip is a + gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. + + This library can optionally read and write gzip streams in memory as well. + + The zlib format was designed to be compact and fast for use in memory + and on communications channels. The gzip format was designed for single- + file compression on file systems, has a larger header than zlib to maintain + directory information, and uses a different, slower check method than zlib. + + The library does not install any signal handler. The decoder checks + the consistency of the compressed data, so the library should never crash + even in case of corrupted input. +*/ + +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); +typedef void (*free_func) OF((voidpf opaque, voidpf address)); + +struct internal_state; + +typedef struct z_stream_s { + Bytef *next_in; /* next input byte */ + uInt avail_in; /* number of bytes available at next_in */ + uLong total_in; /* total nb of input bytes read so far */ + + Bytef *next_out; /* next output byte should be put there */ + uInt avail_out; /* remaining free space at next_out */ + uLong total_out; /* total nb of bytes output so far */ + + char *msg; /* last error message, NULL if no error */ + struct internal_state FAR *state; /* not visible by applications */ + + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + voidpf opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: binary or text */ + uLong adler; /* adler32 value of the uncompressed data */ + uLong reserved; /* reserved for future use */ +} z_stream; + +typedef z_stream FAR *z_streamp; + +/* + gzip header information passed to and from zlib routines. See RFC 1952 + for more details on the meanings of these fields. +*/ +typedef struct gz_header_s { + int text; /* true if compressed data believed to be text */ + uLong time; /* modification time */ + int xflags; /* extra flags (not used when writing a gzip file) */ + int os; /* operating system */ + Bytef *extra; /* pointer to extra field or Z_NULL if none */ + uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ + uInt extra_max; /* space at extra (only when reading header) */ + Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ + uInt name_max; /* space at name (only when reading header) */ + Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ + uInt comm_max; /* space at comment (only when reading header) */ + int hcrc; /* true if there was or will be a header crc */ + int done; /* true when done reading gzip header (not used + when writing a gzip file) */ +} gz_header; + +typedef gz_header FAR *gz_headerp; + +/* + The application must update next_in and avail_in when avail_in has dropped + to zero. It must update next_out and avail_out when avail_out has dropped + to zero. The application must initialize zalloc, zfree and opaque before + calling the init function. All other fields are set by the compression + library and must not be updated by the application. + + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the + opaque value. + + zalloc must return Z_NULL if there is not enough memory for the object. + If zlib is used in a multi-threaded application, zalloc and zfree must be + thread safe. + + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this if + the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers + returned by zalloc for objects of exactly 65536 bytes *must* have their + offset normalized to zero. The default allocation function provided by this + library ensures this (see zutil.c). To reduce memory requirements and avoid + any allocation of 64K objects, at the expense of compression ratio, compile + the library with -DMAX_WBITS=14 (see zconf.h). + + The fields total_in and total_out can be used for statistics or progress + reports. After compression, total_in holds the total size of the + uncompressed data and may be saved for use in the decompressor (particularly + if the decompressor wants to decompress everything in a single step). +*/ + + /* constants */ + +#define Z_NO_FLUSH 0 +#define Z_PARTIAL_FLUSH 1 +#define Z_SYNC_FLUSH 2 +#define Z_FULL_FLUSH 3 +#define Z_FINISH 4 +#define Z_BLOCK 5 +#define Z_TREES 6 +/* Allowed flush values; see deflate() and inflate() below for details */ + +#define Z_OK 0 +#define Z_STREAM_END 1 +#define Z_NEED_DICT 2 +#define Z_ERRNO (-1) +#define Z_STREAM_ERROR (-2) +#define Z_DATA_ERROR (-3) +#define Z_MEM_ERROR (-4) +#define Z_BUF_ERROR (-5) +#define Z_VERSION_ERROR (-6) +/* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ + +#define Z_NO_COMPRESSION 0 +#define Z_BEST_SPEED 1 +#define Z_BEST_COMPRESSION 9 +#define Z_DEFAULT_COMPRESSION (-1) +/* compression levels */ + +#define Z_FILTERED 1 +#define Z_HUFFMAN_ONLY 2 +#define Z_RLE 3 +#define Z_FIXED 4 +#define Z_DEFAULT_STRATEGY 0 +/* compression strategy; see deflateInit2() below for details */ + +#define Z_BINARY 0 +#define Z_TEXT 1 +#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ +#define Z_UNKNOWN 2 +/* Possible values of the data_type field (though see inflate()) */ + +#define Z_DEFLATED 8 +/* The deflate compression method (the only one supported in this version) */ + +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ + +#define zlib_version zlibVersion() +/* for compatibility with versions < 1.0.2 */ + + + /* basic functions */ + +ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. + If the first character differs, the library code actually used is not + compatible with the zlib.h header file used by the application. This check + is automatically made by deflateInit and inflateInit. + */ + +/* +ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); + + Initializes the internal stream state for compression. The fields + zalloc, zfree and opaque must be initialized before by the caller. If + zalloc and zfree are set to Z_NULL, deflateInit updates them to use default + allocation functions. + + The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: + 1 gives best speed, 9 gives best compression, 0 gives no compression at all + (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION + requests a default compromise between speed and compression (currently + equivalent to level 6). + + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if level is not a valid compression level, or + Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible + with the version assumed by the caller (ZLIB_VERSION). msg is set to null + if there is no error message. deflateInit does not perform any compression: + this will be done by deflate(). +*/ + + +ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +/* + deflate compresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. deflate performs one or both of the + following actions: + + - Compress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in and avail_in are updated and + processing will resume at this point for the next call of deflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. This action is forced if the parameter flush is non zero. + Forcing flush frequently degrades the compression ratio, so this parameter + should be set only when necessary (in interactive applications). Some + output may be provided even if flush is not set. + + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating avail_in or avail_out accordingly; avail_out should + never be zero before the call. The application can consume the compressed + output when it wants, for example when the output buffer is full (avail_out + == 0), or after each call of deflate(). If deflate returns Z_OK and with + zero avail_out, it must be called again after making room in the output + buffer because there might be more output pending. + + Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to + decide how much data to accumulate before producing output, in order to + maximize compression. + + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is + flushed to the output buffer and the output is aligned on a byte boundary, so + that the decompressor can get all input data available so far. (In + particular avail_in is zero after the call if enough output space has been + provided before the call.) Flushing may degrade compression for some + compression algorithms and so it should be used only when necessary. This + completes the current deflate block and follows it with an empty stored block + that is three bits plus filler bits to the next byte, followed by four bytes + (00 00 ff ff). + + If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the + output buffer, but the output is not aligned to a byte boundary. All of the + input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. + This completes the current deflate block and follows it with an empty fixed + codes block that is 10 bits long. This assures that enough bytes are output + in order for the decompressor to finish the block before the empty fixed code + block. + + If flush is set to Z_BLOCK, a deflate block is completed and emitted, as + for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to + seven bits of the current block are held to be written as the next byte after + the next deflate block is completed. In this case, the decompressor may not + be provided enough bits at this point in order to complete decompression of + the data provided so far to the compressor. It may need to wait for the next + block to be emitted. This is for advanced applications that need to control + the emission of deflate blocks. + + If flush is set to Z_FULL_FLUSH, all output is flushed as with + Z_SYNC_FLUSH, and the compression state is reset so that decompression can + restart from this point if previous compressed data has been damaged or if + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade + compression. + + If deflate returns with avail_out == 0, this function must be called again + with the same value of the flush parameter and more output space (updated + avail_out), until the flush is complete (deflate returns with non-zero + avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that + avail_out is greater than six to avoid repeated flush markers due to + avail_out == 0 on return. + + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there was + enough output space; if deflate returns with Z_OK, this function must be + called again with Z_FINISH and more output space (updated avail_out) but no + more input data, until it returns with Z_STREAM_END or an error. After + deflate has returned Z_STREAM_END, the only possible operations on the stream + are deflateReset or deflateEnd. + + Z_FINISH can be used immediately after deflateInit if all the compression + is to be done in a single step. In this case, avail_out must be at least the + value returned by deflateBound (see below). If deflate does not return + Z_STREAM_END, then it must be called again as described above. + + deflate() sets strm->adler to the adler32 checksum of all input read + so far (that is, total_in bytes). + + deflate() may update strm->data_type if it can make a good guess about + the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered + binary. This field is only for information purposes and does not affect the + compression algorithm in any manner. + + deflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if all input has been + consumed and all output has been produced (only when flush is set to + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example + if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible + (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not + fatal, and deflate() can be called again with more input and more output + space to continue compressing. +*/ + + +ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the + stream state was inconsistent, Z_DATA_ERROR if the stream was freed + prematurely (some input or output was discarded). In the error case, msg + may be set but then points to a static string (which must not be + deallocated). +*/ + + +/* +ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); + + Initializes the internal stream state for decompression. The fields + next_in, avail_in, zalloc, zfree and opaque must be initialized before by + the caller. If next_in is not Z_NULL and avail_in is large enough (the + exact value depends on the compression method), inflateInit determines the + compression method from the zlib header and allocates all data structures + accordingly; otherwise the allocation will be deferred to the first call of + inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to + use default allocation functions. + + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit() does not process any header information -- that is deferred + until inflate() is called. +*/ + + +ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +/* + inflate decompresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. inflate performs one or both of the + following actions: + + - Decompress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in is updated and processing will + resume at this point for the next call of inflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. inflate() provides as much output as possible, until there is + no more input data or no more space in the output buffer (see below about + the flush parameter). + + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating the next_* and avail_* values accordingly. The + application can consume the uncompressed output when it wants, for example + when the output buffer is full (avail_out == 0), or after each call of + inflate(). If inflate returns Z_OK and with zero avail_out, it must be + called again after making room in the output buffer because there might be + more output pending. + + The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, + Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much + output as possible to the output buffer. Z_BLOCK requests that inflate() + stop if and when it gets to the next deflate block boundary. When decoding + the zlib or gzip format, this will cause inflate() to return immediately + after the header and before the first block. When doing a raw inflate, + inflate() will go ahead and process the first block, and will return when it + gets to the end of that block, or when it runs out of data. + + The Z_BLOCK option assists in appending to or combining deflate streams. + Also to assist in this, on return inflate() will set strm->data_type to the + number of unused bits in the last byte taken from strm->next_in, plus 64 if + inflate() is currently decoding the last block in the deflate stream, plus + 128 if inflate() returned immediately after decoding an end-of-block code or + decoding the complete header up to just before the first byte of the deflate + stream. The end-of-block will not be indicated until all of the uncompressed + data from that block has been written to strm->next_out. The number of + unused bits may in general be greater than seven, except when bit 7 of + data_type is set, in which case the number of unused bits will be less than + eight. data_type is set as noted here every time inflate() returns for all + flush options, and so can be used to determine the amount of currently + consumed input in bits. + + The Z_TREES option behaves as Z_BLOCK does, but it also returns when the + end of each deflate block header is reached, before any actual data in that + block is decoded. This allows the caller to determine the length of the + deflate block header for later use in random access within a deflate block. + 256 is added to the value of strm->data_type when inflate() returns + immediately after reaching the end of the deflate block header. + + inflate() should normally be called until it returns Z_STREAM_END or an + error. However if all decompression is to be performed in a single step (a + single call of inflate), the parameter flush should be set to Z_FINISH. In + this case all pending input is processed and all pending output is flushed; + avail_out must be large enough to hold all the uncompressed data. (The size + of the uncompressed data may have been saved by the compressor for this + purpose.) The next operation on this stream must be inflateEnd to deallocate + the decompression state. The use of Z_FINISH is never required, but can be + used to inform inflate that a faster approach may be used for the single + inflate() call. + + In this implementation, inflate() always flushes as much output as + possible to the output buffer, and always uses the faster approach on the + first call. So the only effect of the flush parameter in this implementation + is on the return value of inflate(), as noted below, or when it returns early + because Z_BLOCK or Z_TREES is used. + + If a preset dictionary is needed after this call (see inflateSetDictionary + below), inflate sets strm->adler to the adler32 checksum of the dictionary + chosen by the compressor and returns Z_NEED_DICT; otherwise it sets + strm->adler to the adler32 checksum of all output produced so far (that is, + total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described + below. At the end of the stream, inflate() checks that its computed adler32 + checksum is equal to that saved by the compressor and returns Z_STREAM_END + only if the checksum is correct. + + inflate() can decompress and check either zlib-wrapped or gzip-wrapped + deflate data. The header type is detected automatically, if requested when + initializing with inflateInit2(). Any information contained in the gzip + header is not retained, so applications that need that information should + instead use raw inflate, see inflateInit2() below, or inflateBack() and + perform their own processing of the gzip header and trailer. + + inflate() returns Z_OK if some progress has been made (more input processed + or more output produced), Z_STREAM_END if the end of the compressed data has + been reached and all uncompressed output has been produced, Z_NEED_DICT if a + preset dictionary is needed at this point, Z_DATA_ERROR if the input data was + corrupted (input stream not conforming to the zlib format or incorrect check + value), Z_STREAM_ERROR if the stream structure was inconsistent (for example + next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, + Z_BUF_ERROR if no progress is possible or if there was not enough room in the + output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and + inflate() can be called again with more input and more output space to + continue decompressing. If Z_DATA_ERROR is returned, the application may + then call inflateSync() to look for a good compression block if a partial + recovery of the data is desired. +*/ + + +ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state + was inconsistent. In the error case, msg may be set but then points to a + static string (which must not be deallocated). +*/ + + + /* Advanced functions */ + +/* + The following functions are needed only in some special applications. +*/ + +/* +ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy)); + + This is another version of deflateInit with more compression options. The + fields next_in, zalloc, zfree and opaque must be initialized before by the + caller. + + The method parameter is the compression method. It must be Z_DEFLATED in + this version of the library. + + The windowBits parameter is the base two logarithm of the window size + (the size of the history buffer). It should be in the range 8..15 for this + version of the library. Larger values of this parameter result in better + compression at the expense of memory usage. The default value is 15 if + deflateInit is used instead. + + windowBits can also be -8..-15 for raw deflate. In this case, -windowBits + determines the window size. deflate() will then generate raw deflate data + with no zlib header or trailer, and will not compute an adler32 check value. + + windowBits can also be greater than 15 for optional gzip encoding. Add + 16 to windowBits to write a simple gzip header and trailer around the + compressed data instead of a zlib wrapper. The gzip header will have no + file name, no extra data, no comment, no modification time (set to zero), no + header crc, and the operating system will be set to 255 (unknown). If a + gzip stream is being written, strm->adler is a crc32 instead of an adler32. + + The memLevel parameter specifies how much memory should be allocated + for the internal compression state. memLevel=1 uses minimum memory but is + slow and reduces compression ratio; memLevel=9 uses maximum memory for + optimal speed. The default value is 8. See zconf.h for total memory usage + as a function of windowBits and memLevel. + + The strategy parameter is used to tune the compression algorithm. Use the + value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a + filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no + string match), or Z_RLE to limit match distances to one (run-length + encoding). Filtered data consists mostly of small values with a somewhat + random distribution. In this case, the compression algorithm is tuned to + compress them better. The effect of Z_FILTERED is to force more Huffman + coding and less string matching; it is somewhat intermediate between + Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as + fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The + strategy parameter only affects the compression ratio but not the + correctness of the compressed output even if it is not set appropriately. + Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler + decoder for special applications. + + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid + method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is + incompatible with the version assumed by the caller (ZLIB_VERSION). msg is + set to null if there is no error message. deflateInit2 does not perform any + compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the compression dictionary from the given byte sequence + without producing any compressed output. This function must be called + immediately after deflateInit, deflateInit2 or deflateReset, before any call + of deflate. The compressor and decompressor must use exactly the same + dictionary (see inflateSetDictionary). + + The dictionary should consist of strings (byte sequences) that are likely + to be encountered later in the data to be compressed, with the most commonly + used strings preferably put towards the end of the dictionary. Using a + dictionary is most useful when the data to be compressed is short and can be + predicted with good accuracy; the data can then be compressed better than + with the default empty dictionary. + + Depending on the size of the compression data structures selected by + deflateInit or deflateInit2, a part of the dictionary may in effect be + discarded, for example if the dictionary is larger than the window size + provided in deflateInit or deflateInit2. Thus the strings most likely to be + useful should be put at the end of the dictionary, not at the front. In + addition, the current implementation of deflate will use at most the window + size minus 262 bytes of the provided dictionary. + + Upon return of this function, strm->adler is set to the adler32 value + of the dictionary; the decompressor may later use this value to determine + which dictionary has been used by the compressor. (The adler32 value + applies to the whole dictionary even if only a subset of the dictionary is + actually used by the compressor.) If a raw deflate was requested, then the + adler32 value is not computed and strm->adler is not set. + + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent (for example if deflate has already been called for this stream + or if the compression method is bsort). deflateSetDictionary does not + perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when several compression strategies will be + tried, for example when there are several ways of pre-processing the input + data with a filter. The streams that will be discarded should then be freed + by calling deflateEnd. Note that deflateCopy duplicates the internal + compression state which can be quite large, so this strategy is slow and can + consume lots of memory. + + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +/* + This function is equivalent to deflateEnd followed by deflateInit, + but does not free and reallocate all the internal compression state. The + stream will keep the same compression level and any other attributes that + may have been set by deflateInit2. + + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, + int level, + int strategy)); +/* + Dynamically update the compression level and compression strategy. The + interpretation of level and strategy is as in deflateInit2. This can be + used to switch between compression and straight copy of the input data, or + to switch to a different kind of input data requiring a different strategy. + If the compression level is changed, the input available so far is + compressed with the old level (and may be flushed); the new level will take + effect only at the next call of deflate(). + + Before the call of deflateParams, the stream state must be set as for + a call of deflate(), since the currently available input may have to be + compressed and flushed. In particular, strm->avail_out must be non-zero. + + deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source + stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if + strm->avail_out was zero. +*/ + +ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, + int good_length, + int max_lazy, + int nice_length, + int max_chain)); +/* + Fine tune deflate's internal compression parameters. This should only be + used by someone who understands the algorithm used by zlib's deflate for + searching for the best matching string, and even then only by the most + fanatic optimizer trying to squeeze out the last compressed bit for their + specific input data. Read the deflate.c source code for the meaning of the + max_lazy, good_length, nice_length, and max_chain parameters. + + deflateTune() can be called after deflateInit() or deflateInit2(), and + returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. + */ + +ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, + uLong sourceLen)); +/* + deflateBound() returns an upper bound on the compressed size after + deflation of sourceLen bytes. It must be called after deflateInit() or + deflateInit2(), and after deflateSetHeader(), if used. This would be used + to allocate an output buffer for deflation in a single pass, and so would be + called before deflate(). +*/ + +ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + deflatePrime() inserts bits in the deflate output stream. The intent + is that this function is used to start off the deflate output with the bits + leftover from a previous deflate stream when appending to it. As such, this + function can only be used for raw deflate, and must be used before the first + deflate() call after a deflateInit2() or deflateReset(). bits must be less + than or equal to 16, and that many of the least significant bits of value + will be inserted in the output. + + deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, + gz_headerp head)); +/* + deflateSetHeader() provides gzip header information for when a gzip + stream is requested by deflateInit2(). deflateSetHeader() may be called + after deflateInit2() or deflateReset() and before the first call of + deflate(). The text, time, os, extra field, name, and comment information + in the provided gz_header structure are written to the gzip header (xflag is + ignored -- the extra flags are set according to the compression level). The + caller must assure that, if not Z_NULL, name and comment are terminated with + a zero byte, and that if extra is not Z_NULL, that extra_len bytes are + available there. If hcrc is true, a gzip header crc is included. Note that + the current versions of the command-line version of gzip (up through version + 1.3.x) do not support header crc's, and will report that it is a "multi-part + gzip file" and give up. + + If deflateSetHeader is not used, the default gzip header has text false, + the time set to zero, and os set to 255, with no extra, name, or comment + fields. The gzip header is returned to the default state by deflateReset(). + + deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, + int windowBits)); + + This is another version of inflateInit with an extra parameter. The + fields next_in, avail_in, zalloc, zfree and opaque must be initialized + before by the caller. + + The windowBits parameter is the base two logarithm of the maximum window + size (the size of the history buffer). It should be in the range 8..15 for + this version of the library. The default value is 15 if inflateInit is used + instead. windowBits must be greater than or equal to the windowBits value + provided to deflateInit2() while compressing, or it must be equal to 15 if + deflateInit2() was not used. If a compressed stream with a larger window + size is given as input, inflate() will return with the error code + Z_DATA_ERROR instead of trying to allocate a larger window. + + windowBits can also be zero to request that inflate use the window size in + the zlib header of the compressed stream. + + windowBits can also be -8..-15 for raw inflate. In this case, -windowBits + determines the window size. inflate() will then process raw deflate data, + not looking for a zlib or gzip header, not generating a check value, and not + looking for any check values for comparison at the end of the stream. This + is for use with other formats that use the deflate compressed data format + such as zip. Those formats provide their own check values. If a custom + format is developed using the raw deflate format for compressed data, it is + recommended that a check value such as an adler32 or a crc32 be applied to + the uncompressed data as is done in the zlib, gzip, and zip formats. For + most applications, the zlib format should be used as is. Note that comments + above on the use in deflateInit2() applies to the magnitude of windowBits. + + windowBits can also be greater than 15 for optional gzip decoding. Add + 32 to windowBits to enable zlib and gzip decoding with automatic header + detection, or add 16 to decode only the gzip format (the zlib format will + return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a + crc32 instead of an adler32. + + inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit2 does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit2() does not process any header information -- that is + deferred until inflate() is called. +*/ + +ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the decompression dictionary from the given uncompressed byte + sequence. This function must be called immediately after a call of inflate, + if that call returned Z_NEED_DICT. The dictionary chosen by the compressor + can be determined from the adler32 value returned by that call of inflate. + The compressor and decompressor must use exactly the same dictionary (see + deflateSetDictionary). For raw inflate, this function can be called + immediately after inflateInit2() or inflateReset() and before any call of + inflate() to set the dictionary. The application must insure that the + dictionary that was used for compression is provided. + + inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the + expected one (incorrect adler32 value). inflateSetDictionary does not + perform any decompression: this will be done by subsequent calls of + inflate(). +*/ + +ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +/* + Skips invalid compressed data until a full flush point (see above the + description of deflate with Z_FULL_FLUSH) can be found, or until all + available input is skipped. No output is provided. + + inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR + if no more input was provided, Z_DATA_ERROR if no flush point has been + found, or Z_STREAM_ERROR if the stream structure was inconsistent. In the + success case, the application may save the current current value of total_in + which indicates where valid compressed data was found. In the error case, + the application may repeatedly call inflateSync, providing more input each + time, until success or end of the input data. +*/ + +ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when randomly accessing a large stream. The + first pass through the stream can periodically record the inflate state, + allowing restarting inflate at those points when randomly accessing the + stream. + + inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +/* + This function is equivalent to inflateEnd followed by inflateInit, + but does not free and reallocate all the internal decompression state. The + stream will keep attributes that may have been set by inflateInit2. + + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, + int windowBits)); +/* + This function is the same as inflateReset, but it also permits changing + the wrap and window size requests. The windowBits parameter is interpreted + the same as it is for inflateInit2. + + inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL), or if + the windowBits parameter is invalid. +*/ + +ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + This function inserts bits in the inflate input stream. The intent is + that this function is used to start inflating at a bit position in the + middle of a byte. The provided bits will be used before any bytes are used + from next_in. This function should only be used with raw inflate, and + should be used before the first inflate() call after inflateInit2() or + inflateReset(). bits must be less than or equal to 16, and that many of the + least significant bits of value will be inserted in the input. + + If bits is negative, then the input stream bit buffer is emptied. Then + inflatePrime() can be called again to put bits in the buffer. This is used + to clear out bits leftover after feeding inflate a block description prior + to feeding inflate codes. + + inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); +/* + This function returns two values, one in the lower 16 bits of the return + value, and the other in the remaining upper bits, obtained by shifting the + return value down 16 bits. If the upper value is -1 and the lower value is + zero, then inflate() is currently decoding information outside of a block. + If the upper value is -1 and the lower value is non-zero, then inflate is in + the middle of a stored block, with the lower value equaling the number of + bytes from the input remaining to copy. If the upper value is not -1, then + it is the number of bits back from the current bit position in the input of + the code (literal or length/distance pair) currently being processed. In + that case the lower value is the number of bytes already emitted for that + code. + + A code is being processed if inflate is waiting for more input to complete + decoding of the code, or if it has completed decoding but is waiting for + more output space to write the literal or match data. + + inflateMark() is used to mark locations in the input data for random + access, which may be at bit positions, and to note those cases where the + output of a code may span boundaries of random access blocks. The current + location in the input stream can be determined from avail_in and data_type + as noted in the description for the Z_BLOCK flush parameter for inflate. + + inflateMark returns the value noted above or -1 << 16 if the provided + source stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, + gz_headerp head)); +/* + inflateGetHeader() requests that gzip header information be stored in the + provided gz_header structure. inflateGetHeader() may be called after + inflateInit2() or inflateReset(), and before the first call of inflate(). + As inflate() processes the gzip stream, head->done is zero until the header + is completed, at which time head->done is set to one. If a zlib stream is + being decoded, then head->done is set to -1 to indicate that there will be + no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be + used to force inflate() to return immediately after header processing is + complete and before any actual data is decompressed. + + The text, time, xflags, and os fields are filled in with the gzip header + contents. hcrc is set to true if there is a header CRC. (The header CRC + was valid if done is set to one.) If extra is not Z_NULL, then extra_max + contains the maximum number of bytes to write to extra. Once done is true, + extra_len contains the actual extra field length, and extra contains the + extra field, or that field truncated if extra_max is less than extra_len. + If name is not Z_NULL, then up to name_max characters are written there, + terminated with a zero unless the length is greater than name_max. If + comment is not Z_NULL, then up to comm_max characters are written there, + terminated with a zero unless the length is greater than comm_max. When any + of extra, name, or comment are not Z_NULL and the respective field is not + present in the header, then that field is set to Z_NULL to signal its + absence. This allows the use of deflateSetHeader() with the returned + structure to duplicate the header. However if those fields are set to + allocated memory, then the application will need to save those pointers + elsewhere so that they can be eventually freed. + + If inflateGetHeader is not used, then the header information is simply + discarded. The header is always checked for validity, including the header + CRC if present. inflateReset() will reset the process to discard the header + information. The application would need to call inflateGetHeader() again to + retrieve the header from the next gzip stream. + + inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, + unsigned char FAR *window)); + + Initialize the internal stream state for decompression using inflateBack() + calls. The fields zalloc, zfree and opaque in strm must be initialized + before the call. If zalloc and zfree are Z_NULL, then the default library- + derived memory allocation routines are used. windowBits is the base two + logarithm of the window size, in the range 8..15. window is a caller + supplied buffer of that size. Except for special applications where it is + assured that deflate was used with small window sizes, windowBits must be 15 + and a 32K byte window must be supplied to be able to decompress general + deflate streams. + + See inflateBack() for the usage of these routines. + + inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of + the paramaters are invalid, Z_MEM_ERROR if the internal state could not be + allocated, or Z_VERSION_ERROR if the version of the library does not match + the version of the header file. +*/ + +typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); +typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); + +ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, + in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc)); +/* + inflateBack() does a raw inflate with a single call using a call-back + interface for input and output. This is more efficient than inflate() for + file i/o applications in that it avoids copying between the output and the + sliding window by simply making the window itself the output buffer. This + function trusts the application to not change the output buffer passed by + the output function, at least until inflateBack() returns. + + inflateBackInit() must be called first to allocate the internal state + and to initialize the state with the user-provided window buffer. + inflateBack() may then be used multiple times to inflate a complete, raw + deflate stream with each call. inflateBackEnd() is then called to free the + allocated state. + + A raw deflate stream is one with no zlib or gzip header or trailer. + This routine would normally be used in a utility that reads zip or gzip + files and writes out uncompressed files. The utility would decode the + header and process the trailer on its own, hence this routine expects only + the raw deflate stream to decompress. This is different from the normal + behavior of inflate(), which expects either a zlib or gzip header and + trailer around the deflate stream. + + inflateBack() uses two subroutines supplied by the caller that are then + called by inflateBack() for input and output. inflateBack() calls those + routines until it reads a complete deflate stream and writes out all of the + uncompressed data, or until it encounters an error. The function's + parameters and return types are defined above in the in_func and out_func + typedefs. inflateBack() will call in(in_desc, &buf) which should return the + number of bytes of provided input, and a pointer to that input in buf. If + there is no input available, in() must return zero--buf is ignored in that + case--and inflateBack() will return a buffer error. inflateBack() will call + out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() + should return zero on success, or non-zero on failure. If out() returns + non-zero, inflateBack() will return with an error. Neither in() nor out() + are permitted to change the contents of the window provided to + inflateBackInit(), which is also the buffer that out() uses to write from. + The length written by out() will be at most the window size. Any non-zero + amount of input may be provided by in(). + + For convenience, inflateBack() can be provided input on the first call by + setting strm->next_in and strm->avail_in. If that input is exhausted, then + in() will be called. Therefore strm->next_in must be initialized before + calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called + immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in + must also be initialized, and then if strm->avail_in is not zero, input will + initially be taken from strm->next_in[0 .. strm->avail_in - 1]. + + The in_desc and out_desc parameters of inflateBack() is passed as the + first parameter of in() and out() respectively when they are called. These + descriptors can be optionally used to pass any information that the caller- + supplied in() and out() functions need to do their job. + + On return, inflateBack() will set strm->next_in and strm->avail_in to + pass back any unused input that was provided by the last in() call. The + return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR + if in() or out() returned an error, Z_DATA_ERROR if there was a format error + in the deflate stream (in which case strm->msg is set to indicate the nature + of the error), or Z_STREAM_ERROR if the stream was not properly initialized. + In the case of Z_BUF_ERROR, an input or output error can be distinguished + using strm->next_in which will be Z_NULL only if in() returned an error. If + strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning + non-zero. (in() will always be called before out(), so strm->next_in is + assured to be defined if out() returns non-zero.) Note that inflateBack() + cannot return Z_OK. +*/ + +ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +/* + All memory allocated by inflateBackInit() is freed. + + inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream + state was inconsistent. +*/ + +ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +/* Return flags indicating compile-time options. + + Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: + 1.0: size of uInt + 3.2: size of uLong + 5.4: size of voidpf (pointer) + 7.6: size of z_off_t + + Compiler, assembler, and debug options: + 8: DEBUG + 9: ASMV or ASMINF -- use ASM code + 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention + 11: 0 (reserved) + + One-time table building (smaller code, but not thread-safe if true): + 12: BUILDFIXED -- build static block decoding tables when needed + 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed + 14,15: 0 (reserved) + + Library content (indicates missing functionality): + 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking + deflate code when not needed) + 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect + and decode gzip streams (to avoid linking crc code) + 18-19: 0 (reserved) + + Operation variations (changes in library functionality): + 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate + 21: FASTEST -- deflate algorithm with only one, lowest compression level + 22,23: 0 (reserved) + + The sprintf variant used by gzprintf (zero is best): + 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format + 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! + 26: 0 = returns value, 1 = void -- 1 means inferred string length returned + + Remainder: + 27-31: 0 (reserved) + */ + + + /* utility functions */ + +/* + The following utility functions are implemented on top of the basic + stream-oriented functions. To simplify the interface, some default options + are assumed (compression level and memory usage, standard memory allocation + functions). The source code of these utility functions can be modified if + you need special options. +*/ + +ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Compresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer. +*/ + +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, + int level)); +/* + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ + +ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +/* + compressBound() returns an upper bound on the compressed size after + compress() or compress2() on sourceLen bytes. It would be used before a + compress() or compress2() call to allocate the destination buffer. +*/ + +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be large enough to hold the entire + uncompressed data. (The size of the uncompressed data must have been saved + previously by the compressor and transmitted to the decompressor by some + mechanism outside the scope of this compression library.) Upon exit, destLen + is the actual size of the uncompressed buffer. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. +*/ + + + /* gzip file access functions */ + +/* + This library supports reading and writing files in gzip (.gz) format with + an interface similar to that of stdio, using the functions that start with + "gz". The gzip format is different from the zlib format. gzip is a gzip + wrapper, documented in RFC 1952, wrapped around a deflate stream. +*/ + +typedef voidp gzFile; /* opaque gzip file descriptor */ + +/* +ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); + + Opens a gzip (.gz) file for reading or writing. The mode parameter is as + in fopen ("rb" or "wb") but can also include a compression level ("wb9") or + a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only + compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' + for fixed code compression as in "wb9F". (See the description of + deflateInit2 for more information about the strategy parameter.) Also "a" + can be used instead of "w" to request that the gzip stream that will be + written be appended to the file. "+" will result in an error, since reading + and writing to the same gzip file is not supported. + + gzopen can be used to read a file which is not in gzip format; in this + case gzread will directly read from the file without decompression. + + gzopen returns NULL if the file could not be opened, if there was + insufficient memory to allocate the gzFile state, or if an invalid mode was + specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). + errno can be checked to determine if the reason gzopen failed was that the + file could not be opened. +*/ + +ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +/* + gzdopen associates a gzFile with the file descriptor fd. File descriptors + are obtained from calls like open, dup, creat, pipe or fileno (if the file + has been previously opened with fopen). The mode parameter is as in gzopen. + + The next call of gzclose on the returned gzFile will also close the file + descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor + fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, + mode);. The duplicated descriptor should be saved to avoid a leak, since + gzdopen does not close fd if it fails. + + gzdopen returns NULL if there was insufficient memory to allocate the + gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not + provided, or '+' was provided), or if fd is -1. The file descriptor is not + used until the next gz* read, write, seek, or close operation, so gzdopen + will not detect if fd is invalid (unless fd is -1). +*/ + +ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); +/* + Set the internal buffer size used by this library's functions. The + default buffer size is 8192 bytes. This function must be called after + gzopen() or gzdopen(), and before any other calls that read or write the + file. The buffer memory allocation is always deferred to the first read or + write. Two buffers are allocated, either both of the specified size when + writing, or one of the specified size and the other twice that size when + reading. A larger buffer size of, for example, 64K or 128K bytes will + noticeably increase the speed of decompression (reading). + + The new buffer size also affects the maximum length for gzprintf(). + + gzbuffer() returns 0 on success, or -1 on failure, such as being called + too late. +*/ + +ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +/* + Dynamically update the compression level or strategy. See the description + of deflateInit2 for the meaning of these parameters. + + gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not + opened for writing. +*/ + +ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +/* + Reads the given number of uncompressed bytes from the compressed file. If + the input file was not in gzip format, gzread copies the given number of + bytes into the buffer. + + After reaching the end of a gzip stream in the input, gzread will continue + to read, looking for another gzip stream, or failing that, reading the rest + of the input file directly without decompression. The entire input file + will be read if gzread is called until it returns less than the requested + len. + + gzread returns the number of uncompressed bytes actually read, less than + len for end of file, or -1 for error. +*/ + +ZEXTERN int ZEXPORT gzwrite OF((gzFile file, + voidpc buf, unsigned len)); +/* + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of uncompressed bytes written or 0 in case of + error. +*/ + +ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); +/* + Converts, formats, and writes the arguments to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written, or 0 in case of error. The number of + uncompressed bytes written is limited to 8191, or one less than the buffer + size given to gzbuffer(). The caller should assure that this limit is not + exceeded. If it is exceeded, then gzprintf() will return an error (0) with + nothing written. In this case, there may also be a buffer overflow with + unpredictable consequences, which is possible only if zlib was compiled with + the insecure functions sprintf() or vsprintf() because the secure snprintf() + or vsnprintf() functions were not available. This can be determined using + zlibCompileFlags(). +*/ + +ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +/* + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + + gzputs returns the number of characters written, or -1 in case of error. +*/ + +ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +/* + Reads bytes from the compressed file until len-1 characters are read, or a + newline character is read and transferred to buf, or an end-of-file + condition is encountered. If any characters are read or if len == 1, the + string is terminated with a null character. If no characters are read due + to an end-of-file or len < 1, then the buffer is left untouched. + + gzgets returns buf which is a null-terminated string, or it returns NULL + for end-of-file or in case of error. If there was an error, the contents at + buf are indeterminate. +*/ + +ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +/* + Writes c, converted to an unsigned char, into the compressed file. gzputc + returns the value that was written, or -1 in case of error. +*/ + +ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +/* + Reads one byte from the compressed file. gzgetc returns this byte or -1 + in case of end of file or error. +*/ + +ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +/* + Push one character back onto the stream to be read as the first character + on the next read. At least one character of push-back is allowed. + gzungetc() returns the character pushed, or -1 on failure. gzungetc() will + fail if c is -1, and may fail if a character has been pushed but not read + yet. If gzungetc is used immediately after gzopen or gzdopen, at least the + output buffer size of pushed characters is allowed. (See gzbuffer above.) + The pushed character will be discarded if the stream is repositioned with + gzseek() or gzrewind(). +*/ + +ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +/* + Flushes all pending output into the compressed file. The parameter flush + is as in the deflate() function. The return value is the zlib error number + (see function gzerror below). gzflush is only permitted when writing. + + If the flush parameter is Z_FINISH, the remaining data is written and the + gzip stream is completed in the output. If gzwrite() is called again, a new + gzip stream will be started in the output. gzread() is able to read such + concatented gzip streams. + + gzflush should be called only when strictly necessary because it will + degrade compression if called too often. +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, + z_off_t offset, int whence)); + + Sets the starting position for the next gzread or gzwrite on the given + compressed file. The offset represents a number of bytes in the + uncompressed data stream. The whence parameter is defined as in lseek(2); + the value SEEK_END is not supported. + + If the file is opened for reading, this function is emulated but can be + extremely slow. If the file is opened for writing, only forward seeks are + supported; gzseek then compresses a sequence of zeroes up to the new + starting position. + + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error, in + particular if the file is opened for writing and the new starting position + would be before the current position. +*/ + +ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +/* + Rewinds the given file. This function is supported only for reading. + + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); + + Returns the starting position for the next gzread or gzwrite on the given + compressed file. This position represents a number of bytes in the + uncompressed data stream, and is zero when starting, even if appending or + reading a gzip stream from the middle of a file using gzdopen(). + + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); + + Returns the current offset in the file being read or written. This offset + includes the count of bytes that precede the gzip stream, for example when + appending or when using gzdopen() for reading. When reading, the offset + does not include as yet unused buffered input. This information can be used + for a progress indicator. On error, gzoffset() returns -1. +*/ + +ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +/* + Returns true (1) if the end-of-file indicator has been set while reading, + false (0) otherwise. Note that the end-of-file indicator is set only if the + read tried to go past the end of the input, but came up short. Therefore, + just like feof(), gzeof() may return false even if there is no more data to + read, in the event that the last read request was for the exact number of + bytes remaining in the input file. This will happen if the input file size + is an exact multiple of the buffer size. + + If gzeof() returns true, then the read functions will return no more data, + unless the end-of-file indicator is reset by gzclearerr() and the input file + has grown since the previous end of file was detected. +*/ + +ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +/* + Returns true (1) if file is being copied directly while reading, or false + (0) if file is a gzip stream being decompressed. This state can change from + false to true while reading the input file if the end of a gzip stream is + reached, but is followed by data that is not another gzip stream. + + If the input file is empty, gzdirect() will return true, since the input + does not contain a gzip stream. + + If gzdirect() is used immediately after gzopen() or gzdopen() it will + cause buffers to be allocated to allow reading the file to determine if it + is a gzip file. Therefore if gzbuffer() is used, it should be called before + gzdirect(). +*/ + +ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +/* + Flushes all pending output if necessary, closes the compressed file and + deallocates the (de)compression state. Note that once file is closed, you + cannot call gzerror with file, since its structures have been deallocated. + gzclose must not be called more than once on the same file, just as free + must not be called more than once on the same allocation. + + gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a + file operation error, or Z_OK on success. +*/ + +ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); +/* + Same as gzclose(), but gzclose_r() is only for use when reading, and + gzclose_w() is only for use when writing or appending. The advantage to + using these instead of gzclose() is that they avoid linking in zlib + compression or decompression code that is not used when only reading or only + writing respectively. If gzclose() is used, then both compression and + decompression code will be included the application when linking to a static + zlib library. +*/ + +ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +/* + Returns the error message for the last error which occurred on the given + compressed file. errnum is set to zlib error number. If an error occurred + in the file system and not in the compression library, errnum is set to + Z_ERRNO and the application may consult errno to get the exact error code. + + The application must not modify the returned string. Future calls to + this function may invalidate the previously returned string. If file is + closed, then the string previously returned by gzerror will no longer be + available. + + gzerror() should be used to distinguish errors from end-of-file for those + functions above that do not distinguish those cases in their return values. +*/ + +ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +/* + Clears the error and end-of-file flags for file. This is analogous to the + clearerr() function in stdio. This is useful for continuing to read a gzip + file that is being written concurrently. +*/ + + + /* checksum functions */ + +/* + These functions are not related to compression but are exported + anyway because they might be useful in applications using the compression + library. +*/ + +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +/* + Update a running Adler-32 checksum with the bytes buf[0..len-1] and + return the updated checksum. If buf is Z_NULL, this function returns the + required initial value for the checksum. + + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed + much faster. + + Usage example: + + uLong adler = adler32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + adler = adler32(adler, buffer, length); + } + if (adler != original_adler) error(); +*/ + +/* +ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, + z_off_t len2)); + + Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 + and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for + each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of + seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. +*/ + +ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +/* + Update a running CRC-32 with the bytes buf[0..len-1] and return the + updated CRC-32. If buf is Z_NULL, this function returns the required + initial value for the for the crc. Pre- and post-conditioning (one's + complement) is performed within this function so it shouldn't be done by the + application. + + Usage example: + + uLong crc = crc32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + crc = crc32(crc, buffer, length); + } + if (crc != original_crc) error(); +*/ + +/* +ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); + + Combine two CRC-32 check values into one. For two sequences of bytes, + seq1 and seq2 with lengths len1 and len2, CRC-32 check values were + calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 + check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and + len2. +*/ + + + /* various hacks, don't look :) */ + +/* deflateInit and inflateInit are macros to allow checking the zlib version + * and the compiler's view of z_stream: + */ +ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size)); +ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, + unsigned char FAR *window, + const char *version, + int stream_size)); +#define deflateInit(strm, level) \ + deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) +#define inflateInit(strm) \ + inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) +#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ + (strategy), ZLIB_VERSION, sizeof(z_stream)) +#define inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) +#define inflateBackInit(strm, windowBits, window) \ + inflateBackInit_((strm), (windowBits), (window), \ + ZLIB_VERSION, sizeof(z_stream)) + +/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or + * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if + * both are true, the application gets the *64 functions, and the regular + * functions are changed to 64 bits) -- in case these are set on systems + * without large file support, _LFS64_LARGEFILE must also be true + */ +#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); + ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); +#endif + +#if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS-0 == 64 && _LFS64_LARGEFILE-0 +# define gzopen gzopen64 +# define gzseek gzseek64 +# define gztell gztell64 +# define gzoffset gzoffset64 +# define adler32_combine adler32_combine64 +# define crc32_combine crc32_combine64 +# ifdef _LARGEFILE64_SOURCE + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); +# endif +#else + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); +#endif + +/* hack for buggy compilers */ +#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) + struct internal_state {int dummy;}; +#endif + +/* undocumented functions */ +ZEXTERN const char * ZEXPORT zError OF((int)); +ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); +ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); +ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); + +#ifdef __cplusplus +} +#endif + +#endif /* ZLIB_H */ diff --git a/fceumm/utils/zlib/crc32.c b/fceumm/utils/zlib/crc32.c new file mode 100644 index 0000000..91be372 --- /dev/null +++ b/fceumm/utils/zlib/crc32.c @@ -0,0 +1,442 @@ +/* crc32.c -- compute the CRC-32 of a data stream + * Copyright (C) 1995-2006, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + * + * Thanks to Rodney Brown for his contribution of faster + * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing + * tables for updating the shift register in one step with three exclusive-ors + * instead of four steps with four exclusive-ors. This results in about a + * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. + */ + +/* @(#) $Id$ */ + +/* + Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore + protection on the static variables used to control the first-use generation + of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should + first call get_crc_table() to initialize the tables before allowing more than + one thread to use crc32(). + */ + +#ifdef MAKECRCH +# include +# ifndef DYNAMIC_CRC_TABLE +# define DYNAMIC_CRC_TABLE +# endif /* !DYNAMIC_CRC_TABLE */ +#endif /* MAKECRCH */ + +#include "zutil.h" /* for STDC and FAR definitions */ + +#define local static + +/* Find a four-byte integer type for crc32_little() and crc32_big(). */ +#ifndef NOBYFOUR +# ifdef STDC /* need ANSI C limits.h to determine sizes */ +# include +# define BYFOUR +# if (UINT_MAX == 0xffffffffUL) + typedef unsigned int u4; +# else +# if (ULONG_MAX == 0xffffffffUL) + typedef unsigned long u4; +# else +# if (USHRT_MAX == 0xffffffffUL) + typedef unsigned short u4; +# else +# undef BYFOUR /* can't find a four-byte integer type! */ +# endif +# endif +# endif +# endif /* STDC */ +#endif /* !NOBYFOUR */ + +/* Definitions for doing the crc four data bytes at a time. */ +#ifdef BYFOUR +# define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \ + (((w)&0xff00)<<8)+(((w)&0xff)<<24)) + local unsigned long crc32_little OF((unsigned long, + const unsigned char FAR *, unsigned)); + local unsigned long crc32_big OF((unsigned long, + const unsigned char FAR *, unsigned)); +# define TBLS 8 +#else +# define TBLS 1 +#endif /* BYFOUR */ + +/* Local functions for crc concatenation */ +local unsigned long gf2_matrix_times OF((unsigned long *mat, + unsigned long vec)); +local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); +local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2); + + +#ifdef DYNAMIC_CRC_TABLE + +local volatile int crc_table_empty = 1; +local unsigned long FAR crc_table[TBLS][256]; +local void make_crc_table OF((void)); +#ifdef MAKECRCH + local void write_table OF((FILE *, const unsigned long FAR *)); +#endif /* MAKECRCH */ +/* + Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: + x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. + + Polynomials over GF(2) are represented in binary, one bit per coefficient, + with the lowest powers in the most significant bit. Then adding polynomials + is just exclusive-or, and multiplying a polynomial by x is a right shift by + one. If we call the above polynomial p, and represent a byte as the + polynomial q, also with the lowest power in the most significant bit (so the + byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, + where a mod b means the remainder after dividing a by b. + + This calculation is done using the shift-register method of multiplying and + taking the remainder. The register is initialized to zero, and for each + incoming bit, x^32 is added mod p to the register if the bit is a one (where + x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by + x (which is shifting right by one and adding x^32 mod p if the bit shifted + out is a one). We start with the highest power (least significant bit) of + q and repeat for all eight bits of q. + + The first table is simply the CRC of all possible eight bit values. This is + all the information needed to generate CRCs on data a byte at a time for all + combinations of CRC register values and incoming bytes. The remaining tables + allow for word-at-a-time CRC calculation for both big-endian and little- + endian machines, where a word is four bytes. +*/ +local void make_crc_table() +{ + unsigned long c; + int n, k; + unsigned long poly; /* polynomial exclusive-or pattern */ + /* terms of polynomial defining this crc (except x^32): */ + static volatile int first = 1; /* flag to limit concurrent making */ + static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; + + /* See if another task is already doing this (not thread-safe, but better + than nothing -- significantly reduces duration of vulnerability in + case the advice about DYNAMIC_CRC_TABLE is ignored) */ + if (first) { + first = 0; + + /* make exclusive-or pattern from polynomial (0xedb88320UL) */ + poly = 0UL; + for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++) + poly |= 1UL << (31 - p[n]); + + /* generate a crc for every 8-bit value */ + for (n = 0; n < 256; n++) { + c = (unsigned long)n; + for (k = 0; k < 8; k++) + c = c & 1 ? poly ^ (c >> 1) : c >> 1; + crc_table[0][n] = c; + } + +#ifdef BYFOUR + /* generate crc for each value followed by one, two, and three zeros, + and then the byte reversal of those as well as the first table */ + for (n = 0; n < 256; n++) { + c = crc_table[0][n]; + crc_table[4][n] = REV(c); + for (k = 1; k < 4; k++) { + c = crc_table[0][c & 0xff] ^ (c >> 8); + crc_table[k][n] = c; + crc_table[k + 4][n] = REV(c); + } + } +#endif /* BYFOUR */ + + crc_table_empty = 0; + } + else { /* not first */ + /* wait for the other guy to finish (not efficient, but rare) */ + while (crc_table_empty) + ; + } + +#ifdef MAKECRCH + /* write out CRC tables to crc32.h */ + { + FILE *out; + + out = fopen("crc32.h", "w"); + if (out == NULL) return; + fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); + fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); + fprintf(out, "local const unsigned long FAR "); + fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); + write_table(out, crc_table[0]); +# ifdef BYFOUR + fprintf(out, "#ifdef BYFOUR\n"); + for (k = 1; k < 8; k++) { + fprintf(out, " },\n {\n"); + write_table(out, crc_table[k]); + } + fprintf(out, "#endif\n"); +# endif /* BYFOUR */ + fprintf(out, " }\n};\n"); + fclose(out); + } +#endif /* MAKECRCH */ +} + +#ifdef MAKECRCH +local void write_table(out, table) + FILE *out; + const unsigned long FAR *table; +{ + int n; + + for (n = 0; n < 256; n++) + fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n], + n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); +} +#endif /* MAKECRCH */ + +#else /* !DYNAMIC_CRC_TABLE */ +/* ======================================================================== + * Tables of CRC-32s of all single-byte values, made by make_crc_table(). + */ +#include "crc32.h" +#endif /* DYNAMIC_CRC_TABLE */ + +/* ========================================================================= + * This function can be used by asm versions of crc32() + */ +const unsigned long FAR * ZEXPORT get_crc_table() +{ +#ifdef DYNAMIC_CRC_TABLE + if (crc_table_empty) + make_crc_table(); +#endif /* DYNAMIC_CRC_TABLE */ + return (const unsigned long FAR *)crc_table; +} + +/* ========================================================================= */ +#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) +#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 + +/* ========================================================================= */ +unsigned long ZEXPORT crc32(crc, buf, len) + unsigned long crc; + const unsigned char FAR *buf; + uInt len; +{ + if (buf == Z_NULL) return 0UL; + +#ifdef DYNAMIC_CRC_TABLE + if (crc_table_empty) + make_crc_table(); +#endif /* DYNAMIC_CRC_TABLE */ + +#ifdef BYFOUR + if (sizeof(void *) == sizeof(ptrdiff_t)) { + u4 endian; + + endian = 1; + if (*((unsigned char *)(&endian))) + return crc32_little(crc, buf, len); + else + return crc32_big(crc, buf, len); + } +#endif /* BYFOUR */ + crc = crc ^ 0xffffffffUL; + while (len >= 8) { + DO8; + len -= 8; + } + if (len) do { + DO1; + } while (--len); + return crc ^ 0xffffffffUL; +} + +#ifdef BYFOUR + +/* ========================================================================= */ +#define DOLIT4 c ^= *buf4++; \ + c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ + crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] +#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 + +/* ========================================================================= */ +local unsigned long crc32_little(crc, buf, len) + unsigned long crc; + const unsigned char FAR *buf; + unsigned len; +{ + register u4 c; + register const u4 FAR *buf4; + + c = (u4)crc; + c = ~c; + while (len && ((ptrdiff_t)buf & 3)) { + c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); + len--; + } + + buf4 = (const u4 FAR *)(const void FAR *)buf; + while (len >= 32) { + DOLIT32; + len -= 32; + } + while (len >= 4) { + DOLIT4; + len -= 4; + } + buf = (const unsigned char FAR *)buf4; + + if (len) do { + c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); + } while (--len); + c = ~c; + return (unsigned long)c; +} + +/* ========================================================================= */ +#define DOBIG4 c ^= *++buf4; \ + c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ + crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] +#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 + +/* ========================================================================= */ +local unsigned long crc32_big(crc, buf, len) + unsigned long crc; + const unsigned char FAR *buf; + unsigned len; +{ + register u4 c; + register const u4 FAR *buf4; + + c = REV((u4)crc); + c = ~c; + while (len && ((ptrdiff_t)buf & 3)) { + c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); + len--; + } + + buf4 = (const u4 FAR *)(const void FAR *)buf; + buf4--; + while (len >= 32) { + DOBIG32; + len -= 32; + } + while (len >= 4) { + DOBIG4; + len -= 4; + } + buf4++; + buf = (const unsigned char FAR *)buf4; + + if (len) do { + c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); + } while (--len); + c = ~c; + return (unsigned long)(REV(c)); +} + +#endif /* BYFOUR */ + +#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ + +/* ========================================================================= */ +local unsigned long gf2_matrix_times(mat, vec) + unsigned long *mat; + unsigned long vec; +{ + unsigned long sum; + + sum = 0; + while (vec) { + if (vec & 1) + sum ^= *mat; + vec >>= 1; + mat++; + } + return sum; +} + +/* ========================================================================= */ +local void gf2_matrix_square(square, mat) + unsigned long *square; + unsigned long *mat; +{ + int n; + + for (n = 0; n < GF2_DIM; n++) + square[n] = gf2_matrix_times(mat, mat[n]); +} + +/* ========================================================================= */ +local uLong crc32_combine_(crc1, crc2, len2) + uLong crc1; + uLong crc2; + z_off64_t len2; +{ + int n; + unsigned long row; + unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ + unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ + + /* degenerate case (also disallow negative lengths) */ + if (len2 <= 0) + return crc1; + + /* put operator for one zero bit in odd */ + odd[0] = 0xedb88320UL; /* CRC-32 polynomial */ + row = 1; + for (n = 1; n < GF2_DIM; n++) { + odd[n] = row; + row <<= 1; + } + + /* put operator for two zero bits in even */ + gf2_matrix_square(even, odd); + + /* put operator for four zero bits in odd */ + gf2_matrix_square(odd, even); + + /* apply len2 zeros to crc1 (first square will put the operator for one + zero byte, eight zero bits, in even) */ + do { + /* apply zeros operator for this bit of len2 */ + gf2_matrix_square(even, odd); + if (len2 & 1) + crc1 = gf2_matrix_times(even, crc1); + len2 >>= 1; + + /* if no more bits set, then done */ + if (len2 == 0) + break; + + /* another iteration of the loop with odd and even swapped */ + gf2_matrix_square(odd, even); + if (len2 & 1) + crc1 = gf2_matrix_times(odd, crc1); + len2 >>= 1; + + /* if no more bits set, then done */ + } while (len2 != 0); + + /* return combined crc */ + crc1 ^= crc2; + return crc1; +} + +/* ========================================================================= */ +uLong ZEXPORT crc32_combine(crc1, crc2, len2) + uLong crc1; + uLong crc2; + z_off_t len2; +{ + return crc32_combine_(crc1, crc2, len2); +} + +uLong ZEXPORT crc32_combine64(crc1, crc2, len2) + uLong crc1; + uLong crc2; + z_off64_t len2; +{ + return crc32_combine_(crc1, crc2, len2); +} diff --git a/fceumm/utils/zlib/crc32.h b/fceumm/utils/zlib/crc32.h new file mode 100644 index 0000000..8053b61 --- /dev/null +++ b/fceumm/utils/zlib/crc32.h @@ -0,0 +1,441 @@ +/* crc32.h -- tables for rapid CRC calculation + * Generated automatically by crc32.c + */ + +local const unsigned long FAR crc_table[TBLS][256] = +{ + { + 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL, + 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL, + 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL, + 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL, + 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL, + 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL, + 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL, + 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL, + 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL, + 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL, + 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL, + 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL, + 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL, + 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL, + 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL, + 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL, + 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL, + 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL, + 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL, + 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL, + 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL, + 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL, + 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL, + 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL, + 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL, + 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL, + 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL, + 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL, + 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL, + 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL, + 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL, + 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL, + 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL, + 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL, + 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL, + 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL, + 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL, + 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL, + 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL, + 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL, + 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL, + 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL, + 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL, + 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL, + 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL, + 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL, + 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL, + 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL, + 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL, + 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL, + 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL, + 0x2d02ef8dUL +#ifdef BYFOUR + }, + { + 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL, + 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL, + 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL, + 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL, + 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL, + 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL, + 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL, + 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL, + 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL, + 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL, + 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL, + 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL, + 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL, + 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL, + 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL, + 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL, + 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL, + 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL, + 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL, + 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL, + 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL, + 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL, + 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL, + 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL, + 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL, + 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL, + 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL, + 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL, + 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL, + 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL, + 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL, + 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL, + 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL, + 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL, + 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL, + 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL, + 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL, + 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL, + 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL, + 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL, + 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL, + 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL, + 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL, + 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL, + 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL, + 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL, + 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL, + 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL, + 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL, + 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL, + 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL, + 0x9324fd72UL + }, + { + 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL, + 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL, + 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL, + 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL, + 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL, + 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL, + 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL, + 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL, + 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL, + 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL, + 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL, + 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL, + 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL, + 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL, + 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL, + 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL, + 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL, + 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL, + 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL, + 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL, + 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL, + 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL, + 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL, + 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL, + 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL, + 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL, + 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL, + 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL, + 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL, + 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL, + 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL, + 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL, + 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL, + 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL, + 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL, + 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL, + 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL, + 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL, + 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL, + 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL, + 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL, + 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL, + 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL, + 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL, + 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL, + 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL, + 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL, + 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL, + 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL, + 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL, + 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL, + 0xbe9834edUL + }, + { + 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL, + 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL, + 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL, + 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL, + 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL, + 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL, + 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL, + 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL, + 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL, + 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL, + 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL, + 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL, + 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL, + 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL, + 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL, + 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL, + 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL, + 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL, + 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL, + 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL, + 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL, + 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL, + 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL, + 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL, + 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL, + 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL, + 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL, + 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL, + 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL, + 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL, + 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL, + 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL, + 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL, + 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL, + 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL, + 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL, + 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL, + 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL, + 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL, + 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL, + 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL, + 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL, + 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL, + 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL, + 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL, + 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL, + 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL, + 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL, + 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL, + 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL, + 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL, + 0xde0506f1UL + }, + { + 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL, + 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL, + 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL, + 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL, + 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL, + 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL, + 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL, + 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL, + 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL, + 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL, + 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL, + 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL, + 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL, + 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL, + 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL, + 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL, + 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL, + 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL, + 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL, + 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL, + 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL, + 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL, + 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL, + 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL, + 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL, + 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL, + 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL, + 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL, + 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL, + 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL, + 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL, + 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL, + 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL, + 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL, + 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL, + 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL, + 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL, + 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL, + 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL, + 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL, + 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL, + 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL, + 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL, + 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL, + 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL, + 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL, + 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL, + 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL, + 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL, + 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL, + 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL, + 0x8def022dUL + }, + { + 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL, + 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL, + 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL, + 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL, + 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL, + 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL, + 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL, + 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL, + 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL, + 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL, + 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL, + 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL, + 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL, + 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL, + 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL, + 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL, + 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL, + 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL, + 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL, + 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL, + 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL, + 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL, + 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL, + 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL, + 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL, + 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL, + 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL, + 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL, + 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL, + 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL, + 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL, + 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL, + 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL, + 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL, + 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL, + 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL, + 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL, + 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL, + 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL, + 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL, + 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL, + 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL, + 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL, + 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL, + 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL, + 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL, + 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL, + 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL, + 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL, + 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL, + 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL, + 0x72fd2493UL + }, + { + 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL, + 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL, + 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL, + 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL, + 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL, + 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL, + 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL, + 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL, + 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL, + 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL, + 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL, + 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL, + 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL, + 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL, + 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL, + 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL, + 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL, + 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL, + 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL, + 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL, + 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL, + 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL, + 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL, + 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL, + 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL, + 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL, + 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL, + 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL, + 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL, + 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL, + 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL, + 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL, + 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL, + 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL, + 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL, + 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL, + 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL, + 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL, + 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL, + 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL, + 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL, + 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL, + 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL, + 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL, + 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL, + 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL, + 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL, + 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL, + 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL, + 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL, + 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL, + 0xed3498beUL + }, + { + 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL, + 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL, + 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL, + 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL, + 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL, + 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL, + 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL, + 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL, + 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL, + 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL, + 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL, + 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL, + 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL, + 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL, + 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL, + 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL, + 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL, + 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL, + 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL, + 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL, + 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL, + 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL, + 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL, + 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL, + 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL, + 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL, + 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL, + 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL, + 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL, + 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL, + 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL, + 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL, + 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL, + 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL, + 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL, + 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL, + 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL, + 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL, + 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL, + 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL, + 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL, + 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL, + 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL, + 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL, + 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL, + 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL, + 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL, + 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL, + 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL, + 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL, + 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL, + 0xf10605deUL +#endif + } +}; diff --git a/fceumm/utils/zlib/deflate.c b/fceumm/utils/zlib/deflate.c new file mode 100644 index 0000000..5c4022f --- /dev/null +++ b/fceumm/utils/zlib/deflate.c @@ -0,0 +1,1834 @@ +/* deflate.c -- compress data using the deflation algorithm + * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + * ALGORITHM + * + * The "deflation" process depends on being able to identify portions + * of the input text which are identical to earlier input (within a + * sliding window trailing behind the input currently being processed). + * + * The most straightforward technique turns out to be the fastest for + * most input files: try all possible matches and select the longest. + * The key feature of this algorithm is that insertions into the string + * dictionary are very simple and thus fast, and deletions are avoided + * completely. Insertions are performed at each input character, whereas + * string matches are performed only when the previous match ends. So it + * is preferable to spend more time in matches to allow very fast string + * insertions and avoid deletions. The matching algorithm for small + * strings is inspired from that of Rabin & Karp. A brute force approach + * is used to find longer strings when a small match has been found. + * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze + * (by Leonid Broukhis). + * A previous version of this file used a more sophisticated algorithm + * (by Fiala and Greene) which is guaranteed to run in linear amortized + * time, but has a larger average cost, uses more memory and is patented. + * However the F&G algorithm may be faster for some highly redundant + * files if the parameter max_chain_length (described below) is too large. + * + * ACKNOWLEDGEMENTS + * + * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and + * I found it in 'freeze' written by Leonid Broukhis. + * Thanks to many people for bug reports and testing. + * + * REFERENCES + * + * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". + * Available in http://www.ietf.org/rfc/rfc1951.txt + * + * A description of the Rabin and Karp algorithm is given in the book + * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. + * + * Fiala,E.R., and Greene,D.H. + * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 + * + */ + +/* @(#) $Id$ */ + +#include "deflate.h" + +const char deflate_copyright[] = + " deflate 1.2.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler "; +/* + If you use the zlib library in a product, an acknowledgment is welcome + in the documentation of your product. If for some reason you cannot + include such an acknowledgment, I would appreciate that you keep this + copyright string in the executable of your product. + */ + +/* =========================================================================== + * Function prototypes. + */ +typedef enum { + need_more, /* block not completed, need more input or more output */ + block_done, /* block flush performed */ + finish_started, /* finish started, need only more output at next deflate */ + finish_done /* finish done, accept no more input or output */ +} block_state; + +typedef block_state (*compress_func) OF((deflate_state *s, int flush)); +/* Compression function. Returns the block state after the call. */ + +local void fill_window OF((deflate_state *s)); +local block_state deflate_stored OF((deflate_state *s, int flush)); +local block_state deflate_fast OF((deflate_state *s, int flush)); +#ifndef FASTEST +local block_state deflate_slow OF((deflate_state *s, int flush)); +#endif +local block_state deflate_rle OF((deflate_state *s, int flush)); +local block_state deflate_huff OF((deflate_state *s, int flush)); +local void lm_init OF((deflate_state *s)); +local void putShortMSB OF((deflate_state *s, uInt b)); +local void flush_pending OF((z_streamp strm)); +local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); +#ifdef ASMV + void match_init OF((void)); /* asm code initialization */ + uInt longest_match OF((deflate_state *s, IPos cur_match)); +#else +local uInt longest_match OF((deflate_state *s, IPos cur_match)); +#endif + +#ifdef DEBUG +local void check_match OF((deflate_state *s, IPos start, IPos match, + int length)); +#endif + +/* =========================================================================== + * Local data + */ + +#define NIL 0 +/* Tail of hash chains */ + +#ifndef TOO_FAR +# define TOO_FAR 4096 +#endif +/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ + +/* Values for max_lazy_match, good_match and max_chain_length, depending on + * the desired pack level (0..9). The values given below have been tuned to + * exclude worst case performance for pathological files. Better values may be + * found for specific files. + */ +typedef struct config_s { + ush good_length; /* reduce lazy search above this match length */ + ush max_lazy; /* do not perform lazy search above this match length */ + ush nice_length; /* quit search above this match length */ + ush max_chain; + compress_func func; +} config; + +#ifdef FASTEST +local const config configuration_table[2] = { +/* good lazy nice chain */ +/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ +/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */ +#else +local const config configuration_table[10] = { +/* good lazy nice chain */ +/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ +/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */ +/* 2 */ {4, 5, 16, 8, deflate_fast}, +/* 3 */ {4, 6, 32, 32, deflate_fast}, + +/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ +/* 5 */ {8, 16, 32, 32, deflate_slow}, +/* 6 */ {8, 16, 128, 128, deflate_slow}, +/* 7 */ {8, 32, 128, 256, deflate_slow}, +/* 8 */ {32, 128, 258, 1024, deflate_slow}, +/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */ +#endif + +/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 + * For deflate_fast() (levels <= 3) good is ignored and lazy has a different + * meaning. + */ + +#define EQUAL 0 +/* result of memcmp for equal strings */ + +#ifndef NO_DUMMY_DECL +struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ +#endif + +/* =========================================================================== + * Update a hash value with the given input byte + * IN assertion: all calls to to UPDATE_HASH are made with consecutive + * input characters, so that a running hash key can be computed from the + * previous key instead of complete recalculation each time. + */ +#define UPDATE_HASH(s,h,c) (h = (((h)<hash_shift) ^ (c)) & s->hash_mask) + + +/* =========================================================================== + * Insert string str in the dictionary and set match_head to the previous head + * of the hash chain (the most recent string with same hash key). Return + * the previous length of the hash chain. + * If this file is compiled with -DFASTEST, the compression level is forced + * to 1, and no hash chains are maintained. + * IN assertion: all calls to to INSERT_STRING are made with consecutive + * input characters and the first MIN_MATCH bytes of str are valid + * (except for the last MIN_MATCH-1 bytes of the input file). + */ +#ifdef FASTEST +#define INSERT_STRING(s, str, match_head) \ + (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ + match_head = s->head[s->ins_h], \ + s->head[s->ins_h] = (Pos)(str)) +#else +#define INSERT_STRING(s, str, match_head) \ + (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ + match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \ + s->head[s->ins_h] = (Pos)(str)) +#endif + +/* =========================================================================== + * Initialize the hash table (avoiding 64K overflow for 16 bit systems). + * prev[] will be initialized on the fly. + */ +#define CLEAR_HASH(s) \ + s->head[s->hash_size-1] = NIL; \ + zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); + +/* ========================================================================= */ +int ZEXPORT deflateInit_(strm, level, version, stream_size) + z_streamp strm; + int level; + const char *version; + int stream_size; +{ + return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, + Z_DEFAULT_STRATEGY, version, stream_size); + /* To do: ignore strm->next_in if we use it as window */ +} + +/* ========================================================================= */ +int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, + version, stream_size) + z_streamp strm; + int level; + int method; + int windowBits; + int memLevel; + int strategy; + const char *version; + int stream_size; +{ + deflate_state *s; + int wrap = 1; + static const char my_version[] = ZLIB_VERSION; + + ushf *overlay; + /* We overlay pending_buf and d_buf+l_buf. This works since the average + * output size for (length,distance) codes is <= 24 bits. + */ + + if (version == Z_NULL || version[0] != my_version[0] || + stream_size != sizeof(z_stream)) { + return Z_VERSION_ERROR; + } + if (strm == Z_NULL) return Z_STREAM_ERROR; + + strm->msg = Z_NULL; + if (strm->zalloc == (alloc_func)0) { + strm->zalloc = zcalloc; + strm->opaque = (voidpf)0; + } + if (strm->zfree == (free_func)0) strm->zfree = zcfree; + +#ifdef FASTEST + if (level != 0) level = 1; +#else + if (level == Z_DEFAULT_COMPRESSION) level = 6; +#endif + + if (windowBits < 0) { /* suppress zlib wrapper */ + wrap = 0; + windowBits = -windowBits; + } +#ifdef GZIP + else if (windowBits > 15) { + wrap = 2; /* write gzip wrapper instead */ + windowBits -= 16; + } +#endif + if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || + windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || + strategy < 0 || strategy > Z_FIXED) { + return Z_STREAM_ERROR; + } + if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ + s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); + if (s == Z_NULL) return Z_MEM_ERROR; + strm->state = (struct internal_state FAR *)s; + s->strm = strm; + + s->wrap = wrap; + s->gzhead = Z_NULL; + s->w_bits = windowBits; + s->w_size = 1 << s->w_bits; + s->w_mask = s->w_size - 1; + + s->hash_bits = memLevel + 7; + s->hash_size = 1 << s->hash_bits; + s->hash_mask = s->hash_size - 1; + s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); + + s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); + s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); + s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); + + s->high_water = 0; /* nothing written to s->window yet */ + + s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ + + overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); + s->pending_buf = (uchf *) overlay; + s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); + + if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || + s->pending_buf == Z_NULL) { + s->status = FINISH_STATE; + strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); + deflateEnd (strm); + return Z_MEM_ERROR; + } + s->d_buf = overlay + s->lit_bufsize/sizeof(ush); + s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; + + s->level = level; + s->strategy = strategy; + s->method = (Byte)method; + + return deflateReset(strm); +} + +/* ========================================================================= */ +int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) + z_streamp strm; + const Bytef *dictionary; + uInt dictLength; +{ + deflate_state *s; + uInt length = dictLength; + uInt n; + IPos hash_head = 0; + + if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL || + strm->state->wrap == 2 || + (strm->state->wrap == 1 && strm->state->status != INIT_STATE)) + return Z_STREAM_ERROR; + + s = strm->state; + if (s->wrap) + strm->adler = adler32(strm->adler, dictionary, dictLength); + + if (length < MIN_MATCH) return Z_OK; + if (length > s->w_size) { + length = s->w_size; + dictionary += dictLength - length; /* use the tail of the dictionary */ + } + zmemcpy(s->window, dictionary, length); + s->strstart = length; + s->block_start = (long)length; + + /* Insert all strings in the hash table (except for the last two bytes). + * s->lookahead stays null, so s->ins_h will be recomputed at the next + * call of fill_window. + */ + s->ins_h = s->window[0]; + UPDATE_HASH(s, s->ins_h, s->window[1]); + for (n = 0; n <= length - MIN_MATCH; n++) { + INSERT_STRING(s, n, hash_head); + } + if (hash_head) hash_head = 0; /* to make compiler happy */ + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflateReset (strm) + z_streamp strm; +{ + deflate_state *s; + + if (strm == Z_NULL || strm->state == Z_NULL || + strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) { + return Z_STREAM_ERROR; + } + + strm->total_in = strm->total_out = 0; + strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ + strm->data_type = Z_UNKNOWN; + + s = (deflate_state *)strm->state; + s->pending = 0; + s->pending_out = s->pending_buf; + + if (s->wrap < 0) { + s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */ + } + s->status = s->wrap ? INIT_STATE : BUSY_STATE; + strm->adler = +#ifdef GZIP + s->wrap == 2 ? crc32(0L, Z_NULL, 0) : +#endif + adler32(0L, Z_NULL, 0); + s->last_flush = Z_NO_FLUSH; + + _tr_init(s); + lm_init(s); + + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflateSetHeader (strm, head) + z_streamp strm; + gz_headerp head; +{ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + if (strm->state->wrap != 2) return Z_STREAM_ERROR; + strm->state->gzhead = head; + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflatePrime (strm, bits, value) + z_streamp strm; + int bits; + int value; +{ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + strm->state->bi_valid = bits; + strm->state->bi_buf = (ush)(value & ((1 << bits) - 1)); + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflateParams(strm, level, strategy) + z_streamp strm; + int level; + int strategy; +{ + deflate_state *s; + compress_func func; + int err = Z_OK; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + s = strm->state; + +#ifdef FASTEST + if (level != 0) level = 1; +#else + if (level == Z_DEFAULT_COMPRESSION) level = 6; +#endif + if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { + return Z_STREAM_ERROR; + } + func = configuration_table[s->level].func; + + if ((strategy != s->strategy || func != configuration_table[level].func) && + strm->total_in != 0) { + /* Flush the last buffer: */ + err = deflate(strm, Z_BLOCK); + } + if (s->level != level) { + s->level = level; + s->max_lazy_match = configuration_table[level].max_lazy; + s->good_match = configuration_table[level].good_length; + s->nice_match = configuration_table[level].nice_length; + s->max_chain_length = configuration_table[level].max_chain; + } + s->strategy = strategy; + return err; +} + +/* ========================================================================= */ +int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) + z_streamp strm; + int good_length; + int max_lazy; + int nice_length; + int max_chain; +{ + deflate_state *s; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + s = strm->state; + s->good_match = good_length; + s->max_lazy_match = max_lazy; + s->nice_match = nice_length; + s->max_chain_length = max_chain; + return Z_OK; +} + +/* ========================================================================= + * For the default windowBits of 15 and memLevel of 8, this function returns + * a close to exact, as well as small, upper bound on the compressed size. + * They are coded as constants here for a reason--if the #define's are + * changed, then this function needs to be changed as well. The return + * value for 15 and 8 only works for those exact settings. + * + * For any setting other than those defaults for windowBits and memLevel, + * the value returned is a conservative worst case for the maximum expansion + * resulting from using fixed blocks instead of stored blocks, which deflate + * can emit on compressed data for some combinations of the parameters. + * + * This function could be more sophisticated to provide closer upper bounds for + * every combination of windowBits and memLevel. But even the conservative + * upper bound of about 14% expansion does not seem onerous for output buffer + * allocation. + */ +uLong ZEXPORT deflateBound(strm, sourceLen) + z_streamp strm; + uLong sourceLen; +{ + deflate_state *s; + uLong complen, wraplen; + Bytef *str; + + /* conservative upper bound for compressed data */ + complen = sourceLen + + ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; + + /* if can't get parameters, return conservative bound plus zlib wrapper */ + if (strm == Z_NULL || strm->state == Z_NULL) + return complen + 6; + + /* compute wrapper length */ + s = strm->state; + switch (s->wrap) { + case 0: /* raw deflate */ + wraplen = 0; + break; + case 1: /* zlib wrapper */ + wraplen = 6 + (s->strstart ? 4 : 0); + break; + case 2: /* gzip wrapper */ + wraplen = 18; + if (s->gzhead != Z_NULL) { /* user-supplied gzip header */ + if (s->gzhead->extra != Z_NULL) + wraplen += 2 + s->gzhead->extra_len; + str = s->gzhead->name; + if (str != Z_NULL) + do { + wraplen++; + } while (*str++); + str = s->gzhead->comment; + if (str != Z_NULL) + do { + wraplen++; + } while (*str++); + if (s->gzhead->hcrc) + wraplen += 2; + } + break; + default: /* for compiler happiness */ + wraplen = 6; + } + + /* if not default parameters, return conservative bound */ + if (s->w_bits != 15 || s->hash_bits != 8 + 7) + return complen + wraplen; + + /* default settings: return tight bound for that case */ + return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + + (sourceLen >> 25) + 13 - 6 + wraplen; +} + +/* ========================================================================= + * Put a short in the pending buffer. The 16-bit value is put in MSB order. + * IN assertion: the stream state is correct and there is enough room in + * pending_buf. + */ +local void putShortMSB (s, b) + deflate_state *s; + uInt b; +{ + put_byte(s, (Byte)(b >> 8)); + put_byte(s, (Byte)(b & 0xff)); +} + +/* ========================================================================= + * Flush as much pending output as possible. All deflate() output goes + * through this function so some applications may wish to modify it + * to avoid allocating a large strm->next_out buffer and copying into it. + * (See also read_buf()). + */ +local void flush_pending(strm) + z_streamp strm; +{ + unsigned len = strm->state->pending; + + if (len > strm->avail_out) len = strm->avail_out; + if (len == 0) return; + + zmemcpy(strm->next_out, strm->state->pending_out, len); + strm->next_out += len; + strm->state->pending_out += len; + strm->total_out += len; + strm->avail_out -= len; + strm->state->pending -= len; + if (strm->state->pending == 0) { + strm->state->pending_out = strm->state->pending_buf; + } +} + +/* ========================================================================= */ +int ZEXPORT deflate (strm, flush) + z_streamp strm; + int flush; +{ + int old_flush; /* value of flush param for previous deflate call */ + deflate_state *s; + + if (strm == Z_NULL || strm->state == Z_NULL || + flush > Z_BLOCK || flush < 0) { + return Z_STREAM_ERROR; + } + s = strm->state; + + if (strm->next_out == Z_NULL || + (strm->next_in == Z_NULL && strm->avail_in != 0) || + (s->status == FINISH_STATE && flush != Z_FINISH)) { + ERR_RETURN(strm, Z_STREAM_ERROR); + } + if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); + + s->strm = strm; /* just in case */ + old_flush = s->last_flush; + s->last_flush = flush; + + /* Write the header */ + if (s->status == INIT_STATE) { +#ifdef GZIP + if (s->wrap == 2) { + strm->adler = crc32(0L, Z_NULL, 0); + put_byte(s, 31); + put_byte(s, 139); + put_byte(s, 8); + if (s->gzhead == Z_NULL) { + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, s->level == 9 ? 2 : + (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? + 4 : 0)); + put_byte(s, OS_CODE); + s->status = BUSY_STATE; + } + else { + put_byte(s, (s->gzhead->text ? 1 : 0) + + (s->gzhead->hcrc ? 2 : 0) + + (s->gzhead->extra == Z_NULL ? 0 : 4) + + (s->gzhead->name == Z_NULL ? 0 : 8) + + (s->gzhead->comment == Z_NULL ? 0 : 16) + ); + put_byte(s, (Byte)(s->gzhead->time & 0xff)); + put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); + put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); + put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); + put_byte(s, s->level == 9 ? 2 : + (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? + 4 : 0)); + put_byte(s, s->gzhead->os & 0xff); + if (s->gzhead->extra != Z_NULL) { + put_byte(s, s->gzhead->extra_len & 0xff); + put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); + } + if (s->gzhead->hcrc) + strm->adler = crc32(strm->adler, s->pending_buf, + s->pending); + s->gzindex = 0; + s->status = EXTRA_STATE; + } + } + else +#endif + { + uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; + uInt level_flags; + + if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) + level_flags = 0; + else if (s->level < 6) + level_flags = 1; + else if (s->level == 6) + level_flags = 2; + else + level_flags = 3; + header |= (level_flags << 6); + if (s->strstart != 0) header |= PRESET_DICT; + header += 31 - (header % 31); + + s->status = BUSY_STATE; + putShortMSB(s, header); + + /* Save the adler32 of the preset dictionary: */ + if (s->strstart != 0) { + putShortMSB(s, (uInt)(strm->adler >> 16)); + putShortMSB(s, (uInt)(strm->adler & 0xffff)); + } + strm->adler = adler32(0L, Z_NULL, 0); + } + } +#ifdef GZIP + if (s->status == EXTRA_STATE) { + if (s->gzhead->extra != Z_NULL) { + uInt beg = s->pending; /* start of bytes to update crc */ + + while (s->gzindex < (s->gzhead->extra_len & 0xffff)) { + if (s->pending == s->pending_buf_size) { + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + flush_pending(strm); + beg = s->pending; + if (s->pending == s->pending_buf_size) + break; + } + put_byte(s, s->gzhead->extra[s->gzindex]); + s->gzindex++; + } + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + if (s->gzindex == s->gzhead->extra_len) { + s->gzindex = 0; + s->status = NAME_STATE; + } + } + else + s->status = NAME_STATE; + } + if (s->status == NAME_STATE) { + if (s->gzhead->name != Z_NULL) { + uInt beg = s->pending; /* start of bytes to update crc */ + int val; + + do { + if (s->pending == s->pending_buf_size) { + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + flush_pending(strm); + beg = s->pending; + if (s->pending == s->pending_buf_size) { + val = 1; + break; + } + } + val = s->gzhead->name[s->gzindex++]; + put_byte(s, val); + } while (val != 0); + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + if (val == 0) { + s->gzindex = 0; + s->status = COMMENT_STATE; + } + } + else + s->status = COMMENT_STATE; + } + if (s->status == COMMENT_STATE) { + if (s->gzhead->comment != Z_NULL) { + uInt beg = s->pending; /* start of bytes to update crc */ + int val; + + do { + if (s->pending == s->pending_buf_size) { + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + flush_pending(strm); + beg = s->pending; + if (s->pending == s->pending_buf_size) { + val = 1; + break; + } + } + val = s->gzhead->comment[s->gzindex++]; + put_byte(s, val); + } while (val != 0); + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + if (val == 0) + s->status = HCRC_STATE; + } + else + s->status = HCRC_STATE; + } + if (s->status == HCRC_STATE) { + if (s->gzhead->hcrc) { + if (s->pending + 2 > s->pending_buf_size) + flush_pending(strm); + if (s->pending + 2 <= s->pending_buf_size) { + put_byte(s, (Byte)(strm->adler & 0xff)); + put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); + strm->adler = crc32(0L, Z_NULL, 0); + s->status = BUSY_STATE; + } + } + else + s->status = BUSY_STATE; + } +#endif + + /* Flush as much pending output as possible */ + if (s->pending != 0) { + flush_pending(strm); + if (strm->avail_out == 0) { + /* Since avail_out is 0, deflate will be called again with + * more output space, but possibly with both pending and + * avail_in equal to zero. There won't be anything to do, + * but this is not an error situation so make sure we + * return OK instead of BUF_ERROR at next call of deflate: + */ + s->last_flush = -1; + return Z_OK; + } + + /* Make sure there is something to do and avoid duplicate consecutive + * flushes. For repeated and useless calls with Z_FINISH, we keep + * returning Z_STREAM_END instead of Z_BUF_ERROR. + */ + } else if (strm->avail_in == 0 && flush <= old_flush && + flush != Z_FINISH) { + ERR_RETURN(strm, Z_BUF_ERROR); + } + + /* User must not provide more input after the first FINISH: */ + if (s->status == FINISH_STATE && strm->avail_in != 0) { + ERR_RETURN(strm, Z_BUF_ERROR); + } + + /* Start a new block or continue the current one. + */ + if (strm->avail_in != 0 || s->lookahead != 0 || + (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { + block_state bstate; + + bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : + (s->strategy == Z_RLE ? deflate_rle(s, flush) : + (*(configuration_table[s->level].func))(s, flush)); + + if (bstate == finish_started || bstate == finish_done) { + s->status = FINISH_STATE; + } + if (bstate == need_more || bstate == finish_started) { + if (strm->avail_out == 0) { + s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ + } + return Z_OK; + /* If flush != Z_NO_FLUSH && avail_out == 0, the next call + * of deflate should use the same flush parameter to make sure + * that the flush is complete. So we don't have to output an + * empty block here, this will be done at next call. This also + * ensures that for a very small output buffer, we emit at most + * one empty block. + */ + } + if (bstate == block_done) { + if (flush == Z_PARTIAL_FLUSH) { + _tr_align(s); + } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */ + _tr_stored_block(s, (char*)0, 0L, 0); + /* For a full flush, this empty block will be recognized + * as a special marker by inflate_sync(). + */ + if (flush == Z_FULL_FLUSH) { + CLEAR_HASH(s); /* forget history */ + if (s->lookahead == 0) { + s->strstart = 0; + s->block_start = 0L; + } + } + } + flush_pending(strm); + if (strm->avail_out == 0) { + s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ + return Z_OK; + } + } + } + Assert(strm->avail_out > 0, "bug2"); + + if (flush != Z_FINISH) return Z_OK; + if (s->wrap <= 0) return Z_STREAM_END; + + /* Write the trailer */ +#ifdef GZIP + if (s->wrap == 2) { + put_byte(s, (Byte)(strm->adler & 0xff)); + put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); + put_byte(s, (Byte)((strm->adler >> 16) & 0xff)); + put_byte(s, (Byte)((strm->adler >> 24) & 0xff)); + put_byte(s, (Byte)(strm->total_in & 0xff)); + put_byte(s, (Byte)((strm->total_in >> 8) & 0xff)); + put_byte(s, (Byte)((strm->total_in >> 16) & 0xff)); + put_byte(s, (Byte)((strm->total_in >> 24) & 0xff)); + } + else +#endif + { + putShortMSB(s, (uInt)(strm->adler >> 16)); + putShortMSB(s, (uInt)(strm->adler & 0xffff)); + } + flush_pending(strm); + /* If avail_out is zero, the application will call deflate again + * to flush the rest. + */ + if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */ + return s->pending != 0 ? Z_OK : Z_STREAM_END; +} + +/* ========================================================================= */ +int ZEXPORT deflateEnd (strm) + z_streamp strm; +{ + int status; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + + status = strm->state->status; + if (status != INIT_STATE && + status != EXTRA_STATE && + status != NAME_STATE && + status != COMMENT_STATE && + status != HCRC_STATE && + status != BUSY_STATE && + status != FINISH_STATE) { + return Z_STREAM_ERROR; + } + + /* Deallocate in reverse order of allocations: */ + TRY_FREE(strm, strm->state->pending_buf); + TRY_FREE(strm, strm->state->head); + TRY_FREE(strm, strm->state->prev); + TRY_FREE(strm, strm->state->window); + + ZFREE(strm, strm->state); + strm->state = Z_NULL; + + return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; +} + +/* ========================================================================= + * Copy the source state to the destination state. + * To simplify the source, this is not supported for 16-bit MSDOS (which + * doesn't have enough memory anyway to duplicate compression states). + */ +int ZEXPORT deflateCopy (dest, source) + z_streamp dest; + z_streamp source; +{ +#ifdef MAXSEG_64K + return Z_STREAM_ERROR; +#else + deflate_state *ds; + deflate_state *ss; + ushf *overlay; + + + if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { + return Z_STREAM_ERROR; + } + + ss = source->state; + + zmemcpy(dest, source, sizeof(z_stream)); + + ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); + if (ds == Z_NULL) return Z_MEM_ERROR; + dest->state = (struct internal_state FAR *) ds; + zmemcpy(ds, ss, sizeof(deflate_state)); + ds->strm = dest; + + ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); + ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); + ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); + overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); + ds->pending_buf = (uchf *) overlay; + + if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || + ds->pending_buf == Z_NULL) { + deflateEnd (dest); + return Z_MEM_ERROR; + } + /* following zmemcpy do not work for 16-bit MSDOS */ + zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); + zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos)); + zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos)); + zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); + + ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); + ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); + ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; + + ds->l_desc.dyn_tree = ds->dyn_ltree; + ds->d_desc.dyn_tree = ds->dyn_dtree; + ds->bl_desc.dyn_tree = ds->bl_tree; + + return Z_OK; +#endif /* MAXSEG_64K */ +} + +/* =========================================================================== + * Read a new buffer from the current input stream, update the adler32 + * and total number of bytes read. All deflate() input goes through + * this function so some applications may wish to modify it to avoid + * allocating a large strm->next_in buffer and copying from it. + * (See also flush_pending()). + */ +local int read_buf(strm, buf, size) + z_streamp strm; + Bytef *buf; + unsigned size; +{ + unsigned len = strm->avail_in; + + if (len > size) len = size; + if (len == 0) return 0; + + strm->avail_in -= len; + + if (strm->state->wrap == 1) { + strm->adler = adler32(strm->adler, strm->next_in, len); + } +#ifdef GZIP + else if (strm->state->wrap == 2) { + strm->adler = crc32(strm->adler, strm->next_in, len); + } +#endif + zmemcpy(buf, strm->next_in, len); + strm->next_in += len; + strm->total_in += len; + + return (int)len; +} + +/* =========================================================================== + * Initialize the "longest match" routines for a new zlib stream + */ +local void lm_init (s) + deflate_state *s; +{ + s->window_size = (ulg)2L*s->w_size; + + CLEAR_HASH(s); + + /* Set the default configuration parameters: + */ + s->max_lazy_match = configuration_table[s->level].max_lazy; + s->good_match = configuration_table[s->level].good_length; + s->nice_match = configuration_table[s->level].nice_length; + s->max_chain_length = configuration_table[s->level].max_chain; + + s->strstart = 0; + s->block_start = 0L; + s->lookahead = 0; + s->match_length = s->prev_length = MIN_MATCH-1; + s->match_available = 0; + s->ins_h = 0; +#ifndef FASTEST +#ifdef ASMV + match_init(); /* initialize the asm code */ +#endif +#endif +} + +#ifndef FASTEST +/* =========================================================================== + * Set match_start to the longest match starting at the given string and + * return its length. Matches shorter or equal to prev_length are discarded, + * in which case the result is equal to prev_length and match_start is + * garbage. + * IN assertions: cur_match is the head of the hash chain for the current + * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 + * OUT assertion: the match length is not greater than s->lookahead. + */ +#ifndef ASMV +/* For 80x86 and 680x0, an optimized version will be provided in match.asm or + * match.S. The code will be functionally equivalent. + */ +local uInt longest_match(s, cur_match) + deflate_state *s; + IPos cur_match; /* current match */ +{ + unsigned chain_length = s->max_chain_length;/* max hash chain length */ + register Bytef *scan = s->window + s->strstart; /* current string */ + register Bytef *match; /* matched string */ + register int len; /* length of current match */ + int best_len = s->prev_length; /* best match length so far */ + int nice_match = s->nice_match; /* stop if match long enough */ + IPos limit = s->strstart > (IPos)MAX_DIST(s) ? + s->strstart - (IPos)MAX_DIST(s) : NIL; + /* Stop when cur_match becomes <= limit. To simplify the code, + * we prevent matches with the string of window index 0. + */ + Posf *prev = s->prev; + uInt wmask = s->w_mask; + +#ifdef UNALIGNED_OK + /* Compare two bytes at a time. Note: this is not always beneficial. + * Try with and without -DUNALIGNED_OK to check. + */ + register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; + register ush scan_start = *(ushf*)scan; + register ush scan_end = *(ushf*)(scan+best_len-1); +#else + register Bytef *strend = s->window + s->strstart + MAX_MATCH; + register Byte scan_end1 = scan[best_len-1]; + register Byte scan_end = scan[best_len]; +#endif + + /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. + * It is easy to get rid of this optimization if necessary. + */ + Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); + + /* Do not waste too much time if we already have a good match: */ + if (s->prev_length >= s->good_match) { + chain_length >>= 2; + } + /* Do not look for matches beyond the end of the input. This is necessary + * to make deflate deterministic. + */ + if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; + + Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); + + do { + Assert(cur_match < s->strstart, "no future"); + match = s->window + cur_match; + + /* Skip to next match if the match length cannot increase + * or if the match length is less than 2. Note that the checks below + * for insufficient lookahead only occur occasionally for performance + * reasons. Therefore uninitialized memory will be accessed, and + * conditional jumps will be made that depend on those values. + * However the length of the match is limited to the lookahead, so + * the output of deflate is not affected by the uninitialized values. + */ +#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) + /* This code assumes sizeof(unsigned short) == 2. Do not use + * UNALIGNED_OK if your compiler uses a different size. + */ + if (*(ushf*)(match+best_len-1) != scan_end || + *(ushf*)match != scan_start) continue; + + /* It is not necessary to compare scan[2] and match[2] since they are + * always equal when the other bytes match, given that the hash keys + * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at + * strstart+3, +5, ... up to strstart+257. We check for insufficient + * lookahead only every 4th comparison; the 128th check will be made + * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is + * necessary to put more guard bytes at the end of the window, or + * to check more often for insufficient lookahead. + */ + Assert(scan[2] == match[2], "scan[2]?"); + scan++, match++; + do { + } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && + scan < strend); + /* The funny "do {}" generates better code on most compilers */ + + /* Here, scan <= window+strstart+257 */ + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + if (*scan == *match) scan++; + + len = (MAX_MATCH - 1) - (int)(strend-scan); + scan = strend - (MAX_MATCH-1); + +#else /* UNALIGNED_OK */ + + if (match[best_len] != scan_end || + match[best_len-1] != scan_end1 || + *match != *scan || + *++match != scan[1]) continue; + + /* The check at best_len-1 can be removed because it will be made + * again later. (This heuristic is not always a win.) + * It is not necessary to compare scan[2] and match[2] since they + * are always equal when the other bytes match, given that + * the hash keys are equal and that HASH_BITS >= 8. + */ + scan += 2, match++; + Assert(*scan == *match, "match[2]?"); + + /* We check for insufficient lookahead only every 8th comparison; + * the 256th check will be made at strstart+258. + */ + do { + } while (*++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + scan < strend); + + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + + len = MAX_MATCH - (int)(strend - scan); + scan = strend - MAX_MATCH; + +#endif /* UNALIGNED_OK */ + + if (len > best_len) { + s->match_start = cur_match; + best_len = len; + if (len >= nice_match) break; +#ifdef UNALIGNED_OK + scan_end = *(ushf*)(scan+best_len-1); +#else + scan_end1 = scan[best_len-1]; + scan_end = scan[best_len]; +#endif + } + } while ((cur_match = prev[cur_match & wmask]) > limit + && --chain_length != 0); + + if ((uInt)best_len <= s->lookahead) return (uInt)best_len; + return s->lookahead; +} +#endif /* ASMV */ + +#else /* FASTEST */ + +/* --------------------------------------------------------------------------- + * Optimized version for FASTEST only + */ +local uInt longest_match(s, cur_match) + deflate_state *s; + IPos cur_match; /* current match */ +{ + register Bytef *scan = s->window + s->strstart; /* current string */ + register Bytef *match; /* matched string */ + register int len; /* length of current match */ + register Bytef *strend = s->window + s->strstart + MAX_MATCH; + + /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. + * It is easy to get rid of this optimization if necessary. + */ + Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); + + Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); + + Assert(cur_match < s->strstart, "no future"); + + match = s->window + cur_match; + + /* Return failure if the match length is less than 2: + */ + if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; + + /* The check at best_len-1 can be removed because it will be made + * again later. (This heuristic is not always a win.) + * It is not necessary to compare scan[2] and match[2] since they + * are always equal when the other bytes match, given that + * the hash keys are equal and that HASH_BITS >= 8. + */ + scan += 2, match += 2; + Assert(*scan == *match, "match[2]?"); + + /* We check for insufficient lookahead only every 8th comparison; + * the 256th check will be made at strstart+258. + */ + do { + } while (*++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + scan < strend); + + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + + len = MAX_MATCH - (int)(strend - scan); + + if (len < MIN_MATCH) return MIN_MATCH - 1; + + s->match_start = cur_match; + return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; +} + +#endif /* FASTEST */ + +#ifdef DEBUG +/* =========================================================================== + * Check that the match at match_start is indeed a match. + */ +local void check_match(s, start, match, length) + deflate_state *s; + IPos start, match; + int length; +{ + /* check that the match is indeed a match */ + if (zmemcmp(s->window + match, + s->window + start, length) != EQUAL) { + fprintf(stderr, " start %u, match %u, length %d\n", + start, match, length); + do { + fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); + } while (--length != 0); + z_error("invalid match"); + } + if (z_verbose > 1) { + fprintf(stderr,"\\[%d,%d]", start-match, length); + do { putc(s->window[start++], stderr); } while (--length != 0); + } +} +#else +# define check_match(s, start, match, length) +#endif /* DEBUG */ + +/* =========================================================================== + * Fill the window when the lookahead becomes insufficient. + * Updates strstart and lookahead. + * + * IN assertion: lookahead < MIN_LOOKAHEAD + * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD + * At least one byte has been read, or avail_in == 0; reads are + * performed for at least two bytes (required for the zip translate_eol + * option -- not supported here). + */ +local void fill_window(s) + deflate_state *s; +{ + register unsigned n, m; + register Posf *p; + unsigned more; /* Amount of free space at the end of the window. */ + uInt wsize = s->w_size; + + do { + more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); + + /* Deal with !@#$% 64K limit: */ + if (sizeof(int) <= 2) { + if (more == 0 && s->strstart == 0 && s->lookahead == 0) { + more = wsize; + + } else if (more == (unsigned)(-1)) { + /* Very unlikely, but possible on 16 bit machine if + * strstart == 0 && lookahead == 1 (input done a byte at time) + */ + more--; + } + } + + /* If the window is almost full and there is insufficient lookahead, + * move the upper half to the lower one to make room in the upper half. + */ + if (s->strstart >= wsize+MAX_DIST(s)) { + + zmemcpy(s->window, s->window+wsize, (unsigned)wsize); + s->match_start -= wsize; + s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ + s->block_start -= (long) wsize; + + /* Slide the hash table (could be avoided with 32 bit values + at the expense of memory usage). We slide even when level == 0 + to keep the hash table consistent if we switch back to level > 0 + later. (Using level 0 permanently is not an optimal usage of + zlib, so we don't care about this pathological case.) + */ + n = s->hash_size; + p = &s->head[n]; + do { + m = *--p; + *p = (Pos)(m >= wsize ? m-wsize : NIL); + } while (--n); + + n = wsize; +#ifndef FASTEST + p = &s->prev[n]; + do { + m = *--p; + *p = (Pos)(m >= wsize ? m-wsize : NIL); + /* If n is not on any hash chain, prev[n] is garbage but + * its value will never be used. + */ + } while (--n); +#endif + more += wsize; + } + if (s->strm->avail_in == 0) return; + + /* If there was no sliding: + * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && + * more == window_size - lookahead - strstart + * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) + * => more >= window_size - 2*WSIZE + 2 + * In the BIG_MEM or MMAP case (not yet supported), + * window_size == input_size + MIN_LOOKAHEAD && + * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. + * Otherwise, window_size == 2*WSIZE so more >= 2. + * If there was sliding, more >= WSIZE. So in all cases, more >= 2. + */ + Assert(more >= 2, "more < 2"); + + n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); + s->lookahead += n; + + /* Initialize the hash value now that we have some input: */ + if (s->lookahead >= MIN_MATCH) { + s->ins_h = s->window[s->strstart]; + UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); +#if MIN_MATCH != 3 + Call UPDATE_HASH() MIN_MATCH-3 more times +#endif + } + /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, + * but this is not important since only literal bytes will be emitted. + */ + + } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); + + /* If the WIN_INIT bytes after the end of the current data have never been + * written, then zero those bytes in order to avoid memory check reports of + * the use of uninitialized (or uninitialised as Julian writes) bytes by + * the longest match routines. Update the high water mark for the next + * time through here. WIN_INIT is set to MAX_MATCH since the longest match + * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. + */ + if (s->high_water < s->window_size) { + ulg curr = s->strstart + (ulg)(s->lookahead); + ulg init; + + if (s->high_water < curr) { + /* Previous high water mark below current data -- zero WIN_INIT + * bytes or up to end of window, whichever is less. + */ + init = s->window_size - curr; + if (init > WIN_INIT) + init = WIN_INIT; + zmemzero(s->window + curr, (unsigned)init); + s->high_water = curr + init; + } + else if (s->high_water < (ulg)curr + WIN_INIT) { + /* High water mark at or above current data, but below current data + * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up + * to end of window, whichever is less. + */ + init = (ulg)curr + WIN_INIT - s->high_water; + if (init > s->window_size - s->high_water) + init = s->window_size - s->high_water; + zmemzero(s->window + s->high_water, (unsigned)init); + s->high_water += init; + } + } +} + +/* =========================================================================== + * Flush the current block, with given end-of-file flag. + * IN assertion: strstart is set to the end of the current match. + */ +#define FLUSH_BLOCK_ONLY(s, last) { \ + _tr_flush_block(s, (s->block_start >= 0L ? \ + (charf *)&s->window[(unsigned)s->block_start] : \ + (charf *)Z_NULL), \ + (ulg)((long)s->strstart - s->block_start), \ + (last)); \ + s->block_start = s->strstart; \ + flush_pending(s->strm); \ + Tracev((stderr,"[FLUSH]")); \ +} + +/* Same but force premature exit if necessary. */ +#define FLUSH_BLOCK(s, last) { \ + FLUSH_BLOCK_ONLY(s, last); \ + if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ +} + +/* =========================================================================== + * Copy without compression as much as possible from the input stream, return + * the current block state. + * This function does not insert new strings in the dictionary since + * uncompressible data is probably not useful. This function is used + * only for the level=0 compression option. + * NOTE: this function should be optimized to avoid extra copying from + * window to pending_buf. + */ +local block_state deflate_stored(s, flush) + deflate_state *s; + int flush; +{ + /* Stored blocks are limited to 0xffff bytes, pending_buf is limited + * to pending_buf_size, and each stored block has a 5 byte header: + */ + ulg max_block_size = 0xffff; + ulg max_start; + + if (max_block_size > s->pending_buf_size - 5) { + max_block_size = s->pending_buf_size - 5; + } + + /* Copy as much as possible from input to output: */ + for (;;) { + /* Fill the window as much as possible: */ + if (s->lookahead <= 1) { + + Assert(s->strstart < s->w_size+MAX_DIST(s) || + s->block_start >= (long)s->w_size, "slide too late"); + + fill_window(s); + if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; + + if (s->lookahead == 0) break; /* flush the current block */ + } + Assert(s->block_start >= 0L, "block gone"); + + s->strstart += s->lookahead; + s->lookahead = 0; + + /* Emit a stored block if pending_buf will be full: */ + max_start = s->block_start + max_block_size; + if (s->strstart == 0 || (ulg)s->strstart >= max_start) { + /* strstart == 0 is possible when wraparound on 16-bit machine */ + s->lookahead = (uInt)(s->strstart - max_start); + s->strstart = (uInt)max_start; + FLUSH_BLOCK(s, 0); + } + /* Flush if we may have to slide, otherwise block_start may become + * negative and the data will be gone: + */ + if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { + FLUSH_BLOCK(s, 0); + } + } + FLUSH_BLOCK(s, flush == Z_FINISH); + return flush == Z_FINISH ? finish_done : block_done; +} + +/* =========================================================================== + * Compress as much as possible from the input stream, return the current + * block state. + * This function does not perform lazy evaluation of matches and inserts + * new strings in the dictionary only for unmatched strings or for short + * matches. It is used only for the fast compression options. + */ +local block_state deflate_fast(s, flush) + deflate_state *s; + int flush; +{ + IPos hash_head; /* head of the hash chain */ + int bflush; /* set if current block must be flushed */ + + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the next match, plus MIN_MATCH bytes to insert the + * string following the next match. + */ + if (s->lookahead < MIN_LOOKAHEAD) { + fill_window(s); + if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { + return need_more; + } + if (s->lookahead == 0) break; /* flush the current block */ + } + + /* Insert the string window[strstart .. strstart+2] in the + * dictionary, and set hash_head to the head of the hash chain: + */ + hash_head = NIL; + if (s->lookahead >= MIN_MATCH) { + INSERT_STRING(s, s->strstart, hash_head); + } + + /* Find the longest match, discarding those <= prev_length. + * At this point we have always match_length < MIN_MATCH + */ + if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { + /* To simplify the code, we prevent matches with the string + * of window index 0 (in particular we have to avoid a match + * of the string with itself at the start of the input file). + */ + s->match_length = longest_match (s, hash_head); + /* longest_match() sets match_start */ + } + if (s->match_length >= MIN_MATCH) { + check_match(s, s->strstart, s->match_start, s->match_length); + + _tr_tally_dist(s, s->strstart - s->match_start, + s->match_length - MIN_MATCH, bflush); + + s->lookahead -= s->match_length; + + /* Insert new strings in the hash table only if the match length + * is not too large. This saves time but degrades compression. + */ +#ifndef FASTEST + if (s->match_length <= s->max_insert_length && + s->lookahead >= MIN_MATCH) { + s->match_length--; /* string at strstart already in table */ + do { + s->strstart++; + INSERT_STRING(s, s->strstart, hash_head); + /* strstart never exceeds WSIZE-MAX_MATCH, so there are + * always MIN_MATCH bytes ahead. + */ + } while (--s->match_length != 0); + s->strstart++; + } else +#endif + { + s->strstart += s->match_length; + s->match_length = 0; + s->ins_h = s->window[s->strstart]; + UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); +#if MIN_MATCH != 3 + Call UPDATE_HASH() MIN_MATCH-3 more times +#endif + /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not + * matter since it will be recomputed at next deflate call. + */ + } + } else { + /* No match, output a literal byte */ + Tracevv((stderr,"%c", s->window[s->strstart])); + _tr_tally_lit (s, s->window[s->strstart], bflush); + s->lookahead--; + s->strstart++; + } + if (bflush) FLUSH_BLOCK(s, 0); + } + FLUSH_BLOCK(s, flush == Z_FINISH); + return flush == Z_FINISH ? finish_done : block_done; +} + +#ifndef FASTEST +/* =========================================================================== + * Same as above, but achieves better compression. We use a lazy + * evaluation for matches: a match is finally adopted only if there is + * no better match at the next window position. + */ +local block_state deflate_slow(s, flush) + deflate_state *s; + int flush; +{ + IPos hash_head; /* head of hash chain */ + int bflush; /* set if current block must be flushed */ + + /* Process the input block. */ + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the next match, plus MIN_MATCH bytes to insert the + * string following the next match. + */ + if (s->lookahead < MIN_LOOKAHEAD) { + fill_window(s); + if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { + return need_more; + } + if (s->lookahead == 0) break; /* flush the current block */ + } + + /* Insert the string window[strstart .. strstart+2] in the + * dictionary, and set hash_head to the head of the hash chain: + */ + hash_head = NIL; + if (s->lookahead >= MIN_MATCH) { + INSERT_STRING(s, s->strstart, hash_head); + } + + /* Find the longest match, discarding those <= prev_length. + */ + s->prev_length = s->match_length, s->prev_match = s->match_start; + s->match_length = MIN_MATCH-1; + + if (hash_head != NIL && s->prev_length < s->max_lazy_match && + s->strstart - hash_head <= MAX_DIST(s)) { + /* To simplify the code, we prevent matches with the string + * of window index 0 (in particular we have to avoid a match + * of the string with itself at the start of the input file). + */ + s->match_length = longest_match (s, hash_head); + /* longest_match() sets match_start */ + + if (s->match_length <= 5 && (s->strategy == Z_FILTERED +#if TOO_FAR <= 32767 + || (s->match_length == MIN_MATCH && + s->strstart - s->match_start > TOO_FAR) +#endif + )) { + + /* If prev_match is also MIN_MATCH, match_start is garbage + * but we will ignore the current match anyway. + */ + s->match_length = MIN_MATCH-1; + } + } + /* If there was a match at the previous step and the current + * match is not better, output the previous match: + */ + if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { + uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; + /* Do not insert strings in hash table beyond this. */ + + check_match(s, s->strstart-1, s->prev_match, s->prev_length); + + _tr_tally_dist(s, s->strstart -1 - s->prev_match, + s->prev_length - MIN_MATCH, bflush); + + /* Insert in hash table all strings up to the end of the match. + * strstart-1 and strstart are already inserted. If there is not + * enough lookahead, the last two strings are not inserted in + * the hash table. + */ + s->lookahead -= s->prev_length-1; + s->prev_length -= 2; + do { + if (++s->strstart <= max_insert) { + INSERT_STRING(s, s->strstart, hash_head); + } + } while (--s->prev_length != 0); + s->match_available = 0; + s->match_length = MIN_MATCH-1; + s->strstart++; + + if (bflush) FLUSH_BLOCK(s, 0); + + } else if (s->match_available) { + /* If there was no match at the previous position, output a + * single literal. If there was a match but the current match + * is longer, truncate the previous match to a single literal. + */ + Tracevv((stderr,"%c", s->window[s->strstart-1])); + _tr_tally_lit(s, s->window[s->strstart-1], bflush); + if (bflush) { + FLUSH_BLOCK_ONLY(s, 0); + } + s->strstart++; + s->lookahead--; + if (s->strm->avail_out == 0) return need_more; + } else { + /* There is no previous match to compare with, wait for + * the next step to decide. + */ + s->match_available = 1; + s->strstart++; + s->lookahead--; + } + } + Assert (flush != Z_NO_FLUSH, "no flush?"); + if (s->match_available) { + Tracevv((stderr,"%c", s->window[s->strstart-1])); + _tr_tally_lit(s, s->window[s->strstart-1], bflush); + s->match_available = 0; + } + FLUSH_BLOCK(s, flush == Z_FINISH); + return flush == Z_FINISH ? finish_done : block_done; +} +#endif /* FASTEST */ + +/* =========================================================================== + * For Z_RLE, simply look for runs of bytes, generate matches only of distance + * one. Do not maintain a hash table. (It will be regenerated if this run of + * deflate switches away from Z_RLE.) + */ +local block_state deflate_rle(s, flush) + deflate_state *s; + int flush; +{ + int bflush; /* set if current block must be flushed */ + uInt prev; /* byte at distance one to match */ + Bytef *scan, *strend; /* scan goes up to strend for length of run */ + + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the longest encodable run. + */ + if (s->lookahead < MAX_MATCH) { + fill_window(s); + if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) { + return need_more; + } + if (s->lookahead == 0) break; /* flush the current block */ + } + + /* See how many times the previous byte repeats */ + s->match_length = 0; + if (s->lookahead >= MIN_MATCH && s->strstart > 0) { + scan = s->window + s->strstart - 1; + prev = *scan; + if (prev == *++scan && prev == *++scan && prev == *++scan) { + strend = s->window + s->strstart + MAX_MATCH; + do { + } while (prev == *++scan && prev == *++scan && + prev == *++scan && prev == *++scan && + prev == *++scan && prev == *++scan && + prev == *++scan && prev == *++scan && + scan < strend); + s->match_length = MAX_MATCH - (int)(strend - scan); + if (s->match_length > s->lookahead) + s->match_length = s->lookahead; + } + } + + /* Emit match if have run of MIN_MATCH or longer, else emit literal */ + if (s->match_length >= MIN_MATCH) { + check_match(s, s->strstart, s->strstart - 1, s->match_length); + + _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush); + + s->lookahead -= s->match_length; + s->strstart += s->match_length; + s->match_length = 0; + } else { + /* No match, output a literal byte */ + Tracevv((stderr,"%c", s->window[s->strstart])); + _tr_tally_lit (s, s->window[s->strstart], bflush); + s->lookahead--; + s->strstart++; + } + if (bflush) FLUSH_BLOCK(s, 0); + } + FLUSH_BLOCK(s, flush == Z_FINISH); + return flush == Z_FINISH ? finish_done : block_done; +} + +/* =========================================================================== + * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. + * (It will be regenerated if this run of deflate switches away from Huffman.) + */ +local block_state deflate_huff(s, flush) + deflate_state *s; + int flush; +{ + int bflush; /* set if current block must be flushed */ + + for (;;) { + /* Make sure that we have a literal to write. */ + if (s->lookahead == 0) { + fill_window(s); + if (s->lookahead == 0) { + if (flush == Z_NO_FLUSH) + return need_more; + break; /* flush the current block */ + } + } + + /* Output a literal byte */ + s->match_length = 0; + Tracevv((stderr,"%c", s->window[s->strstart])); + _tr_tally_lit (s, s->window[s->strstart], bflush); + s->lookahead--; + s->strstart++; + if (bflush) FLUSH_BLOCK(s, 0); + } + FLUSH_BLOCK(s, flush == Z_FINISH); + return flush == Z_FINISH ? finish_done : block_done; +} diff --git a/fceumm/utils/zlib/deflate.h b/fceumm/utils/zlib/deflate.h new file mode 100644 index 0000000..cbf0d1e --- /dev/null +++ b/fceumm/utils/zlib/deflate.h @@ -0,0 +1,342 @@ +/* deflate.h -- internal compression state + * Copyright (C) 1995-2010 Jean-loup Gailly + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* @(#) $Id$ */ + +#ifndef DEFLATE_H +#define DEFLATE_H + +#include "zutil.h" + +/* define NO_GZIP when compiling if you want to disable gzip header and + trailer creation by deflate(). NO_GZIP would be used to avoid linking in + the crc code when it is not needed. For shared libraries, gzip encoding + should be left enabled. */ +#ifndef NO_GZIP +# define GZIP +#endif + +/* =========================================================================== + * Internal compression state. + */ + +#define LENGTH_CODES 29 +/* number of length codes, not counting the special END_BLOCK code */ + +#define LITERALS 256 +/* number of literal bytes 0..255 */ + +#define L_CODES (LITERALS+1+LENGTH_CODES) +/* number of Literal or Length codes, including the END_BLOCK code */ + +#define D_CODES 30 +/* number of distance codes */ + +#define BL_CODES 19 +/* number of codes used to transfer the bit lengths */ + +#define HEAP_SIZE (2*L_CODES+1) +/* maximum heap size */ + +#define MAX_BITS 15 +/* All codes must not exceed MAX_BITS bits */ + +#define INIT_STATE 42 +#define EXTRA_STATE 69 +#define NAME_STATE 73 +#define COMMENT_STATE 91 +#define HCRC_STATE 103 +#define BUSY_STATE 113 +#define FINISH_STATE 666 +/* Stream status */ + + +/* Data structure describing a single value and its code string. */ +typedef struct ct_data_s { + union { + ush freq; /* frequency count */ + ush code; /* bit string */ + } fc; + union { + ush dad; /* father node in Huffman tree */ + ush len; /* length of bit string */ + } dl; +} FAR ct_data; + +#define Freq fc.freq +#define Code fc.code +#define Dad dl.dad +#define Len dl.len + +typedef struct static_tree_desc_s static_tree_desc; + +typedef struct tree_desc_s { + ct_data *dyn_tree; /* the dynamic tree */ + int max_code; /* largest code with non zero frequency */ + static_tree_desc *stat_desc; /* the corresponding static tree */ +} FAR tree_desc; + +typedef ush Pos; +typedef Pos FAR Posf; +typedef unsigned IPos; + +/* A Pos is an index in the character window. We use short instead of int to + * save space in the various tables. IPos is used only for parameter passing. + */ + +typedef struct internal_state { + z_streamp strm; /* pointer back to this zlib stream */ + int status; /* as the name implies */ + Bytef *pending_buf; /* output still pending */ + ulg pending_buf_size; /* size of pending_buf */ + Bytef *pending_out; /* next pending byte to output to the stream */ + uInt pending; /* nb of bytes in the pending buffer */ + int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ + gz_headerp gzhead; /* gzip header information to write */ + uInt gzindex; /* where in extra, name, or comment */ + Byte method; /* STORED (for zip only) or DEFLATED */ + int last_flush; /* value of flush param for previous deflate call */ + + /* used by deflate.c: */ + + uInt w_size; /* LZ77 window size (32K by default) */ + uInt w_bits; /* log2(w_size) (8..16) */ + uInt w_mask; /* w_size - 1 */ + + Bytef *window; + /* Sliding window. Input bytes are read into the second half of the window, + * and move to the first half later to keep a dictionary of at least wSize + * bytes. With this organization, matches are limited to a distance of + * wSize-MAX_MATCH bytes, but this ensures that IO is always + * performed with a length multiple of the block size. Also, it limits + * the window size to 64K, which is quite useful on MSDOS. + * To do: use the user input buffer as sliding window. + */ + + ulg window_size; + /* Actual size of window: 2*wSize, except when the user input buffer + * is directly used as sliding window. + */ + + Posf *prev; + /* Link to older string with same hash index. To limit the size of this + * array to 64K, this link is maintained only for the last 32K strings. + * An index in this array is thus a window index modulo 32K. + */ + + Posf *head; /* Heads of the hash chains or NIL. */ + + uInt ins_h; /* hash index of string to be inserted */ + uInt hash_size; /* number of elements in hash table */ + uInt hash_bits; /* log2(hash_size) */ + uInt hash_mask; /* hash_size-1 */ + + uInt hash_shift; + /* Number of bits by which ins_h must be shifted at each input + * step. It must be such that after MIN_MATCH steps, the oldest + * byte no longer takes part in the hash key, that is: + * hash_shift * MIN_MATCH >= hash_bits + */ + + long block_start; + /* Window position at the beginning of the current output block. Gets + * negative when the window is moved backwards. + */ + + uInt match_length; /* length of best match */ + IPos prev_match; /* previous match */ + int match_available; /* set if previous match exists */ + uInt strstart; /* start of string to insert */ + uInt match_start; /* start of matching string */ + uInt lookahead; /* number of valid bytes ahead in window */ + + uInt prev_length; + /* Length of the best match at previous step. Matches not greater than this + * are discarded. This is used in the lazy match evaluation. + */ + + uInt max_chain_length; + /* To speed up deflation, hash chains are never searched beyond this + * length. A higher limit improves compression ratio but degrades the + * speed. + */ + + uInt max_lazy_match; + /* Attempt to find a better match only when the current match is strictly + * smaller than this value. This mechanism is used only for compression + * levels >= 4. + */ +# define max_insert_length max_lazy_match + /* Insert new strings in the hash table only if the match length is not + * greater than this length. This saves time but degrades compression. + * max_insert_length is used only for compression levels <= 3. + */ + + int level; /* compression level (1..9) */ + int strategy; /* favor or force Huffman coding*/ + + uInt good_match; + /* Use a faster search when the previous match is longer than this */ + + int nice_match; /* Stop searching when current match exceeds this */ + + /* used by trees.c: */ + /* Didn't use ct_data typedef below to supress compiler warning */ + struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ + struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ + struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ + + struct tree_desc_s l_desc; /* desc. for literal tree */ + struct tree_desc_s d_desc; /* desc. for distance tree */ + struct tree_desc_s bl_desc; /* desc. for bit length tree */ + + ush bl_count[MAX_BITS+1]; + /* number of codes at each bit length for an optimal tree */ + + int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ + int heap_len; /* number of elements in the heap */ + int heap_max; /* element of largest frequency */ + /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. + * The same heap array is used to build all trees. + */ + + uch depth[2*L_CODES+1]; + /* Depth of each subtree used as tie breaker for trees of equal frequency + */ + + uchf *l_buf; /* buffer for literals or lengths */ + + uInt lit_bufsize; + /* Size of match buffer for literals/lengths. There are 4 reasons for + * limiting lit_bufsize to 64K: + * - frequencies can be kept in 16 bit counters + * - if compression is not successful for the first block, all input + * data is still in the window so we can still emit a stored block even + * when input comes from standard input. (This can also be done for + * all blocks if lit_bufsize is not greater than 32K.) + * - if compression is not successful for a file smaller than 64K, we can + * even emit a stored file instead of a stored block (saving 5 bytes). + * This is applicable only for zip (not gzip or zlib). + * - creating new Huffman trees less frequently may not provide fast + * adaptation to changes in the input data statistics. (Take for + * example a binary file with poorly compressible code followed by + * a highly compressible string table.) Smaller buffer sizes give + * fast adaptation but have of course the overhead of transmitting + * trees more frequently. + * - I can't count above 4 + */ + + uInt last_lit; /* running index in l_buf */ + + ushf *d_buf; + /* Buffer for distances. To simplify the code, d_buf and l_buf have + * the same number of elements. To use different lengths, an extra flag + * array would be necessary. + */ + + ulg opt_len; /* bit length of current block with optimal trees */ + ulg static_len; /* bit length of current block with static trees */ + uInt matches; /* number of string matches in current block */ + int last_eob_len; /* bit length of EOB code for last block */ + +#ifdef DEBUG + ulg compressed_len; /* total bit length of compressed file mod 2^32 */ + ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ +#endif + + ush bi_buf; + /* Output buffer. bits are inserted starting at the bottom (least + * significant bits). + */ + int bi_valid; + /* Number of valid bits in bi_buf. All bits above the last valid bit + * are always zero. + */ + + ulg high_water; + /* High water mark offset in window for initialized bytes -- bytes above + * this are set to zero in order to avoid memory check warnings when + * longest match routines access bytes past the input. This is then + * updated to the new high water mark. + */ + +} FAR deflate_state; + +/* Output a byte on the stream. + * IN assertion: there is enough room in pending_buf. + */ +#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} + + +#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) +/* Minimum amount of lookahead, except at the end of the input file. + * See deflate.c for comments about the MIN_MATCH+1. + */ + +#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) +/* In order to simplify the code, particularly on 16 bit machines, match + * distances are limited to MAX_DIST instead of WSIZE. + */ + +#define WIN_INIT MAX_MATCH +/* Number of bytes after end of data in window to initialize in order to avoid + memory checker errors from longest match routines */ + + /* in trees.c */ +void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); +int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); +void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, + ulg stored_len, int last)); +void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); +void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, + ulg stored_len, int last)); + +#define d_code(dist) \ + ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) +/* Mapping from a distance to a distance code. dist is the distance - 1 and + * must not have side effects. _dist_code[256] and _dist_code[257] are never + * used. + */ + +#ifndef DEBUG +/* Inline versions of _tr_tally for speed: */ + +#if defined(GEN_TREES_H) || !defined(STDC) + extern uch ZLIB_INTERNAL _length_code[]; + extern uch ZLIB_INTERNAL _dist_code[]; +#else + extern const uch ZLIB_INTERNAL _length_code[]; + extern const uch ZLIB_INTERNAL _dist_code[]; +#endif + +# define _tr_tally_lit(s, c, flush) \ + { uch cc = (c); \ + s->d_buf[s->last_lit] = 0; \ + s->l_buf[s->last_lit++] = cc; \ + s->dyn_ltree[cc].Freq++; \ + flush = (s->last_lit == s->lit_bufsize-1); \ + } +# define _tr_tally_dist(s, distance, length, flush) \ + { uch len = (length); \ + ush dist = (distance); \ + s->d_buf[s->last_lit] = dist; \ + s->l_buf[s->last_lit++] = len; \ + dist--; \ + s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ + s->dyn_dtree[d_code(dist)].Freq++; \ + flush = (s->last_lit == s->lit_bufsize-1); \ + } +#else +# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) +# define _tr_tally_dist(s, distance, length, flush) \ + flush = _tr_tally(s, distance, length) +#endif + +#endif /* DEFLATE_H */ diff --git a/fceumm/utils/zlib/gzclose.c b/fceumm/utils/zlib/gzclose.c new file mode 100644 index 0000000..caeb99a --- /dev/null +++ b/fceumm/utils/zlib/gzclose.c @@ -0,0 +1,25 @@ +/* gzclose.c -- zlib gzclose() function + * Copyright (C) 2004, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "gzguts.h" + +/* gzclose() is in a separate file so that it is linked in only if it is used. + That way the other gzclose functions can be used instead to avoid linking in + unneeded compression or decompression routines. */ +int ZEXPORT gzclose(file) + gzFile file; +{ +#ifndef NO_GZCOMPRESS + gz_statep state; + + if (file == NULL) + return Z_STREAM_ERROR; + state = (gz_statep)file; + + return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); +#else + return gzclose_r(file); +#endif +} diff --git a/fceumm/utils/zlib/gzguts.h b/fceumm/utils/zlib/gzguts.h new file mode 100644 index 0000000..32401e8 --- /dev/null +++ b/fceumm/utils/zlib/gzguts.h @@ -0,0 +1,135 @@ +/* gzguts.h -- zlib internal header definitions for gz* operations + * Copyright (C) 2004, 2005, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#ifdef _LARGEFILE64_SOURCE +# ifndef _LARGEFILE_SOURCE +# define _LARGEFILE_SOURCE 1 +# endif +# ifdef _FILE_OFFSET_BITS +# undef _FILE_OFFSET_BITS +# endif +#endif + +#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ) +# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) +#else +# define ZLIB_INTERNAL +#endif + +#include +#include "zlib.h" +#ifdef STDC +# include +# include +# include +#endif +#include +#ifndef _MSC_VER +#include +#endif + +#ifdef NO_DEFLATE /* for compatibility with old definition */ +# define NO_GZCOMPRESS +#endif + +#ifdef _MSC_VER +# include +# define vsnprintf _vsnprintf +#endif + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + +/* gz* functions always use library allocation functions */ +#ifndef STDC + extern voidp malloc OF((uInt size)); + extern void free OF((voidpf ptr)); +#endif + +/* get errno and strerror definition */ +#if defined UNDER_CE +# include +# define zstrerror() gz_strwinerror((DWORD)GetLastError()) +#else +# ifdef STDC +# include +# define zstrerror() strerror(errno) +# else +# define zstrerror() "stdio error (consult errno)" +# endif +#endif + +/* provide prototypes for these when building zlib without LFS */ +#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); + ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); +#endif + +/* default i/o buffer size -- double this for output when reading */ +#define GZBUFSIZE 8192 + +/* gzip modes, also provide a little integrity check on the passed structure */ +#define GZ_NONE 0 +#define GZ_READ 7247 +#define GZ_WRITE 31153 +#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ + +/* values for gz_state how */ +#define LOOK 0 /* look for a gzip header */ +#define COPY 1 /* copy input directly */ +#define GZIP 2 /* decompress a gzip stream */ + +/* internal gzip file state data structure */ +typedef struct { + /* used for both reading and writing */ + int mode; /* see gzip modes above */ + int fd; /* file descriptor */ + char *path; /* path or fd for error messages */ + z_off64_t pos; /* current position in uncompressed data */ + unsigned size; /* buffer size, zero if not allocated yet */ + unsigned want; /* requested buffer size, default is GZBUFSIZE */ + unsigned char *in; /* input buffer */ + unsigned char *out; /* output buffer (double-sized when reading) */ + unsigned char *next; /* next output data to deliver or write */ + /* just for reading */ + unsigned have; /* amount of output data unused at next */ + int eof; /* true if end of input file reached */ + z_off64_t start; /* where the gzip data started, for rewinding */ + z_off64_t raw; /* where the raw data started, for seeking */ + int how; /* 0: get header, 1: copy, 2: decompress */ + int direct; /* true if last read direct, false if gzip */ + /* just for writing */ + int level; /* compression level */ + int strategy; /* compression strategy */ + /* seek request */ + z_off64_t skip; /* amount to skip (already rewound if backwards) */ + int seek; /* true if seek request pending */ + /* error information */ + int err; /* error code */ + char *msg; /* error message */ + /* zlib inflate or deflate stream */ + z_stream strm; /* stream structure in-place (not a pointer) */ +} gz_state; +typedef gz_state FAR *gz_statep; + +/* shared functions */ +void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); +#if defined UNDER_CE +char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); +#endif + +/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t + value -- needed when comparing unsigned to z_off64_t, which is signed + (possible z_off64_t types off_t, off64_t, and long are all signed) */ +#ifdef INT_MAX +# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) +#else +unsigned ZLIB_INTERNAL gz_intmax OF((void)); +# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) +#endif diff --git a/fceumm/utils/zlib/gzlib.c b/fceumm/utils/zlib/gzlib.c new file mode 100644 index 0000000..603e60e --- /dev/null +++ b/fceumm/utils/zlib/gzlib.c @@ -0,0 +1,537 @@ +/* gzlib.c -- zlib functions common to reading and writing gzip files + * Copyright (C) 2004, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "gzguts.h" + +#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 +# define LSEEK lseek64 +#else +# define LSEEK lseek +#endif + +/* Local functions */ +local void gz_reset OF((gz_statep)); +local gzFile gz_open OF((const char *, int, const char *)); + +#if defined UNDER_CE + +/* Map the Windows error number in ERROR to a locale-dependent error message + string and return a pointer to it. Typically, the values for ERROR come + from GetLastError. + + The string pointed to shall not be modified by the application, but may be + overwritten by a subsequent call to gz_strwinerror + + The gz_strwinerror function does not change the current setting of + GetLastError. */ +char ZLIB_INTERNAL *gz_strwinerror (error) + DWORD error; +{ + static char buf[1024]; + + wchar_t *msgbuf; + DWORD lasterr = GetLastError(); + DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_ALLOCATE_BUFFER, + NULL, + error, + 0, /* Default language */ + (LPVOID)&msgbuf, + 0, + NULL); + if (chars != 0) { + /* If there is an \r\n appended, zap it. */ + if (chars >= 2 + && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { + chars -= 2; + msgbuf[chars] = 0; + } + + if (chars > sizeof (buf) - 1) { + chars = sizeof (buf) - 1; + msgbuf[chars] = 0; + } + + wcstombs(buf, msgbuf, chars + 1); + LocalFree(msgbuf); + } + else { + sprintf(buf, "unknown win32 error (%ld)", error); + } + + SetLastError(lasterr); + return buf; +} + +#endif /* UNDER_CE */ + +/* Reset gzip file state */ +local void gz_reset(state) + gz_statep state; +{ + if (state->mode == GZ_READ) { /* for reading ... */ + state->have = 0; /* no output data available */ + state->eof = 0; /* not at end of file */ + state->how = LOOK; /* look for gzip header */ + state->direct = 1; /* default for empty file */ + } + state->seek = 0; /* no seek request pending */ + gz_error(state, Z_OK, NULL); /* clear error */ + state->pos = 0; /* no uncompressed data yet */ + state->strm.avail_in = 0; /* no input data yet */ +} + +/* Open a gzip file either by name or file descriptor. */ +local gzFile gz_open(path, fd, mode) + const char *path; + int fd; + const char *mode; +{ + gz_statep state; + + /* allocate gzFile structure to return */ + state = malloc(sizeof(gz_state)); + if (state == NULL) + return NULL; + state->size = 0; /* no buffers allocated yet */ + state->want = GZBUFSIZE; /* requested buffer size */ + state->msg = NULL; /* no error message yet */ + + /* interpret mode */ + state->mode = GZ_NONE; + state->level = Z_DEFAULT_COMPRESSION; + state->strategy = Z_DEFAULT_STRATEGY; + while (*mode) { + if (*mode >= '0' && *mode <= '9') + state->level = *mode - '0'; + else + switch (*mode) { + case 'r': + state->mode = GZ_READ; + break; +#ifndef NO_GZCOMPRESS + case 'w': + state->mode = GZ_WRITE; + break; + case 'a': + state->mode = GZ_APPEND; + break; +#endif + case '+': /* can't read and write at the same time */ + free(state); + return NULL; + case 'b': /* ignore -- will request binary anyway */ + break; + case 'f': + state->strategy = Z_FILTERED; + break; + case 'h': + state->strategy = Z_HUFFMAN_ONLY; + break; + case 'R': + state->strategy = Z_RLE; + break; + case 'F': + state->strategy = Z_FIXED; + default: /* could consider as an error, but just ignore */ + ; + } + mode++; + } + + /* must provide an "r", "w", or "a" */ + if (state->mode == GZ_NONE) { + free(state); + return NULL; + } + + /* save the path name for error messages */ + state->path = malloc(strlen(path) + 1); + if (state->path == NULL) { + free(state); + return NULL; + } + strcpy(state->path, path); + + /* open the file with the appropriate mode (or just use fd) */ + state->fd = fd != -1 ? fd : + open(path, +#ifdef O_LARGEFILE + O_LARGEFILE | +#endif +#ifdef O_BINARY + O_BINARY | +#endif + (state->mode == GZ_READ ? + O_RDONLY : + (O_WRONLY | O_CREAT | ( + state->mode == GZ_WRITE ? + O_TRUNC : + O_APPEND))), + 0666); + if (state->fd == -1) { + free(state->path); + free(state); + return NULL; + } + if (state->mode == GZ_APPEND) + state->mode = GZ_WRITE; /* simplify later checks */ + + /* save the current position for rewinding (only if reading) */ + if (state->mode == GZ_READ) { + state->start = LSEEK(state->fd, 0, SEEK_CUR); + if (state->start == -1) state->start = 0; + } + + /* initialize stream */ + gz_reset(state); + + /* return stream */ + return (gzFile)state; +} + +/* -- see zlib.h -- */ +gzFile ZEXPORT gzopen(path, mode) + const char *path; + const char *mode; +{ + return gz_open(path, -1, mode); +} + +/* -- see zlib.h -- */ +gzFile ZEXPORT gzopen64(path, mode) + const char *path; + const char *mode; +{ + return gz_open(path, -1, mode); +} + +/* -- see zlib.h -- */ +gzFile ZEXPORT gzdopen(fd, mode) + int fd; + const char *mode; +{ + char *path; /* identifier for error messages */ + gzFile gz; + + if (fd == -1 || (path = malloc(7 + 3 * sizeof(int))) == NULL) + return NULL; + sprintf(path, "", fd); /* for debugging */ + gz = gz_open(path, fd, mode); + free(path); + return gz; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzbuffer(file, size) + gzFile file; + unsigned size; +{ + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return -1; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return -1; + + /* make sure we haven't already allocated memory */ + if (state->size != 0) + return -1; + + /* check and set requested size */ + if (size == 0) + return -1; + state->want = size; + return 0; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzrewind(file) + gzFile file; +{ + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + + /* check that we're reading and that there's no error */ + if (state->mode != GZ_READ || state->err != Z_OK) + return -1; + + /* back up and start over */ + if (LSEEK(state->fd, state->start, SEEK_SET) == -1) + return -1; + gz_reset(state); + return 0; +} + +/* -- see zlib.h -- */ +z_off64_t ZEXPORT gzseek64(file, offset, whence) + gzFile file; + z_off64_t offset; + int whence; +{ + unsigned n; + z_off64_t ret; + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return -1; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return -1; + + /* check that there's no error */ + if (state->err != Z_OK) + return -1; + + /* can only seek from start or relative to current position */ + if (whence != SEEK_SET && whence != SEEK_CUR) + return -1; + + /* normalize offset to a SEEK_CUR specification */ + if (whence == SEEK_SET) + offset -= state->pos; + else if (state->seek) + offset += state->skip; + state->seek = 0; + + /* if within raw area while reading, just go there */ + if (state->mode == GZ_READ && state->how == COPY && + state->pos + offset >= state->raw) { + ret = LSEEK(state->fd, offset - state->have, SEEK_CUR); + if (ret == -1) + return -1; + state->have = 0; + state->eof = 0; + state->seek = 0; + gz_error(state, Z_OK, NULL); + state->strm.avail_in = 0; + state->pos += offset; + return state->pos; + } + + /* calculate skip amount, rewinding if needed for back seek when reading */ + if (offset < 0) { + if (state->mode != GZ_READ) /* writing -- can't go backwards */ + return -1; + offset += state->pos; + if (offset < 0) /* before start of file! */ + return -1; + if (gzrewind(file) == -1) /* rewind, then skip to offset */ + return -1; + } + + /* if reading, skip what's in output buffer (one less gzgetc() check) */ + if (state->mode == GZ_READ) { + n = GT_OFF(state->have) || (z_off64_t)state->have > offset ? + (unsigned)offset : state->have; + state->have -= n; + state->next += n; + state->pos += n; + offset -= n; + } + + /* request skip (if not zero) */ + if (offset) { + state->seek = 1; + state->skip = offset; + } + return state->pos + offset; +} + +/* -- see zlib.h -- */ +z_off_t ZEXPORT gzseek(file, offset, whence) + gzFile file; + z_off_t offset; + int whence; +{ + z_off64_t ret; + + ret = gzseek64(file, (z_off64_t)offset, whence); + return ret == (z_off_t)ret ? (z_off_t)ret : -1; +} + +/* -- see zlib.h -- */ +z_off64_t ZEXPORT gztell64(file) + gzFile file; +{ + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return -1; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return -1; + + /* return position */ + return state->pos + (state->seek ? state->skip : 0); +} + +/* -- see zlib.h -- */ +z_off_t ZEXPORT gztell(file) + gzFile file; +{ + z_off64_t ret; + + ret = gztell64(file); + return ret == (z_off_t)ret ? (z_off_t)ret : -1; +} + +/* -- see zlib.h -- */ +z_off64_t ZEXPORT gzoffset64(file) + gzFile file; +{ + z_off64_t offset; + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return -1; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return -1; + + /* compute and return effective offset in file */ + offset = LSEEK(state->fd, 0, SEEK_CUR); + if (offset == -1) + return -1; + if (state->mode == GZ_READ) /* reading */ + offset -= state->strm.avail_in; /* don't count buffered input */ + return offset; +} + +/* -- see zlib.h -- */ +z_off_t ZEXPORT gzoffset(file) + gzFile file; +{ + z_off64_t ret; + + ret = gzoffset64(file); + return ret == (z_off_t)ret ? (z_off_t)ret : -1; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzeof(file) + gzFile file; +{ + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return 0; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return 0; + + /* return end-of-file state */ + return state->mode == GZ_READ ? + (state->eof && state->strm.avail_in == 0 && state->have == 0) : 0; +} + +/* -- see zlib.h -- */ +const char * ZEXPORT gzerror(file, errnum) + gzFile file; + int *errnum; +{ + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return NULL; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return NULL; + + /* return error information */ + if (errnum != NULL) + *errnum = state->err; + return state->msg == NULL ? "" : state->msg; +} + +/* -- see zlib.h -- */ +void ZEXPORT gzclearerr(file) + gzFile file; +{ + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return; + + /* clear error and end-of-file */ + if (state->mode == GZ_READ) + state->eof = 0; + gz_error(state, Z_OK, NULL); +} + +/* Create an error message in allocated memory and set state->err and + state->msg accordingly. Free any previous error message already there. Do + not try to free or allocate space if the error is Z_MEM_ERROR (out of + memory). Simply save the error message as a static string. If there is an + allocation failure constructing the error message, then convert the error to + out of memory. */ +void ZLIB_INTERNAL gz_error(state, err, msg) + gz_statep state; + int err; + const char *msg; +{ + /* free previously allocated message and clear */ + if (state->msg != NULL) { + if (state->err != Z_MEM_ERROR) + free(state->msg); + state->msg = NULL; + } + + /* set error code, and if no message, then done */ + state->err = err; + if (msg == NULL) + return; + + /* for an out of memory error, save as static string */ + if (err == Z_MEM_ERROR) { + state->msg = (char *)msg; + return; + } + + /* construct error message with path */ + if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { + state->err = Z_MEM_ERROR; + state->msg = (char *)"out of memory"; + return; + } + strcpy(state->msg, state->path); + strcat(state->msg, ": "); + strcat(state->msg, msg); + return; +} + +#ifndef INT_MAX +/* portably return maximum value for an int (when limits.h presumed not + available) -- we need to do this to cover cases where 2's complement not + used, since C standard permits 1's complement and sign-bit representations, + otherwise we could just use ((unsigned)-1) >> 1 */ +unsigned ZLIB_INTERNAL gz_intmax() +{ + unsigned p, q; + + p = 1; + do { + q = p; + p <<= 1; + p++; + } while (p > q); + return q >> 1; +} +#endif diff --git a/fceumm/utils/zlib/gzread.c b/fceumm/utils/zlib/gzread.c new file mode 100644 index 0000000..548201a --- /dev/null +++ b/fceumm/utils/zlib/gzread.c @@ -0,0 +1,653 @@ +/* gzread.c -- zlib functions for reading gzip files + * Copyright (C) 2004, 2005, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "gzguts.h" + +/* Local functions */ +local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *)); +local int gz_avail OF((gz_statep)); +local int gz_next4 OF((gz_statep, unsigned long *)); +local int gz_head OF((gz_statep)); +local int gz_decomp OF((gz_statep)); +local int gz_make OF((gz_statep)); +local int gz_skip OF((gz_statep, z_off64_t)); + +/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from + state->fd, and update state->eof, state->err, and state->msg as appropriate. + This function needs to loop on read(), since read() is not guaranteed to + read the number of bytes requested, depending on the type of descriptor. */ +local int gz_load(state, buf, len, have) + gz_statep state; + unsigned char *buf; + unsigned len; + unsigned *have; +{ + int ret; + + *have = 0; + do { + ret = read(state->fd, buf + *have, len - *have); + if (ret <= 0) + break; + *have += ret; + } while (*have < len); + if (ret < 0) { + gz_error(state, Z_ERRNO, zstrerror()); + return -1; + } + if (ret == 0) + state->eof = 1; + return 0; +} + +/* Load up input buffer and set eof flag if last data loaded -- return -1 on + error, 0 otherwise. Note that the eof flag is set when the end of the input + file is reached, even though there may be unused data in the buffer. Once + that data has been used, no more attempts will be made to read the file. + gz_avail() assumes that strm->avail_in == 0. */ +local int gz_avail(state) + gz_statep state; +{ + z_streamp strm = &(state->strm); + + if (state->err != Z_OK) + return -1; + if (state->eof == 0) { + if (gz_load(state, state->in, state->size, + (unsigned *)&(strm->avail_in)) == -1) + return -1; + strm->next_in = state->in; + } + return 0; +} + +/* Get next byte from input, or -1 if end or error. */ +#define NEXT() ((strm->avail_in == 0 && gz_avail(state) == -1) ? -1 : \ + (strm->avail_in == 0 ? -1 : \ + (strm->avail_in--, *(strm->next_in)++))) + +/* Get a four-byte little-endian integer and return 0 on success and the value + in *ret. Otherwise -1 is returned and *ret is not modified. */ +local int gz_next4(state, ret) + gz_statep state; + unsigned long *ret; +{ + int ch; + unsigned long val; + z_streamp strm = &(state->strm); + + val = NEXT(); + val += (unsigned)NEXT() << 8; + val += (unsigned long)NEXT() << 16; + ch = NEXT(); + if (ch == -1) + return -1; + val += (unsigned long)ch << 24; + *ret = val; + return 0; +} + +/* Look for gzip header, set up for inflate or copy. state->have must be zero. + If this is the first time in, allocate required memory. state->how will be + left unchanged if there is no more input data available, will be set to COPY + if there is no gzip header and direct copying will be performed, or it will + be set to GZIP for decompression, and the gzip header will be skipped so + that the next available input data is the raw deflate stream. If direct + copying, then leftover input data from the input buffer will be copied to + the output buffer. In that case, all further file reads will be directly to + either the output buffer or a user buffer. If decompressing, the inflate + state and the check value will be initialized. gz_head() will return 0 on + success or -1 on failure. Failures may include read errors or gzip header + errors. */ +local int gz_head(state) + gz_statep state; +{ + z_streamp strm = &(state->strm); + int flags; + unsigned len; + + /* allocate read buffers and inflate memory */ + if (state->size == 0) { + /* allocate buffers */ + state->in = malloc(state->want); + state->out = malloc(state->want << 1); + if (state->in == NULL || state->out == NULL) { + if (state->out != NULL) + free(state->out); + if (state->in != NULL) + free(state->in); + gz_error(state, Z_MEM_ERROR, "out of memory"); + return -1; + } + state->size = state->want; + + /* allocate inflate memory */ + state->strm.zalloc = Z_NULL; + state->strm.zfree = Z_NULL; + state->strm.opaque = Z_NULL; + state->strm.avail_in = 0; + state->strm.next_in = Z_NULL; + if (inflateInit2(&(state->strm), -15) != Z_OK) { /* raw inflate */ + free(state->out); + free(state->in); + state->size = 0; + gz_error(state, Z_MEM_ERROR, "out of memory"); + return -1; + } + } + + /* get some data in the input buffer */ + if (strm->avail_in == 0) { + if (gz_avail(state) == -1) + return -1; + if (strm->avail_in == 0) + return 0; + } + + /* look for the gzip magic header bytes 31 and 139 */ + if (strm->next_in[0] == 31) { + strm->avail_in--; + strm->next_in++; + if (strm->avail_in == 0 && gz_avail(state) == -1) + return -1; + if (strm->avail_in && strm->next_in[0] == 139) { + /* we have a gzip header, woo hoo! */ + strm->avail_in--; + strm->next_in++; + + /* skip rest of header */ + if (NEXT() != 8) { /* compression method */ + gz_error(state, Z_DATA_ERROR, "unknown compression method"); + return -1; + } + flags = NEXT(); + if (flags & 0xe0) { /* reserved flag bits */ + gz_error(state, Z_DATA_ERROR, "unknown header flags set"); + return -1; + } + NEXT(); /* modification time */ + NEXT(); + NEXT(); + NEXT(); + NEXT(); /* extra flags */ + NEXT(); /* operating system */ + if (flags & 4) { /* extra field */ + len = (unsigned)NEXT(); + len += (unsigned)NEXT() << 8; + while (len--) + if (NEXT() < 0) + break; + } + if (flags & 8) /* file name */ + while (NEXT() > 0) + ; + if (flags & 16) /* comment */ + while (NEXT() > 0) + ; + if (flags & 2) { /* header crc */ + NEXT(); + NEXT(); + } + /* an unexpected end of file is not checked for here -- it will be + noticed on the first request for uncompressed data */ + + /* set up for decompression */ + inflateReset(strm); + strm->adler = crc32(0L, Z_NULL, 0); + state->how = GZIP; + state->direct = 0; + return 0; + } + else { + /* not a gzip file -- save first byte (31) and fall to raw i/o */ + state->out[0] = 31; + state->have = 1; + } + } + + /* doing raw i/o, save start of raw data for seeking, copy any leftover + input to output -- this assumes that the output buffer is larger than + the input buffer, which also assures space for gzungetc() */ + state->raw = state->pos; + state->next = state->out; + if (strm->avail_in) { + memcpy(state->next + state->have, strm->next_in, strm->avail_in); + state->have += strm->avail_in; + strm->avail_in = 0; + } + state->how = COPY; + state->direct = 1; + return 0; +} + +/* Decompress from input to the provided next_out and avail_out in the state. + If the end of the compressed data is reached, then verify the gzip trailer + check value and length (modulo 2^32). state->have and state->next are set + to point to the just decompressed data, and the crc is updated. If the + trailer is verified, state->how is reset to LOOK to look for the next gzip + stream or raw data, once state->have is depleted. Returns 0 on success, -1 + on failure. Failures may include invalid compressed data or a failed gzip + trailer verification. */ +local int gz_decomp(state) + gz_statep state; +{ + int ret; + unsigned had; + unsigned long crc, len; + z_streamp strm = &(state->strm); + + /* fill output buffer up to end of deflate stream */ + had = strm->avail_out; + do { + /* get more input for inflate() */ + if (strm->avail_in == 0 && gz_avail(state) == -1) + return -1; + if (strm->avail_in == 0) { + gz_error(state, Z_DATA_ERROR, "unexpected end of file"); + return -1; + } + + /* decompress and handle errors */ + ret = inflate(strm, Z_NO_FLUSH); + if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) { + gz_error(state, Z_STREAM_ERROR, + "internal error: inflate stream corrupt"); + return -1; + } + if (ret == Z_MEM_ERROR) { + gz_error(state, Z_MEM_ERROR, "out of memory"); + return -1; + } + if (ret == Z_DATA_ERROR) { /* deflate stream invalid */ + gz_error(state, Z_DATA_ERROR, + strm->msg == NULL ? "compressed data error" : strm->msg); + return -1; + } + } while (strm->avail_out && ret != Z_STREAM_END); + + /* update available output and crc check value */ + state->have = had - strm->avail_out; + state->next = strm->next_out - state->have; + strm->adler = crc32(strm->adler, state->next, state->have); + + /* check gzip trailer if at end of deflate stream */ + if (ret == Z_STREAM_END) { + if (gz_next4(state, &crc) == -1 || gz_next4(state, &len) == -1) { + gz_error(state, Z_DATA_ERROR, "unexpected end of file"); + return -1; + } + if (crc != strm->adler) { + gz_error(state, Z_DATA_ERROR, "incorrect data check"); + return -1; + } + if (len != (strm->total_out & 0xffffffffL)) { + gz_error(state, Z_DATA_ERROR, "incorrect length check"); + return -1; + } + state->how = LOOK; /* ready for next stream, once have is 0 (leave + state->direct unchanged to remember how) */ + } + + /* good decompression */ + return 0; +} + +/* Make data and put in the output buffer. Assumes that state->have == 0. + Data is either copied from the input file or decompressed from the input + file depending on state->how. If state->how is LOOK, then a gzip header is + looked for (and skipped if found) to determine wither to copy or decompress. + Returns -1 on error, otherwise 0. gz_make() will leave state->have as COPY + or GZIP unless the end of the input file has been reached and all data has + been processed. */ +local int gz_make(state) + gz_statep state; +{ + z_streamp strm = &(state->strm); + + if (state->how == LOOK) { /* look for gzip header */ + if (gz_head(state) == -1) + return -1; + if (state->have) /* got some data from gz_head() */ + return 0; + } + if (state->how == COPY) { /* straight copy */ + if (gz_load(state, state->out, state->size << 1, &(state->have)) == -1) + return -1; + state->next = state->out; + } + else if (state->how == GZIP) { /* decompress */ + strm->avail_out = state->size << 1; + strm->next_out = state->out; + if (gz_decomp(state) == -1) + return -1; + } + return 0; +} + +/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */ +local int gz_skip(state, len) + gz_statep state; + z_off64_t len; +{ + unsigned n; + + /* skip over len bytes or reach end-of-file, whichever comes first */ + while (len) + /* skip over whatever is in output buffer */ + if (state->have) { + n = GT_OFF(state->have) || (z_off64_t)state->have > len ? + (unsigned)len : state->have; + state->have -= n; + state->next += n; + state->pos += n; + len -= n; + } + + /* output buffer empty -- return if we're at the end of the input */ + else if (state->eof && state->strm.avail_in == 0) + break; + + /* need more data to skip -- load up output buffer */ + else { + /* get more output, looking for header if required */ + if (gz_make(state) == -1) + return -1; + } + return 0; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzread(file, buf, len) + gzFile file; + voidp buf; + unsigned len; +{ + unsigned got, n; + gz_statep state; + z_streamp strm; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're reading and that there's no error */ + if (state->mode != GZ_READ || state->err != Z_OK) + return -1; + + /* since an int is returned, make sure len fits in one, otherwise return + with an error (this avoids the flaw in the interface) */ + if ((int)len < 0) { + gz_error(state, Z_BUF_ERROR, "requested length does not fit in int"); + return -1; + } + + /* if len is zero, avoid unnecessary operations */ + if (len == 0) + return 0; + + /* process a skip request */ + if (state->seek) { + state->seek = 0; + if (gz_skip(state, state->skip) == -1) + return -1; + } + + /* get len bytes to buf, or less than len if at the end */ + got = 0; + do { + /* first just try copying data from the output buffer */ + if (state->have) { + n = state->have > len ? len : state->have; + memcpy(buf, state->next, n); + state->next += n; + state->have -= n; + } + + /* output buffer empty -- return if we're at the end of the input */ + else if (state->eof && strm->avail_in == 0) + break; + + /* need output data -- for small len or new stream load up our output + buffer */ + else if (state->how == LOOK || len < (state->size << 1)) { + /* get more output, looking for header if required */ + if (gz_make(state) == -1) + return -1; + continue; /* no progress yet -- go back to memcpy() above */ + /* the copy above assures that we will leave with space in the + output buffer, allowing at least one gzungetc() to succeed */ + } + + /* large len -- read directly into user buffer */ + else if (state->how == COPY) { /* read directly */ + if (gz_load(state, buf, len, &n) == -1) + return -1; + } + + /* large len -- decompress directly into user buffer */ + else { /* state->how == GZIP */ + strm->avail_out = len; + strm->next_out = buf; + if (gz_decomp(state) == -1) + return -1; + n = state->have; + state->have = 0; + } + + /* update progress */ + len -= n; + buf = (char *)buf + n; + got += n; + state->pos += n; + } while (len); + + /* return number of bytes read into user buffer (will fit in int) */ + return (int)got; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzgetc(file) + gzFile file; +{ + int ret; + unsigned char buf[1]; + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + + /* check that we're reading and that there's no error */ + if (state->mode != GZ_READ || state->err != Z_OK) + return -1; + + /* try output buffer (no need to check for skip request) */ + if (state->have) { + state->have--; + state->pos++; + return *(state->next)++; + } + + /* nothing there -- try gzread() */ + ret = gzread(file, buf, 1); + return ret < 1 ? -1 : buf[0]; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzungetc(c, file) + int c; + gzFile file; +{ + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + + /* check that we're reading and that there's no error */ + if (state->mode != GZ_READ || state->err != Z_OK) + return -1; + + /* process a skip request */ + if (state->seek) { + state->seek = 0; + if (gz_skip(state, state->skip) == -1) + return -1; + } + + /* can't push EOF */ + if (c < 0) + return -1; + + /* if output buffer empty, put byte at end (allows more pushing) */ + if (state->have == 0) { + state->have = 1; + state->next = state->out + (state->size << 1) - 1; + state->next[0] = c; + state->pos--; + return c; + } + + /* if no room, give up (must have already done a gzungetc()) */ + if (state->have == (state->size << 1)) { + gz_error(state, Z_BUF_ERROR, "out of room to push characters"); + return -1; + } + + /* slide output data if needed and insert byte before existing data */ + if (state->next == state->out) { + unsigned char *src = state->out + state->have; + unsigned char *dest = state->out + (state->size << 1); + while (src > state->out) + *--dest = *--src; + state->next = dest; + } + state->have++; + state->next--; + state->next[0] = c; + state->pos--; + return c; +} + +/* -- see zlib.h -- */ +char * ZEXPORT gzgets(file, buf, len) + gzFile file; + char *buf; + int len; +{ + unsigned left, n; + char *str; + unsigned char *eol; + gz_statep state; + + /* check parameters and get internal structure */ + if (file == NULL || buf == NULL || len < 1) + return NULL; + state = (gz_statep)file; + + /* check that we're reading and that there's no error */ + if (state->mode != GZ_READ || state->err != Z_OK) + return NULL; + + /* process a skip request */ + if (state->seek) { + state->seek = 0; + if (gz_skip(state, state->skip) == -1) + return NULL; + } + + /* copy output bytes up to new line or len - 1, whichever comes first -- + append a terminating zero to the string (we don't check for a zero in + the contents, let the user worry about that) */ + str = buf; + left = (unsigned)len - 1; + if (left) do { + /* assure that something is in the output buffer */ + if (state->have == 0) { + if (gz_make(state) == -1) + return NULL; /* error */ + if (state->have == 0) { /* end of file */ + if (buf == str) /* got bupkus */ + return NULL; + break; /* got something -- return it */ + } + } + + /* look for end-of-line in current output buffer */ + n = state->have > left ? left : state->have; + eol = memchr(state->next, '\n', n); + if (eol != NULL) + n = (unsigned)(eol - state->next) + 1; + + /* copy through end-of-line, or remainder if not found */ + memcpy(buf, state->next, n); + state->have -= n; + state->next += n; + state->pos += n; + left -= n; + buf += n; + } while (left && eol == NULL); + + /* found end-of-line or out of space -- terminate string and return it */ + buf[0] = 0; + return str; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzdirect(file) + gzFile file; +{ + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return 0; + state = (gz_statep)file; + + /* check that we're reading */ + if (state->mode != GZ_READ) + return 0; + + /* if the state is not known, but we can find out, then do so (this is + mainly for right after a gzopen() or gzdopen()) */ + if (state->how == LOOK && state->have == 0) + (void)gz_head(state); + + /* return 1 if reading direct, 0 if decompressing a gzip stream */ + return state->direct; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzclose_r(file) + gzFile file; +{ + int ret; + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return Z_STREAM_ERROR; + state = (gz_statep)file; + + /* check that we're reading */ + if (state->mode != GZ_READ) + return Z_STREAM_ERROR; + + /* free memory and close file */ + if (state->size) { + inflateEnd(&(state->strm)); + free(state->out); + free(state->in); + } + gz_error(state, Z_OK, NULL); + free(state->path); + ret = close(state->fd); + free(state); + return ret ? Z_ERRNO : Z_OK; +} diff --git a/fceumm/utils/zlib/gzwrite.c b/fceumm/utils/zlib/gzwrite.c new file mode 100644 index 0000000..e8defc6 --- /dev/null +++ b/fceumm/utils/zlib/gzwrite.c @@ -0,0 +1,531 @@ +/* gzwrite.c -- zlib functions for writing gzip files + * Copyright (C) 2004, 2005, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "gzguts.h" + +/* Local functions */ +local int gz_init OF((gz_statep)); +local int gz_comp OF((gz_statep, int)); +local int gz_zero OF((gz_statep, z_off64_t)); + +/* Initialize state for writing a gzip file. Mark initialization by setting + state->size to non-zero. Return -1 on failure or 0 on success. */ +local int gz_init(state) + gz_statep state; +{ + int ret; + z_streamp strm = &(state->strm); + + /* allocate input and output buffers */ + state->in = malloc(state->want); + state->out = malloc(state->want); + if (state->in == NULL || state->out == NULL) { + if (state->out != NULL) + free(state->out); + if (state->in != NULL) + free(state->in); + gz_error(state, Z_MEM_ERROR, "out of memory"); + return -1; + } + + /* allocate deflate memory, set up for gzip compression */ + strm->zalloc = Z_NULL; + strm->zfree = Z_NULL; + strm->opaque = Z_NULL; + ret = deflateInit2(strm, state->level, Z_DEFLATED, + 15 + 16, 8, state->strategy); + if (ret != Z_OK) { + free(state->in); + gz_error(state, Z_MEM_ERROR, "out of memory"); + return -1; + } + + /* mark state as initialized */ + state->size = state->want; + + /* initialize write buffer */ + strm->avail_out = state->size; + strm->next_out = state->out; + state->next = strm->next_out; + return 0; +} + +/* Compress whatever is at avail_in and next_in and write to the output file. + Return -1 if there is an error writing to the output file, otherwise 0. + flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH, + then the deflate() state is reset to start a new gzip stream. */ +local int gz_comp(state, flush) + gz_statep state; + int flush; +{ + int ret, got; + unsigned have; + z_streamp strm = &(state->strm); + + /* allocate memory if this is the first time through */ + if (state->size == 0 && gz_init(state) == -1) + return -1; + + /* run deflate() on provided input until it produces no more output */ + ret = Z_OK; + do { + /* write out current buffer contents if full, or if flushing, but if + doing Z_FINISH then don't write until we get to Z_STREAM_END */ + if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && + (flush != Z_FINISH || ret == Z_STREAM_END))) { + have = (unsigned)(strm->next_out - state->next); + if (have && ((got = write(state->fd, state->next, have)) < 0 || + (unsigned)got != have)) { + gz_error(state, Z_ERRNO, zstrerror()); + return -1; + } + if (strm->avail_out == 0) { + strm->avail_out = state->size; + strm->next_out = state->out; + } + state->next = strm->next_out; + } + + /* compress */ + have = strm->avail_out; + ret = deflate(strm, flush); + if (ret == Z_STREAM_ERROR) { + gz_error(state, Z_STREAM_ERROR, + "internal error: deflate stream corrupt"); + return -1; + } + have -= strm->avail_out; + } while (have); + + /* if that completed a deflate stream, allow another to start */ + if (flush == Z_FINISH) + deflateReset(strm); + + /* all done, no errors */ + return 0; +} + +/* Compress len zeros to output. Return -1 on error, 0 on success. */ +local int gz_zero(state, len) + gz_statep state; + z_off64_t len; +{ + int first; + unsigned n; + z_streamp strm = &(state->strm); + + /* consume whatever's left in the input buffer */ + if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) + return -1; + + /* compress len zeros (len guaranteed > 0) */ + first = 1; + while (len) { + n = GT_OFF(state->size) || (z_off64_t)state->size > len ? + (unsigned)len : state->size; + if (first) { + memset(state->in, 0, n); + first = 0; + } + strm->avail_in = n; + strm->next_in = state->in; + state->pos += n; + if (gz_comp(state, Z_NO_FLUSH) == -1) + return -1; + len -= n; + } + return 0; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzwrite(file, buf, len) + gzFile file; + voidpc buf; + unsigned len; +{ + unsigned put = len; + unsigned n; + gz_statep state; + z_streamp strm; + + /* get internal structure */ + if (file == NULL) + return 0; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return 0; + + /* since an int is returned, make sure len fits in one, otherwise return + with an error (this avoids the flaw in the interface) */ + if ((int)len < 0) { + gz_error(state, Z_BUF_ERROR, "requested length does not fit in int"); + return 0; + } + + /* if len is zero, avoid unnecessary operations */ + if (len == 0) + return 0; + + /* allocate memory if this is the first time through */ + if (state->size == 0 && gz_init(state) == -1) + return 0; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return 0; + } + + /* for small len, copy to input buffer, otherwise compress directly */ + if (len < state->size) { + /* copy to input buffer, compress when full */ + do { + if (strm->avail_in == 0) + strm->next_in = state->in; + n = state->size - strm->avail_in; + if (n > len) + n = len; + memcpy(strm->next_in + strm->avail_in, buf, n); + strm->avail_in += n; + state->pos += n; + buf = (char *)buf + n; + len -= n; + if (len && gz_comp(state, Z_NO_FLUSH) == -1) + return 0; + } while (len); + } + else { + /* consume whatever's left in the input buffer */ + if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) + return 0; + + /* directly compress user buffer to file */ + strm->avail_in = len; + strm->next_in = (voidp)buf; + state->pos += len; + if (gz_comp(state, Z_NO_FLUSH) == -1) + return 0; + } + + /* input was all buffered or compressed (put will fit in int) */ + return (int)put; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzputc(file, c) + gzFile file; + int c; +{ + unsigned char buf[1]; + gz_statep state; + z_streamp strm; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return -1; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return -1; + } + + /* try writing to input buffer for speed (state->size == 0 if buffer not + initialized) */ + if (strm->avail_in < state->size) { + if (strm->avail_in == 0) + strm->next_in = state->in; + strm->next_in[strm->avail_in++] = c; + state->pos++; + return c; + } + + /* no room in buffer or not initialized, use gz_write() */ + buf[0] = c; + if (gzwrite(file, buf, 1) != 1) + return -1; + return c; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzputs(file, str) + gzFile file; + const char *str; +{ + int ret; + unsigned len; + + /* write string */ + len = (unsigned)strlen(str); + ret = gzwrite(file, str, len); + return ret == 0 && len != 0 ? -1 : ret; +} + +#ifdef STDC +#include + +/* -- see zlib.h -- */ +int ZEXPORTVA gzprintf (gzFile file, const char *format, ...) +{ + int size, len; + gz_statep state; + z_streamp strm; + va_list va; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return 0; + + /* make sure we have some buffer space */ + if (state->size == 0 && gz_init(state) == -1) + return 0; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return 0; + } + + /* consume whatever's left in the input buffer */ + if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) + return 0; + + /* do the printf() into the input buffer, put length in len */ + size = (int)(state->size); + state->in[size - 1] = 0; + va_start(va, format); +#ifdef NO_vsnprintf +# ifdef HAS_vsprintf_void + (void)vsprintf(state->in, format, va); + va_end(va); + for (len = 0; len < size; len++) + if (state->in[len] == 0) break; +# else + len = vsprintf(state->in, format, va); + va_end(va); +# endif +#else +# ifdef HAS_vsnprintf_void + (void)vsnprintf(state->in, size, format, va); + va_end(va); + len = strlen(state->in); +# else + len = vsnprintf((char *)(state->in), size, format, va); + va_end(va); +# endif +#endif + + /* check that printf() results fit in buffer */ + if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) + return 0; + + /* update buffer and position, defer compression until needed */ + strm->avail_in = (unsigned)len; + strm->next_in = state->in; + state->pos += len; + return len; +} + +#else /* !STDC */ + +/* -- see zlib.h -- */ +int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) + gzFile file; + const char *format; + int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; +{ + int size, len; + gz_statep state; + z_streamp strm; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return 0; + + /* make sure we have some buffer space */ + if (state->size == 0 && gz_init(state) == -1) + return 0; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return 0; + } + + /* consume whatever's left in the input buffer */ + if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) + return 0; + + /* do the printf() into the input buffer, put length in len */ + size = (int)(state->size); + state->in[size - 1] = 0; +#ifdef NO_snprintf +# ifdef HAS_sprintf_void + sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); + for (len = 0; len < size; len++) + if (state->in[len] == 0) break; +# else + len = sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); +# endif +#else +# ifdef HAS_snprintf_void + snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); + len = strlen(state->in); +# else + len = snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); +# endif +#endif + + /* check that printf() results fit in buffer */ + if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) + return 0; + + /* update buffer and position, defer compression until needed */ + strm->avail_in = (unsigned)len; + strm->next_in = state->in; + state->pos += len; + return len; +} + +#endif + +/* -- see zlib.h -- */ +int ZEXPORT gzflush(file, flush) + gzFile file; + int flush; +{ + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return Z_STREAM_ERROR; + + /* check flush parameter */ + if (flush < 0 || flush > Z_FINISH) + return Z_STREAM_ERROR; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return -1; + } + + /* compress remaining data with requested flush */ + gz_comp(state, flush); + return state->err; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzsetparams(file, level, strategy) + gzFile file; + int level; + int strategy; +{ + gz_statep state; + z_streamp strm; + + /* get internal structure */ + if (file == NULL) + return Z_STREAM_ERROR; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return Z_STREAM_ERROR; + + /* if no change is requested, then do nothing */ + if (level == state->level && strategy == state->strategy) + return Z_OK; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return -1; + } + + /* change compression parameters for subsequent input */ + if (state->size) { + /* flush previous input with previous parameters before changing */ + if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1) + return state->err; + deflateParams(strm, level, strategy); + } + state->level = level; + state->strategy = strategy; + return Z_OK; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzclose_w(file) + gzFile file; +{ + int ret = 0; + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return Z_STREAM_ERROR; + state = (gz_statep)file; + + /* check that we're writing */ + if (state->mode != GZ_WRITE) + return Z_STREAM_ERROR; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + ret += gz_zero(state, state->skip); + } + + /* flush, free memory, and close file */ + ret += gz_comp(state, Z_FINISH); + (void)deflateEnd(&(state->strm)); + free(state->out); + free(state->in); + gz_error(state, Z_OK, NULL); + free(state->path); + ret += close(state->fd); + free(state); + return ret ? Z_ERRNO : Z_OK; +} diff --git a/fceumm/utils/zlib/infback.c b/fceumm/utils/zlib/infback.c new file mode 100644 index 0000000..af3a8c9 --- /dev/null +++ b/fceumm/utils/zlib/infback.c @@ -0,0 +1,632 @@ +/* infback.c -- inflate using a call-back interface + * Copyright (C) 1995-2009 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + This code is largely copied from inflate.c. Normally either infback.o or + inflate.o would be linked into an application--not both. The interface + with inffast.c is retained so that optimized assembler-coded versions of + inflate_fast() can be used with either inflate.c or infback.c. + */ + +#include "zutil.h" +#include "inftrees.h" +#include "inflate.h" +#include "inffast.h" + +/* function prototypes */ +local void fixedtables OF((struct inflate_state FAR *state)); + +/* + strm provides memory allocation functions in zalloc and zfree, or + Z_NULL to use the library memory allocation functions. + + windowBits is in the range 8..15, and window is a user-supplied + window and output buffer that is 2**windowBits bytes. + */ +int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size) +z_streamp strm; +int windowBits; +unsigned char FAR *window; +const char *version; +int stream_size; +{ + struct inflate_state FAR *state; + + if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || + stream_size != (int)(sizeof(z_stream))) + return Z_VERSION_ERROR; + if (strm == Z_NULL || window == Z_NULL || + windowBits < 8 || windowBits > 15) + return Z_STREAM_ERROR; + strm->msg = Z_NULL; /* in case we return an error */ + if (strm->zalloc == (alloc_func)0) { + strm->zalloc = zcalloc; + strm->opaque = (voidpf)0; + } + if (strm->zfree == (free_func)0) strm->zfree = zcfree; + state = (struct inflate_state FAR *)ZALLOC(strm, 1, + sizeof(struct inflate_state)); + if (state == Z_NULL) return Z_MEM_ERROR; + Tracev((stderr, "inflate: allocated\n")); + strm->state = (struct internal_state FAR *)state; + state->dmax = 32768U; + state->wbits = windowBits; + state->wsize = 1U << windowBits; + state->window = window; + state->wnext = 0; + state->whave = 0; + return Z_OK; +} + +/* + Return state with length and distance decoding tables and index sizes set to + fixed code decoding. Normally this returns fixed tables from inffixed.h. + If BUILDFIXED is defined, then instead this routine builds the tables the + first time it's called, and returns those tables the first time and + thereafter. This reduces the size of the code by about 2K bytes, in + exchange for a little execution time. However, BUILDFIXED should not be + used for threaded applications, since the rewriting of the tables and virgin + may not be thread-safe. + */ +local void fixedtables(state) +struct inflate_state FAR *state; +{ +#ifdef BUILDFIXED + static int virgin = 1; + static code *lenfix, *distfix; + static code fixed[544]; + + /* build fixed huffman tables if first call (may not be thread safe) */ + if (virgin) { + unsigned sym, bits; + static code *next; + + /* literal/length table */ + sym = 0; + while (sym < 144) state->lens[sym++] = 8; + while (sym < 256) state->lens[sym++] = 9; + while (sym < 280) state->lens[sym++] = 7; + while (sym < 288) state->lens[sym++] = 8; + next = fixed; + lenfix = next; + bits = 9; + inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); + + /* distance table */ + sym = 0; + while (sym < 32) state->lens[sym++] = 5; + distfix = next; + bits = 5; + inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); + + /* do this just once */ + virgin = 0; + } +#else /* !BUILDFIXED */ +# include "inffixed.h" +#endif /* BUILDFIXED */ + state->lencode = lenfix; + state->lenbits = 9; + state->distcode = distfix; + state->distbits = 5; +} + +/* Macros for inflateBack(): */ + +/* Load returned state from inflate_fast() */ +#define LOAD() \ + do { \ + put = strm->next_out; \ + left = strm->avail_out; \ + next = strm->next_in; \ + have = strm->avail_in; \ + hold = state->hold; \ + bits = state->bits; \ + } while (0) + +/* Set state from registers for inflate_fast() */ +#define RESTORE() \ + do { \ + strm->next_out = put; \ + strm->avail_out = left; \ + strm->next_in = next; \ + strm->avail_in = have; \ + state->hold = hold; \ + state->bits = bits; \ + } while (0) + +/* Clear the input bit accumulator */ +#define INITBITS() \ + do { \ + hold = 0; \ + bits = 0; \ + } while (0) + +/* Assure that some input is available. If input is requested, but denied, + then return a Z_BUF_ERROR from inflateBack(). */ +#define PULL() \ + do { \ + if (have == 0) { \ + have = in(in_desc, &next); \ + if (have == 0) { \ + next = Z_NULL; \ + ret = Z_BUF_ERROR; \ + goto inf_leave; \ + } \ + } \ + } while (0) + +/* Get a byte of input into the bit accumulator, or return from inflateBack() + with an error if there is no input available. */ +#define PULLBYTE() \ + do { \ + PULL(); \ + have--; \ + hold += (unsigned long)(*next++) << bits; \ + bits += 8; \ + } while (0) + +/* Assure that there are at least n bits in the bit accumulator. If there is + not enough available input to do that, then return from inflateBack() with + an error. */ +#define NEEDBITS(n) \ + do { \ + while (bits < (unsigned)(n)) \ + PULLBYTE(); \ + } while (0) + +/* Return the low n bits of the bit accumulator (n < 16) */ +#define BITS(n) \ + ((unsigned)hold & ((1U << (n)) - 1)) + +/* Remove n bits from the bit accumulator */ +#define DROPBITS(n) \ + do { \ + hold >>= (n); \ + bits -= (unsigned)(n); \ + } while (0) + +/* Remove zero to seven bits as needed to go to a byte boundary */ +#define BYTEBITS() \ + do { \ + hold >>= bits & 7; \ + bits -= bits & 7; \ + } while (0) + +/* Assure that some output space is available, by writing out the window + if it's full. If the write fails, return from inflateBack() with a + Z_BUF_ERROR. */ +#define ROOM() \ + do { \ + if (left == 0) { \ + put = state->window; \ + left = state->wsize; \ + state->whave = left; \ + if (out(out_desc, put, left)) { \ + ret = Z_BUF_ERROR; \ + goto inf_leave; \ + } \ + } \ + } while (0) + +/* + strm provides the memory allocation functions and window buffer on input, + and provides information on the unused input on return. For Z_DATA_ERROR + returns, strm will also provide an error message. + + in() and out() are the call-back input and output functions. When + inflateBack() needs more input, it calls in(). When inflateBack() has + filled the window with output, or when it completes with data in the + window, it calls out() to write out the data. The application must not + change the provided input until in() is called again or inflateBack() + returns. The application must not change the window/output buffer until + inflateBack() returns. + + in() and out() are called with a descriptor parameter provided in the + inflateBack() call. This parameter can be a structure that provides the + information required to do the read or write, as well as accumulated + information on the input and output such as totals and check values. + + in() should return zero on failure. out() should return non-zero on + failure. If either in() or out() fails, than inflateBack() returns a + Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it + was in() or out() that caused in the error. Otherwise, inflateBack() + returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format + error, or Z_MEM_ERROR if it could not allocate memory for the state. + inflateBack() can also return Z_STREAM_ERROR if the input parameters + are not correct, i.e. strm is Z_NULL or the state was not initialized. + */ +int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) +z_streamp strm; +in_func in; +void FAR *in_desc; +out_func out; +void FAR *out_desc; +{ + struct inflate_state FAR *state; + unsigned char FAR *next; /* next input */ + unsigned char FAR *put; /* next output */ + unsigned have, left; /* available input and output */ + unsigned long hold; /* bit buffer */ + unsigned bits; /* bits in bit buffer */ + unsigned copy; /* number of stored or match bytes to copy */ + unsigned char FAR *from; /* where to copy match bytes from */ + code here; /* current decoding table entry */ + code last; /* parent table entry */ + unsigned len; /* length to copy for repeats, bits to drop */ + int ret; /* return code */ + static const unsigned short order[19] = /* permutation of code lengths */ + {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; + + /* Check that the strm exists and that the state was initialized */ + if (strm == Z_NULL || strm->state == Z_NULL) + return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + + /* Reset the state */ + strm->msg = Z_NULL; + state->mode = TYPE; + state->last = 0; + state->whave = 0; + next = strm->next_in; + have = next != Z_NULL ? strm->avail_in : 0; + hold = 0; + bits = 0; + put = state->window; + left = state->wsize; + + /* Inflate until end of block marked as last */ + for (;;) + switch (state->mode) { + case TYPE: + /* determine and dispatch block type */ + if (state->last) { + BYTEBITS(); + state->mode = DONE; + break; + } + NEEDBITS(3); + state->last = BITS(1); + DROPBITS(1); + switch (BITS(2)) { + case 0: /* stored block */ + Tracev((stderr, "inflate: stored block%s\n", + state->last ? " (last)" : "")); + state->mode = STORED; + break; + case 1: /* fixed block */ + fixedtables(state); + Tracev((stderr, "inflate: fixed codes block%s\n", + state->last ? " (last)" : "")); + state->mode = LEN; /* decode codes */ + break; + case 2: /* dynamic block */ + Tracev((stderr, "inflate: dynamic codes block%s\n", + state->last ? " (last)" : "")); + state->mode = TABLE; + break; + case 3: + strm->msg = (char *)"invalid block type"; + state->mode = BAD; + } + DROPBITS(2); + break; + + case STORED: + /* get and verify stored block length */ + BYTEBITS(); /* go to byte boundary */ + NEEDBITS(32); + if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { + strm->msg = (char *)"invalid stored block lengths"; + state->mode = BAD; + break; + } + state->length = (unsigned)hold & 0xffff; + Tracev((stderr, "inflate: stored length %u\n", + state->length)); + INITBITS(); + + /* copy stored block from input to output */ + while (state->length != 0) { + copy = state->length; + PULL(); + ROOM(); + if (copy > have) copy = have; + if (copy > left) copy = left; + zmemcpy(put, next, copy); + have -= copy; + next += copy; + left -= copy; + put += copy; + state->length -= copy; + } + Tracev((stderr, "inflate: stored end\n")); + state->mode = TYPE; + break; + + case TABLE: + /* get dynamic table entries descriptor */ + NEEDBITS(14); + state->nlen = BITS(5) + 257; + DROPBITS(5); + state->ndist = BITS(5) + 1; + DROPBITS(5); + state->ncode = BITS(4) + 4; + DROPBITS(4); +#ifndef PKZIP_BUG_WORKAROUND + if (state->nlen > 286 || state->ndist > 30) { + strm->msg = (char *)"too many length or distance symbols"; + state->mode = BAD; + break; + } +#endif + Tracev((stderr, "inflate: table sizes ok\n")); + + /* get code length code lengths (not a typo) */ + state->have = 0; + while (state->have < state->ncode) { + NEEDBITS(3); + state->lens[order[state->have++]] = (unsigned short)BITS(3); + DROPBITS(3); + } + while (state->have < 19) + state->lens[order[state->have++]] = 0; + state->next = state->codes; + state->lencode = (code const FAR *)(state->next); + state->lenbits = 7; + ret = inflate_table(CODES, state->lens, 19, &(state->next), + &(state->lenbits), state->work); + if (ret) { + strm->msg = (char *)"invalid code lengths set"; + state->mode = BAD; + break; + } + Tracev((stderr, "inflate: code lengths ok\n")); + + /* get length and distance code code lengths */ + state->have = 0; + while (state->have < state->nlen + state->ndist) { + for (;;) { + here = state->lencode[BITS(state->lenbits)]; + if ((unsigned)(here.bits) <= bits) break; + PULLBYTE(); + } + if (here.val < 16) { + NEEDBITS(here.bits); + DROPBITS(here.bits); + state->lens[state->have++] = here.val; + } + else { + if (here.val == 16) { + NEEDBITS(here.bits + 2); + DROPBITS(here.bits); + if (state->have == 0) { + strm->msg = (char *)"invalid bit length repeat"; + state->mode = BAD; + break; + } + len = (unsigned)(state->lens[state->have - 1]); + copy = 3 + BITS(2); + DROPBITS(2); + } + else if (here.val == 17) { + NEEDBITS(here.bits + 3); + DROPBITS(here.bits); + len = 0; + copy = 3 + BITS(3); + DROPBITS(3); + } + else { + NEEDBITS(here.bits + 7); + DROPBITS(here.bits); + len = 0; + copy = 11 + BITS(7); + DROPBITS(7); + } + if (state->have + copy > state->nlen + state->ndist) { + strm->msg = (char *)"invalid bit length repeat"; + state->mode = BAD; + break; + } + while (copy--) + state->lens[state->have++] = (unsigned short)len; + } + } + + /* handle error breaks in while */ + if (state->mode == BAD) break; + + /* check for end-of-block code (better have one) */ + if (state->lens[256] == 0) { + strm->msg = (char *)"invalid code -- missing end-of-block"; + state->mode = BAD; + break; + } + + /* build code tables -- note: do not change the lenbits or distbits + values here (9 and 6) without reading the comments in inftrees.h + concerning the ENOUGH constants, which depend on those values */ + state->next = state->codes; + state->lencode = (code const FAR *)(state->next); + state->lenbits = 9; + ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), + &(state->lenbits), state->work); + if (ret) { + strm->msg = (char *)"invalid literal/lengths set"; + state->mode = BAD; + break; + } + state->distcode = (code const FAR *)(state->next); + state->distbits = 6; + ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, + &(state->next), &(state->distbits), state->work); + if (ret) { + strm->msg = (char *)"invalid distances set"; + state->mode = BAD; + break; + } + Tracev((stderr, "inflate: codes ok\n")); + state->mode = LEN; + + case LEN: + /* use inflate_fast() if we have enough input and output */ + if (have >= 6 && left >= 258) { + RESTORE(); + if (state->whave < state->wsize) + state->whave = state->wsize - left; + inflate_fast(strm, state->wsize); + LOAD(); + break; + } + + /* get a literal, length, or end-of-block code */ + for (;;) { + here = state->lencode[BITS(state->lenbits)]; + if ((unsigned)(here.bits) <= bits) break; + PULLBYTE(); + } + if (here.op && (here.op & 0xf0) == 0) { + last = here; + for (;;) { + here = state->lencode[last.val + + (BITS(last.bits + last.op) >> last.bits)]; + if ((unsigned)(last.bits + here.bits) <= bits) break; + PULLBYTE(); + } + DROPBITS(last.bits); + } + DROPBITS(here.bits); + state->length = (unsigned)here.val; + + /* process literal */ + if (here.op == 0) { + Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? + "inflate: literal '%c'\n" : + "inflate: literal 0x%02x\n", here.val)); + ROOM(); + *put++ = (unsigned char)(state->length); + left--; + state->mode = LEN; + break; + } + + /* process end of block */ + if (here.op & 32) { + Tracevv((stderr, "inflate: end of block\n")); + state->mode = TYPE; + break; + } + + /* invalid code */ + if (here.op & 64) { + strm->msg = (char *)"invalid literal/length code"; + state->mode = BAD; + break; + } + + /* length code -- get extra bits, if any */ + state->extra = (unsigned)(here.op) & 15; + if (state->extra != 0) { + NEEDBITS(state->extra); + state->length += BITS(state->extra); + DROPBITS(state->extra); + } + Tracevv((stderr, "inflate: length %u\n", state->length)); + + /* get distance code */ + for (;;) { + here = state->distcode[BITS(state->distbits)]; + if ((unsigned)(here.bits) <= bits) break; + PULLBYTE(); + } + if ((here.op & 0xf0) == 0) { + last = here; + for (;;) { + here = state->distcode[last.val + + (BITS(last.bits + last.op) >> last.bits)]; + if ((unsigned)(last.bits + here.bits) <= bits) break; + PULLBYTE(); + } + DROPBITS(last.bits); + } + DROPBITS(here.bits); + if (here.op & 64) { + strm->msg = (char *)"invalid distance code"; + state->mode = BAD; + break; + } + state->offset = (unsigned)here.val; + + /* get distance extra bits, if any */ + state->extra = (unsigned)(here.op) & 15; + if (state->extra != 0) { + NEEDBITS(state->extra); + state->offset += BITS(state->extra); + DROPBITS(state->extra); + } + if (state->offset > state->wsize - (state->whave < state->wsize ? + left : 0)) { + strm->msg = (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } + Tracevv((stderr, "inflate: distance %u\n", state->offset)); + + /* copy match from window to output */ + do { + ROOM(); + copy = state->wsize - state->offset; + if (copy < left) { + from = put + copy; + copy = left - copy; + } + else { + from = put - state->offset; + copy = left; + } + if (copy > state->length) copy = state->length; + state->length -= copy; + left -= copy; + do { + *put++ = *from++; + } while (--copy); + } while (state->length != 0); + break; + + case DONE: + /* inflate stream terminated properly -- write leftover output */ + ret = Z_STREAM_END; + if (left < state->wsize) { + if (out(out_desc, state->window, state->wsize - left)) + ret = Z_BUF_ERROR; + } + goto inf_leave; + + case BAD: + ret = Z_DATA_ERROR; + goto inf_leave; + + default: /* can't happen, but makes compilers happy */ + ret = Z_STREAM_ERROR; + goto inf_leave; + } + + /* Return unused input */ + inf_leave: + strm->next_in = next; + strm->avail_in = have; + return ret; +} + +int ZEXPORT inflateBackEnd(strm) +z_streamp strm; +{ + if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) + return Z_STREAM_ERROR; + ZFREE(strm, strm->state); + strm->state = Z_NULL; + Tracev((stderr, "inflate: end\n")); + return Z_OK; +} diff --git a/fceumm/utils/zlib/inffast.c b/fceumm/utils/zlib/inffast.c new file mode 100644 index 0000000..2f1d60b --- /dev/null +++ b/fceumm/utils/zlib/inffast.c @@ -0,0 +1,340 @@ +/* inffast.c -- fast decoding + * Copyright (C) 1995-2008, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "zutil.h" +#include "inftrees.h" +#include "inflate.h" +#include "inffast.h" + +#ifndef ASMINF + +/* Allow machine dependent optimization for post-increment or pre-increment. + Based on testing to date, + Pre-increment preferred for: + - PowerPC G3 (Adler) + - MIPS R5000 (Randers-Pehrson) + Post-increment preferred for: + - none + No measurable difference: + - Pentium III (Anderson) + - M68060 (Nikl) + */ +#ifdef POSTINC +# define OFF 0 +# define PUP(a) *(a)++ +#else +# define OFF 1 +# define PUP(a) *++(a) +#endif + +/* + Decode literal, length, and distance codes and write out the resulting + literal and match bytes until either not enough input or output is + available, an end-of-block is encountered, or a data error is encountered. + When large enough input and output buffers are supplied to inflate(), for + example, a 16K input buffer and a 64K output buffer, more than 95% of the + inflate execution time is spent in this routine. + + Entry assumptions: + + state->mode == LEN + strm->avail_in >= 6 + strm->avail_out >= 258 + start >= strm->avail_out + state->bits < 8 + + On return, state->mode is one of: + + LEN -- ran out of enough output space or enough available input + TYPE -- reached end of block code, inflate() to interpret next block + BAD -- error in block data + + Notes: + + - The maximum input bits used by a length/distance pair is 15 bits for the + length code, 5 bits for the length extra, 15 bits for the distance code, + and 13 bits for the distance extra. This totals 48 bits, or six bytes. + Therefore if strm->avail_in >= 6, then there is enough input to avoid + checking for available input while decoding. + + - The maximum bytes that a single length/distance pair can output is 258 + bytes, which is the maximum length that can be coded. inflate_fast() + requires strm->avail_out >= 258 for each loop to avoid checking for + output space. + */ +void ZLIB_INTERNAL inflate_fast(strm, start) +z_streamp strm; +unsigned start; /* inflate()'s starting value for strm->avail_out */ +{ + struct inflate_state FAR *state; + unsigned char FAR *in; /* local strm->next_in */ + unsigned char FAR *last; /* while in < last, enough input available */ + unsigned char FAR *out; /* local strm->next_out */ + unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ + unsigned char FAR *end; /* while out < end, enough space available */ +#ifdef INFLATE_STRICT + unsigned dmax; /* maximum distance from zlib header */ +#endif + unsigned wsize; /* window size or zero if not using window */ + unsigned whave; /* valid bytes in the window */ + unsigned wnext; /* window write index */ + unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ + unsigned long hold; /* local strm->hold */ + unsigned bits; /* local strm->bits */ + code const FAR *lcode; /* local strm->lencode */ + code const FAR *dcode; /* local strm->distcode */ + unsigned lmask; /* mask for first level of length codes */ + unsigned dmask; /* mask for first level of distance codes */ + code here; /* retrieved table entry */ + unsigned op; /* code bits, operation, extra bits, or */ + /* window position, window bytes to copy */ + unsigned len; /* match length, unused bytes */ + unsigned dist; /* match distance */ + unsigned char FAR *from; /* where to copy match from */ + + /* copy state to local variables */ + state = (struct inflate_state FAR *)strm->state; + in = strm->next_in - OFF; + last = in + (strm->avail_in - 5); + out = strm->next_out - OFF; + beg = out - (start - strm->avail_out); + end = out + (strm->avail_out - 257); +#ifdef INFLATE_STRICT + dmax = state->dmax; +#endif + wsize = state->wsize; + whave = state->whave; + wnext = state->wnext; + window = state->window; + hold = state->hold; + bits = state->bits; + lcode = state->lencode; + dcode = state->distcode; + lmask = (1U << state->lenbits) - 1; + dmask = (1U << state->distbits) - 1; + + /* decode literals and length/distances until end-of-block or not enough + input data or output space */ + do { + if (bits < 15) { + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + } + here = lcode[hold & lmask]; + dolen: + op = (unsigned)(here.bits); + hold >>= op; + bits -= op; + op = (unsigned)(here.op); + if (op == 0) { /* literal */ + Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? + "inflate: literal '%c'\n" : + "inflate: literal 0x%02x\n", here.val)); + PUP(out) = (unsigned char)(here.val); + } + else if (op & 16) { /* length base */ + len = (unsigned)(here.val); + op &= 15; /* number of extra bits */ + if (op) { + if (bits < op) { + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + } + len += (unsigned)hold & ((1U << op) - 1); + hold >>= op; + bits -= op; + } + Tracevv((stderr, "inflate: length %u\n", len)); + if (bits < 15) { + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + } + here = dcode[hold & dmask]; + dodist: + op = (unsigned)(here.bits); + hold >>= op; + bits -= op; + op = (unsigned)(here.op); + if (op & 16) { /* distance base */ + dist = (unsigned)(here.val); + op &= 15; /* number of extra bits */ + if (bits < op) { + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + if (bits < op) { + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + } + } + dist += (unsigned)hold & ((1U << op) - 1); +#ifdef INFLATE_STRICT + if (dist > dmax) { + strm->msg = (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } +#endif + hold >>= op; + bits -= op; + Tracevv((stderr, "inflate: distance %u\n", dist)); + op = (unsigned)(out - beg); /* max distance in output */ + if (dist > op) { /* see if copy from window */ + op = dist - op; /* distance back in window */ + if (op > whave) { + if (state->sane) { + strm->msg = + (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } +#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR + if (len <= op - whave) { + do { + PUP(out) = 0; + } while (--len); + continue; + } + len -= op - whave; + do { + PUP(out) = 0; + } while (--op > whave); + if (op == 0) { + from = out - dist; + do { + PUP(out) = PUP(from); + } while (--len); + continue; + } +#endif + } + from = window - OFF; + if (wnext == 0) { /* very common case */ + from += wsize - op; + if (op < len) { /* some from window */ + len -= op; + do { + PUP(out) = PUP(from); + } while (--op); + from = out - dist; /* rest from output */ + } + } + else if (wnext < op) { /* wrap around window */ + from += wsize + wnext - op; + op -= wnext; + if (op < len) { /* some from end of window */ + len -= op; + do { + PUP(out) = PUP(from); + } while (--op); + from = window - OFF; + if (wnext < len) { /* some from start of window */ + op = wnext; + len -= op; + do { + PUP(out) = PUP(from); + } while (--op); + from = out - dist; /* rest from output */ + } + } + } + else { /* contiguous in window */ + from += wnext - op; + if (op < len) { /* some from window */ + len -= op; + do { + PUP(out) = PUP(from); + } while (--op); + from = out - dist; /* rest from output */ + } + } + while (len > 2) { + PUP(out) = PUP(from); + PUP(out) = PUP(from); + PUP(out) = PUP(from); + len -= 3; + } + if (len) { + PUP(out) = PUP(from); + if (len > 1) + PUP(out) = PUP(from); + } + } + else { + from = out - dist; /* copy direct from output */ + do { /* minimum length is three */ + PUP(out) = PUP(from); + PUP(out) = PUP(from); + PUP(out) = PUP(from); + len -= 3; + } while (len > 2); + if (len) { + PUP(out) = PUP(from); + if (len > 1) + PUP(out) = PUP(from); + } + } + } + else if ((op & 64) == 0) { /* 2nd level distance code */ + here = dcode[here.val + (hold & ((1U << op) - 1))]; + goto dodist; + } + else { + strm->msg = (char *)"invalid distance code"; + state->mode = BAD; + break; + } + } + else if ((op & 64) == 0) { /* 2nd level length code */ + here = lcode[here.val + (hold & ((1U << op) - 1))]; + goto dolen; + } + else if (op & 32) { /* end-of-block */ + Tracevv((stderr, "inflate: end of block\n")); + state->mode = TYPE; + break; + } + else { + strm->msg = (char *)"invalid literal/length code"; + state->mode = BAD; + break; + } + } while (in < last && out < end); + + /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ + len = bits >> 3; + in -= len; + bits -= len << 3; + hold &= (1U << bits) - 1; + + /* update state and return */ + strm->next_in = in + OFF; + strm->next_out = out + OFF; + strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); + strm->avail_out = (unsigned)(out < end ? + 257 + (end - out) : 257 - (out - end)); + state->hold = hold; + state->bits = bits; + return; +} + +/* + inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): + - Using bit fields for code structure + - Different op definition to avoid & for extra bits (do & for table bits) + - Three separate decoding do-loops for direct, window, and wnext == 0 + - Special case for distance > 1 copies to do overlapped load and store copy + - Explicit branch predictions (based on measured branch probabilities) + - Deferring match copy and interspersed it with decoding subsequent codes + - Swapping literal/length else + - Swapping window/direct else + - Larger unrolled copy loops (three is about right) + - Moving len -= 3 statement into middle of loop + */ + +#endif /* !ASMINF */ diff --git a/fceumm/utils/zlib/inffast.h b/fceumm/utils/zlib/inffast.h new file mode 100644 index 0000000..e5c1aa4 --- /dev/null +++ b/fceumm/utils/zlib/inffast.h @@ -0,0 +1,11 @@ +/* inffast.h -- header to use inffast.c + * Copyright (C) 1995-2003, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); diff --git a/fceumm/utils/zlib/inffixed.h b/fceumm/utils/zlib/inffixed.h new file mode 100644 index 0000000..75ed4b5 --- /dev/null +++ b/fceumm/utils/zlib/inffixed.h @@ -0,0 +1,94 @@ + /* inffixed.h -- table for decoding fixed codes + * Generated automatically by makefixed(). + */ + + /* WARNING: this file should *not* be used by applications. It + is part of the implementation of the compression library and + is subject to change. Applications should only use zlib.h. + */ + + static const code lenfix[512] = { + {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, + {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, + {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, + {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, + {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, + {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, + {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, + {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, + {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, + {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, + {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, + {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, + {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, + {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, + {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, + {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, + {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, + {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, + {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, + {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, + {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, + {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, + {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, + {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, + {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, + {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, + {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, + {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, + {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, + {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, + {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, + {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, + {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, + {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, + {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, + {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, + {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, + {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, + {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, + {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, + {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, + {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, + {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, + {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, + {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, + {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, + {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, + {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, + {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, + {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, + {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, + {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, + {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, + {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, + {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, + {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, + {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, + {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, + {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, + {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, + {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, + {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, + {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, + {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, + {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, + {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, + {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, + {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, + {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, + {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, + {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, + {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, + {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, + {0,9,255} + }; + + static const code distfix[32] = { + {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, + {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, + {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, + {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, + {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, + {22,5,193},{64,5,0} + }; diff --git a/fceumm/utils/zlib/inflate.c b/fceumm/utils/zlib/inflate.c new file mode 100644 index 0000000..a8431ab --- /dev/null +++ b/fceumm/utils/zlib/inflate.c @@ -0,0 +1,1480 @@ +/* inflate.c -- zlib decompression + * Copyright (C) 1995-2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + * Change history: + * + * 1.2.beta0 24 Nov 2002 + * - First version -- complete rewrite of inflate to simplify code, avoid + * creation of window when not needed, minimize use of window when it is + * needed, make inffast.c even faster, implement gzip decoding, and to + * improve code readability and style over the previous zlib inflate code + * + * 1.2.beta1 25 Nov 2002 + * - Use pointers for available input and output checking in inffast.c + * - Remove input and output counters in inffast.c + * - Change inffast.c entry and loop from avail_in >= 7 to >= 6 + * - Remove unnecessary second byte pull from length extra in inffast.c + * - Unroll direct copy to three copies per loop in inffast.c + * + * 1.2.beta2 4 Dec 2002 + * - Change external routine names to reduce potential conflicts + * - Correct filename to inffixed.h for fixed tables in inflate.c + * - Make hbuf[] unsigned char to match parameter type in inflate.c + * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset) + * to avoid negation problem on Alphas (64 bit) in inflate.c + * + * 1.2.beta3 22 Dec 2002 + * - Add comments on state->bits assertion in inffast.c + * - Add comments on op field in inftrees.h + * - Fix bug in reuse of allocated window after inflateReset() + * - Remove bit fields--back to byte structure for speed + * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths + * - Change post-increments to pre-increments in inflate_fast(), PPC biased? + * - Add compile time option, POSTINC, to use post-increments instead (Intel?) + * - Make MATCH copy in inflate() much faster for when inflate_fast() not used + * - Use local copies of stream next and avail values, as well as local bit + * buffer and bit count in inflate()--for speed when inflate_fast() not used + * + * 1.2.beta4 1 Jan 2003 + * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings + * - Move a comment on output buffer sizes from inffast.c to inflate.c + * - Add comments in inffast.c to introduce the inflate_fast() routine + * - Rearrange window copies in inflate_fast() for speed and simplification + * - Unroll last copy for window match in inflate_fast() + * - Use local copies of window variables in inflate_fast() for speed + * - Pull out common wnext == 0 case for speed in inflate_fast() + * - Make op and len in inflate_fast() unsigned for consistency + * - Add FAR to lcode and dcode declarations in inflate_fast() + * - Simplified bad distance check in inflate_fast() + * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new + * source file infback.c to provide a call-back interface to inflate for + * programs like gzip and unzip -- uses window as output buffer to avoid + * window copying + * + * 1.2.beta5 1 Jan 2003 + * - Improved inflateBack() interface to allow the caller to provide initial + * input in strm. + * - Fixed stored blocks bug in inflateBack() + * + * 1.2.beta6 4 Jan 2003 + * - Added comments in inffast.c on effectiveness of POSTINC + * - Typecasting all around to reduce compiler warnings + * - Changed loops from while (1) or do {} while (1) to for (;;), again to + * make compilers happy + * - Changed type of window in inflateBackInit() to unsigned char * + * + * 1.2.beta7 27 Jan 2003 + * - Changed many types to unsigned or unsigned short to avoid warnings + * - Added inflateCopy() function + * + * 1.2.0 9 Mar 2003 + * - Changed inflateBack() interface to provide separate opaque descriptors + * for the in() and out() functions + * - Changed inflateBack() argument and in_func typedef to swap the length + * and buffer address return values for the input function + * - Check next_in and next_out for Z_NULL on entry to inflate() + * + * The history for versions after 1.2.0 are in ChangeLog in zlib distribution. + */ + +#include "zutil.h" +#include "inftrees.h" +#include "inflate.h" +#include "inffast.h" + +#ifdef MAKEFIXED +# ifndef BUILDFIXED +# define BUILDFIXED +# endif +#endif + +/* function prototypes */ +local void fixedtables OF((struct inflate_state FAR *state)); +local int updatewindow OF((z_streamp strm, unsigned out)); +#ifdef BUILDFIXED + void makefixed OF((void)); +#endif +local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf, + unsigned len)); + +int ZEXPORT inflateReset(strm) +z_streamp strm; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + strm->total_in = strm->total_out = state->total = 0; + strm->msg = Z_NULL; + strm->adler = 1; /* to support ill-conceived Java test suite */ + state->mode = HEAD; + state->last = 0; + state->havedict = 0; + state->dmax = 32768U; + state->head = Z_NULL; + state->wsize = 0; + state->whave = 0; + state->wnext = 0; + state->hold = 0; + state->bits = 0; + state->lencode = state->distcode = state->next = state->codes; + state->sane = 1; + state->back = -1; + Tracev((stderr, "inflate: reset\n")); + return Z_OK; +} + +int ZEXPORT inflateReset2(strm, windowBits) +z_streamp strm; +int windowBits; +{ + int wrap; + struct inflate_state FAR *state; + + /* get the state */ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + + /* extract wrap request from windowBits parameter */ + if (windowBits < 0) { + wrap = 0; + windowBits = -windowBits; + } + else { + wrap = (windowBits >> 4) + 1; +#ifdef GUNZIP + if (windowBits < 48) + windowBits &= 15; +#endif + } + + /* set number of window bits, free window if different */ + if (windowBits && (windowBits < 8 || windowBits > 15)) + return Z_STREAM_ERROR; + if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) { + ZFREE(strm, state->window); + state->window = Z_NULL; + } + + /* update state and reset the rest of it */ + state->wrap = wrap; + state->wbits = (unsigned)windowBits; + return inflateReset(strm); +} + +int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) +z_streamp strm; +int windowBits; +const char *version; +int stream_size; +{ + int ret; + struct inflate_state FAR *state; + + if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || + stream_size != (int)(sizeof(z_stream))) + return Z_VERSION_ERROR; + if (strm == Z_NULL) return Z_STREAM_ERROR; + strm->msg = Z_NULL; /* in case we return an error */ + if (strm->zalloc == (alloc_func)0) { + strm->zalloc = zcalloc; + strm->opaque = (voidpf)0; + } + if (strm->zfree == (free_func)0) strm->zfree = zcfree; + state = (struct inflate_state FAR *) + ZALLOC(strm, 1, sizeof(struct inflate_state)); + if (state == Z_NULL) return Z_MEM_ERROR; + Tracev((stderr, "inflate: allocated\n")); + strm->state = (struct internal_state FAR *)state; + state->window = Z_NULL; + ret = inflateReset2(strm, windowBits); + if (ret != Z_OK) { + ZFREE(strm, state); + strm->state = Z_NULL; + } + return ret; +} + +int ZEXPORT inflateInit_(strm, version, stream_size) +z_streamp strm; +const char *version; +int stream_size; +{ + return inflateInit2_(strm, DEF_WBITS, version, stream_size); +} + +int ZEXPORT inflatePrime(strm, bits, value) +z_streamp strm; +int bits; +int value; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if (bits < 0) { + state->hold = 0; + state->bits = 0; + return Z_OK; + } + if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR; + value &= (1L << bits) - 1; + state->hold += value << state->bits; + state->bits += bits; + return Z_OK; +} + +/* + Return state with length and distance decoding tables and index sizes set to + fixed code decoding. Normally this returns fixed tables from inffixed.h. + If BUILDFIXED is defined, then instead this routine builds the tables the + first time it's called, and returns those tables the first time and + thereafter. This reduces the size of the code by about 2K bytes, in + exchange for a little execution time. However, BUILDFIXED should not be + used for threaded applications, since the rewriting of the tables and virgin + may not be thread-safe. + */ +local void fixedtables(state) +struct inflate_state FAR *state; +{ +#ifdef BUILDFIXED + static int virgin = 1; + static code *lenfix, *distfix; + static code fixed[544]; + + /* build fixed huffman tables if first call (may not be thread safe) */ + if (virgin) { + unsigned sym, bits; + static code *next; + + /* literal/length table */ + sym = 0; + while (sym < 144) state->lens[sym++] = 8; + while (sym < 256) state->lens[sym++] = 9; + while (sym < 280) state->lens[sym++] = 7; + while (sym < 288) state->lens[sym++] = 8; + next = fixed; + lenfix = next; + bits = 9; + inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); + + /* distance table */ + sym = 0; + while (sym < 32) state->lens[sym++] = 5; + distfix = next; + bits = 5; + inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); + + /* do this just once */ + virgin = 0; + } +#else /* !BUILDFIXED */ +# include "inffixed.h" +#endif /* BUILDFIXED */ + state->lencode = lenfix; + state->lenbits = 9; + state->distcode = distfix; + state->distbits = 5; +} + +#ifdef MAKEFIXED +#include + +/* + Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also + defines BUILDFIXED, so the tables are built on the fly. makefixed() writes + those tables to stdout, which would be piped to inffixed.h. A small program + can simply call makefixed to do this: + + void makefixed(void); + + int main(void) + { + makefixed(); + return 0; + } + + Then that can be linked with zlib built with MAKEFIXED defined and run: + + a.out > inffixed.h + */ +void makefixed() +{ + unsigned low, size; + struct inflate_state state; + + fixedtables(&state); + puts(" /* inffixed.h -- table for decoding fixed codes"); + puts(" * Generated automatically by makefixed()."); + puts(" */"); + puts(""); + puts(" /* WARNING: this file should *not* be used by applications."); + puts(" It is part of the implementation of this library and is"); + puts(" subject to change. Applications should only use zlib.h."); + puts(" */"); + puts(""); + size = 1U << 9; + printf(" static const code lenfix[%u] = {", size); + low = 0; + for (;;) { + if ((low % 7) == 0) printf("\n "); + printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits, + state.lencode[low].val); + if (++low == size) break; + putchar(','); + } + puts("\n };"); + size = 1U << 5; + printf("\n static const code distfix[%u] = {", size); + low = 0; + for (;;) { + if ((low % 6) == 0) printf("\n "); + printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, + state.distcode[low].val); + if (++low == size) break; + putchar(','); + } + puts("\n };"); +} +#endif /* MAKEFIXED */ + +/* + Update the window with the last wsize (normally 32K) bytes written before + returning. If window does not exist yet, create it. This is only called + when a window is already in use, or when output has been written during this + inflate call, but the end of the deflate stream has not been reached yet. + It is also called to create a window for dictionary data when a dictionary + is loaded. + + Providing output buffers larger than 32K to inflate() should provide a speed + advantage, since only the last 32K of output is copied to the sliding window + upon return from inflate(), and since all distances after the first 32K of + output will fall in the output data, making match copies simpler and faster. + The advantage may be dependent on the size of the processor's data caches. + */ +local int updatewindow(strm, out) +z_streamp strm; +unsigned out; +{ + struct inflate_state FAR *state; + unsigned copy, dist; + + state = (struct inflate_state FAR *)strm->state; + + /* if it hasn't been done already, allocate space for the window */ + if (state->window == Z_NULL) { + state->window = (unsigned char FAR *) + ZALLOC(strm, 1U << state->wbits, + sizeof(unsigned char)); + if (state->window == Z_NULL) return 1; + } + + /* if window not in use yet, initialize */ + if (state->wsize == 0) { + state->wsize = 1U << state->wbits; + state->wnext = 0; + state->whave = 0; + } + + /* copy state->wsize or less output bytes into the circular window */ + copy = out - strm->avail_out; + if (copy >= state->wsize) { + zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); + state->wnext = 0; + state->whave = state->wsize; + } + else { + dist = state->wsize - state->wnext; + if (dist > copy) dist = copy; + zmemcpy(state->window + state->wnext, strm->next_out - copy, dist); + copy -= dist; + if (copy) { + zmemcpy(state->window, strm->next_out - copy, copy); + state->wnext = copy; + state->whave = state->wsize; + } + else { + state->wnext += dist; + if (state->wnext == state->wsize) state->wnext = 0; + if (state->whave < state->wsize) state->whave += dist; + } + } + return 0; +} + +/* Macros for inflate(): */ + +/* check function to use adler32() for zlib or crc32() for gzip */ +#ifdef GUNZIP +# define UPDATE(check, buf, len) \ + (state->flags ? crc32(check, buf, len) : adler32(check, buf, len)) +#else +# define UPDATE(check, buf, len) adler32(check, buf, len) +#endif + +/* check macros for header crc */ +#ifdef GUNZIP +# define CRC2(check, word) \ + do { \ + hbuf[0] = (unsigned char)(word); \ + hbuf[1] = (unsigned char)((word) >> 8); \ + check = crc32(check, hbuf, 2); \ + } while (0) + +# define CRC4(check, word) \ + do { \ + hbuf[0] = (unsigned char)(word); \ + hbuf[1] = (unsigned char)((word) >> 8); \ + hbuf[2] = (unsigned char)((word) >> 16); \ + hbuf[3] = (unsigned char)((word) >> 24); \ + check = crc32(check, hbuf, 4); \ + } while (0) +#endif + +/* Load registers with state in inflate() for speed */ +#define LOAD() \ + do { \ + put = strm->next_out; \ + left = strm->avail_out; \ + next = strm->next_in; \ + have = strm->avail_in; \ + hold = state->hold; \ + bits = state->bits; \ + } while (0) + +/* Restore state from registers in inflate() */ +#define RESTORE() \ + do { \ + strm->next_out = put; \ + strm->avail_out = left; \ + strm->next_in = next; \ + strm->avail_in = have; \ + state->hold = hold; \ + state->bits = bits; \ + } while (0) + +/* Clear the input bit accumulator */ +#define INITBITS() \ + do { \ + hold = 0; \ + bits = 0; \ + } while (0) + +/* Get a byte of input into the bit accumulator, or return from inflate() + if there is no input available. */ +#define PULLBYTE() \ + do { \ + if (have == 0) goto inf_leave; \ + have--; \ + hold += (unsigned long)(*next++) << bits; \ + bits += 8; \ + } while (0) + +/* Assure that there are at least n bits in the bit accumulator. If there is + not enough available input to do that, then return from inflate(). */ +#define NEEDBITS(n) \ + do { \ + while (bits < (unsigned)(n)) \ + PULLBYTE(); \ + } while (0) + +/* Return the low n bits of the bit accumulator (n < 16) */ +#define BITS(n) \ + ((unsigned)hold & ((1U << (n)) - 1)) + +/* Remove n bits from the bit accumulator */ +#define DROPBITS(n) \ + do { \ + hold >>= (n); \ + bits -= (unsigned)(n); \ + } while (0) + +/* Remove zero to seven bits as needed to go to a byte boundary */ +#define BYTEBITS() \ + do { \ + hold >>= bits & 7; \ + bits -= bits & 7; \ + } while (0) + +/* Reverse the bytes in a 32-bit value */ +#define REVERSE(q) \ + ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ + (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) + +/* + inflate() uses a state machine to process as much input data and generate as + much output data as possible before returning. The state machine is + structured roughly as follows: + + for (;;) switch (state) { + ... + case STATEn: + if (not enough input data or output space to make progress) + return; + ... make progress ... + state = STATEm; + break; + ... + } + + so when inflate() is called again, the same case is attempted again, and + if the appropriate resources are provided, the machine proceeds to the + next state. The NEEDBITS() macro is usually the way the state evaluates + whether it can proceed or should return. NEEDBITS() does the return if + the requested bits are not available. The typical use of the BITS macros + is: + + NEEDBITS(n); + ... do something with BITS(n) ... + DROPBITS(n); + + where NEEDBITS(n) either returns from inflate() if there isn't enough + input left to load n bits into the accumulator, or it continues. BITS(n) + gives the low n bits in the accumulator. When done, DROPBITS(n) drops + the low n bits off the accumulator. INITBITS() clears the accumulator + and sets the number of available bits to zero. BYTEBITS() discards just + enough bits to put the accumulator on a byte boundary. After BYTEBITS() + and a NEEDBITS(8), then BITS(8) would return the next byte in the stream. + + NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return + if there is no input available. The decoding of variable length codes uses + PULLBYTE() directly in order to pull just enough bytes to decode the next + code, and no more. + + Some states loop until they get enough input, making sure that enough + state information is maintained to continue the loop where it left off + if NEEDBITS() returns in the loop. For example, want, need, and keep + would all have to actually be part of the saved state in case NEEDBITS() + returns: + + case STATEw: + while (want < need) { + NEEDBITS(n); + keep[want++] = BITS(n); + DROPBITS(n); + } + state = STATEx; + case STATEx: + + As shown above, if the next state is also the next case, then the break + is omitted. + + A state may also return if there is not enough output space available to + complete that state. Those states are copying stored data, writing a + literal byte, and copying a matching string. + + When returning, a "goto inf_leave" is used to update the total counters, + update the check value, and determine whether any progress has been made + during that inflate() call in order to return the proper return code. + Progress is defined as a change in either strm->avail_in or strm->avail_out. + When there is a window, goto inf_leave will update the window with the last + output written. If a goto inf_leave occurs in the middle of decompression + and there is no window currently, goto inf_leave will create one and copy + output to the window for the next call of inflate(). + + In this implementation, the flush parameter of inflate() only affects the + return code (per zlib.h). inflate() always writes as much as possible to + strm->next_out, given the space available and the provided input--the effect + documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers + the allocation of and copying into a sliding window until necessary, which + provides the effect documented in zlib.h for Z_FINISH when the entire input + stream available. So the only thing the flush parameter actually does is: + when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it + will return Z_BUF_ERROR if it has not reached the end of the stream. + */ + +int ZEXPORT inflate(strm, flush) +z_streamp strm; +int flush; +{ + struct inflate_state FAR *state; + unsigned char FAR *next; /* next input */ + unsigned char FAR *put; /* next output */ + unsigned have, left; /* available input and output */ + unsigned long hold; /* bit buffer */ + unsigned bits; /* bits in bit buffer */ + unsigned in, out; /* save starting available input and output */ + unsigned copy; /* number of stored or match bytes to copy */ + unsigned char FAR *from; /* where to copy match bytes from */ + code here; /* current decoding table entry */ + code last; /* parent table entry */ + unsigned len; /* length to copy for repeats, bits to drop */ + int ret; /* return code */ +#ifdef GUNZIP + unsigned char hbuf[4]; /* buffer for gzip header crc calculation */ +#endif + static const unsigned short order[19] = /* permutation of code lengths */ + {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; + + if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL || + (strm->next_in == Z_NULL && strm->avail_in != 0)) + return Z_STREAM_ERROR; + + state = (struct inflate_state FAR *)strm->state; + if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */ + LOAD(); + in = have; + out = left; + ret = Z_OK; + for (;;) + switch (state->mode) { + case HEAD: + if (state->wrap == 0) { + state->mode = TYPEDO; + break; + } + NEEDBITS(16); +#ifdef GUNZIP + if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */ + state->check = crc32(0L, Z_NULL, 0); + CRC2(state->check, hold); + INITBITS(); + state->mode = FLAGS; + break; + } + state->flags = 0; /* expect zlib header */ + if (state->head != Z_NULL) + state->head->done = -1; + if (!(state->wrap & 1) || /* check if zlib header allowed */ +#else + if ( +#endif + ((BITS(8) << 8) + (hold >> 8)) % 31) { + strm->msg = (char *)"incorrect header check"; + state->mode = BAD; + break; + } + if (BITS(4) != Z_DEFLATED) { + strm->msg = (char *)"unknown compression method"; + state->mode = BAD; + break; + } + DROPBITS(4); + len = BITS(4) + 8; + if (state->wbits == 0) + state->wbits = len; + else if (len > state->wbits) { + strm->msg = (char *)"invalid window size"; + state->mode = BAD; + break; + } + state->dmax = 1U << len; + Tracev((stderr, "inflate: zlib header ok\n")); + strm->adler = state->check = adler32(0L, Z_NULL, 0); + state->mode = hold & 0x200 ? DICTID : TYPE; + INITBITS(); + break; +#ifdef GUNZIP + case FLAGS: + NEEDBITS(16); + state->flags = (int)(hold); + if ((state->flags & 0xff) != Z_DEFLATED) { + strm->msg = (char *)"unknown compression method"; + state->mode = BAD; + break; + } + if (state->flags & 0xe000) { + strm->msg = (char *)"unknown header flags set"; + state->mode = BAD; + break; + } + if (state->head != Z_NULL) + state->head->text = (int)((hold >> 8) & 1); + if (state->flags & 0x0200) CRC2(state->check, hold); + INITBITS(); + state->mode = TIME; + case TIME: + NEEDBITS(32); + if (state->head != Z_NULL) + state->head->time = hold; + if (state->flags & 0x0200) CRC4(state->check, hold); + INITBITS(); + state->mode = OS; + case OS: + NEEDBITS(16); + if (state->head != Z_NULL) { + state->head->xflags = (int)(hold & 0xff); + state->head->os = (int)(hold >> 8); + } + if (state->flags & 0x0200) CRC2(state->check, hold); + INITBITS(); + state->mode = EXLEN; + case EXLEN: + if (state->flags & 0x0400) { + NEEDBITS(16); + state->length = (unsigned)(hold); + if (state->head != Z_NULL) + state->head->extra_len = (unsigned)hold; + if (state->flags & 0x0200) CRC2(state->check, hold); + INITBITS(); + } + else if (state->head != Z_NULL) + state->head->extra = Z_NULL; + state->mode = EXTRA; + case EXTRA: + if (state->flags & 0x0400) { + copy = state->length; + if (copy > have) copy = have; + if (copy) { + if (state->head != Z_NULL && + state->head->extra != Z_NULL) { + len = state->head->extra_len - state->length; + zmemcpy(state->head->extra + len, next, + len + copy > state->head->extra_max ? + state->head->extra_max - len : copy); + } + if (state->flags & 0x0200) + state->check = crc32(state->check, next, copy); + have -= copy; + next += copy; + state->length -= copy; + } + if (state->length) goto inf_leave; + } + state->length = 0; + state->mode = NAME; + case NAME: + if (state->flags & 0x0800) { + if (have == 0) goto inf_leave; + copy = 0; + do { + len = (unsigned)(next[copy++]); + if (state->head != Z_NULL && + state->head->name != Z_NULL && + state->length < state->head->name_max) + state->head->name[state->length++] = len; + } while (len && copy < have); + if (state->flags & 0x0200) + state->check = crc32(state->check, next, copy); + have -= copy; + next += copy; + if (len) goto inf_leave; + } + else if (state->head != Z_NULL) + state->head->name = Z_NULL; + state->length = 0; + state->mode = COMMENT; + case COMMENT: + if (state->flags & 0x1000) { + if (have == 0) goto inf_leave; + copy = 0; + do { + len = (unsigned)(next[copy++]); + if (state->head != Z_NULL && + state->head->comment != Z_NULL && + state->length < state->head->comm_max) + state->head->comment[state->length++] = len; + } while (len && copy < have); + if (state->flags & 0x0200) + state->check = crc32(state->check, next, copy); + have -= copy; + next += copy; + if (len) goto inf_leave; + } + else if (state->head != Z_NULL) + state->head->comment = Z_NULL; + state->mode = HCRC; + case HCRC: + if (state->flags & 0x0200) { + NEEDBITS(16); + if (hold != (state->check & 0xffff)) { + strm->msg = (char *)"header crc mismatch"; + state->mode = BAD; + break; + } + INITBITS(); + } + if (state->head != Z_NULL) { + state->head->hcrc = (int)((state->flags >> 9) & 1); + state->head->done = 1; + } + strm->adler = state->check = crc32(0L, Z_NULL, 0); + state->mode = TYPE; + break; +#endif + case DICTID: + NEEDBITS(32); + strm->adler = state->check = REVERSE(hold); + INITBITS(); + state->mode = DICT; + case DICT: + if (state->havedict == 0) { + RESTORE(); + return Z_NEED_DICT; + } + strm->adler = state->check = adler32(0L, Z_NULL, 0); + state->mode = TYPE; + case TYPE: + if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave; + case TYPEDO: + if (state->last) { + BYTEBITS(); + state->mode = CHECK; + break; + } + NEEDBITS(3); + state->last = BITS(1); + DROPBITS(1); + switch (BITS(2)) { + case 0: /* stored block */ + Tracev((stderr, "inflate: stored block%s\n", + state->last ? " (last)" : "")); + state->mode = STORED; + break; + case 1: /* fixed block */ + fixedtables(state); + Tracev((stderr, "inflate: fixed codes block%s\n", + state->last ? " (last)" : "")); + state->mode = LEN_; /* decode codes */ + if (flush == Z_TREES) { + DROPBITS(2); + goto inf_leave; + } + break; + case 2: /* dynamic block */ + Tracev((stderr, "inflate: dynamic codes block%s\n", + state->last ? " (last)" : "")); + state->mode = TABLE; + break; + case 3: + strm->msg = (char *)"invalid block type"; + state->mode = BAD; + } + DROPBITS(2); + break; + case STORED: + BYTEBITS(); /* go to byte boundary */ + NEEDBITS(32); + if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { + strm->msg = (char *)"invalid stored block lengths"; + state->mode = BAD; + break; + } + state->length = (unsigned)hold & 0xffff; + Tracev((stderr, "inflate: stored length %u\n", + state->length)); + INITBITS(); + state->mode = COPY_; + if (flush == Z_TREES) goto inf_leave; + case COPY_: + state->mode = COPY; + case COPY: + copy = state->length; + if (copy) { + if (copy > have) copy = have; + if (copy > left) copy = left; + if (copy == 0) goto inf_leave; + zmemcpy(put, next, copy); + have -= copy; + next += copy; + left -= copy; + put += copy; + state->length -= copy; + break; + } + Tracev((stderr, "inflate: stored end\n")); + state->mode = TYPE; + break; + case TABLE: + NEEDBITS(14); + state->nlen = BITS(5) + 257; + DROPBITS(5); + state->ndist = BITS(5) + 1; + DROPBITS(5); + state->ncode = BITS(4) + 4; + DROPBITS(4); +#ifndef PKZIP_BUG_WORKAROUND + if (state->nlen > 286 || state->ndist > 30) { + strm->msg = (char *)"too many length or distance symbols"; + state->mode = BAD; + break; + } +#endif + Tracev((stderr, "inflate: table sizes ok\n")); + state->have = 0; + state->mode = LENLENS; + case LENLENS: + while (state->have < state->ncode) { + NEEDBITS(3); + state->lens[order[state->have++]] = (unsigned short)BITS(3); + DROPBITS(3); + } + while (state->have < 19) + state->lens[order[state->have++]] = 0; + state->next = state->codes; + state->lencode = (code const FAR *)(state->next); + state->lenbits = 7; + ret = inflate_table(CODES, state->lens, 19, &(state->next), + &(state->lenbits), state->work); + if (ret) { + strm->msg = (char *)"invalid code lengths set"; + state->mode = BAD; + break; + } + Tracev((stderr, "inflate: code lengths ok\n")); + state->have = 0; + state->mode = CODELENS; + case CODELENS: + while (state->have < state->nlen + state->ndist) { + for (;;) { + here = state->lencode[BITS(state->lenbits)]; + if ((unsigned)(here.bits) <= bits) break; + PULLBYTE(); + } + if (here.val < 16) { + NEEDBITS(here.bits); + DROPBITS(here.bits); + state->lens[state->have++] = here.val; + } + else { + if (here.val == 16) { + NEEDBITS(here.bits + 2); + DROPBITS(here.bits); + if (state->have == 0) { + strm->msg = (char *)"invalid bit length repeat"; + state->mode = BAD; + break; + } + len = state->lens[state->have - 1]; + copy = 3 + BITS(2); + DROPBITS(2); + } + else if (here.val == 17) { + NEEDBITS(here.bits + 3); + DROPBITS(here.bits); + len = 0; + copy = 3 + BITS(3); + DROPBITS(3); + } + else { + NEEDBITS(here.bits + 7); + DROPBITS(here.bits); + len = 0; + copy = 11 + BITS(7); + DROPBITS(7); + } + if (state->have + copy > state->nlen + state->ndist) { + strm->msg = (char *)"invalid bit length repeat"; + state->mode = BAD; + break; + } + while (copy--) + state->lens[state->have++] = (unsigned short)len; + } + } + + /* handle error breaks in while */ + if (state->mode == BAD) break; + + /* check for end-of-block code (better have one) */ + if (state->lens[256] == 0) { + strm->msg = (char *)"invalid code -- missing end-of-block"; + state->mode = BAD; + break; + } + + /* build code tables -- note: do not change the lenbits or distbits + values here (9 and 6) without reading the comments in inftrees.h + concerning the ENOUGH constants, which depend on those values */ + state->next = state->codes; + state->lencode = (code const FAR *)(state->next); + state->lenbits = 9; + ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), + &(state->lenbits), state->work); + if (ret) { + strm->msg = (char *)"invalid literal/lengths set"; + state->mode = BAD; + break; + } + state->distcode = (code const FAR *)(state->next); + state->distbits = 6; + ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, + &(state->next), &(state->distbits), state->work); + if (ret) { + strm->msg = (char *)"invalid distances set"; + state->mode = BAD; + break; + } + Tracev((stderr, "inflate: codes ok\n")); + state->mode = LEN_; + if (flush == Z_TREES) goto inf_leave; + case LEN_: + state->mode = LEN; + case LEN: + if (have >= 6 && left >= 258) { + RESTORE(); + inflate_fast(strm, out); + LOAD(); + if (state->mode == TYPE) + state->back = -1; + break; + } + state->back = 0; + for (;;) { + here = state->lencode[BITS(state->lenbits)]; + if ((unsigned)(here.bits) <= bits) break; + PULLBYTE(); + } + if (here.op && (here.op & 0xf0) == 0) { + last = here; + for (;;) { + here = state->lencode[last.val + + (BITS(last.bits + last.op) >> last.bits)]; + if ((unsigned)(last.bits + here.bits) <= bits) break; + PULLBYTE(); + } + DROPBITS(last.bits); + state->back += last.bits; + } + DROPBITS(here.bits); + state->back += here.bits; + state->length = (unsigned)here.val; + if ((int)(here.op) == 0) { + Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? + "inflate: literal '%c'\n" : + "inflate: literal 0x%02x\n", here.val)); + state->mode = LIT; + break; + } + if (here.op & 32) { + Tracevv((stderr, "inflate: end of block\n")); + state->back = -1; + state->mode = TYPE; + break; + } + if (here.op & 64) { + strm->msg = (char *)"invalid literal/length code"; + state->mode = BAD; + break; + } + state->extra = (unsigned)(here.op) & 15; + state->mode = LENEXT; + case LENEXT: + if (state->extra) { + NEEDBITS(state->extra); + state->length += BITS(state->extra); + DROPBITS(state->extra); + state->back += state->extra; + } + Tracevv((stderr, "inflate: length %u\n", state->length)); + state->was = state->length; + state->mode = DIST; + case DIST: + for (;;) { + here = state->distcode[BITS(state->distbits)]; + if ((unsigned)(here.bits) <= bits) break; + PULLBYTE(); + } + if ((here.op & 0xf0) == 0) { + last = here; + for (;;) { + here = state->distcode[last.val + + (BITS(last.bits + last.op) >> last.bits)]; + if ((unsigned)(last.bits + here.bits) <= bits) break; + PULLBYTE(); + } + DROPBITS(last.bits); + state->back += last.bits; + } + DROPBITS(here.bits); + state->back += here.bits; + if (here.op & 64) { + strm->msg = (char *)"invalid distance code"; + state->mode = BAD; + break; + } + state->offset = (unsigned)here.val; + state->extra = (unsigned)(here.op) & 15; + state->mode = DISTEXT; + case DISTEXT: + if (state->extra) { + NEEDBITS(state->extra); + state->offset += BITS(state->extra); + DROPBITS(state->extra); + state->back += state->extra; + } +#ifdef INFLATE_STRICT + if (state->offset > state->dmax) { + strm->msg = (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } +#endif + Tracevv((stderr, "inflate: distance %u\n", state->offset)); + state->mode = MATCH; + case MATCH: + if (left == 0) goto inf_leave; + copy = out - left; + if (state->offset > copy) { /* copy from window */ + copy = state->offset - copy; + if (copy > state->whave) { + if (state->sane) { + strm->msg = (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } +#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR + Trace((stderr, "inflate.c too far\n")); + copy -= state->whave; + if (copy > state->length) copy = state->length; + if (copy > left) copy = left; + left -= copy; + state->length -= copy; + do { + *put++ = 0; + } while (--copy); + if (state->length == 0) state->mode = LEN; + break; +#endif + } + if (copy > state->wnext) { + copy -= state->wnext; + from = state->window + (state->wsize - copy); + } + else + from = state->window + (state->wnext - copy); + if (copy > state->length) copy = state->length; + } + else { /* copy from output */ + from = put - state->offset; + copy = state->length; + } + if (copy > left) copy = left; + left -= copy; + state->length -= copy; + do { + *put++ = *from++; + } while (--copy); + if (state->length == 0) state->mode = LEN; + break; + case LIT: + if (left == 0) goto inf_leave; + *put++ = (unsigned char)(state->length); + left--; + state->mode = LEN; + break; + case CHECK: + if (state->wrap) { + NEEDBITS(32); + out -= left; + strm->total_out += out; + state->total += out; + if (out) + strm->adler = state->check = + UPDATE(state->check, put - out, out); + out = left; + if (( +#ifdef GUNZIP + state->flags ? hold : +#endif + REVERSE(hold)) != state->check) { + strm->msg = (char *)"incorrect data check"; + state->mode = BAD; + break; + } + INITBITS(); + Tracev((stderr, "inflate: check matches trailer\n")); + } +#ifdef GUNZIP + state->mode = LENGTH; + case LENGTH: + if (state->wrap && state->flags) { + NEEDBITS(32); + if (hold != (state->total & 0xffffffffUL)) { + strm->msg = (char *)"incorrect length check"; + state->mode = BAD; + break; + } + INITBITS(); + Tracev((stderr, "inflate: length matches trailer\n")); + } +#endif + state->mode = DONE; + case DONE: + ret = Z_STREAM_END; + goto inf_leave; + case BAD: + ret = Z_DATA_ERROR; + goto inf_leave; + case MEM: + return Z_MEM_ERROR; + case SYNC: + default: + return Z_STREAM_ERROR; + } + + /* + Return from inflate(), updating the total counts and the check value. + If there was no progress during the inflate() call, return a buffer + error. Call updatewindow() to create and/or update the window state. + Note: a memory error from inflate() is non-recoverable. + */ + inf_leave: + RESTORE(); + if (state->wsize || (state->mode < CHECK && out != strm->avail_out)) + if (updatewindow(strm, out)) { + state->mode = MEM; + return Z_MEM_ERROR; + } + in -= strm->avail_in; + out -= strm->avail_out; + strm->total_in += in; + strm->total_out += out; + state->total += out; + if (state->wrap && out) + strm->adler = state->check = + UPDATE(state->check, strm->next_out - out, out); + strm->data_type = state->bits + (state->last ? 64 : 0) + + (state->mode == TYPE ? 128 : 0) + + (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0); + if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK) + ret = Z_BUF_ERROR; + return ret; +} + +int ZEXPORT inflateEnd(strm) +z_streamp strm; +{ + struct inflate_state FAR *state; + if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) + return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if (state->window != Z_NULL) ZFREE(strm, state->window); + ZFREE(strm, strm->state); + strm->state = Z_NULL; + Tracev((stderr, "inflate: end\n")); + return Z_OK; +} + +int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength) +z_streamp strm; +const Bytef *dictionary; +uInt dictLength; +{ + struct inflate_state FAR *state; + unsigned long id; + + /* check state */ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if (state->wrap != 0 && state->mode != DICT) + return Z_STREAM_ERROR; + + /* check for correct dictionary id */ + if (state->mode == DICT) { + id = adler32(0L, Z_NULL, 0); + id = adler32(id, dictionary, dictLength); + if (id != state->check) + return Z_DATA_ERROR; + } + + /* copy dictionary to window */ + if (updatewindow(strm, strm->avail_out)) { + state->mode = MEM; + return Z_MEM_ERROR; + } + if (dictLength > state->wsize) { + zmemcpy(state->window, dictionary + dictLength - state->wsize, + state->wsize); + state->whave = state->wsize; + } + else { + zmemcpy(state->window + state->wsize - dictLength, dictionary, + dictLength); + state->whave = dictLength; + } + state->havedict = 1; + Tracev((stderr, "inflate: dictionary set\n")); + return Z_OK; +} + +int ZEXPORT inflateGetHeader(strm, head) +z_streamp strm; +gz_headerp head; +{ + struct inflate_state FAR *state; + + /* check state */ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if ((state->wrap & 2) == 0) return Z_STREAM_ERROR; + + /* save header structure */ + state->head = head; + head->done = 0; + return Z_OK; +} + +/* + Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found + or when out of input. When called, *have is the number of pattern bytes + found in order so far, in 0..3. On return *have is updated to the new + state. If on return *have equals four, then the pattern was found and the + return value is how many bytes were read including the last byte of the + pattern. If *have is less than four, then the pattern has not been found + yet and the return value is len. In the latter case, syncsearch() can be + called again with more data and the *have state. *have is initialized to + zero for the first call. + */ +local unsigned syncsearch(have, buf, len) +unsigned FAR *have; +unsigned char FAR *buf; +unsigned len; +{ + unsigned got; + unsigned next; + + got = *have; + next = 0; + while (next < len && got < 4) { + if ((int)(buf[next]) == (got < 2 ? 0 : 0xff)) + got++; + else if (buf[next]) + got = 0; + else + got = 4 - got; + next++; + } + *have = got; + return next; +} + +int ZEXPORT inflateSync(strm) +z_streamp strm; +{ + unsigned len; /* number of bytes to look at or looked at */ + unsigned long in, out; /* temporary to save total_in and total_out */ + unsigned char buf[4]; /* to restore bit buffer to byte string */ + struct inflate_state FAR *state; + + /* check parameters */ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR; + + /* if first time, start search in bit buffer */ + if (state->mode != SYNC) { + state->mode = SYNC; + state->hold <<= state->bits & 7; + state->bits -= state->bits & 7; + len = 0; + while (state->bits >= 8) { + buf[len++] = (unsigned char)(state->hold); + state->hold >>= 8; + state->bits -= 8; + } + state->have = 0; + syncsearch(&(state->have), buf, len); + } + + /* search available input */ + len = syncsearch(&(state->have), strm->next_in, strm->avail_in); + strm->avail_in -= len; + strm->next_in += len; + strm->total_in += len; + + /* return no joy or set up to restart inflate() on a new block */ + if (state->have != 4) return Z_DATA_ERROR; + in = strm->total_in; out = strm->total_out; + inflateReset(strm); + strm->total_in = in; strm->total_out = out; + state->mode = TYPE; + return Z_OK; +} + +/* + Returns true if inflate is currently at the end of a block generated by + Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP + implementation to provide an additional safety check. PPP uses + Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored + block. When decompressing, PPP checks that at the end of input packet, + inflate is waiting for these length bytes. + */ +int ZEXPORT inflateSyncPoint(strm) +z_streamp strm; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + return state->mode == STORED && state->bits == 0; +} + +int ZEXPORT inflateCopy(dest, source) +z_streamp dest; +z_streamp source; +{ + struct inflate_state FAR *state; + struct inflate_state FAR *copy; + unsigned char FAR *window; + unsigned wsize; + + /* check input */ + if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL || + source->zalloc == (alloc_func)0 || source->zfree == (free_func)0) + return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)source->state; + + /* allocate space */ + copy = (struct inflate_state FAR *) + ZALLOC(source, 1, sizeof(struct inflate_state)); + if (copy == Z_NULL) return Z_MEM_ERROR; + window = Z_NULL; + if (state->window != Z_NULL) { + window = (unsigned char FAR *) + ZALLOC(source, 1U << state->wbits, sizeof(unsigned char)); + if (window == Z_NULL) { + ZFREE(source, copy); + return Z_MEM_ERROR; + } + } + + /* copy state */ + zmemcpy(dest, source, sizeof(z_stream)); + zmemcpy(copy, state, sizeof(struct inflate_state)); + if (state->lencode >= state->codes && + state->lencode <= state->codes + ENOUGH - 1) { + copy->lencode = copy->codes + (state->lencode - state->codes); + copy->distcode = copy->codes + (state->distcode - state->codes); + } + copy->next = copy->codes + (state->next - state->codes); + if (window != Z_NULL) { + wsize = 1U << state->wbits; + zmemcpy(window, state->window, wsize); + } + copy->window = window; + dest->state = (struct internal_state FAR *)copy; + return Z_OK; +} + +int ZEXPORT inflateUndermine(strm, subvert) +z_streamp strm; +int subvert; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + state->sane = !subvert; +#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR + return Z_OK; +#else + state->sane = 1; + return Z_DATA_ERROR; +#endif +} + +long ZEXPORT inflateMark(strm) +z_streamp strm; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16; + state = (struct inflate_state FAR *)strm->state; + return ((long)(state->back) << 16) + + (state->mode == COPY ? state->length : + (state->mode == MATCH ? state->was - state->length : 0)); +} diff --git a/fceumm/utils/zlib/inflate.h b/fceumm/utils/zlib/inflate.h new file mode 100644 index 0000000..95f4986 --- /dev/null +++ b/fceumm/utils/zlib/inflate.h @@ -0,0 +1,122 @@ +/* inflate.h -- internal inflate state definition + * Copyright (C) 1995-2009 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* define NO_GZIP when compiling if you want to disable gzip header and + trailer decoding by inflate(). NO_GZIP would be used to avoid linking in + the crc code when it is not needed. For shared libraries, gzip decoding + should be left enabled. */ +#ifndef NO_GZIP +# define GUNZIP +#endif + +/* Possible inflate modes between inflate() calls */ +typedef enum { + HEAD, /* i: waiting for magic header */ + FLAGS, /* i: waiting for method and flags (gzip) */ + TIME, /* i: waiting for modification time (gzip) */ + OS, /* i: waiting for extra flags and operating system (gzip) */ + EXLEN, /* i: waiting for extra length (gzip) */ + EXTRA, /* i: waiting for extra bytes (gzip) */ + NAME, /* i: waiting for end of file name (gzip) */ + COMMENT, /* i: waiting for end of comment (gzip) */ + HCRC, /* i: waiting for header crc (gzip) */ + DICTID, /* i: waiting for dictionary check value */ + DICT, /* waiting for inflateSetDictionary() call */ + TYPE, /* i: waiting for type bits, including last-flag bit */ + TYPEDO, /* i: same, but skip check to exit inflate on new block */ + STORED, /* i: waiting for stored size (length and complement) */ + COPY_, /* i/o: same as COPY below, but only first time in */ + COPY, /* i/o: waiting for input or output to copy stored block */ + TABLE, /* i: waiting for dynamic block table lengths */ + LENLENS, /* i: waiting for code length code lengths */ + CODELENS, /* i: waiting for length/lit and distance code lengths */ + LEN_, /* i: same as LEN below, but only first time in */ + LEN, /* i: waiting for length/lit/eob code */ + LENEXT, /* i: waiting for length extra bits */ + DIST, /* i: waiting for distance code */ + DISTEXT, /* i: waiting for distance extra bits */ + MATCH, /* o: waiting for output space to copy string */ + LIT, /* o: waiting for output space to write literal */ + CHECK, /* i: waiting for 32-bit check value */ + LENGTH, /* i: waiting for 32-bit length (gzip) */ + DONE, /* finished check, done -- remain here until reset */ + BAD, /* got a data error -- remain here until reset */ + MEM, /* got an inflate() memory error -- remain here until reset */ + SYNC /* looking for synchronization bytes to restart inflate() */ +} inflate_mode; + +/* + State transitions between above modes - + + (most modes can go to BAD or MEM on error -- not shown for clarity) + + Process header: + HEAD -> (gzip) or (zlib) or (raw) + (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> + HCRC -> TYPE + (zlib) -> DICTID or TYPE + DICTID -> DICT -> TYPE + (raw) -> TYPEDO + Read deflate blocks: + TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK + STORED -> COPY_ -> COPY -> TYPE + TABLE -> LENLENS -> CODELENS -> LEN_ + LEN_ -> LEN + Read deflate codes in fixed or dynamic block: + LEN -> LENEXT or LIT or TYPE + LENEXT -> DIST -> DISTEXT -> MATCH -> LEN + LIT -> LEN + Process trailer: + CHECK -> LENGTH -> DONE + */ + +/* state maintained between inflate() calls. Approximately 10K bytes. */ +struct inflate_state { + inflate_mode mode; /* current inflate mode */ + int last; /* true if processing last block */ + int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ + int havedict; /* true if dictionary provided */ + int flags; /* gzip header method and flags (0 if zlib) */ + unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ + unsigned long check; /* protected copy of check value */ + unsigned long total; /* protected copy of output count */ + gz_headerp head; /* where to save gzip header information */ + /* sliding window */ + unsigned wbits; /* log base 2 of requested window size */ + unsigned wsize; /* window size or zero if not using window */ + unsigned whave; /* valid bytes in the window */ + unsigned wnext; /* window write index */ + unsigned char FAR *window; /* allocated sliding window, if needed */ + /* bit accumulator */ + unsigned long hold; /* input bit accumulator */ + unsigned bits; /* number of bits in "in" */ + /* for string and stored block copying */ + unsigned length; /* literal or length of data to copy */ + unsigned offset; /* distance back to copy string from */ + /* for table and code decoding */ + unsigned extra; /* extra bits needed */ + /* fixed and dynamic code tables */ + code const FAR *lencode; /* starting table for length/literal codes */ + code const FAR *distcode; /* starting table for distance codes */ + unsigned lenbits; /* index bits for lencode */ + unsigned distbits; /* index bits for distcode */ + /* dynamic table building */ + unsigned ncode; /* number of code length code lengths */ + unsigned nlen; /* number of length code lengths */ + unsigned ndist; /* number of distance code lengths */ + unsigned have; /* number of code lengths in lens[] */ + code FAR *next; /* next available space in codes[] */ + unsigned short lens[320]; /* temporary storage for code lengths */ + unsigned short work[288]; /* work area for code table building */ + code codes[ENOUGH]; /* space for code tables */ + int sane; /* if false, allow invalid distance too far */ + int back; /* bits back of last unprocessed length/lit */ + unsigned was; /* initial length of match */ +}; diff --git a/fceumm/utils/zlib/inftrees.c b/fceumm/utils/zlib/inftrees.c new file mode 100644 index 0000000..11e9c52 --- /dev/null +++ b/fceumm/utils/zlib/inftrees.c @@ -0,0 +1,330 @@ +/* inftrees.c -- generate Huffman trees for efficient decoding + * Copyright (C) 1995-2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "zutil.h" +#include "inftrees.h" + +#define MAXBITS 15 + +const char inflate_copyright[] = + " inflate 1.2.5 Copyright 1995-2010 Mark Adler "; +/* + If you use the zlib library in a product, an acknowledgment is welcome + in the documentation of your product. If for some reason you cannot + include such an acknowledgment, I would appreciate that you keep this + copyright string in the executable of your product. + */ + +/* + Build a set of tables to decode the provided canonical Huffman code. + The code lengths are lens[0..codes-1]. The result starts at *table, + whose indices are 0..2^bits-1. work is a writable array of at least + lens shorts, which is used as a work area. type is the type of code + to be generated, CODES, LENS, or DISTS. On return, zero is success, + -1 is an invalid code, and +1 means that ENOUGH isn't enough. table + on return points to the next available entry's address. bits is the + requested root table index bits, and on return it is the actual root + table index bits. It will differ if the request is greater than the + longest code or if it is less than the shortest code. + */ +int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) +codetype type; +unsigned short FAR *lens; +unsigned codes; +code FAR * FAR *table; +unsigned FAR *bits; +unsigned short FAR *work; +{ + unsigned len; /* a code's length in bits */ + unsigned sym; /* index of code symbols */ + unsigned min, max; /* minimum and maximum code lengths */ + unsigned root; /* number of index bits for root table */ + unsigned curr; /* number of index bits for current table */ + unsigned drop; /* code bits to drop for sub-table */ + int left; /* number of prefix codes available */ + unsigned used; /* code entries in table used */ + unsigned huff; /* Huffman code */ + unsigned incr; /* for incrementing code, index */ + unsigned fill; /* index for replicating entries */ + unsigned low; /* low bits for current root entry */ + unsigned mask; /* mask for low root bits */ + code here; /* table entry for duplication */ + code FAR *next; /* next available space in table */ + const unsigned short FAR *base; /* base value table to use */ + const unsigned short FAR *extra; /* extra bits table to use */ + int end; /* use base and extra for symbol > end */ + unsigned short count[MAXBITS+1]; /* number of codes of each length */ + unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ + static const unsigned short lbase[31] = { /* Length codes 257..285 base */ + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, + 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; + static const unsigned short lext[31] = { /* Length codes 257..285 extra */ + 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 73, 195}; + static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, + 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, + 8193, 12289, 16385, 24577, 0, 0}; + static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ + 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, + 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, + 28, 28, 29, 29, 64, 64}; + + /* + Process a set of code lengths to create a canonical Huffman code. The + code lengths are lens[0..codes-1]. Each length corresponds to the + symbols 0..codes-1. The Huffman code is generated by first sorting the + symbols by length from short to long, and retaining the symbol order + for codes with equal lengths. Then the code starts with all zero bits + for the first code of the shortest length, and the codes are integer + increments for the same length, and zeros are appended as the length + increases. For the deflate format, these bits are stored backwards + from their more natural integer increment ordering, and so when the + decoding tables are built in the large loop below, the integer codes + are incremented backwards. + + This routine assumes, but does not check, that all of the entries in + lens[] are in the range 0..MAXBITS. The caller must assure this. + 1..MAXBITS is interpreted as that code length. zero means that that + symbol does not occur in this code. + + The codes are sorted by computing a count of codes for each length, + creating from that a table of starting indices for each length in the + sorted table, and then entering the symbols in order in the sorted + table. The sorted table is work[], with that space being provided by + the caller. + + The length counts are used for other purposes as well, i.e. finding + the minimum and maximum length codes, determining if there are any + codes at all, checking for a valid set of lengths, and looking ahead + at length counts to determine sub-table sizes when building the + decoding tables. + */ + + /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ + for (len = 0; len <= MAXBITS; len++) + count[len] = 0; + for (sym = 0; sym < codes; sym++) + count[lens[sym]]++; + + /* bound code lengths, force root to be within code lengths */ + root = *bits; + for (max = MAXBITS; max >= 1; max--) + if (count[max] != 0) break; + if (root > max) root = max; + if (max == 0) { /* no symbols to code at all */ + here.op = (unsigned char)64; /* invalid code marker */ + here.bits = (unsigned char)1; + here.val = (unsigned short)0; + *(*table)++ = here; /* make a table to force an error */ + *(*table)++ = here; + *bits = 1; + return 0; /* no symbols, but wait for decoding to report error */ + } + for (min = 1; min < max; min++) + if (count[min] != 0) break; + if (root < min) root = min; + + /* check for an over-subscribed or incomplete set of lengths */ + left = 1; + for (len = 1; len <= MAXBITS; len++) { + left <<= 1; + left -= count[len]; + if (left < 0) return -1; /* over-subscribed */ + } + if (left > 0 && (type == CODES || max != 1)) + return -1; /* incomplete set */ + + /* generate offsets into symbol table for each length for sorting */ + offs[1] = 0; + for (len = 1; len < MAXBITS; len++) + offs[len + 1] = offs[len] + count[len]; + + /* sort symbols by length, by symbol order within each length */ + for (sym = 0; sym < codes; sym++) + if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; + + /* + Create and fill in decoding tables. In this loop, the table being + filled is at next and has curr index bits. The code being used is huff + with length len. That code is converted to an index by dropping drop + bits off of the bottom. For codes where len is less than drop + curr, + those top drop + curr - len bits are incremented through all values to + fill the table with replicated entries. + + root is the number of index bits for the root table. When len exceeds + root, sub-tables are created pointed to by the root entry with an index + of the low root bits of huff. This is saved in low to check for when a + new sub-table should be started. drop is zero when the root table is + being filled, and drop is root when sub-tables are being filled. + + When a new sub-table is needed, it is necessary to look ahead in the + code lengths to determine what size sub-table is needed. The length + counts are used for this, and so count[] is decremented as codes are + entered in the tables. + + used keeps track of how many table entries have been allocated from the + provided *table space. It is checked for LENS and DIST tables against + the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in + the initial root table size constants. See the comments in inftrees.h + for more information. + + sym increments through all symbols, and the loop terminates when + all codes of length max, i.e. all codes, have been processed. This + routine permits incomplete codes, so another loop after this one fills + in the rest of the decoding tables with invalid code markers. + */ + + /* set up for code type */ + switch (type) { + case CODES: + base = extra = work; /* dummy value--not used */ + end = 19; + break; + case LENS: + base = lbase; + base -= 257; + extra = lext; + extra -= 257; + end = 256; + break; + default: /* DISTS */ + base = dbase; + extra = dext; + end = -1; + } + + /* initialize state for loop */ + huff = 0; /* starting code */ + sym = 0; /* starting code symbol */ + len = min; /* starting code length */ + next = *table; /* current table to fill in */ + curr = root; /* current table index bits */ + drop = 0; /* current bits to drop from code for index */ + low = (unsigned)(-1); /* trigger new sub-table when len > root */ + used = 1U << root; /* use root table entries */ + mask = used - 1; /* mask for comparing low */ + + /* check available table space */ + if ((type == LENS && used >= ENOUGH_LENS) || + (type == DISTS && used >= ENOUGH_DISTS)) + return 1; + + /* process all codes and make table entries */ + for (;;) { + /* create table entry */ + here.bits = (unsigned char)(len - drop); + if ((int)(work[sym]) < end) { + here.op = (unsigned char)0; + here.val = work[sym]; + } + else if ((int)(work[sym]) > end) { + here.op = (unsigned char)(extra[work[sym]]); + here.val = base[work[sym]]; + } + else { + here.op = (unsigned char)(32 + 64); /* end of block */ + here.val = 0; + } + + /* replicate for those indices with low len bits equal to huff */ + incr = 1U << (len - drop); + fill = 1U << curr; + min = fill; /* save offset to next table */ + do { + fill -= incr; + next[(huff >> drop) + fill] = here; + } while (fill != 0); + + /* backwards increment the len-bit code huff */ + incr = 1U << (len - 1); + while (huff & incr) + incr >>= 1; + if (incr != 0) { + huff &= incr - 1; + huff += incr; + } + else + huff = 0; + + /* go to next symbol, update count, len */ + sym++; + if (--(count[len]) == 0) { + if (len == max) break; + len = lens[work[sym]]; + } + + /* create new sub-table if needed */ + if (len > root && (huff & mask) != low) { + /* if first time, transition to sub-tables */ + if (drop == 0) + drop = root; + + /* increment past last table */ + next += min; /* here min is 1 << curr */ + + /* determine length of next table */ + curr = len - drop; + left = (int)(1 << curr); + while (curr + drop < max) { + left -= count[curr + drop]; + if (left <= 0) break; + curr++; + left <<= 1; + } + + /* check for enough space */ + used += 1U << curr; + if ((type == LENS && used >= ENOUGH_LENS) || + (type == DISTS && used >= ENOUGH_DISTS)) + return 1; + + /* point entry in root table to sub-table */ + low = huff & mask; + (*table)[low].op = (unsigned char)curr; + (*table)[low].bits = (unsigned char)root; + (*table)[low].val = (unsigned short)(next - *table); + } + } + + /* + Fill in rest of table for incomplete codes. This loop is similar to the + loop above in incrementing huff for table indices. It is assumed that + len is equal to curr + drop, so there is no loop needed to increment + through high index bits. When the current sub-table is filled, the loop + drops back to the root table to fill in any remaining entries there. + */ + here.op = (unsigned char)64; /* invalid code marker */ + here.bits = (unsigned char)(len - drop); + here.val = (unsigned short)0; + while (huff != 0) { + /* when done with sub-table, drop back to root table */ + if (drop != 0 && (huff & mask) != low) { + drop = 0; + len = root; + next = *table; + here.bits = (unsigned char)len; + } + + /* put invalid code marker in table */ + next[huff >> drop] = here; + + /* backwards increment the len-bit code huff */ + incr = 1U << (len - 1); + while (huff & incr) + incr >>= 1; + if (incr != 0) { + huff &= incr - 1; + huff += incr; + } + else + huff = 0; + } + + /* set return parameters */ + *table += used; + *bits = root; + return 0; +} diff --git a/fceumm/utils/zlib/inftrees.h b/fceumm/utils/zlib/inftrees.h new file mode 100644 index 0000000..baa53a0 --- /dev/null +++ b/fceumm/utils/zlib/inftrees.h @@ -0,0 +1,62 @@ +/* inftrees.h -- header to use inftrees.c + * Copyright (C) 1995-2005, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* Structure for decoding tables. Each entry provides either the + information needed to do the operation requested by the code that + indexed that table entry, or it provides a pointer to another + table that indexes more bits of the code. op indicates whether + the entry is a pointer to another table, a literal, a length or + distance, an end-of-block, or an invalid code. For a table + pointer, the low four bits of op is the number of index bits of + that table. For a length or distance, the low four bits of op + is the number of extra bits to get after the code. bits is + the number of bits in this code or part of the code to drop off + of the bit buffer. val is the actual byte to output in the case + of a literal, the base length or distance, or the offset from + the current table to the next table. Each entry is four bytes. */ +typedef struct { + unsigned char op; /* operation, extra bits, table bits */ + unsigned char bits; /* bits in this part of the code */ + unsigned short val; /* offset in table or code value */ +} code; + +/* op values as set by inflate_table(): + 00000000 - literal + 0000tttt - table link, tttt != 0 is the number of table index bits + 0001eeee - length or distance, eeee is the number of extra bits + 01100000 - end of block + 01000000 - invalid code + */ + +/* Maximum size of the dynamic table. The maximum number of code structures is + 1444, which is the sum of 852 for literal/length codes and 592 for distance + codes. These values were found by exhaustive searches using the program + examples/enough.c found in the zlib distribtution. The arguments to that + program are the number of symbols, the initial root table size, and the + maximum bit length of a code. "enough 286 9 15" for literal/length codes + returns returns 852, and "enough 30 6 15" for distance codes returns 592. + The initial root table size (9 or 6) is found in the fifth argument of the + inflate_table() calls in inflate.c and infback.c. If the root table size is + changed, then these maximum sizes would be need to be recalculated and + updated. */ +#define ENOUGH_LENS 852 +#define ENOUGH_DISTS 592 +#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) + +/* Type of code to build for inflate_table() */ +typedef enum { + CODES, + LENS, + DISTS +} codetype; + +int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, + unsigned codes, code FAR * FAR *table, + unsigned FAR *bits, unsigned short FAR *work)); diff --git a/fceumm/utils/zlib/trees.c b/fceumm/utils/zlib/trees.c new file mode 100644 index 0000000..56e9bb1 --- /dev/null +++ b/fceumm/utils/zlib/trees.c @@ -0,0 +1,1244 @@ +/* trees.c -- output deflated data using Huffman coding + * Copyright (C) 1995-2010 Jean-loup Gailly + * detect_data_type() function provided freely by Cosmin Truta, 2006 + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + * ALGORITHM + * + * The "deflation" process uses several Huffman trees. The more + * common source values are represented by shorter bit sequences. + * + * Each code tree is stored in a compressed form which is itself + * a Huffman encoding of the lengths of all the code strings (in + * ascending order by source values). The actual code strings are + * reconstructed from the lengths in the inflate process, as described + * in the deflate specification. + * + * REFERENCES + * + * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". + * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc + * + * Storer, James A. + * Data Compression: Methods and Theory, pp. 49-50. + * Computer Science Press, 1988. ISBN 0-7167-8156-5. + * + * Sedgewick, R. + * Algorithms, p290. + * Addison-Wesley, 1983. ISBN 0-201-06672-6. + */ + +/* @(#) $Id$ */ + +/* #define GEN_TREES_H */ + +#include "deflate.h" + +#ifdef DEBUG +# include +#endif + +/* =========================================================================== + * Constants + */ + +#define MAX_BL_BITS 7 +/* Bit length codes must not exceed MAX_BL_BITS bits */ + +#define END_BLOCK 256 +/* end of block literal code */ + +#define REP_3_6 16 +/* repeat previous bit length 3-6 times (2 bits of repeat count) */ + +#define REPZ_3_10 17 +/* repeat a zero length 3-10 times (3 bits of repeat count) */ + +#define REPZ_11_138 18 +/* repeat a zero length 11-138 times (7 bits of repeat count) */ + +local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ + = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; + +local const int extra_dbits[D_CODES] /* extra bits for each distance code */ + = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; + +local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */ + = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; + +local const uch bl_order[BL_CODES] + = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; +/* The lengths of the bit length codes are sent in order of decreasing + * probability, to avoid transmitting the lengths for unused bit length codes. + */ + +#define Buf_size (8 * 2*sizeof(char)) +/* Number of bits used within bi_buf. (bi_buf might be implemented on + * more than 16 bits on some systems.) + */ + +/* =========================================================================== + * Local data. These are initialized only once. + */ + +#define DIST_CODE_LEN 512 /* see definition of array dist_code below */ + +#if defined(GEN_TREES_H) || !defined(STDC) +/* non ANSI compilers may not accept trees.h */ + +local ct_data static_ltree[L_CODES+2]; +/* The static literal tree. Since the bit lengths are imposed, there is no + * need for the L_CODES extra codes used during heap construction. However + * The codes 286 and 287 are needed to build a canonical tree (see _tr_init + * below). + */ + +local ct_data static_dtree[D_CODES]; +/* The static distance tree. (Actually a trivial tree since all codes use + * 5 bits.) + */ + +uch _dist_code[DIST_CODE_LEN]; +/* Distance codes. The first 256 values correspond to the distances + * 3 .. 258, the last 256 values correspond to the top 8 bits of + * the 15 bit distances. + */ + +uch _length_code[MAX_MATCH-MIN_MATCH+1]; +/* length code for each normalized match length (0 == MIN_MATCH) */ + +local int base_length[LENGTH_CODES]; +/* First normalized length for each code (0 = MIN_MATCH) */ + +local int base_dist[D_CODES]; +/* First normalized distance for each code (0 = distance of 1) */ + +#else +# include "trees.h" +#endif /* GEN_TREES_H */ + +struct static_tree_desc_s { + const ct_data *static_tree; /* static tree or NULL */ + const intf *extra_bits; /* extra bits for each code or NULL */ + int extra_base; /* base index for extra_bits */ + int elems; /* max number of elements in the tree */ + int max_length; /* max bit length for the codes */ +}; + +local static_tree_desc static_l_desc = +{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; + +local static_tree_desc static_d_desc = +{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; + +local static_tree_desc static_bl_desc = +{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; + +/* =========================================================================== + * Local (static) routines in this file. + */ + +local void tr_static_init OF((void)); +local void init_block OF((deflate_state *s)); +local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); +local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); +local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); +local void build_tree OF((deflate_state *s, tree_desc *desc)); +local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); +local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); +local int build_bl_tree OF((deflate_state *s)); +local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, + int blcodes)); +local void compress_block OF((deflate_state *s, ct_data *ltree, + ct_data *dtree)); +local int detect_data_type OF((deflate_state *s)); +local unsigned bi_reverse OF((unsigned value, int length)); +local void bi_windup OF((deflate_state *s)); +local void bi_flush OF((deflate_state *s)); +local void copy_block OF((deflate_state *s, charf *buf, unsigned len, + int header)); + +#ifdef GEN_TREES_H +local void gen_trees_header OF((void)); +#endif + +#ifndef DEBUG +# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) + /* Send a code of the given tree. c and tree must not have side effects */ + +#else /* DEBUG */ +# define send_code(s, c, tree) \ + { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ + send_bits(s, tree[c].Code, tree[c].Len); } +#endif + +/* =========================================================================== + * Output a short LSB first on the stream. + * IN assertion: there is enough room in pendingBuf. + */ +#define put_short(s, w) { \ + put_byte(s, (uch)((w) & 0xff)); \ + put_byte(s, (uch)((ush)(w) >> 8)); \ +} + +/* =========================================================================== + * Send a value on a given number of bits. + * IN assertion: length <= 16 and value fits in length bits. + */ +#ifdef DEBUG +local void send_bits OF((deflate_state *s, int value, int length)); + +local void send_bits(s, value, length) + deflate_state *s; + int value; /* value to send */ + int length; /* number of bits */ +{ + Tracevv((stderr," l %2d v %4x ", length, value)); + Assert(length > 0 && length <= 15, "invalid length"); + s->bits_sent += (ulg)length; + + /* If not enough room in bi_buf, use (valid) bits from bi_buf and + * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid)) + * unused bits in value. + */ + if (s->bi_valid > (int)Buf_size - length) { + s->bi_buf |= (ush)value << s->bi_valid; + put_short(s, s->bi_buf); + s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); + s->bi_valid += length - Buf_size; + } else { + s->bi_buf |= (ush)value << s->bi_valid; + s->bi_valid += length; + } +} +#else /* !DEBUG */ + +#define send_bits(s, value, length) \ +{ int len = length;\ + if (s->bi_valid > (int)Buf_size - len) {\ + int val = value;\ + s->bi_buf |= (ush)val << s->bi_valid;\ + put_short(s, s->bi_buf);\ + s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ + s->bi_valid += len - Buf_size;\ + } else {\ + s->bi_buf |= (ush)(value) << s->bi_valid;\ + s->bi_valid += len;\ + }\ +} +#endif /* DEBUG */ + + +/* the arguments must not have side effects */ + +/* =========================================================================== + * Initialize the various 'constant' tables. + */ +local void tr_static_init() +{ +#if defined(GEN_TREES_H) || !defined(STDC) + static int static_init_done = 0; + int n; /* iterates over tree elements */ + int bits; /* bit counter */ + int length; /* length value */ + int code; /* code value */ + int dist; /* distance index */ + ush bl_count[MAX_BITS+1]; + /* number of codes at each bit length for an optimal tree */ + + if (static_init_done) return; + + /* For some embedded targets, global variables are not initialized: */ +#ifdef NO_INIT_GLOBAL_POINTERS + static_l_desc.static_tree = static_ltree; + static_l_desc.extra_bits = extra_lbits; + static_d_desc.static_tree = static_dtree; + static_d_desc.extra_bits = extra_dbits; + static_bl_desc.extra_bits = extra_blbits; +#endif + + /* Initialize the mapping length (0..255) -> length code (0..28) */ + length = 0; + for (code = 0; code < LENGTH_CODES-1; code++) { + base_length[code] = length; + for (n = 0; n < (1< dist code (0..29) */ + dist = 0; + for (code = 0 ; code < 16; code++) { + base_dist[code] = dist; + for (n = 0; n < (1<>= 7; /* from now on, all distances are divided by 128 */ + for ( ; code < D_CODES; code++) { + base_dist[code] = dist << 7; + for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { + _dist_code[256 + dist++] = (uch)code; + } + } + Assert (dist == 256, "tr_static_init: 256+dist != 512"); + + /* Construct the codes of the static literal tree */ + for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; + n = 0; + while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++; + while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++; + while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++; + while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++; + /* Codes 286 and 287 do not exist, but we must include them in the + * tree construction to get a canonical Huffman tree (longest code + * all ones) + */ + gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count); + + /* The static distance tree is trivial: */ + for (n = 0; n < D_CODES; n++) { + static_dtree[n].Len = 5; + static_dtree[n].Code = bi_reverse((unsigned)n, 5); + } + static_init_done = 1; + +# ifdef GEN_TREES_H + gen_trees_header(); +# endif +#endif /* defined(GEN_TREES_H) || !defined(STDC) */ +} + +/* =========================================================================== + * Genererate the file trees.h describing the static trees. + */ +#ifdef GEN_TREES_H +# ifndef DEBUG +# include +# endif + +# define SEPARATOR(i, last, width) \ + ((i) == (last)? "\n};\n\n" : \ + ((i) % (width) == (width)-1 ? ",\n" : ", ")) + +void gen_trees_header() +{ + FILE *header = fopen("trees.h", "w"); + int i; + + Assert (header != NULL, "Can't open trees.h"); + fprintf(header, + "/* header created automatically with -DGEN_TREES_H */\n\n"); + + fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); + for (i = 0; i < L_CODES+2; i++) { + fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, + static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); + } + + fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); + for (i = 0; i < D_CODES; i++) { + fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, + static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); + } + + fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n"); + for (i = 0; i < DIST_CODE_LEN; i++) { + fprintf(header, "%2u%s", _dist_code[i], + SEPARATOR(i, DIST_CODE_LEN-1, 20)); + } + + fprintf(header, + "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); + for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { + fprintf(header, "%2u%s", _length_code[i], + SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); + } + + fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); + for (i = 0; i < LENGTH_CODES; i++) { + fprintf(header, "%1u%s", base_length[i], + SEPARATOR(i, LENGTH_CODES-1, 20)); + } + + fprintf(header, "local const int base_dist[D_CODES] = {\n"); + for (i = 0; i < D_CODES; i++) { + fprintf(header, "%5u%s", base_dist[i], + SEPARATOR(i, D_CODES-1, 10)); + } + + fclose(header); +} +#endif /* GEN_TREES_H */ + +/* =========================================================================== + * Initialize the tree data structures for a new zlib stream. + */ +void ZLIB_INTERNAL _tr_init(s) + deflate_state *s; +{ + tr_static_init(); + + s->l_desc.dyn_tree = s->dyn_ltree; + s->l_desc.stat_desc = &static_l_desc; + + s->d_desc.dyn_tree = s->dyn_dtree; + s->d_desc.stat_desc = &static_d_desc; + + s->bl_desc.dyn_tree = s->bl_tree; + s->bl_desc.stat_desc = &static_bl_desc; + + s->bi_buf = 0; + s->bi_valid = 0; + s->last_eob_len = 8; /* enough lookahead for inflate */ +#ifdef DEBUG + s->compressed_len = 0L; + s->bits_sent = 0L; +#endif + + /* Initialize the first block of the first file: */ + init_block(s); +} + +/* =========================================================================== + * Initialize a new block. + */ +local void init_block(s) + deflate_state *s; +{ + int n; /* iterates over tree elements */ + + /* Initialize the trees. */ + for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; + for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; + for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; + + s->dyn_ltree[END_BLOCK].Freq = 1; + s->opt_len = s->static_len = 0L; + s->last_lit = s->matches = 0; +} + +#define SMALLEST 1 +/* Index within the heap array of least frequent node in the Huffman tree */ + + +/* =========================================================================== + * Remove the smallest element from the heap and recreate the heap with + * one less element. Updates heap and heap_len. + */ +#define pqremove(s, tree, top) \ +{\ + top = s->heap[SMALLEST]; \ + s->heap[SMALLEST] = s->heap[s->heap_len--]; \ + pqdownheap(s, tree, SMALLEST); \ +} + +/* =========================================================================== + * Compares to subtrees, using the tree depth as tie breaker when + * the subtrees have equal frequency. This minimizes the worst case length. + */ +#define smaller(tree, n, m, depth) \ + (tree[n].Freq < tree[m].Freq || \ + (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) + +/* =========================================================================== + * Restore the heap property by moving down the tree starting at node k, + * exchanging a node with the smallest of its two sons if necessary, stopping + * when the heap property is re-established (each father smaller than its + * two sons). + */ +local void pqdownheap(s, tree, k) + deflate_state *s; + ct_data *tree; /* the tree to restore */ + int k; /* node to move down */ +{ + int v = s->heap[k]; + int j = k << 1; /* left son of k */ + while (j <= s->heap_len) { + /* Set j to the smallest of the two sons: */ + if (j < s->heap_len && + smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { + j++; + } + /* Exit if v is smaller than both sons */ + if (smaller(tree, v, s->heap[j], s->depth)) break; + + /* Exchange v with the smallest son */ + s->heap[k] = s->heap[j]; k = j; + + /* And continue down the tree, setting j to the left son of k */ + j <<= 1; + } + s->heap[k] = v; +} + +/* =========================================================================== + * Compute the optimal bit lengths for a tree and update the total bit length + * for the current block. + * IN assertion: the fields freq and dad are set, heap[heap_max] and + * above are the tree nodes sorted by increasing frequency. + * OUT assertions: the field len is set to the optimal bit length, the + * array bl_count contains the frequencies for each bit length. + * The length opt_len is updated; static_len is also updated if stree is + * not null. + */ +local void gen_bitlen(s, desc) + deflate_state *s; + tree_desc *desc; /* the tree descriptor */ +{ + ct_data *tree = desc->dyn_tree; + int max_code = desc->max_code; + const ct_data *stree = desc->stat_desc->static_tree; + const intf *extra = desc->stat_desc->extra_bits; + int base = desc->stat_desc->extra_base; + int max_length = desc->stat_desc->max_length; + int h; /* heap index */ + int n, m; /* iterate over the tree elements */ + int bits; /* bit length */ + int xbits; /* extra bits */ + ush f; /* frequency */ + int overflow = 0; /* number of elements with bit length too large */ + + for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; + + /* In a first pass, compute the optimal bit lengths (which may + * overflow in the case of the bit length tree). + */ + tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ + + for (h = s->heap_max+1; h < HEAP_SIZE; h++) { + n = s->heap[h]; + bits = tree[tree[n].Dad].Len + 1; + if (bits > max_length) bits = max_length, overflow++; + tree[n].Len = (ush)bits; + /* We overwrite tree[n].Dad which is no longer needed */ + + if (n > max_code) continue; /* not a leaf node */ + + s->bl_count[bits]++; + xbits = 0; + if (n >= base) xbits = extra[n-base]; + f = tree[n].Freq; + s->opt_len += (ulg)f * (bits + xbits); + if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); + } + if (overflow == 0) return; + + Trace((stderr,"\nbit length overflow\n")); + /* This happens for example on obj2 and pic of the Calgary corpus */ + + /* Find the first bit length which could increase: */ + do { + bits = max_length-1; + while (s->bl_count[bits] == 0) bits--; + s->bl_count[bits]--; /* move one leaf down the tree */ + s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ + s->bl_count[max_length]--; + /* The brother of the overflow item also moves one step up, + * but this does not affect bl_count[max_length] + */ + overflow -= 2; + } while (overflow > 0); + + /* Now recompute all bit lengths, scanning in increasing frequency. + * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all + * lengths instead of fixing only the wrong ones. This idea is taken + * from 'ar' written by Haruhiko Okumura.) + */ + for (bits = max_length; bits != 0; bits--) { + n = s->bl_count[bits]; + while (n != 0) { + m = s->heap[--h]; + if (m > max_code) continue; + if ((unsigned) tree[m].Len != (unsigned) bits) { + Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); + s->opt_len += ((long)bits - (long)tree[m].Len) + *(long)tree[m].Freq; + tree[m].Len = (ush)bits; + } + n--; + } + } +} + +/* =========================================================================== + * Generate the codes for a given tree and bit counts (which need not be + * optimal). + * IN assertion: the array bl_count contains the bit length statistics for + * the given tree and the field len is set for all tree elements. + * OUT assertion: the field code is set for all tree elements of non + * zero code length. + */ +local void gen_codes (tree, max_code, bl_count) + ct_data *tree; /* the tree to decorate */ + int max_code; /* largest code with non zero frequency */ + ushf *bl_count; /* number of codes at each bit length */ +{ + ush next_code[MAX_BITS+1]; /* next code value for each bit length */ + ush code = 0; /* running code value */ + int bits; /* bit index */ + int n; /* code index */ + + /* The distribution counts are first used to generate the code values + * without bit reversal. + */ + for (bits = 1; bits <= MAX_BITS; bits++) { + next_code[bits] = code = (code + bl_count[bits-1]) << 1; + } + /* Check that the bit counts in bl_count are consistent. The last code + * must be all ones. + */ + Assert (code + bl_count[MAX_BITS]-1 == (1<dyn_tree; + const ct_data *stree = desc->stat_desc->static_tree; + int elems = desc->stat_desc->elems; + int n, m; /* iterate over heap elements */ + int max_code = -1; /* largest code with non zero frequency */ + int node; /* new node being created */ + + /* Construct the initial heap, with least frequent element in + * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. + * heap[0] is not used. + */ + s->heap_len = 0, s->heap_max = HEAP_SIZE; + + for (n = 0; n < elems; n++) { + if (tree[n].Freq != 0) { + s->heap[++(s->heap_len)] = max_code = n; + s->depth[n] = 0; + } else { + tree[n].Len = 0; + } + } + + /* The pkzip format requires that at least one distance code exists, + * and that at least one bit should be sent even if there is only one + * possible code. So to avoid special checks later on we force at least + * two codes of non zero frequency. + */ + while (s->heap_len < 2) { + node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); + tree[node].Freq = 1; + s->depth[node] = 0; + s->opt_len--; if (stree) s->static_len -= stree[node].Len; + /* node is 0 or 1 so it does not have extra bits */ + } + desc->max_code = max_code; + + /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, + * establish sub-heaps of increasing lengths: + */ + for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); + + /* Construct the Huffman tree by repeatedly combining the least two + * frequent nodes. + */ + node = elems; /* next internal node of the tree */ + do { + pqremove(s, tree, n); /* n = node of least frequency */ + m = s->heap[SMALLEST]; /* m = node of next least frequency */ + + s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */ + s->heap[--(s->heap_max)] = m; + + /* Create a new node father of n and m */ + tree[node].Freq = tree[n].Freq + tree[m].Freq; + s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ? + s->depth[n] : s->depth[m]) + 1); + tree[n].Dad = tree[m].Dad = (ush)node; +#ifdef DUMP_BL_TREE + if (tree == s->bl_tree) { + fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", + node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); + } +#endif + /* and insert the new node in the heap */ + s->heap[SMALLEST] = node++; + pqdownheap(s, tree, SMALLEST); + + } while (s->heap_len >= 2); + + s->heap[--(s->heap_max)] = s->heap[SMALLEST]; + + /* At this point, the fields freq and dad are set. We can now + * generate the bit lengths. + */ + gen_bitlen(s, (tree_desc *)desc); + + /* The field len is now set, we can generate the bit codes */ + gen_codes ((ct_data *)tree, max_code, s->bl_count); +} + +/* =========================================================================== + * Scan a literal or distance tree to determine the frequencies of the codes + * in the bit length tree. + */ +local void scan_tree (s, tree, max_code) + deflate_state *s; + ct_data *tree; /* the tree to be scanned */ + int max_code; /* and its largest code of non zero frequency */ +{ + int n; /* iterates over all tree elements */ + int prevlen = -1; /* last emitted length */ + int curlen; /* length of current code */ + int nextlen = tree[0].Len; /* length of next code */ + int count = 0; /* repeat count of the current code */ + int max_count = 7; /* max repeat count */ + int min_count = 4; /* min repeat count */ + + if (nextlen == 0) max_count = 138, min_count = 3; + tree[max_code+1].Len = (ush)0xffff; /* guard */ + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; nextlen = tree[n+1].Len; + if (++count < max_count && curlen == nextlen) { + continue; + } else if (count < min_count) { + s->bl_tree[curlen].Freq += count; + } else if (curlen != 0) { + if (curlen != prevlen) s->bl_tree[curlen].Freq++; + s->bl_tree[REP_3_6].Freq++; + } else if (count <= 10) { + s->bl_tree[REPZ_3_10].Freq++; + } else { + s->bl_tree[REPZ_11_138].Freq++; + } + count = 0; prevlen = curlen; + if (nextlen == 0) { + max_count = 138, min_count = 3; + } else if (curlen == nextlen) { + max_count = 6, min_count = 3; + } else { + max_count = 7, min_count = 4; + } + } +} + +/* =========================================================================== + * Send a literal or distance tree in compressed form, using the codes in + * bl_tree. + */ +local void send_tree (s, tree, max_code) + deflate_state *s; + ct_data *tree; /* the tree to be scanned */ + int max_code; /* and its largest code of non zero frequency */ +{ + int n; /* iterates over all tree elements */ + int prevlen = -1; /* last emitted length */ + int curlen; /* length of current code */ + int nextlen = tree[0].Len; /* length of next code */ + int count = 0; /* repeat count of the current code */ + int max_count = 7; /* max repeat count */ + int min_count = 4; /* min repeat count */ + + /* tree[max_code+1].Len = -1; */ /* guard already set */ + if (nextlen == 0) max_count = 138, min_count = 3; + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; nextlen = tree[n+1].Len; + if (++count < max_count && curlen == nextlen) { + continue; + } else if (count < min_count) { + do { send_code(s, curlen, s->bl_tree); } while (--count != 0); + + } else if (curlen != 0) { + if (curlen != prevlen) { + send_code(s, curlen, s->bl_tree); count--; + } + Assert(count >= 3 && count <= 6, " 3_6?"); + send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); + + } else if (count <= 10) { + send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3); + + } else { + send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7); + } + count = 0; prevlen = curlen; + if (nextlen == 0) { + max_count = 138, min_count = 3; + } else if (curlen == nextlen) { + max_count = 6, min_count = 3; + } else { + max_count = 7, min_count = 4; + } + } +} + +/* =========================================================================== + * Construct the Huffman tree for the bit lengths and return the index in + * bl_order of the last bit length code to send. + */ +local int build_bl_tree(s) + deflate_state *s; +{ + int max_blindex; /* index of last bit length code of non zero freq */ + + /* Determine the bit length frequencies for literal and distance trees */ + scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code); + scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code); + + /* Build the bit length tree: */ + build_tree(s, (tree_desc *)(&(s->bl_desc))); + /* opt_len now includes the length of the tree representations, except + * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. + */ + + /* Determine the number of bit length codes to send. The pkzip format + * requires that at least 4 bit length codes be sent. (appnote.txt says + * 3 but the actual value used is 4.) + */ + for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { + if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; + } + /* Update opt_len to include the bit length tree and counts */ + s->opt_len += 3*(max_blindex+1) + 5+5+4; + Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", + s->opt_len, s->static_len)); + + return max_blindex; +} + +/* =========================================================================== + * Send the header for a block using dynamic Huffman trees: the counts, the + * lengths of the bit length codes, the literal tree and the distance tree. + * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. + */ +local void send_all_trees(s, lcodes, dcodes, blcodes) + deflate_state *s; + int lcodes, dcodes, blcodes; /* number of codes for each tree */ +{ + int rank; /* index in bl_order */ + + Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); + Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, + "too many codes"); + Tracev((stderr, "\nbl counts: ")); + send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ + send_bits(s, dcodes-1, 5); + send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ + for (rank = 0; rank < blcodes; rank++) { + Tracev((stderr, "\nbl code %2d ", bl_order[rank])); + send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); + } + Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); + + send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ + Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); + + send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ + Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); +} + +/* =========================================================================== + * Send a stored block + */ +void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) + deflate_state *s; + charf *buf; /* input block */ + ulg stored_len; /* length of input block */ + int last; /* one if this is the last block for a file */ +{ + send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */ +#ifdef DEBUG + s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; + s->compressed_len += (stored_len + 4) << 3; +#endif + copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ +} + +/* =========================================================================== + * Send one empty static block to give enough lookahead for inflate. + * This takes 10 bits, of which 7 may remain in the bit buffer. + * The current inflate code requires 9 bits of lookahead. If the + * last two codes for the previous block (real code plus EOB) were coded + * on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode + * the last real code. In this case we send two empty static blocks instead + * of one. (There are no problems if the previous block is stored or fixed.) + * To simplify the code, we assume the worst case of last real code encoded + * on one bit only. + */ +void ZLIB_INTERNAL _tr_align(s) + deflate_state *s; +{ + send_bits(s, STATIC_TREES<<1, 3); + send_code(s, END_BLOCK, static_ltree); +#ifdef DEBUG + s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ +#endif + bi_flush(s); + /* Of the 10 bits for the empty block, we have already sent + * (10 - bi_valid) bits. The lookahead for the last real code (before + * the EOB of the previous block) was thus at least one plus the length + * of the EOB plus what we have just sent of the empty static block. + */ + if (1 + s->last_eob_len + 10 - s->bi_valid < 9) { + send_bits(s, STATIC_TREES<<1, 3); + send_code(s, END_BLOCK, static_ltree); +#ifdef DEBUG + s->compressed_len += 10L; +#endif + bi_flush(s); + } + s->last_eob_len = 7; +} + +/* =========================================================================== + * Determine the best encoding for the current block: dynamic trees, static + * trees or store, and output the encoded block to the zip file. + */ +void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) + deflate_state *s; + charf *buf; /* input block, or NULL if too old */ + ulg stored_len; /* length of input block */ + int last; /* one if this is the last block for a file */ +{ + ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ + int max_blindex = 0; /* index of last bit length code of non zero freq */ + + /* Build the Huffman trees unless a stored block is forced */ + if (s->level > 0) { + + /* Check if the file is binary or text */ + if (s->strm->data_type == Z_UNKNOWN) + s->strm->data_type = detect_data_type(s); + + /* Construct the literal and distance trees */ + build_tree(s, (tree_desc *)(&(s->l_desc))); + Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, + s->static_len)); + + build_tree(s, (tree_desc *)(&(s->d_desc))); + Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, + s->static_len)); + /* At this point, opt_len and static_len are the total bit lengths of + * the compressed block data, excluding the tree representations. + */ + + /* Build the bit length tree for the above two trees, and get the index + * in bl_order of the last bit length code to send. + */ + max_blindex = build_bl_tree(s); + + /* Determine the best encoding. Compute the block lengths in bytes. */ + opt_lenb = (s->opt_len+3+7)>>3; + static_lenb = (s->static_len+3+7)>>3; + + Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", + opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, + s->last_lit)); + + if (static_lenb <= opt_lenb) opt_lenb = static_lenb; + + } else { + Assert(buf != (char*)0, "lost buf"); + opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ + } + +#ifdef FORCE_STORED + if (buf != (char*)0) { /* force stored block */ +#else + if (stored_len+4 <= opt_lenb && buf != (char*)0) { + /* 4: two words for the lengths */ +#endif + /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. + * Otherwise we can't have processed more than WSIZE input bytes since + * the last block flush, because compression would have been + * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to + * transform a block into a stored block. + */ + _tr_stored_block(s, buf, stored_len, last); + +#ifdef FORCE_STATIC + } else if (static_lenb >= 0) { /* force static trees */ +#else + } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { +#endif + send_bits(s, (STATIC_TREES<<1)+last, 3); + compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); +#ifdef DEBUG + s->compressed_len += 3 + s->static_len; +#endif + } else { + send_bits(s, (DYN_TREES<<1)+last, 3); + send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, + max_blindex+1); + compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree); +#ifdef DEBUG + s->compressed_len += 3 + s->opt_len; +#endif + } + Assert (s->compressed_len == s->bits_sent, "bad compressed size"); + /* The above check is made mod 2^32, for files larger than 512 MB + * and uLong implemented on 32 bits. + */ + init_block(s); + + if (last) { + bi_windup(s); +#ifdef DEBUG + s->compressed_len += 7; /* align on byte boundary */ +#endif + } + Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, + s->compressed_len-7*last)); +} + +/* =========================================================================== + * Save the match info and tally the frequency counts. Return true if + * the current block must be flushed. + */ +int ZLIB_INTERNAL _tr_tally (s, dist, lc) + deflate_state *s; + unsigned dist; /* distance of matched string */ + unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ +{ + s->d_buf[s->last_lit] = (ush)dist; + s->l_buf[s->last_lit++] = (uch)lc; + if (dist == 0) { + /* lc is the unmatched char */ + s->dyn_ltree[lc].Freq++; + } else { + s->matches++; + /* Here, lc is the match length - MIN_MATCH */ + dist--; /* dist = match distance - 1 */ + Assert((ush)dist < (ush)MAX_DIST(s) && + (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && + (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); + + s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; + s->dyn_dtree[d_code(dist)].Freq++; + } + +#ifdef TRUNCATE_BLOCK + /* Try to guess if it is profitable to stop the current block here */ + if ((s->last_lit & 0x1fff) == 0 && s->level > 2) { + /* Compute an upper bound for the compressed length */ + ulg out_length = (ulg)s->last_lit*8L; + ulg in_length = (ulg)((long)s->strstart - s->block_start); + int dcode; + for (dcode = 0; dcode < D_CODES; dcode++) { + out_length += (ulg)s->dyn_dtree[dcode].Freq * + (5L+extra_dbits[dcode]); + } + out_length >>= 3; + Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", + s->last_lit, in_length, out_length, + 100L - out_length*100L/in_length)); + if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1; + } +#endif + return (s->last_lit == s->lit_bufsize-1); + /* We avoid equality with lit_bufsize because of wraparound at 64K + * on 16 bit machines and because stored blocks are restricted to + * 64K-1 bytes. + */ +} + +/* =========================================================================== + * Send the block data compressed using the given Huffman trees + */ +local void compress_block(s, ltree, dtree) + deflate_state *s; + ct_data *ltree; /* literal tree */ + ct_data *dtree; /* distance tree */ +{ + unsigned dist; /* distance of matched string */ + int lc; /* match length or unmatched char (if dist == 0) */ + unsigned lx = 0; /* running index in l_buf */ + unsigned code; /* the code to send */ + int extra; /* number of extra bits to send */ + + if (s->last_lit != 0) do { + dist = s->d_buf[lx]; + lc = s->l_buf[lx++]; + if (dist == 0) { + send_code(s, lc, ltree); /* send a literal byte */ + Tracecv(isgraph(lc), (stderr," '%c' ", lc)); + } else { + /* Here, lc is the match length - MIN_MATCH */ + code = _length_code[lc]; + send_code(s, code+LITERALS+1, ltree); /* send the length code */ + extra = extra_lbits[code]; + if (extra != 0) { + lc -= base_length[code]; + send_bits(s, lc, extra); /* send the extra length bits */ + } + dist--; /* dist is now the match distance - 1 */ + code = d_code(dist); + Assert (code < D_CODES, "bad d_code"); + + send_code(s, code, dtree); /* send the distance code */ + extra = extra_dbits[code]; + if (extra != 0) { + dist -= base_dist[code]; + send_bits(s, dist, extra); /* send the extra distance bits */ + } + } /* literal or match pair ? */ + + /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ + Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, + "pendingBuf overflow"); + + } while (lx < s->last_lit); + + send_code(s, END_BLOCK, ltree); + s->last_eob_len = ltree[END_BLOCK].Len; +} + +/* =========================================================================== + * Check if the data type is TEXT or BINARY, using the following algorithm: + * - TEXT if the two conditions below are satisfied: + * a) There are no non-portable control characters belonging to the + * "black list" (0..6, 14..25, 28..31). + * b) There is at least one printable character belonging to the + * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). + * - BINARY otherwise. + * - The following partially-portable control characters form a + * "gray list" that is ignored in this detection algorithm: + * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). + * IN assertion: the fields Freq of dyn_ltree are set. + */ +local int detect_data_type(s) + deflate_state *s; +{ + /* black_mask is the bit mask of black-listed bytes + * set bits 0..6, 14..25, and 28..31 + * 0xf3ffc07f = binary 11110011111111111100000001111111 + */ + unsigned long black_mask = 0xf3ffc07fUL; + int n; + + /* Check for non-textual ("black-listed") bytes. */ + for (n = 0; n <= 31; n++, black_mask >>= 1) + if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0)) + return Z_BINARY; + + /* Check for textual ("white-listed") bytes. */ + if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 + || s->dyn_ltree[13].Freq != 0) + return Z_TEXT; + for (n = 32; n < LITERALS; n++) + if (s->dyn_ltree[n].Freq != 0) + return Z_TEXT; + + /* There are no "black-listed" or "white-listed" bytes: + * this stream either is empty or has tolerated ("gray-listed") bytes only. + */ + return Z_BINARY; +} + +/* =========================================================================== + * Reverse the first len bits of a code, using straightforward code (a faster + * method would use a table) + * IN assertion: 1 <= len <= 15 + */ +local unsigned bi_reverse(code, len) + unsigned code; /* the value to invert */ + int len; /* its bit length */ +{ + register unsigned res = 0; + do { + res |= code & 1; + code >>= 1, res <<= 1; + } while (--len > 0); + return res >> 1; +} + +/* =========================================================================== + * Flush the bit buffer, keeping at most 7 bits in it. + */ +local void bi_flush(s) + deflate_state *s; +{ + if (s->bi_valid == 16) { + put_short(s, s->bi_buf); + s->bi_buf = 0; + s->bi_valid = 0; + } else if (s->bi_valid >= 8) { + put_byte(s, (Byte)s->bi_buf); + s->bi_buf >>= 8; + s->bi_valid -= 8; + } +} + +/* =========================================================================== + * Flush the bit buffer and align the output on a byte boundary + */ +local void bi_windup(s) + deflate_state *s; +{ + if (s->bi_valid > 8) { + put_short(s, s->bi_buf); + } else if (s->bi_valid > 0) { + put_byte(s, (Byte)s->bi_buf); + } + s->bi_buf = 0; + s->bi_valid = 0; +#ifdef DEBUG + s->bits_sent = (s->bits_sent+7) & ~7; +#endif +} + +/* =========================================================================== + * Copy a stored block, storing first the length and its + * one's complement if requested. + */ +local void copy_block(s, buf, len, header) + deflate_state *s; + charf *buf; /* the input data */ + unsigned len; /* its length */ + int header; /* true if block header must be written */ +{ + bi_windup(s); /* align on byte boundary */ + s->last_eob_len = 8; /* enough lookahead for inflate */ + + if (header) { + put_short(s, (ush)len); + put_short(s, (ush)~len); +#ifdef DEBUG + s->bits_sent += 2*16; +#endif + } +#ifdef DEBUG + s->bits_sent += (ulg)len<<3; +#endif + while (len--) { + put_byte(s, *buf++); + } +} diff --git a/fceumm/utils/zlib/trees.h b/fceumm/utils/zlib/trees.h new file mode 100644 index 0000000..d35639d --- /dev/null +++ b/fceumm/utils/zlib/trees.h @@ -0,0 +1,128 @@ +/* header created automatically with -DGEN_TREES_H */ + +local const ct_data static_ltree[L_CODES+2] = { +{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, +{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, +{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, +{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, +{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, +{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, +{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, +{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, +{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, +{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, +{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, +{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, +{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, +{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, +{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, +{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, +{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, +{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, +{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, +{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, +{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, +{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, +{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, +{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, +{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, +{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, +{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, +{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, +{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, +{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, +{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, +{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, +{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, +{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, +{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, +{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, +{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, +{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, +{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, +{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, +{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, +{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, +{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, +{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, +{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, +{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, +{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, +{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, +{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, +{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, +{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, +{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, +{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, +{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, +{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, +{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, +{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, +{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} +}; + +local const ct_data static_dtree[D_CODES] = { +{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, +{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, +{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, +{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, +{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, +{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} +}; + +const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = { + 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, + 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, +10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, +11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, +12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, +13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, +13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, +18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, +23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, +24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, +27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, +27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, +28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, +28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, +28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 +}; + +const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, +13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, +17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, +19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, +21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, +22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, +23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, +24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, +25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, +25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, +26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, +27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 +}; + +local const int base_length[LENGTH_CODES] = { +0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, +64, 80, 96, 112, 128, 160, 192, 224, 0 +}; + +local const int base_dist[D_CODES] = { + 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, + 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, + 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 +}; + diff --git a/fceumm/utils/zlib/uncompr.c b/fceumm/utils/zlib/uncompr.c new file mode 100644 index 0000000..ad98be3 --- /dev/null +++ b/fceumm/utils/zlib/uncompr.c @@ -0,0 +1,59 @@ +/* uncompr.c -- decompress a memory buffer + * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#define ZLIB_INTERNAL +#include "zlib.h" + +/* =========================================================================== + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total + size of the destination buffer, which must be large enough to hold the + entire uncompressed data. (The size of the uncompressed data must have + been saved previously by the compressor and transmitted to the decompressor + by some mechanism outside the scope of this compression library.) + Upon exit, destLen is the actual size of the compressed buffer. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted. +*/ +int ZEXPORT uncompress (dest, destLen, source, sourceLen) + Bytef *dest; + uLongf *destLen; + const Bytef *source; + uLong sourceLen; +{ + z_stream stream; + int err; + + stream.next_in = (Bytef*)source; + stream.avail_in = (uInt)sourceLen; + /* Check for source > 64K on 16-bit machine: */ + if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; + + stream.next_out = dest; + stream.avail_out = (uInt)*destLen; + if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; + + stream.zalloc = (alloc_func)0; + stream.zfree = (free_func)0; + + err = inflateInit(&stream); + if (err != Z_OK) return err; + + err = inflate(&stream, Z_FINISH); + if (err != Z_STREAM_END) { + inflateEnd(&stream); + if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) + return Z_DATA_ERROR; + return err; + } + *destLen = stream.total_out; + + err = inflateEnd(&stream); + return err; +} diff --git a/fceumm/utils/zlib/zconf.h b/fceumm/utils/zlib/zconf.h new file mode 100644 index 0000000..02ce56c --- /dev/null +++ b/fceumm/utils/zlib/zconf.h @@ -0,0 +1,428 @@ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2010 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#ifndef ZCONF_H +#define ZCONF_H + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + * Even better than compiling with -DZ_PREFIX would be to use configure to set + * this permanently in zconf.h using "./configure --zprefix". + */ +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ + +/* all linked symbols */ +# define _dist_code z__dist_code +# define _length_code z__length_code +# define _tr_align z__tr_align +# define _tr_flush_block z__tr_flush_block +# define _tr_init z__tr_init +# define _tr_stored_block z__tr_stored_block +# define _tr_tally z__tr_tally +# define adler32 z_adler32 +# define adler32_combine z_adler32_combine +# define adler32_combine64 z_adler32_combine64 +# define compress z_compress +# define compress2 z_compress2 +# define compressBound z_compressBound +# define crc32 z_crc32 +# define crc32_combine z_crc32_combine +# define crc32_combine64 z_crc32_combine64 +# define deflate z_deflate +# define deflateBound z_deflateBound +# define deflateCopy z_deflateCopy +# define deflateEnd z_deflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateInit_ z_deflateInit_ +# define deflateParams z_deflateParams +# define deflatePrime z_deflatePrime +# define deflateReset z_deflateReset +# define deflateSetDictionary z_deflateSetDictionary +# define deflateSetHeader z_deflateSetHeader +# define deflateTune z_deflateTune +# define deflate_copyright z_deflate_copyright +# define get_crc_table z_get_crc_table +# define gz_error z_gz_error +# define gz_intmax z_gz_intmax +# define gz_strwinerror z_gz_strwinerror +# define gzbuffer z_gzbuffer +# define gzclearerr z_gzclearerr +# define gzclose z_gzclose +# define gzclose_r z_gzclose_r +# define gzclose_w z_gzclose_w +# define gzdirect z_gzdirect +# define gzdopen z_gzdopen +# define gzeof z_gzeof +# define gzerror z_gzerror +# define gzflush z_gzflush +# define gzgetc z_gzgetc +# define gzgets z_gzgets +# define gzoffset z_gzoffset +# define gzoffset64 z_gzoffset64 +# define gzopen z_gzopen +# define gzopen64 z_gzopen64 +# define gzprintf z_gzprintf +# define gzputc z_gzputc +# define gzputs z_gzputs +# define gzread z_gzread +# define gzrewind z_gzrewind +# define gzseek z_gzseek +# define gzseek64 z_gzseek64 +# define gzsetparams z_gzsetparams +# define gztell z_gztell +# define gztell64 z_gztell64 +# define gzungetc z_gzungetc +# define gzwrite z_gzwrite +# define inflate z_inflate +# define inflateBack z_inflateBack +# define inflateBackEnd z_inflateBackEnd +# define inflateBackInit_ z_inflateBackInit_ +# define inflateCopy z_inflateCopy +# define inflateEnd z_inflateEnd +# define inflateGetHeader z_inflateGetHeader +# define inflateInit2_ z_inflateInit2_ +# define inflateInit_ z_inflateInit_ +# define inflateMark z_inflateMark +# define inflatePrime z_inflatePrime +# define inflateReset z_inflateReset +# define inflateReset2 z_inflateReset2 +# define inflateSetDictionary z_inflateSetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateUndermine z_inflateUndermine +# define inflate_copyright z_inflate_copyright +# define inflate_fast z_inflate_fast +# define inflate_table z_inflate_table +# define uncompress z_uncompress +# define zError z_zError +# define zcalloc z_zcalloc +# define zcfree z_zcfree +# define zlibCompileFlags z_zlibCompileFlags +# define zlibVersion z_zlibVersion + +/* all zlib typedefs in zlib.h and zconf.h */ +# define Byte z_Byte +# define Bytef z_Bytef +# define alloc_func z_alloc_func +# define charf z_charf +# define free_func z_free_func +# define gzFile z_gzFile +# define gz_header z_gz_header +# define gz_headerp z_gz_headerp +# define in_func z_in_func +# define intf z_intf +# define out_func z_out_func +# define uInt z_uInt +# define uIntf z_uIntf +# define uLong z_uLong +# define uLongf z_uLongf +# define voidp z_voidp +# define voidpc z_voidpc +# define voidpf z_voidpf + +/* all zlib structs in zlib.h and zconf.h */ +# define gz_header_s z_gz_header_s +# define internal_state z_internal_state + +#endif + +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) +# define OS2 +#endif +#if defined(_WINDOWS) && !defined(WINDOWS) +# define WINDOWS +#endif +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) +# ifndef WIN32 +# define WIN32 +# endif +#endif +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) +# ifndef SYS16BIT +# define SYS16BIT +# endif +# endif +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#ifdef SYS16BIT +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) +# define STDC +#endif +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) +# define STDC +#endif +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) +# define STDC +#endif +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) +# define STDC +#endif + +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ +# define STDC +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const /* note: need a more gentle solution here */ +# endif +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#ifdef SYS16BIT +# if defined(M_I86SM) || defined(M_I86MM) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +# endif +# if (defined(__SMALL__) || defined(__MEDIUM__)) + /* Turbo C small or medium model */ +# define SMALL_MEDIUM +# ifdef __BORLANDC__ +# define FAR _far +# else +# define FAR far +# endif +# endif +#endif + +#if defined(WINDOWS) || defined(WIN32) + /* If building or using zlib as a DLL, define ZLIB_DLL. + * This is not mandatory, but it offers a little performance increase. + */ +# ifdef ZLIB_DLL +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +# endif +# endif /* ZLIB_DLL */ + /* If building or using zlib with the WINAPI/WINAPIV calling convention, + * define ZLIB_WINAPI. + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. + */ +# ifdef ZLIB_WINAPI +# ifdef FAR +# undef FAR +# endif +# include + /* No need for _export, use ZLIB.DEF instead. */ + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR CDECL +# endif +# endif +#endif + +#if defined (__BEOS__) +# ifdef ZLIB_DLL +# ifdef ZLIB_INTERNAL +# define ZEXPORT __declspec(dllexport) +# define ZEXPORTVA __declspec(dllexport) +# else +# define ZEXPORT __declspec(dllimport) +# define ZEXPORTVA __declspec(dllimport) +# endif +# endif +#endif + +#ifndef ZEXTERN +# define ZEXTERN extern +#endif +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(__MACTYPES__) +typedef unsigned char Byte; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void const *voidpc; + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte const *voidpc; + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + +#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_UNISTD_H +#endif + +#ifdef STDC +# include /* for off_t */ +#endif + +/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and + * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even + * though the former does not conform to the LFS document), but considering + * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as + * equivalently requesting no 64-bit operations + */ +#if -_LARGEFILE64_SOURCE - -1 == 1 +# undef _LARGEFILE64_SOURCE +#endif + +#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) +# include /* for SEEK_* and off_t */ +# ifdef VMS +# include /* for off_t */ +# endif +# ifndef z_off_t +# define z_off_t off_t +# endif +#endif + +#ifndef SEEK_SET +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif + +#ifndef z_off_t +# define z_off_t long +#endif + +#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 +# define z_off64_t off64_t +#else +# define z_off64_t z_off_t +#endif + +#if defined(__OS400__) +# define NO_vsnprintf +#endif + +#if defined(__MVS__) +# define NO_vsnprintf +#endif + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) + #pragma map(deflateInit_,"DEIN") + #pragma map(deflateInit2_,"DEIN2") + #pragma map(deflateEnd,"DEEND") + #pragma map(deflateBound,"DEBND") + #pragma map(inflateInit_,"ININ") + #pragma map(inflateInit2_,"ININ2") + #pragma map(inflateEnd,"INEND") + #pragma map(inflateSync,"INSY") + #pragma map(inflateSetDictionary,"INSEDI") + #pragma map(compressBound,"CMBND") + #pragma map(inflate_table,"INTABL") + #pragma map(inflate_fast,"INFA") + #pragma map(inflate_copyright,"INCOPY") +#endif + +#endif /* ZCONF_H */ diff --git a/fceumm/utils/zlib/zlib.h b/fceumm/utils/zlib/zlib.h new file mode 100644 index 0000000..bfbba83 --- /dev/null +++ b/fceumm/utils/zlib/zlib.h @@ -0,0 +1,1613 @@ +/* zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.5, April 19th, 2010 + + Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + + + The data format used by the zlib library is described by RFCs (Request for + Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt + (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). +*/ + +#ifndef ZLIB_H +#define ZLIB_H + +#include "zconf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ZLIB_VERSION "1.2.5" +#define ZLIB_VERNUM 0x1250 +#define ZLIB_VER_MAJOR 1 +#define ZLIB_VER_MINOR 2 +#define ZLIB_VER_REVISION 5 +#define ZLIB_VER_SUBREVISION 0 + +/* + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed data. + This version of the library supports only one compression method (deflation) + but other algorithms will be added later and will have the same stream + interface. + + Compression can be done in a single step if the buffers are large enough, + or can be done by repeated calls of the compression function. In the latter + case, the application must provide more input and/or consume the output + (providing more output space) before each call. + + The compressed data format used by default by the in-memory functions is + the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped + around a deflate stream, which is itself documented in RFC 1951. + + The library also supports reading and writing files in gzip (.gz) format + with an interface similar to that of stdio using the functions that start + with "gz". The gzip format is different from the zlib format. gzip is a + gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. + + This library can optionally read and write gzip streams in memory as well. + + The zlib format was designed to be compact and fast for use in memory + and on communications channels. The gzip format was designed for single- + file compression on file systems, has a larger header than zlib to maintain + directory information, and uses a different, slower check method than zlib. + + The library does not install any signal handler. The decoder checks + the consistency of the compressed data, so the library should never crash + even in case of corrupted input. +*/ + +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); +typedef void (*free_func) OF((voidpf opaque, voidpf address)); + +struct internal_state; + +typedef struct z_stream_s { + Bytef *next_in; /* next input byte */ + uInt avail_in; /* number of bytes available at next_in */ + uLong total_in; /* total nb of input bytes read so far */ + + Bytef *next_out; /* next output byte should be put there */ + uInt avail_out; /* remaining free space at next_out */ + uLong total_out; /* total nb of bytes output so far */ + + char *msg; /* last error message, NULL if no error */ + struct internal_state FAR *state; /* not visible by applications */ + + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + voidpf opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: binary or text */ + uLong adler; /* adler32 value of the uncompressed data */ + uLong reserved; /* reserved for future use */ +} z_stream; + +typedef z_stream FAR *z_streamp; + +/* + gzip header information passed to and from zlib routines. See RFC 1952 + for more details on the meanings of these fields. +*/ +typedef struct gz_header_s { + int text; /* true if compressed data believed to be text */ + uLong time; /* modification time */ + int xflags; /* extra flags (not used when writing a gzip file) */ + int os; /* operating system */ + Bytef *extra; /* pointer to extra field or Z_NULL if none */ + uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ + uInt extra_max; /* space at extra (only when reading header) */ + Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ + uInt name_max; /* space at name (only when reading header) */ + Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ + uInt comm_max; /* space at comment (only when reading header) */ + int hcrc; /* true if there was or will be a header crc */ + int done; /* true when done reading gzip header (not used + when writing a gzip file) */ +} gz_header; + +typedef gz_header FAR *gz_headerp; + +/* + The application must update next_in and avail_in when avail_in has dropped + to zero. It must update next_out and avail_out when avail_out has dropped + to zero. The application must initialize zalloc, zfree and opaque before + calling the init function. All other fields are set by the compression + library and must not be updated by the application. + + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the + opaque value. + + zalloc must return Z_NULL if there is not enough memory for the object. + If zlib is used in a multi-threaded application, zalloc and zfree must be + thread safe. + + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this if + the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers + returned by zalloc for objects of exactly 65536 bytes *must* have their + offset normalized to zero. The default allocation function provided by this + library ensures this (see zutil.c). To reduce memory requirements and avoid + any allocation of 64K objects, at the expense of compression ratio, compile + the library with -DMAX_WBITS=14 (see zconf.h). + + The fields total_in and total_out can be used for statistics or progress + reports. After compression, total_in holds the total size of the + uncompressed data and may be saved for use in the decompressor (particularly + if the decompressor wants to decompress everything in a single step). +*/ + + /* constants */ + +#define Z_NO_FLUSH 0 +#define Z_PARTIAL_FLUSH 1 +#define Z_SYNC_FLUSH 2 +#define Z_FULL_FLUSH 3 +#define Z_FINISH 4 +#define Z_BLOCK 5 +#define Z_TREES 6 +/* Allowed flush values; see deflate() and inflate() below for details */ + +#define Z_OK 0 +#define Z_STREAM_END 1 +#define Z_NEED_DICT 2 +#define Z_ERRNO (-1) +#define Z_STREAM_ERROR (-2) +#define Z_DATA_ERROR (-3) +#define Z_MEM_ERROR (-4) +#define Z_BUF_ERROR (-5) +#define Z_VERSION_ERROR (-6) +/* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ + +#define Z_NO_COMPRESSION 0 +#define Z_BEST_SPEED 1 +#define Z_BEST_COMPRESSION 9 +#define Z_DEFAULT_COMPRESSION (-1) +/* compression levels */ + +#define Z_FILTERED 1 +#define Z_HUFFMAN_ONLY 2 +#define Z_RLE 3 +#define Z_FIXED 4 +#define Z_DEFAULT_STRATEGY 0 +/* compression strategy; see deflateInit2() below for details */ + +#define Z_BINARY 0 +#define Z_TEXT 1 +#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ +#define Z_UNKNOWN 2 +/* Possible values of the data_type field (though see inflate()) */ + +#define Z_DEFLATED 8 +/* The deflate compression method (the only one supported in this version) */ + +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ + +#define zlib_version zlibVersion() +/* for compatibility with versions < 1.0.2 */ + + + /* basic functions */ + +ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. + If the first character differs, the library code actually used is not + compatible with the zlib.h header file used by the application. This check + is automatically made by deflateInit and inflateInit. + */ + +/* +ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); + + Initializes the internal stream state for compression. The fields + zalloc, zfree and opaque must be initialized before by the caller. If + zalloc and zfree are set to Z_NULL, deflateInit updates them to use default + allocation functions. + + The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: + 1 gives best speed, 9 gives best compression, 0 gives no compression at all + (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION + requests a default compromise between speed and compression (currently + equivalent to level 6). + + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if level is not a valid compression level, or + Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible + with the version assumed by the caller (ZLIB_VERSION). msg is set to null + if there is no error message. deflateInit does not perform any compression: + this will be done by deflate(). +*/ + + +ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +/* + deflate compresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. deflate performs one or both of the + following actions: + + - Compress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in and avail_in are updated and + processing will resume at this point for the next call of deflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. This action is forced if the parameter flush is non zero. + Forcing flush frequently degrades the compression ratio, so this parameter + should be set only when necessary (in interactive applications). Some + output may be provided even if flush is not set. + + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating avail_in or avail_out accordingly; avail_out should + never be zero before the call. The application can consume the compressed + output when it wants, for example when the output buffer is full (avail_out + == 0), or after each call of deflate(). If deflate returns Z_OK and with + zero avail_out, it must be called again after making room in the output + buffer because there might be more output pending. + + Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to + decide how much data to accumulate before producing output, in order to + maximize compression. + + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is + flushed to the output buffer and the output is aligned on a byte boundary, so + that the decompressor can get all input data available so far. (In + particular avail_in is zero after the call if enough output space has been + provided before the call.) Flushing may degrade compression for some + compression algorithms and so it should be used only when necessary. This + completes the current deflate block and follows it with an empty stored block + that is three bits plus filler bits to the next byte, followed by four bytes + (00 00 ff ff). + + If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the + output buffer, but the output is not aligned to a byte boundary. All of the + input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. + This completes the current deflate block and follows it with an empty fixed + codes block that is 10 bits long. This assures that enough bytes are output + in order for the decompressor to finish the block before the empty fixed code + block. + + If flush is set to Z_BLOCK, a deflate block is completed and emitted, as + for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to + seven bits of the current block are held to be written as the next byte after + the next deflate block is completed. In this case, the decompressor may not + be provided enough bits at this point in order to complete decompression of + the data provided so far to the compressor. It may need to wait for the next + block to be emitted. This is for advanced applications that need to control + the emission of deflate blocks. + + If flush is set to Z_FULL_FLUSH, all output is flushed as with + Z_SYNC_FLUSH, and the compression state is reset so that decompression can + restart from this point if previous compressed data has been damaged or if + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade + compression. + + If deflate returns with avail_out == 0, this function must be called again + with the same value of the flush parameter and more output space (updated + avail_out), until the flush is complete (deflate returns with non-zero + avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that + avail_out is greater than six to avoid repeated flush markers due to + avail_out == 0 on return. + + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there was + enough output space; if deflate returns with Z_OK, this function must be + called again with Z_FINISH and more output space (updated avail_out) but no + more input data, until it returns with Z_STREAM_END or an error. After + deflate has returned Z_STREAM_END, the only possible operations on the stream + are deflateReset or deflateEnd. + + Z_FINISH can be used immediately after deflateInit if all the compression + is to be done in a single step. In this case, avail_out must be at least the + value returned by deflateBound (see below). If deflate does not return + Z_STREAM_END, then it must be called again as described above. + + deflate() sets strm->adler to the adler32 checksum of all input read + so far (that is, total_in bytes). + + deflate() may update strm->data_type if it can make a good guess about + the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered + binary. This field is only for information purposes and does not affect the + compression algorithm in any manner. + + deflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if all input has been + consumed and all output has been produced (only when flush is set to + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example + if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible + (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not + fatal, and deflate() can be called again with more input and more output + space to continue compressing. +*/ + + +ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the + stream state was inconsistent, Z_DATA_ERROR if the stream was freed + prematurely (some input or output was discarded). In the error case, msg + may be set but then points to a static string (which must not be + deallocated). +*/ + + +/* +ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); + + Initializes the internal stream state for decompression. The fields + next_in, avail_in, zalloc, zfree and opaque must be initialized before by + the caller. If next_in is not Z_NULL and avail_in is large enough (the + exact value depends on the compression method), inflateInit determines the + compression method from the zlib header and allocates all data structures + accordingly; otherwise the allocation will be deferred to the first call of + inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to + use default allocation functions. + + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit() does not process any header information -- that is deferred + until inflate() is called. +*/ + + +ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +/* + inflate decompresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. inflate performs one or both of the + following actions: + + - Decompress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in is updated and processing will + resume at this point for the next call of inflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. inflate() provides as much output as possible, until there is + no more input data or no more space in the output buffer (see below about + the flush parameter). + + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating the next_* and avail_* values accordingly. The + application can consume the uncompressed output when it wants, for example + when the output buffer is full (avail_out == 0), or after each call of + inflate(). If inflate returns Z_OK and with zero avail_out, it must be + called again after making room in the output buffer because there might be + more output pending. + + The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, + Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much + output as possible to the output buffer. Z_BLOCK requests that inflate() + stop if and when it gets to the next deflate block boundary. When decoding + the zlib or gzip format, this will cause inflate() to return immediately + after the header and before the first block. When doing a raw inflate, + inflate() will go ahead and process the first block, and will return when it + gets to the end of that block, or when it runs out of data. + + The Z_BLOCK option assists in appending to or combining deflate streams. + Also to assist in this, on return inflate() will set strm->data_type to the + number of unused bits in the last byte taken from strm->next_in, plus 64 if + inflate() is currently decoding the last block in the deflate stream, plus + 128 if inflate() returned immediately after decoding an end-of-block code or + decoding the complete header up to just before the first byte of the deflate + stream. The end-of-block will not be indicated until all of the uncompressed + data from that block has been written to strm->next_out. The number of + unused bits may in general be greater than seven, except when bit 7 of + data_type is set, in which case the number of unused bits will be less than + eight. data_type is set as noted here every time inflate() returns for all + flush options, and so can be used to determine the amount of currently + consumed input in bits. + + The Z_TREES option behaves as Z_BLOCK does, but it also returns when the + end of each deflate block header is reached, before any actual data in that + block is decoded. This allows the caller to determine the length of the + deflate block header for later use in random access within a deflate block. + 256 is added to the value of strm->data_type when inflate() returns + immediately after reaching the end of the deflate block header. + + inflate() should normally be called until it returns Z_STREAM_END or an + error. However if all decompression is to be performed in a single step (a + single call of inflate), the parameter flush should be set to Z_FINISH. In + this case all pending input is processed and all pending output is flushed; + avail_out must be large enough to hold all the uncompressed data. (The size + of the uncompressed data may have been saved by the compressor for this + purpose.) The next operation on this stream must be inflateEnd to deallocate + the decompression state. The use of Z_FINISH is never required, but can be + used to inform inflate that a faster approach may be used for the single + inflate() call. + + In this implementation, inflate() always flushes as much output as + possible to the output buffer, and always uses the faster approach on the + first call. So the only effect of the flush parameter in this implementation + is on the return value of inflate(), as noted below, or when it returns early + because Z_BLOCK or Z_TREES is used. + + If a preset dictionary is needed after this call (see inflateSetDictionary + below), inflate sets strm->adler to the adler32 checksum of the dictionary + chosen by the compressor and returns Z_NEED_DICT; otherwise it sets + strm->adler to the adler32 checksum of all output produced so far (that is, + total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described + below. At the end of the stream, inflate() checks that its computed adler32 + checksum is equal to that saved by the compressor and returns Z_STREAM_END + only if the checksum is correct. + + inflate() can decompress and check either zlib-wrapped or gzip-wrapped + deflate data. The header type is detected automatically, if requested when + initializing with inflateInit2(). Any information contained in the gzip + header is not retained, so applications that need that information should + instead use raw inflate, see inflateInit2() below, or inflateBack() and + perform their own processing of the gzip header and trailer. + + inflate() returns Z_OK if some progress has been made (more input processed + or more output produced), Z_STREAM_END if the end of the compressed data has + been reached and all uncompressed output has been produced, Z_NEED_DICT if a + preset dictionary is needed at this point, Z_DATA_ERROR if the input data was + corrupted (input stream not conforming to the zlib format or incorrect check + value), Z_STREAM_ERROR if the stream structure was inconsistent (for example + next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, + Z_BUF_ERROR if no progress is possible or if there was not enough room in the + output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and + inflate() can be called again with more input and more output space to + continue decompressing. If Z_DATA_ERROR is returned, the application may + then call inflateSync() to look for a good compression block if a partial + recovery of the data is desired. +*/ + + +ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state + was inconsistent. In the error case, msg may be set but then points to a + static string (which must not be deallocated). +*/ + + + /* Advanced functions */ + +/* + The following functions are needed only in some special applications. +*/ + +/* +ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy)); + + This is another version of deflateInit with more compression options. The + fields next_in, zalloc, zfree and opaque must be initialized before by the + caller. + + The method parameter is the compression method. It must be Z_DEFLATED in + this version of the library. + + The windowBits parameter is the base two logarithm of the window size + (the size of the history buffer). It should be in the range 8..15 for this + version of the library. Larger values of this parameter result in better + compression at the expense of memory usage. The default value is 15 if + deflateInit is used instead. + + windowBits can also be -8..-15 for raw deflate. In this case, -windowBits + determines the window size. deflate() will then generate raw deflate data + with no zlib header or trailer, and will not compute an adler32 check value. + + windowBits can also be greater than 15 for optional gzip encoding. Add + 16 to windowBits to write a simple gzip header and trailer around the + compressed data instead of a zlib wrapper. The gzip header will have no + file name, no extra data, no comment, no modification time (set to zero), no + header crc, and the operating system will be set to 255 (unknown). If a + gzip stream is being written, strm->adler is a crc32 instead of an adler32. + + The memLevel parameter specifies how much memory should be allocated + for the internal compression state. memLevel=1 uses minimum memory but is + slow and reduces compression ratio; memLevel=9 uses maximum memory for + optimal speed. The default value is 8. See zconf.h for total memory usage + as a function of windowBits and memLevel. + + The strategy parameter is used to tune the compression algorithm. Use the + value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a + filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no + string match), or Z_RLE to limit match distances to one (run-length + encoding). Filtered data consists mostly of small values with a somewhat + random distribution. In this case, the compression algorithm is tuned to + compress them better. The effect of Z_FILTERED is to force more Huffman + coding and less string matching; it is somewhat intermediate between + Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as + fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The + strategy parameter only affects the compression ratio but not the + correctness of the compressed output even if it is not set appropriately. + Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler + decoder for special applications. + + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid + method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is + incompatible with the version assumed by the caller (ZLIB_VERSION). msg is + set to null if there is no error message. deflateInit2 does not perform any + compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the compression dictionary from the given byte sequence + without producing any compressed output. This function must be called + immediately after deflateInit, deflateInit2 or deflateReset, before any call + of deflate. The compressor and decompressor must use exactly the same + dictionary (see inflateSetDictionary). + + The dictionary should consist of strings (byte sequences) that are likely + to be encountered later in the data to be compressed, with the most commonly + used strings preferably put towards the end of the dictionary. Using a + dictionary is most useful when the data to be compressed is short and can be + predicted with good accuracy; the data can then be compressed better than + with the default empty dictionary. + + Depending on the size of the compression data structures selected by + deflateInit or deflateInit2, a part of the dictionary may in effect be + discarded, for example if the dictionary is larger than the window size + provided in deflateInit or deflateInit2. Thus the strings most likely to be + useful should be put at the end of the dictionary, not at the front. In + addition, the current implementation of deflate will use at most the window + size minus 262 bytes of the provided dictionary. + + Upon return of this function, strm->adler is set to the adler32 value + of the dictionary; the decompressor may later use this value to determine + which dictionary has been used by the compressor. (The adler32 value + applies to the whole dictionary even if only a subset of the dictionary is + actually used by the compressor.) If a raw deflate was requested, then the + adler32 value is not computed and strm->adler is not set. + + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent (for example if deflate has already been called for this stream + or if the compression method is bsort). deflateSetDictionary does not + perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when several compression strategies will be + tried, for example when there are several ways of pre-processing the input + data with a filter. The streams that will be discarded should then be freed + by calling deflateEnd. Note that deflateCopy duplicates the internal + compression state which can be quite large, so this strategy is slow and can + consume lots of memory. + + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +/* + This function is equivalent to deflateEnd followed by deflateInit, + but does not free and reallocate all the internal compression state. The + stream will keep the same compression level and any other attributes that + may have been set by deflateInit2. + + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, + int level, + int strategy)); +/* + Dynamically update the compression level and compression strategy. The + interpretation of level and strategy is as in deflateInit2. This can be + used to switch between compression and straight copy of the input data, or + to switch to a different kind of input data requiring a different strategy. + If the compression level is changed, the input available so far is + compressed with the old level (and may be flushed); the new level will take + effect only at the next call of deflate(). + + Before the call of deflateParams, the stream state must be set as for + a call of deflate(), since the currently available input may have to be + compressed and flushed. In particular, strm->avail_out must be non-zero. + + deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source + stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if + strm->avail_out was zero. +*/ + +ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, + int good_length, + int max_lazy, + int nice_length, + int max_chain)); +/* + Fine tune deflate's internal compression parameters. This should only be + used by someone who understands the algorithm used by zlib's deflate for + searching for the best matching string, and even then only by the most + fanatic optimizer trying to squeeze out the last compressed bit for their + specific input data. Read the deflate.c source code for the meaning of the + max_lazy, good_length, nice_length, and max_chain parameters. + + deflateTune() can be called after deflateInit() or deflateInit2(), and + returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. + */ + +ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, + uLong sourceLen)); +/* + deflateBound() returns an upper bound on the compressed size after + deflation of sourceLen bytes. It must be called after deflateInit() or + deflateInit2(), and after deflateSetHeader(), if used. This would be used + to allocate an output buffer for deflation in a single pass, and so would be + called before deflate(). +*/ + +ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + deflatePrime() inserts bits in the deflate output stream. The intent + is that this function is used to start off the deflate output with the bits + leftover from a previous deflate stream when appending to it. As such, this + function can only be used for raw deflate, and must be used before the first + deflate() call after a deflateInit2() or deflateReset(). bits must be less + than or equal to 16, and that many of the least significant bits of value + will be inserted in the output. + + deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, + gz_headerp head)); +/* + deflateSetHeader() provides gzip header information for when a gzip + stream is requested by deflateInit2(). deflateSetHeader() may be called + after deflateInit2() or deflateReset() and before the first call of + deflate(). The text, time, os, extra field, name, and comment information + in the provided gz_header structure are written to the gzip header (xflag is + ignored -- the extra flags are set according to the compression level). The + caller must assure that, if not Z_NULL, name and comment are terminated with + a zero byte, and that if extra is not Z_NULL, that extra_len bytes are + available there. If hcrc is true, a gzip header crc is included. Note that + the current versions of the command-line version of gzip (up through version + 1.3.x) do not support header crc's, and will report that it is a "multi-part + gzip file" and give up. + + If deflateSetHeader is not used, the default gzip header has text false, + the time set to zero, and os set to 255, with no extra, name, or comment + fields. The gzip header is returned to the default state by deflateReset(). + + deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, + int windowBits)); + + This is another version of inflateInit with an extra parameter. The + fields next_in, avail_in, zalloc, zfree and opaque must be initialized + before by the caller. + + The windowBits parameter is the base two logarithm of the maximum window + size (the size of the history buffer). It should be in the range 8..15 for + this version of the library. The default value is 15 if inflateInit is used + instead. windowBits must be greater than or equal to the windowBits value + provided to deflateInit2() while compressing, or it must be equal to 15 if + deflateInit2() was not used. If a compressed stream with a larger window + size is given as input, inflate() will return with the error code + Z_DATA_ERROR instead of trying to allocate a larger window. + + windowBits can also be zero to request that inflate use the window size in + the zlib header of the compressed stream. + + windowBits can also be -8..-15 for raw inflate. In this case, -windowBits + determines the window size. inflate() will then process raw deflate data, + not looking for a zlib or gzip header, not generating a check value, and not + looking for any check values for comparison at the end of the stream. This + is for use with other formats that use the deflate compressed data format + such as zip. Those formats provide their own check values. If a custom + format is developed using the raw deflate format for compressed data, it is + recommended that a check value such as an adler32 or a crc32 be applied to + the uncompressed data as is done in the zlib, gzip, and zip formats. For + most applications, the zlib format should be used as is. Note that comments + above on the use in deflateInit2() applies to the magnitude of windowBits. + + windowBits can also be greater than 15 for optional gzip decoding. Add + 32 to windowBits to enable zlib and gzip decoding with automatic header + detection, or add 16 to decode only the gzip format (the zlib format will + return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a + crc32 instead of an adler32. + + inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit2 does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit2() does not process any header information -- that is + deferred until inflate() is called. +*/ + +ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the decompression dictionary from the given uncompressed byte + sequence. This function must be called immediately after a call of inflate, + if that call returned Z_NEED_DICT. The dictionary chosen by the compressor + can be determined from the adler32 value returned by that call of inflate. + The compressor and decompressor must use exactly the same dictionary (see + deflateSetDictionary). For raw inflate, this function can be called + immediately after inflateInit2() or inflateReset() and before any call of + inflate() to set the dictionary. The application must insure that the + dictionary that was used for compression is provided. + + inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the + expected one (incorrect adler32 value). inflateSetDictionary does not + perform any decompression: this will be done by subsequent calls of + inflate(). +*/ + +ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +/* + Skips invalid compressed data until a full flush point (see above the + description of deflate with Z_FULL_FLUSH) can be found, or until all + available input is skipped. No output is provided. + + inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR + if no more input was provided, Z_DATA_ERROR if no flush point has been + found, or Z_STREAM_ERROR if the stream structure was inconsistent. In the + success case, the application may save the current current value of total_in + which indicates where valid compressed data was found. In the error case, + the application may repeatedly call inflateSync, providing more input each + time, until success or end of the input data. +*/ + +ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when randomly accessing a large stream. The + first pass through the stream can periodically record the inflate state, + allowing restarting inflate at those points when randomly accessing the + stream. + + inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +/* + This function is equivalent to inflateEnd followed by inflateInit, + but does not free and reallocate all the internal decompression state. The + stream will keep attributes that may have been set by inflateInit2. + + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, + int windowBits)); +/* + This function is the same as inflateReset, but it also permits changing + the wrap and window size requests. The windowBits parameter is interpreted + the same as it is for inflateInit2. + + inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL), or if + the windowBits parameter is invalid. +*/ + +ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + This function inserts bits in the inflate input stream. The intent is + that this function is used to start inflating at a bit position in the + middle of a byte. The provided bits will be used before any bytes are used + from next_in. This function should only be used with raw inflate, and + should be used before the first inflate() call after inflateInit2() or + inflateReset(). bits must be less than or equal to 16, and that many of the + least significant bits of value will be inserted in the input. + + If bits is negative, then the input stream bit buffer is emptied. Then + inflatePrime() can be called again to put bits in the buffer. This is used + to clear out bits leftover after feeding inflate a block description prior + to feeding inflate codes. + + inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); +/* + This function returns two values, one in the lower 16 bits of the return + value, and the other in the remaining upper bits, obtained by shifting the + return value down 16 bits. If the upper value is -1 and the lower value is + zero, then inflate() is currently decoding information outside of a block. + If the upper value is -1 and the lower value is non-zero, then inflate is in + the middle of a stored block, with the lower value equaling the number of + bytes from the input remaining to copy. If the upper value is not -1, then + it is the number of bits back from the current bit position in the input of + the code (literal or length/distance pair) currently being processed. In + that case the lower value is the number of bytes already emitted for that + code. + + A code is being processed if inflate is waiting for more input to complete + decoding of the code, or if it has completed decoding but is waiting for + more output space to write the literal or match data. + + inflateMark() is used to mark locations in the input data for random + access, which may be at bit positions, and to note those cases where the + output of a code may span boundaries of random access blocks. The current + location in the input stream can be determined from avail_in and data_type + as noted in the description for the Z_BLOCK flush parameter for inflate. + + inflateMark returns the value noted above or -1 << 16 if the provided + source stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, + gz_headerp head)); +/* + inflateGetHeader() requests that gzip header information be stored in the + provided gz_header structure. inflateGetHeader() may be called after + inflateInit2() or inflateReset(), and before the first call of inflate(). + As inflate() processes the gzip stream, head->done is zero until the header + is completed, at which time head->done is set to one. If a zlib stream is + being decoded, then head->done is set to -1 to indicate that there will be + no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be + used to force inflate() to return immediately after header processing is + complete and before any actual data is decompressed. + + The text, time, xflags, and os fields are filled in with the gzip header + contents. hcrc is set to true if there is a header CRC. (The header CRC + was valid if done is set to one.) If extra is not Z_NULL, then extra_max + contains the maximum number of bytes to write to extra. Once done is true, + extra_len contains the actual extra field length, and extra contains the + extra field, or that field truncated if extra_max is less than extra_len. + If name is not Z_NULL, then up to name_max characters are written there, + terminated with a zero unless the length is greater than name_max. If + comment is not Z_NULL, then up to comm_max characters are written there, + terminated with a zero unless the length is greater than comm_max. When any + of extra, name, or comment are not Z_NULL and the respective field is not + present in the header, then that field is set to Z_NULL to signal its + absence. This allows the use of deflateSetHeader() with the returned + structure to duplicate the header. However if those fields are set to + allocated memory, then the application will need to save those pointers + elsewhere so that they can be eventually freed. + + If inflateGetHeader is not used, then the header information is simply + discarded. The header is always checked for validity, including the header + CRC if present. inflateReset() will reset the process to discard the header + information. The application would need to call inflateGetHeader() again to + retrieve the header from the next gzip stream. + + inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, + unsigned char FAR *window)); + + Initialize the internal stream state for decompression using inflateBack() + calls. The fields zalloc, zfree and opaque in strm must be initialized + before the call. If zalloc and zfree are Z_NULL, then the default library- + derived memory allocation routines are used. windowBits is the base two + logarithm of the window size, in the range 8..15. window is a caller + supplied buffer of that size. Except for special applications where it is + assured that deflate was used with small window sizes, windowBits must be 15 + and a 32K byte window must be supplied to be able to decompress general + deflate streams. + + See inflateBack() for the usage of these routines. + + inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of + the paramaters are invalid, Z_MEM_ERROR if the internal state could not be + allocated, or Z_VERSION_ERROR if the version of the library does not match + the version of the header file. +*/ + +typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); +typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); + +ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, + in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc)); +/* + inflateBack() does a raw inflate with a single call using a call-back + interface for input and output. This is more efficient than inflate() for + file i/o applications in that it avoids copying between the output and the + sliding window by simply making the window itself the output buffer. This + function trusts the application to not change the output buffer passed by + the output function, at least until inflateBack() returns. + + inflateBackInit() must be called first to allocate the internal state + and to initialize the state with the user-provided window buffer. + inflateBack() may then be used multiple times to inflate a complete, raw + deflate stream with each call. inflateBackEnd() is then called to free the + allocated state. + + A raw deflate stream is one with no zlib or gzip header or trailer. + This routine would normally be used in a utility that reads zip or gzip + files and writes out uncompressed files. The utility would decode the + header and process the trailer on its own, hence this routine expects only + the raw deflate stream to decompress. This is different from the normal + behavior of inflate(), which expects either a zlib or gzip header and + trailer around the deflate stream. + + inflateBack() uses two subroutines supplied by the caller that are then + called by inflateBack() for input and output. inflateBack() calls those + routines until it reads a complete deflate stream and writes out all of the + uncompressed data, or until it encounters an error. The function's + parameters and return types are defined above in the in_func and out_func + typedefs. inflateBack() will call in(in_desc, &buf) which should return the + number of bytes of provided input, and a pointer to that input in buf. If + there is no input available, in() must return zero--buf is ignored in that + case--and inflateBack() will return a buffer error. inflateBack() will call + out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() + should return zero on success, or non-zero on failure. If out() returns + non-zero, inflateBack() will return with an error. Neither in() nor out() + are permitted to change the contents of the window provided to + inflateBackInit(), which is also the buffer that out() uses to write from. + The length written by out() will be at most the window size. Any non-zero + amount of input may be provided by in(). + + For convenience, inflateBack() can be provided input on the first call by + setting strm->next_in and strm->avail_in. If that input is exhausted, then + in() will be called. Therefore strm->next_in must be initialized before + calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called + immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in + must also be initialized, and then if strm->avail_in is not zero, input will + initially be taken from strm->next_in[0 .. strm->avail_in - 1]. + + The in_desc and out_desc parameters of inflateBack() is passed as the + first parameter of in() and out() respectively when they are called. These + descriptors can be optionally used to pass any information that the caller- + supplied in() and out() functions need to do their job. + + On return, inflateBack() will set strm->next_in and strm->avail_in to + pass back any unused input that was provided by the last in() call. The + return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR + if in() or out() returned an error, Z_DATA_ERROR if there was a format error + in the deflate stream (in which case strm->msg is set to indicate the nature + of the error), or Z_STREAM_ERROR if the stream was not properly initialized. + In the case of Z_BUF_ERROR, an input or output error can be distinguished + using strm->next_in which will be Z_NULL only if in() returned an error. If + strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning + non-zero. (in() will always be called before out(), so strm->next_in is + assured to be defined if out() returns non-zero.) Note that inflateBack() + cannot return Z_OK. +*/ + +ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +/* + All memory allocated by inflateBackInit() is freed. + + inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream + state was inconsistent. +*/ + +ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +/* Return flags indicating compile-time options. + + Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: + 1.0: size of uInt + 3.2: size of uLong + 5.4: size of voidpf (pointer) + 7.6: size of z_off_t + + Compiler, assembler, and debug options: + 8: DEBUG + 9: ASMV or ASMINF -- use ASM code + 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention + 11: 0 (reserved) + + One-time table building (smaller code, but not thread-safe if true): + 12: BUILDFIXED -- build static block decoding tables when needed + 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed + 14,15: 0 (reserved) + + Library content (indicates missing functionality): + 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking + deflate code when not needed) + 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect + and decode gzip streams (to avoid linking crc code) + 18-19: 0 (reserved) + + Operation variations (changes in library functionality): + 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate + 21: FASTEST -- deflate algorithm with only one, lowest compression level + 22,23: 0 (reserved) + + The sprintf variant used by gzprintf (zero is best): + 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format + 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! + 26: 0 = returns value, 1 = void -- 1 means inferred string length returned + + Remainder: + 27-31: 0 (reserved) + */ + + + /* utility functions */ + +/* + The following utility functions are implemented on top of the basic + stream-oriented functions. To simplify the interface, some default options + are assumed (compression level and memory usage, standard memory allocation + functions). The source code of these utility functions can be modified if + you need special options. +*/ + +ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Compresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer. +*/ + +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, + int level)); +/* + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ + +ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +/* + compressBound() returns an upper bound on the compressed size after + compress() or compress2() on sourceLen bytes. It would be used before a + compress() or compress2() call to allocate the destination buffer. +*/ + +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be large enough to hold the entire + uncompressed data. (The size of the uncompressed data must have been saved + previously by the compressor and transmitted to the decompressor by some + mechanism outside the scope of this compression library.) Upon exit, destLen + is the actual size of the uncompressed buffer. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. +*/ + + + /* gzip file access functions */ + +/* + This library supports reading and writing files in gzip (.gz) format with + an interface similar to that of stdio, using the functions that start with + "gz". The gzip format is different from the zlib format. gzip is a gzip + wrapper, documented in RFC 1952, wrapped around a deflate stream. +*/ + +typedef voidp gzFile; /* opaque gzip file descriptor */ + +/* +ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); + + Opens a gzip (.gz) file for reading or writing. The mode parameter is as + in fopen ("rb" or "wb") but can also include a compression level ("wb9") or + a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only + compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' + for fixed code compression as in "wb9F". (See the description of + deflateInit2 for more information about the strategy parameter.) Also "a" + can be used instead of "w" to request that the gzip stream that will be + written be appended to the file. "+" will result in an error, since reading + and writing to the same gzip file is not supported. + + gzopen can be used to read a file which is not in gzip format; in this + case gzread will directly read from the file without decompression. + + gzopen returns NULL if the file could not be opened, if there was + insufficient memory to allocate the gzFile state, or if an invalid mode was + specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). + errno can be checked to determine if the reason gzopen failed was that the + file could not be opened. +*/ + +ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +/* + gzdopen associates a gzFile with the file descriptor fd. File descriptors + are obtained from calls like open, dup, creat, pipe or fileno (if the file + has been previously opened with fopen). The mode parameter is as in gzopen. + + The next call of gzclose on the returned gzFile will also close the file + descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor + fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, + mode);. The duplicated descriptor should be saved to avoid a leak, since + gzdopen does not close fd if it fails. + + gzdopen returns NULL if there was insufficient memory to allocate the + gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not + provided, or '+' was provided), or if fd is -1. The file descriptor is not + used until the next gz* read, write, seek, or close operation, so gzdopen + will not detect if fd is invalid (unless fd is -1). +*/ + +ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); +/* + Set the internal buffer size used by this library's functions. The + default buffer size is 8192 bytes. This function must be called after + gzopen() or gzdopen(), and before any other calls that read or write the + file. The buffer memory allocation is always deferred to the first read or + write. Two buffers are allocated, either both of the specified size when + writing, or one of the specified size and the other twice that size when + reading. A larger buffer size of, for example, 64K or 128K bytes will + noticeably increase the speed of decompression (reading). + + The new buffer size also affects the maximum length for gzprintf(). + + gzbuffer() returns 0 on success, or -1 on failure, such as being called + too late. +*/ + +ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +/* + Dynamically update the compression level or strategy. See the description + of deflateInit2 for the meaning of these parameters. + + gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not + opened for writing. +*/ + +ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +/* + Reads the given number of uncompressed bytes from the compressed file. If + the input file was not in gzip format, gzread copies the given number of + bytes into the buffer. + + After reaching the end of a gzip stream in the input, gzread will continue + to read, looking for another gzip stream, or failing that, reading the rest + of the input file directly without decompression. The entire input file + will be read if gzread is called until it returns less than the requested + len. + + gzread returns the number of uncompressed bytes actually read, less than + len for end of file, or -1 for error. +*/ + +ZEXTERN int ZEXPORT gzwrite OF((gzFile file, + voidpc buf, unsigned len)); +/* + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of uncompressed bytes written or 0 in case of + error. +*/ + +ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); +/* + Converts, formats, and writes the arguments to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written, or 0 in case of error. The number of + uncompressed bytes written is limited to 8191, or one less than the buffer + size given to gzbuffer(). The caller should assure that this limit is not + exceeded. If it is exceeded, then gzprintf() will return an error (0) with + nothing written. In this case, there may also be a buffer overflow with + unpredictable consequences, which is possible only if zlib was compiled with + the insecure functions sprintf() or vsprintf() because the secure snprintf() + or vsnprintf() functions were not available. This can be determined using + zlibCompileFlags(). +*/ + +ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +/* + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + + gzputs returns the number of characters written, or -1 in case of error. +*/ + +ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +/* + Reads bytes from the compressed file until len-1 characters are read, or a + newline character is read and transferred to buf, or an end-of-file + condition is encountered. If any characters are read or if len == 1, the + string is terminated with a null character. If no characters are read due + to an end-of-file or len < 1, then the buffer is left untouched. + + gzgets returns buf which is a null-terminated string, or it returns NULL + for end-of-file or in case of error. If there was an error, the contents at + buf are indeterminate. +*/ + +ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +/* + Writes c, converted to an unsigned char, into the compressed file. gzputc + returns the value that was written, or -1 in case of error. +*/ + +ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +/* + Reads one byte from the compressed file. gzgetc returns this byte or -1 + in case of end of file or error. +*/ + +ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +/* + Push one character back onto the stream to be read as the first character + on the next read. At least one character of push-back is allowed. + gzungetc() returns the character pushed, or -1 on failure. gzungetc() will + fail if c is -1, and may fail if a character has been pushed but not read + yet. If gzungetc is used immediately after gzopen or gzdopen, at least the + output buffer size of pushed characters is allowed. (See gzbuffer above.) + The pushed character will be discarded if the stream is repositioned with + gzseek() or gzrewind(). +*/ + +ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +/* + Flushes all pending output into the compressed file. The parameter flush + is as in the deflate() function. The return value is the zlib error number + (see function gzerror below). gzflush is only permitted when writing. + + If the flush parameter is Z_FINISH, the remaining data is written and the + gzip stream is completed in the output. If gzwrite() is called again, a new + gzip stream will be started in the output. gzread() is able to read such + concatented gzip streams. + + gzflush should be called only when strictly necessary because it will + degrade compression if called too often. +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, + z_off_t offset, int whence)); + + Sets the starting position for the next gzread or gzwrite on the given + compressed file. The offset represents a number of bytes in the + uncompressed data stream. The whence parameter is defined as in lseek(2); + the value SEEK_END is not supported. + + If the file is opened for reading, this function is emulated but can be + extremely slow. If the file is opened for writing, only forward seeks are + supported; gzseek then compresses a sequence of zeroes up to the new + starting position. + + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error, in + particular if the file is opened for writing and the new starting position + would be before the current position. +*/ + +ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +/* + Rewinds the given file. This function is supported only for reading. + + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); + + Returns the starting position for the next gzread or gzwrite on the given + compressed file. This position represents a number of bytes in the + uncompressed data stream, and is zero when starting, even if appending or + reading a gzip stream from the middle of a file using gzdopen(). + + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); + + Returns the current offset in the file being read or written. This offset + includes the count of bytes that precede the gzip stream, for example when + appending or when using gzdopen() for reading. When reading, the offset + does not include as yet unused buffered input. This information can be used + for a progress indicator. On error, gzoffset() returns -1. +*/ + +ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +/* + Returns true (1) if the end-of-file indicator has been set while reading, + false (0) otherwise. Note that the end-of-file indicator is set only if the + read tried to go past the end of the input, but came up short. Therefore, + just like feof(), gzeof() may return false even if there is no more data to + read, in the event that the last read request was for the exact number of + bytes remaining in the input file. This will happen if the input file size + is an exact multiple of the buffer size. + + If gzeof() returns true, then the read functions will return no more data, + unless the end-of-file indicator is reset by gzclearerr() and the input file + has grown since the previous end of file was detected. +*/ + +ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +/* + Returns true (1) if file is being copied directly while reading, or false + (0) if file is a gzip stream being decompressed. This state can change from + false to true while reading the input file if the end of a gzip stream is + reached, but is followed by data that is not another gzip stream. + + If the input file is empty, gzdirect() will return true, since the input + does not contain a gzip stream. + + If gzdirect() is used immediately after gzopen() or gzdopen() it will + cause buffers to be allocated to allow reading the file to determine if it + is a gzip file. Therefore if gzbuffer() is used, it should be called before + gzdirect(). +*/ + +ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +/* + Flushes all pending output if necessary, closes the compressed file and + deallocates the (de)compression state. Note that once file is closed, you + cannot call gzerror with file, since its structures have been deallocated. + gzclose must not be called more than once on the same file, just as free + must not be called more than once on the same allocation. + + gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a + file operation error, or Z_OK on success. +*/ + +ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); +/* + Same as gzclose(), but gzclose_r() is only for use when reading, and + gzclose_w() is only for use when writing or appending. The advantage to + using these instead of gzclose() is that they avoid linking in zlib + compression or decompression code that is not used when only reading or only + writing respectively. If gzclose() is used, then both compression and + decompression code will be included the application when linking to a static + zlib library. +*/ + +ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +/* + Returns the error message for the last error which occurred on the given + compressed file. errnum is set to zlib error number. If an error occurred + in the file system and not in the compression library, errnum is set to + Z_ERRNO and the application may consult errno to get the exact error code. + + The application must not modify the returned string. Future calls to + this function may invalidate the previously returned string. If file is + closed, then the string previously returned by gzerror will no longer be + available. + + gzerror() should be used to distinguish errors from end-of-file for those + functions above that do not distinguish those cases in their return values. +*/ + +ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +/* + Clears the error and end-of-file flags for file. This is analogous to the + clearerr() function in stdio. This is useful for continuing to read a gzip + file that is being written concurrently. +*/ + + + /* checksum functions */ + +/* + These functions are not related to compression but are exported + anyway because they might be useful in applications using the compression + library. +*/ + +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +/* + Update a running Adler-32 checksum with the bytes buf[0..len-1] and + return the updated checksum. If buf is Z_NULL, this function returns the + required initial value for the checksum. + + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed + much faster. + + Usage example: + + uLong adler = adler32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + adler = adler32(adler, buffer, length); + } + if (adler != original_adler) error(); +*/ + +/* +ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, + z_off_t len2)); + + Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 + and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for + each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of + seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. +*/ + +ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +/* + Update a running CRC-32 with the bytes buf[0..len-1] and return the + updated CRC-32. If buf is Z_NULL, this function returns the required + initial value for the for the crc. Pre- and post-conditioning (one's + complement) is performed within this function so it shouldn't be done by the + application. + + Usage example: + + uLong crc = crc32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + crc = crc32(crc, buffer, length); + } + if (crc != original_crc) error(); +*/ + +/* +ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); + + Combine two CRC-32 check values into one. For two sequences of bytes, + seq1 and seq2 with lengths len1 and len2, CRC-32 check values were + calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 + check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and + len2. +*/ + + + /* various hacks, don't look :) */ + +/* deflateInit and inflateInit are macros to allow checking the zlib version + * and the compiler's view of z_stream: + */ +ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size)); +ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, + unsigned char FAR *window, + const char *version, + int stream_size)); +#define deflateInit(strm, level) \ + deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) +#define inflateInit(strm) \ + inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) +#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ + (strategy), ZLIB_VERSION, sizeof(z_stream)) +#define inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) +#define inflateBackInit(strm, windowBits, window) \ + inflateBackInit_((strm), (windowBits), (window), \ + ZLIB_VERSION, sizeof(z_stream)) + +/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or + * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if + * both are true, the application gets the *64 functions, and the regular + * functions are changed to 64 bits) -- in case these are set on systems + * without large file support, _LFS64_LARGEFILE must also be true + */ +#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); + ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); +#endif + +#if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS-0 == 64 && _LFS64_LARGEFILE-0 +# define gzopen gzopen64 +# define gzseek gzseek64 +# define gztell gztell64 +# define gzoffset gzoffset64 +# define adler32_combine adler32_combine64 +# define crc32_combine crc32_combine64 +# ifdef _LARGEFILE64_SOURCE + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); +# endif +#else + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); +#endif + +/* hack for buggy compilers */ +#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) + struct internal_state {int dummy;}; +#endif + +/* undocumented functions */ +ZEXTERN const char * ZEXPORT zError OF((int)); +ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); +ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); +ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); + +#ifdef __cplusplus +} +#endif + +#endif /* ZLIB_H */ diff --git a/fceumm/utils/zlib/zutil.c b/fceumm/utils/zlib/zutil.c new file mode 100644 index 0000000..898ed34 --- /dev/null +++ b/fceumm/utils/zlib/zutil.c @@ -0,0 +1,318 @@ +/* zutil.c -- target dependent utility functions for the compression library + * Copyright (C) 1995-2005, 2010 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#include "zutil.h" + +#ifndef NO_DUMMY_DECL +struct internal_state {int dummy;}; /* for buggy compilers */ +#endif + +const char * const z_errmsg[10] = { +"need dictionary", /* Z_NEED_DICT 2 */ +"stream end", /* Z_STREAM_END 1 */ +"", /* Z_OK 0 */ +"file error", /* Z_ERRNO (-1) */ +"stream error", /* Z_STREAM_ERROR (-2) */ +"data error", /* Z_DATA_ERROR (-3) */ +"insufficient memory", /* Z_MEM_ERROR (-4) */ +"buffer error", /* Z_BUF_ERROR (-5) */ +"incompatible version",/* Z_VERSION_ERROR (-6) */ +""}; + + +const char * ZEXPORT zlibVersion() +{ + return ZLIB_VERSION; +} + +uLong ZEXPORT zlibCompileFlags() +{ + uLong flags; + + flags = 0; + switch ((int)(sizeof(uInt))) { + case 2: break; + case 4: flags += 1; break; + case 8: flags += 2; break; + default: flags += 3; + } + switch ((int)(sizeof(uLong))) { + case 2: break; + case 4: flags += 1 << 2; break; + case 8: flags += 2 << 2; break; + default: flags += 3 << 2; + } + switch ((int)(sizeof(voidpf))) { + case 2: break; + case 4: flags += 1 << 4; break; + case 8: flags += 2 << 4; break; + default: flags += 3 << 4; + } + switch ((int)(sizeof(z_off_t))) { + case 2: break; + case 4: flags += 1 << 6; break; + case 8: flags += 2 << 6; break; + default: flags += 3 << 6; + } +#ifdef DEBUG + flags += 1 << 8; +#endif +#if defined(ASMV) || defined(ASMINF) + flags += 1 << 9; +#endif +#ifdef ZLIB_WINAPI + flags += 1 << 10; +#endif +#ifdef BUILDFIXED + flags += 1 << 12; +#endif +#ifdef DYNAMIC_CRC_TABLE + flags += 1 << 13; +#endif +#ifdef NO_GZCOMPRESS + flags += 1L << 16; +#endif +#ifdef NO_GZIP + flags += 1L << 17; +#endif +#ifdef PKZIP_BUG_WORKAROUND + flags += 1L << 20; +#endif +#ifdef FASTEST + flags += 1L << 21; +#endif +#ifdef STDC +# ifdef NO_vsnprintf + flags += 1L << 25; +# ifdef HAS_vsprintf_void + flags += 1L << 26; +# endif +# else +# ifdef HAS_vsnprintf_void + flags += 1L << 26; +# endif +# endif +#else + flags += 1L << 24; +# ifdef NO_snprintf + flags += 1L << 25; +# ifdef HAS_sprintf_void + flags += 1L << 26; +# endif +# else +# ifdef HAS_snprintf_void + flags += 1L << 26; +# endif +# endif +#endif + return flags; +} + +#ifdef DEBUG + +# ifndef verbose +# define verbose 0 +# endif +int ZLIB_INTERNAL z_verbose = verbose; + +void ZLIB_INTERNAL z_error (m) + char *m; +{ + fprintf(stderr, "%s\n", m); + exit(1); +} +#endif + +/* exported to allow conversion of error code to string for compress() and + * uncompress() + */ +const char * ZEXPORT zError(err) + int err; +{ + return ERR_MSG(err); +} + +#if defined(_WIN32_WCE) + /* The Microsoft C Run-Time Library for Windows CE doesn't have + * errno. We define it as a global variable to simplify porting. + * Its value is always 0 and should not be used. + */ + int errno = 0; +#endif + +#ifndef HAVE_MEMCPY + +void ZLIB_INTERNAL zmemcpy(dest, source, len) + Bytef* dest; + const Bytef* source; + uInt len; +{ + if (len == 0) return; + do { + *dest++ = *source++; /* ??? to be unrolled */ + } while (--len != 0); +} + +int ZLIB_INTERNAL zmemcmp(s1, s2, len) + const Bytef* s1; + const Bytef* s2; + uInt len; +{ + uInt j; + + for (j = 0; j < len; j++) { + if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; + } + return 0; +} + +void ZLIB_INTERNAL zmemzero(dest, len) + Bytef* dest; + uInt len; +{ + if (len == 0) return; + do { + *dest++ = 0; /* ??? to be unrolled */ + } while (--len != 0); +} +#endif + + +#ifdef SYS16BIT + +#ifdef __TURBOC__ +/* Turbo C in 16-bit mode */ + +# define MY_ZCALLOC + +/* Turbo C malloc() does not allow dynamic allocation of 64K bytes + * and farmalloc(64K) returns a pointer with an offset of 8, so we + * must fix the pointer. Warning: the pointer must be put back to its + * original form in order to free it, use zcfree(). + */ + +#define MAX_PTR 10 +/* 10*64K = 640K */ + +local int next_ptr = 0; + +typedef struct ptr_table_s { + voidpf org_ptr; + voidpf new_ptr; +} ptr_table; + +local ptr_table table[MAX_PTR]; +/* This table is used to remember the original form of pointers + * to large buffers (64K). Such pointers are normalized with a zero offset. + * Since MSDOS is not a preemptive multitasking OS, this table is not + * protected from concurrent access. This hack doesn't work anyway on + * a protected system like OS/2. Use Microsoft C instead. + */ + +voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) +{ + voidpf buf = opaque; /* just to make some compilers happy */ + ulg bsize = (ulg)items*size; + + /* If we allocate less than 65520 bytes, we assume that farmalloc + * will return a usable pointer which doesn't have to be normalized. + */ + if (bsize < 65520L) { + buf = farmalloc(bsize); + if (*(ush*)&buf != 0) return buf; + } else { + buf = farmalloc(bsize + 16L); + } + if (buf == NULL || next_ptr >= MAX_PTR) return NULL; + table[next_ptr].org_ptr = buf; + + /* Normalize the pointer to seg:0 */ + *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; + *(ush*)&buf = 0; + table[next_ptr++].new_ptr = buf; + return buf; +} + +void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) +{ + int n; + if (*(ush*)&ptr != 0) { /* object < 64K */ + farfree(ptr); + return; + } + /* Find the original pointer */ + for (n = 0; n < next_ptr; n++) { + if (ptr != table[n].new_ptr) continue; + + farfree(table[n].org_ptr); + while (++n < next_ptr) { + table[n-1] = table[n]; + } + next_ptr--; + return; + } + ptr = opaque; /* just to make some compilers happy */ + Assert(0, "zcfree: ptr not found"); +} + +#endif /* __TURBOC__ */ + + +#ifdef M_I86 +/* Microsoft C in 16-bit mode */ + +# define MY_ZCALLOC + +#if (!defined(_MSC_VER) || (_MSC_VER <= 600)) +# define _halloc halloc +# define _hfree hfree +#endif + +voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) +{ + if (opaque) opaque = 0; /* to make compiler happy */ + return _halloc((long)items, size); +} + +void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) +{ + if (opaque) opaque = 0; /* to make compiler happy */ + _hfree(ptr); +} + +#endif /* M_I86 */ + +#endif /* SYS16BIT */ + + +#ifndef MY_ZCALLOC /* Any system without a special alloc function */ + +#ifndef STDC +extern voidp malloc OF((uInt size)); +extern voidp calloc OF((uInt items, uInt size)); +extern void free OF((voidpf ptr)); +#endif + +voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) + voidpf opaque; + unsigned items; + unsigned size; +{ + if (opaque) items += size - size; /* make compiler happy */ + return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : + (voidpf)calloc(items, size); +} + +void ZLIB_INTERNAL zcfree (opaque, ptr) + voidpf opaque; + voidpf ptr; +{ + free(ptr); + if (opaque) return; /* make compiler happy */ +} + +#endif /* MY_ZCALLOC */ diff --git a/fceumm/utils/zlib/zutil.h b/fceumm/utils/zlib/zutil.h new file mode 100644 index 0000000..258fa88 --- /dev/null +++ b/fceumm/utils/zlib/zutil.h @@ -0,0 +1,274 @@ +/* zutil.h -- internal interface and configuration of the compression library + * Copyright (C) 1995-2010 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* @(#) $Id$ */ + +#ifndef ZUTIL_H +#define ZUTIL_H + +#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ) +# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) +#else +# define ZLIB_INTERNAL +#endif + +#include "zlib.h" + +#ifdef STDC +# if !(defined(_WIN32_WCE) && defined(_MSC_VER)) +# include +# endif +# include +# include +#endif + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + +typedef unsigned char uch; +typedef uch FAR uchf; +typedef unsigned short ush; +typedef ush FAR ushf; +typedef unsigned long ulg; + +extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ +/* (size given to avoid silly warnings with Visual C++) */ + +#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] + +#define ERR_RETURN(strm,err) \ + return (strm->msg = (char*)ERR_MSG(err), (err)) +/* To be used only when the state is known to be valid */ + + /* common constants */ + +#ifndef DEF_WBITS +# define DEF_WBITS MAX_WBITS +#endif +/* default windowBits for decompression. MAX_WBITS is for compression only */ + +#if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +#else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +#endif +/* default memLevel */ + +#define STORED_BLOCK 0 +#define STATIC_TREES 1 +#define DYN_TREES 2 +/* The three kinds of block type */ + +#define MIN_MATCH 3 +#define MAX_MATCH 258 +/* The minimum and maximum match lengths */ + +#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ + + /* target dependencies */ + +#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) +# define OS_CODE 0x00 +# if defined(__TURBOC__) || defined(__BORLANDC__) +# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) + /* Allow compilation with ANSI keywords only enabled */ + void _Cdecl farfree( void *block ); + void *_Cdecl farmalloc( unsigned long nbytes ); +# else +# include +# endif +# else /* MSC or DJGPP */ +# include +# endif +#endif + +#ifdef AMIGA +# define OS_CODE 0x01 +#endif + +#if defined(VAXC) || defined(VMS) +# define OS_CODE 0x02 +# define F_OPEN(name, mode) \ + fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") +#endif + +#if defined(ATARI) || defined(atarist) +# define OS_CODE 0x05 +#endif + +#ifdef OS2 +# define OS_CODE 0x06 +# ifdef M_I86 +# include +# endif +#endif + +#if defined(MACOS) || defined(TARGET_OS_MAC) +# define OS_CODE 0x07 +# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os +# include /* for fdopen */ +# else +# ifndef fdopen +# define fdopen(fd,mode) NULL /* No fdopen() */ +# endif +# endif +#endif + +#ifdef TOPS20 +# define OS_CODE 0x0a +#endif + +#ifdef WIN32 +# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ +# define OS_CODE 0x0b +# endif +#endif + +#ifdef __50SERIES /* Prime/PRIMOS */ +# define OS_CODE 0x0f +#endif + +#if defined(_BEOS_) || defined(RISCOS) +# define fdopen(fd,mode) NULL /* No fdopen() */ +#endif + +#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX +# if defined(_WIN32_WCE) +# define fdopen(fd,mode) NULL /* No fdopen() */ +# ifndef _PTRDIFF_T_DEFINED + typedef int ptrdiff_t; +# define _PTRDIFF_T_DEFINED +# endif +# else +# define fdopen(fd,type) _fdopen(fd,type) +# endif +#endif + +#if defined(__BORLANDC__) + #pragma warn -8004 + #pragma warn -8008 + #pragma warn -8066 +#endif + +/* provide prototypes for these when building zlib without LFS */ +#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); +#endif + + /* common defaults */ + +#ifndef OS_CODE +# define OS_CODE 0x03 /* assume Unix */ +#endif + +#ifndef F_OPEN +# define F_OPEN(name, mode) fopen((name), (mode)) +#endif + + /* functions */ + +#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) +# ifndef HAVE_VSNPRINTF +# define HAVE_VSNPRINTF +# endif +#endif +#if defined(__CYGWIN__) +# ifndef HAVE_VSNPRINTF +# define HAVE_VSNPRINTF +# endif +#endif +#ifndef HAVE_VSNPRINTF +# ifdef MSDOS + /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), + but for now we just assume it doesn't. */ +# define NO_vsnprintf +# endif +# ifdef __TURBOC__ +# define NO_vsnprintf +# endif +# ifdef WIN32 + /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ +# if !defined(vsnprintf) && !defined(NO_vsnprintf) +# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) +# define vsnprintf _vsnprintf +# endif +# endif +# endif +# ifdef __SASC +# define NO_vsnprintf +# endif +#endif +#ifdef VMS +# define NO_vsnprintf +#endif + +#if defined(pyr) +# define NO_MEMCPY +#endif +#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) + /* Use our own functions for small and medium model with MSC <= 5.0. + * You may have to use the same strategy for Borland C (untested). + * The __SC__ check is for Symantec. + */ +# define NO_MEMCPY +#endif +#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) +# define HAVE_MEMCPY +#endif +#ifdef HAVE_MEMCPY +# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ +# define zmemcpy _fmemcpy +# define zmemcmp _fmemcmp +# define zmemzero(dest, len) _fmemset(dest, 0, len) +# else +# define zmemcpy memcpy +# define zmemcmp memcmp +# define zmemzero(dest, len) memset(dest, 0, len) +# endif +#else + void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); + int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); + void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); +#endif + +/* Diagnostic functions */ +#ifdef DEBUG +# include + extern int ZLIB_INTERNAL z_verbose; + extern void ZLIB_INTERNAL z_error OF((char *m)); +# define Assert(cond,msg) {if(!(cond)) z_error(msg);} +# define Trace(x) {if (z_verbose>=0) fprintf x ;} +# define Tracev(x) {if (z_verbose>0) fprintf x ;} +# define Tracevv(x) {if (z_verbose>1) fprintf x ;} +# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} +# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} +#else +# define Assert(cond,msg) +# define Trace(x) +# define Tracev(x) +# define Tracevv(x) +# define Tracec(c,x) +# define Tracecv(c,x) +#endif + + +voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, + unsigned size)); +void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); + +#define ZALLOC(strm, items, size) \ + (*((strm)->zalloc))((strm)->opaque, (items), (size)) +#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) +#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} + +#endif /* ZUTIL_H */