code
stringlengths
1
2.01M
repo_name
stringlengths
3
62
path
stringlengths
1
267
language
stringclasses
231 values
license
stringclasses
13 values
size
int64
1
2.01M
using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; namespace ScheduleManagement.DAL { /// <summary> /// 数据访问层_用户信息操作类(增、删除、改) /// </summary> public class User_Dal { //读取配置文件,配置数据库连接字符串 string cn = Properties.Settings.Default.ConnectionString; /// <summary> /// 添加一个新用户 /// </summary> /// <param name="user">用户信息实体要设置U_Name,U_Password两个属性值</param> public bool AddUser() { string commandText = "p_adduser"; SqlParameter[] commandParameters = new SqlParameter[2]; commandParameters[0] = new SqlParameter("@u_Name", ScheduleManagement.MODEL.Users.U_Name); commandParameters[1] = new SqlParameter("@u_Password", ScheduleManagement.MODEL.Users.U_Password); SqlHelper.ExecuteNonQuery(cn,commandText,commandParameters); return true; } /// <summary> /// 检查用户是否合法并返回用户权限 /// </summary> /// <param name="userinfo"></param> /// <returns></returns> public int CheckUser() { string commandText = "p_checkuser"; SqlParameter[] commandParameters = new SqlParameter[3]; commandParameters[0] = new SqlParameter("@u_Name", ScheduleManagement.MODEL.Users.U_Name); commandParameters[1] = new SqlParameter("@u_Password", ScheduleManagement.MODEL.Users.U_Password); commandParameters[2] = new SqlParameter("@ch_Id", SqlDbType.Int, 1); commandParameters[2].Direction = ParameterDirection.Output; int flag = Convert.ToInt32(SqlHelper.ExecuteScalar(cn, CommandType.StoredProcedure, commandText, commandParameters)); if (flag != 0) { return 0; } else { return Convert.ToInt32(commandParameters[2].Value); } } /// <summary> /// 删除用户 /// </summary> /// <param name="userinfo"></param> public void DelUser() { string commandText = "p_deluser"; SqlParameter[] commandParameters = new SqlParameter[1]; commandParameters[0] = new SqlParameter("@u_Name",ScheduleManagement.MODEL.Users.U_Name); SqlHelper.ExecuteNonQuery(cn, CommandType.StoredProcedure, commandText,commandParameters); } /// <summary> /// 查询管理员管理密码 /// </summary> /// <param name="admininfo"></param> /// <returns></returns> public string CheckAdmin() { string commandText = "p_checkAdmin"; SqlParameter[] commandParameters = new SqlParameter[1]; commandParameters[0] = new SqlParameter("@u_Name", ScheduleManagement.MODEL.Users.U_Name); string psw =SqlHelper.ExecuteScalar(cn, CommandType.StoredProcedure, commandText, commandParameters).ToString(); return psw; } /// <summary> /// 设置新用户管理员权限 /// </summary> /// <param name="usrename"></param> public void ChangeAdmin(string username) { string commandText = "p_changeAdmin"; SqlParameter[] commandParameters = new SqlParameter[1]; commandParameters[0] = new SqlParameter("@u_Name", username); SqlHelper.ExecuteNonQuery(cn, CommandType.StoredProcedure, commandText, commandParameters).ToString(); } } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.DAL/User_Dal.cs
C#
mpl11
3,807
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // 有关程序集的常规信息通过下列属性集 // 控制。更改这些属性值可修改 // 与程序集关联的信息。 [assembly: AssemblyTitle("ScheduleManagement.DAL")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("微软中国")] [assembly: AssemblyProduct("ScheduleManagement.DAL")] [assembly: AssemblyCopyright("版权所有 (C) 微软中国 2011")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // 将 ComVisible 设置为 false 使此程序集中的类型 // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, // 则将该类型上的 ComVisible 属性设置为 true。 [assembly: ComVisible(false)] // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID [assembly: Guid("c75e7dad-88c4-4abf-b168-d11d19a2f7df")] // 程序集的版本信息由下面四个值组成: // // 主版本 // 次版本 // 内部版本号 // 修订号 // // 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值, // 方法是按如下所示使用“*”: [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.DAL/Properties/AssemblyInfo.cs
C#
mpl11
1,363
using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; namespace ScheduleManagement.DAL { /// <summary> /// 数据访问层_登陆处理类 /// </summary> public class Login_Dal { //读取配置文件,配置数据库连接字符串 string cn = Properties.Settings.Default.ConnectionString; /// <summary> /// 列出所有的用户信息并根据最后登陆时间排序 /// </summary> /// <returns></returns> public SqlDataReader List() { string commandText = "p_select"; SqlDataReader dr = SqlHelper.ExecuteReader(cn, CommandType.StoredProcedure, commandText); return dr; } /// <summary> /// 检查用户是否为记住密码,如果为真,则返回密码,否则返回"" /// </summary> /// <param name="username">用户名</param> /// <returns></returns> public string IsRemember(string username) { string commandText = "p_isremember"; SqlParameter[] commandParameters = new SqlParameter[2]; commandParameters[0]=new SqlParameter("@u_Name",username); commandParameters[1]=new SqlParameter("@u_Password",SqlDbType.VarChar,30); commandParameters[1].Direction=ParameterDirection.Output; int i = Convert.ToInt32(SqlHelper.ExecuteScalar(cn, CommandType.StoredProcedure,commandText,commandParameters));//返回值为1则 if (i == 1) { return commandParameters[1].Value.ToString(); } else { return ""; } } /// <summary> /// 查询用户是否合法 /// </summary> /// <param name="userinfo">用户表结构</param> /// <returns></returns> public int CheckUser() { string commandText = "p_checkuser"; SqlParameter[] commandParameters = new SqlParameter[3]; commandParameters[0] = new SqlParameter("@u_Name", ScheduleManagement.MODEL.Users.U_Name); commandParameters[1] = new SqlParameter("@u_Password", ScheduleManagement.MODEL.Users.U_Password); commandParameters[2] = new SqlParameter("@ch_Id", SqlDbType.Int, 1); commandParameters[2].Direction = ParameterDirection.Output; int flag =Convert.ToInt32(SqlHelper.ExecuteScalar(cn, CommandType.StoredProcedure, commandText, commandParameters)); return flag; } /// <summary> /// 更新用户登陆信息表 /// </summary> /// <param name="username">用户名</param> /// <param name="chkstate">记住密码状态</param> public void UpdateLoginInfo(string username,int chkstate) { try { string commandText = "p_updatelogininfo"; SqlParameter[] commandParameters = new SqlParameter[2]; commandParameters[0] = new SqlParameter("@u_Name",username); commandParameters[1] = new SqlParameter("@l_Rememberpsw", chkstate); SqlHelper.ExecuteNonQuery(cn, CommandType.StoredProcedure, commandText, commandParameters); } catch (Exception) {}//遇到错误跳过 } public int ReturnUserId() { string commandText = "p_returnUserId"; SqlParameter[] commandParameters = new SqlParameter[1]; commandParameters[0] = new SqlParameter("@u_Name",ScheduleManagement.MODEL.Users.U_Name); return (int)SqlHelper.ExecuteScalar(cn, CommandType.StoredProcedure, commandText, commandParameters); } } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.DAL/Login_Dal.cs
C#
mpl11
3,902
using System; using System.Collections.Generic; using System.Text; namespace ScheduleManagement.BLL { public class MainFrom_Bll { ScheduleManagement.DAL.MainFrom_Dal mainfrmDALOperation = new ScheduleManagement.DAL.MainFrom_Dal(); public System.Data.DataSet List(int flag,int u_Id) { return mainfrmDALOperation.List(flag,u_Id); } public System.Data.SqlClient.SqlDataReader List_cboRemind() { return mainfrmDALOperation.ListRemind(); } public System.Data.SqlClient.SqlDataReader List_cboSqType() { return mainfrmDALOperation.ListSqType(); } public System.Data.SqlClient.SqlDataReader List_cboStpType() { return mainfrmDALOperation.ListStpType(); } public System.Data.SqlClient.SqlDataReader List_cboStatus() { return mainfrmDALOperation.ListStatus(); } public System.Data.DataSet Select(bool p_Merge, bool p_HideFinish, string p,string type) { if (p_Merge == false) { return mainfrmDALOperation.SigleSelect(p_HideFinish,p,type); } else { return mainfrmDALOperation.MergeSelect(p_HideFinish,p); } } //public System.Data.DataSet ListAllSchedule() //{ // return mainfrmDALOperation.ListAll(flag,u_Id); //} //查询当前用户所有日程信息 public System.Data.DataSet ListAllSchedule() { return mainfrmDALOperation.ListAll(); } //public ScheduleManagement.MODEL.Schedulequality GetStpId(string p) //{ // return mainfrmDALOperation.GetStpId(p); //} //public ScheduleManagement.MODEL.Schedulequality GetSqId(string p) //{ // return mainfrmDALOperation.GetSqId(p); //} public string GetSqId(string p) { return mainfrmDALOperation.GetSqId(p); } public string GetStpId(string p) { return mainfrmDALOperation.GetStpId(p); } public void AddSchedule(ScheduleManagement.MODEL.Schedule sch) { mainfrmDALOperation.AddSchedule(sch); } } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.BLL/MainFrom_Bll.cs
C#
mpl11
2,431
using System; using System.Collections.Generic; using System.Text; namespace ScheduleManagement.BLL { /// <summary> /// 用户信息操作类 /// </summary> public class User_BLL { //实例化数据访问层_用户信息操作类 ScheduleManagement.DAL.User_Dal userSQLOperation = new ScheduleManagement.DAL.User_Dal(); //实例化数据访问层_登陆处理类 验证用户名是否存在时要用到 ScheduleManagement.DAL.Login_Dal loginDal = new ScheduleManagement.DAL.Login_Dal(); //实例化用户信息实体 //ScheduleManagement.MODEL.Users userinfo = new ScheduleManagement.MODEL.Users(); /// <summary> /// 添加新用户 /// </summary> /// <param name="username">新用户名</param> /// <param name="psw">密码</param> /// <param name="pswcheck">确认密码</param> /// <returns></returns> public bool Adduser(string username, string psw, string pswcheck) { ScheduleManagement.MODEL.Users.U_Name = username; ScheduleManagement.MODEL.Users.U_Password = ""; if (ScheduleManagement.MODEL.Users.U_Name.Equals(string.Empty)) { throw new Exception("用户名不能为空,请重新输入!"); } else { if (psw!=pswcheck) { throw new Exception("两次密码不一致,请重新输入!"); } else if (loginDal.CheckUser() != 1) { throw new Exception("用户名已经存在!"); } else { ScheduleManagement.MODEL.Users.U_Password = psw; userSQLOperation.AddUser(); return true; } } } /// <summary> /// 删除用户 /// </summary> /// <param name="userinfo">Users_Model实体</param> /// <returns></returns> public void Deluser() { userSQLOperation.DelUser(); } /// <summary> /// 检查用户是否合法并返回用户权限 /// </summary> /// <param name="userinfo"></param> /// <returns></returns> public int CheckUser() { if (ScheduleManagement.MODEL.Users.U_Name.Equals(string.Empty)) { throw new Exception("用户名不能为空"); } else { int flag = userSQLOperation.CheckUser();//检查用户是否合法并返回权限 return flag; } } /// <summary> /// 验证用户管理密码是否正确 /// </summary> /// <param name="admininfo"></param> /// <param name="adminpsw"></param> /// <returns></returns> public bool CheckAdmin() { string tempPsw = userSQLOperation.CheckAdmin(); if (tempPsw.Equals(ScheduleManagement.MODEL.Admininfo.A_Password)) { return true; } else { return false; } } /// <summary> /// 权限转移 /// </summary> /// <param name="usrename">转移对象</param> public void ChangeAdmin(string username) { userSQLOperation.ChangeAdmin(username);//设置该用户管理员权限 } } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.BLL/User_BLL.cs
C#
mpl11
3,713
using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; namespace ScheduleManagement.BLL { /// <summary> /// 用户登陆处理类 /// </summary> public class Login_Bll { ScheduleManagement.DAL.Login_Dal loginDal = new ScheduleManagement.DAL.Login_Dal(); ScheduleManagement.DAL.User_Dal userDal = new ScheduleManagement.DAL.User_Dal(); //列出所有的好友信息并根据最后登陆时间排序 public SqlDataReader List() { SqlDataReader dr = loginDal.List(); return dr; } //检查用户是否为记住密码 public string IsRemember(string username) { return loginDal.IsRemember(username); } //验证用户是否合法,并更新登陆信息 public bool CheckUser(int chkstate) { if (ScheduleManagement.MODEL.Users.U_Name.Equals(string.Empty) || ScheduleManagement.MODEL.Users.U_Name.Equals(null)) { throw new Exception("用户名不能为空"); } else { int flag = loginDal.CheckUser();//检查用户是否合法 if (flag==0) { //如果用户合法则更新登陆信息返回成功 loginDal.UpdateLoginInfo(ScheduleManagement.MODEL.Users.U_Name, chkstate);//更新登陆信息 return true; } else if (flag == 1) { throw new Exception("用户不存在!"); } else if (flag == 2) { throw new Exception("密码不正确!"); } else { throw new Exception("遇到未知错误!"); } } } /// <summary> /// 获取用户ID及权限 /// </summary> public void SetUserInfo() { ScheduleManagement.MODEL.Users.Ch_Id = userDal.CheckUser(); ScheduleManagement.MODEL.Users.U_Id = loginDal.ReturnUserId(); } } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.BLL/Login_Bll.cs
C#
mpl11
2,307
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // 有关程序集的常规信息通过下列属性集 // 控制。更改这些属性值可修改 // 与程序集关联的信息。 [assembly: AssemblyTitle("ScheduleManagement.BLL")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("微软中国")] [assembly: AssemblyProduct("ScheduleManagement.BLL")] [assembly: AssemblyCopyright("版权所有 (C) 微软中国 2011")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // 将 ComVisible 设置为 false 使此程序集中的类型 // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, // 则将该类型上的 ComVisible 属性设置为 true。 [assembly: ComVisible(false)] // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID [assembly: Guid("b1610e61-ff81-4822-b1e8-e577a6555636")] // 程序集的版本信息由下面四个值组成: // // 主版本 // 次版本 // 内部版本号 // 修订号 // // 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值, // 方法是按如下所示使用“*”: [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.BLL/Properties/AssemblyInfo.cs
C#
mpl11
1,363
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // 有关程序集的常规信息通过下列属性集 // 控制。更改这些属性值可修改 // 与程序集关联的信息。 [assembly: AssemblyTitle("ScheduleManagement")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("微软中国")] [assembly: AssemblyProduct("ScheduleManagement")] [assembly: AssemblyCopyright("版权所有 (C) 微软中国 2011")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // 将 ComVisible 设置为 false 使此程序集中的类型 // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, // 则将该类型上的 ComVisible 属性设置为 true。 [assembly: ComVisible(false)] // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID [assembly: Guid("d7cbbe5d-8c23-40cb-9ef5-9002116ca583")] // 程序集的版本信息由下面四个值组成: // // 主版本 // 次版本 // 内部版本号 // 修订号 // [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement/Properties/AssemblyInfo.cs
C#
mpl11
1,208
using System; using System.Collections.Generic; using System.Windows.Forms; namespace ScheduleManagement { static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new ScheduleManagement.UI.frm_Main()); } } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement/Program.cs
C#
mpl11
502
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace ScheduleManagement.UI { public partial class frm_Main : Form { //当前窗体对象 public static frm_Main Instance; public frm_Main() { frm_Login login = new frm_Login();//获取登录窗体实例 if (login.ShowDialog() != DialogResult.OK)//login.ShowDialog()会进行阻塞,主窗体等待login返回DialogResult结果 { Environment.Exit(Environment.ExitCode);//退出程序 return; } InitializeComponent();//构造主窗体 Instance = this; } ScheduleManagement.BLL.MainFrom_Bll mainfrmBllOperation = new ScheduleManagement.BLL.MainFrom_Bll(); BindingSource myBindingSource = new BindingSource(); //绑定数据源 ,创建数据源:BindingSource对象 BindingSource myBindindSource2 = new BindingSource(); DataSet myDataSet = new DataSet(); //全局变量 bool p_HideFinish; bool p_Merge; private void frm_Main_Load(object sender, EventArgs e) { ListSchedule(0, ScheduleManagement.MODEL.Users.U_Id);//网格数据绑定初始化 dgrdView1.Columns.Add("剩余时间", "剩余时间"); ListSelect();//查询区数据绑定初台化 ListAllSchedule();//管理区日程绑定 #region 窗体控件属性设置 dtpDate.Format = DateTimePickerFormat.Short;//短日期格式 dtpTime.Format = DateTimePickerFormat.Time;//时间格式 dtpTime.ShowUpDown = true;//数字显示、上下选择模式 dtpDelayed.Format = DateTimePickerFormat.Time; dtpDelayed.ShowUpDown = true; dgrdView1.RowHeadersVisible = false;//隐藏第一列 dgrdView1.Columns[1].Frozen = true;//冻结第二列 dgrdView1.Columns[0].Resizable = DataGridViewTriState.False;//列宽不可调 dgrdView1.Columns[1].Resizable = DataGridViewTriState.False;//列宽不可调 dgrdView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;//排序模式 dgrdView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);//设置列宽为自动调整模式 dgrdView2.RowHeadersVisible = false;//隐藏第一列 dgrdView2.Columns[1].Frozen = true;//冻结第二列 dgrdView2.Columns[0].Resizable = DataGridViewTriState.False;//列宽不可调 dgrdView2.Columns[1].Resizable = DataGridViewTriState.False;//列宽不可调 dgrdView2.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;//排序模式 dgrdView2.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);//设置列宽为自动调整模式 p_HideFinish = chkHideFinish.Checked; p_Merge = chkMerge.Checked; cboAnnouncement.Items.Add("是"); cboAnnouncement.Items.Add("否"); cboCascade.Items.Add("是"); cboCascade.Items.Add("否"); cboAddCascade.Items.Add("上级"); cboAddCascade.Items.Add("并行"); radAtTime.Checked = true; chkRemind.Checked = true; chkCascade.Checked = false; Remindtimer.Interval = 1000; Remindtimer.Enabled = true; openFileDialog1.Filter = "音乐文件(*.mp3)|*.mp3|所有文件(*.*)|*.*"; notifyIcon1.Text = "日程管理系统 测试版"; notifyIcon1.Visible = false; //数据绑定 cboScheduleQuality.DataBindings.Add("TEXT", myBindindSource2, "属性"); cboScheduleType.DataBindings.Add("TEXT", myBindindSource2, "日程类型"); //cboRemind.DataBindings.Add("TEXT",myBindindSource2,"提醒"); txtVoice.DataBindings.Add("TEXT", myBindindSource2, "提醒音乐"); txt.DataBindings.Add("TEXT", myBindindSource2, "日程内容"); comboBox13.Items.Add("日程类型"); comboBox13.Items.Add("日程状态"); #endregion ShowScheduleInfo();//状态栏信息 } //网络数据绑定 private void ListSchedule(int flag,int u_Id) { myDataSet = mainfrmBllOperation.List(flag, ScheduleManagement.MODEL.Users.U_Id); myBindingSource.DataSource = myDataSet.Tables[0]; //数据源的数据 dgrdView1.DataSource = myBindingSource; //dgrdView1.Columns[dgrdView1.Columns.Count-1].Frozen = true;//冻结第二列 } //显示所有日程信息 private void ListAllSchedule() { myDataSet = mainfrmBllOperation.ListAllSchedule(); myBindindSource2.DataSource = myDataSet.Tables[0]; dgrdView2.DataSource = myBindindSource2; } //查询区下拉列表框数据绑定 private void ListSelect() { //添加前先把原来的数据清空 cboRemind.Items.Clear(); cboSqType.Items.Clear(); cboStpType.Items.Clear(); cboStatus.Items.Clear(); cboScheduleQuality.Items.Clear(); cboScheduleType.Items.Clear(); cboIsRemind.Items.Clear(); //调用BLL层处理请求 SqlDataReader dr; dr = mainfrmBllOperation.List_cboRemind(); while (dr.Read()) { cboRemind.Items.Add(dr[0]);//查询区提醒类型; cboIsRemind.Items.Add(dr[0]);//添加编辑区提醒类型 } dr=mainfrmBllOperation.List_cboSqType(); while (dr.Read()) { cboSqType.Items.Add(dr[0]);//查询区日程属性 cboScheduleQuality.Items.Add(dr[0]);//添加编辑区日程属性 } dr = mainfrmBllOperation.List_cboStpType(); while (dr.Read()) { cboStpType.Items.Add(dr[0]);//查询区日程类型 cboScheduleType.Items.Add(dr[0]);//添加编辑区日程类型 } dr = mainfrmBllOperation.List_cboStatus(); while (dr.Read()) { cboStatus.Items.Add(dr[0]);//查询区日程状态 } } private void ShowScheduleInfo() { //实例化状态栏显示方法 ScheduleManagement.BLL.StatusInfo_Bll link = new ScheduleManagement.BLL.StatusInfo_Bll(); //设置状态栏的标签文本,显示当前用户的事务状态 string ScheduleInfo = link.StatusInfo(); tlsStatusInfo.Text = ScheduleInfo; } //合并查询 private void chkMerge_CheckedChanged(object sender, EventArgs e) { if (chkMerge.Checked == true) { } else { } p_Merge = chkMerge.Checked;// } //隐藏完成项 private void chkHideFinish_CheckedChanged(object sender, EventArgs e) { if (chkHideFinish.Checked == true) { groupBox1.Text = "当天待处理日程"; ListSchedule(1, ScheduleManagement.MODEL.Users.U_Id);//网格数据绑定初始化 } else { groupBox1.Text = "当天全部日程"; ListSchedule(0, ScheduleManagement.MODEL.Users.U_Id);//网格数据绑定初始化 } p_HideFinish = chkHideFinish.Checked; } //按提醒类型查询 private void cboRemind_SelectedIndexChanged(object sender, EventArgs e) { myDataSet= mainfrmBllOperation.Select(p_Merge, p_HideFinish, "Remind", cboRemind.SelectedItem.ToString().Trim()); myBindingSource.DataSource = myDataSet.Tables[0]; } //按日程属性查询 private void cboSqType_SelectedIndexChanged(object sender, EventArgs e) { myDataSet= mainfrmBllOperation.Select(p_Merge, p_HideFinish, "SqType", cboSqType.SelectedItem.ToString().Trim()); myBindingSource.DataSource = myDataSet.Tables[0]; } //按日程类型查询 private void cboStpType_SelectedIndexChanged(object sender, EventArgs e) { myDataSet = mainfrmBllOperation.Select(p_Merge, p_HideFinish, "StpType",cboStpType.SelectedItem.ToString().Trim()); myBindingSource.DataSource = myDataSet.Tables[0]; } //按是否为级联日程查询 private void cboCascade_SelectedIndexChanged(object sender, EventArgs e) { myDataSet = mainfrmBllOperation.Select(p_Merge, p_HideFinish, "Cascade", cboCascade.SelectedItem.ToString().Trim()); myBindingSource.DataSource = myDataSet.Tables[0]; } //按权限查询 private void cboAnnouncement_SelectedIndexChanged(object sender, EventArgs e) { myDataSet = mainfrmBllOperation.Select(p_Merge, p_HideFinish, "Announ",cboAnnouncement.SelectedItem.ToString().Trim()); myBindingSource.DataSource = myDataSet.Tables[0]; } //按日程状态查询 private void cboStatus_SelectedIndexChanged(object sender, EventArgs e) { myDataSet = mainfrmBllOperation.Select(p_Merge, p_HideFinish, "Status",cboStatus.SelectedItem.ToString().Trim()); myBindingSource.DataSource = myDataSet.Tables[0]; } //定时与延时 private void radAtTime_CheckedChanged(object sender, EventArgs e) { if (radAtTime.Checked == true) { dtpDate.Enabled = true; dtpTime.Enabled = true; dtpDelayed.Enabled = false; } else { dtpDate.Enabled = false; dtpTime.Enabled = false; dtpDelayed.Enabled = true; } } //添加编辑模块是否提醒 private void chkRemind_CheckedChanged(object sender, EventArgs e) { if (chkRemind.Checked == false) { cboIsRemind.Enabled = false; } else { cboIsRemind.Enabled = true; } } private void chkCascade_CheckedChanged(object sender, EventArgs e) { if (chkCascade.Checked == false) { cboAddCascade.Enabled = false; cboSId.Enabled = false; } else { cboAddCascade.Enabled = true; cboSId.Enabled = true; } } /// <summary> /// 退出选项事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> //private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) //{ // ScheduleManagement.UI.ClosePoint clopot = new ScheduleManagement.UI.ClosePoint(); // clopot.Show(); //} /// <summary> /// 执行时间提醒倒计时 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Remindtimer_Tick(object sender, EventArgs e) { this.Text = String.Format("日程管理系统 - {0} - BY 10ATA3 第五小组",DateTime.Now.ToString()); } // private void dgrdView1_Click(object sender, EventArgs e) { } private void radAtTime_CheckedChanged_1(object sender, EventArgs e) { if (radAtTime.Checked == true) { dtpDate.Enabled = true; dtpTime.Enabled = true; dtpDelayed.Enabled = false; } else { dtpDate.Enabled = false; dtpTime.Enabled = false; dtpDelayed.Enabled = true; } } private void btnSelectVoice_Click(object sender, EventArgs e) { switch (openFileDialog1.ShowDialog()) { case DialogResult.Yes: case DialogResult.OK: break; default: return; } txtVoice.Text = openFileDialog1.FileName; } private void btnCancelRemind_Click(object sender, EventArgs e) { // MessageBox.Show("未完成"); } private void btnDel_Click(object sender, EventArgs e) { MessageBox.Show("未完成"); } private void btnFinish_Click(object sender, EventArgs e) { MessageBox.Show("未完成"); } private void btnAddSche_Click(object sender, EventArgs e) { ScheduleManagement.MODEL.Schedule sch = new ScheduleManagement.MODEL.Schedule(); ScheduleManagement.MODEL.Schedulequality a = new ScheduleManagement.MODEL.Schedulequality(); a.Sq_Id= "3"; sch.Schedulequality = a; ScheduleManagement.MODEL.Scheduletype b = new ScheduleManagement.MODEL.Scheduletype(); //b.Stp_Id = mainfrmBllOperation.GetStpId(cboScheduleType.SelectedItem.ToString()); b.Stp_Id = "5"; sch.Scheduletype = b; sch.S_Content = txt.Text; sch.S_Cascade = true; ScheduleManagement.MODEL.Remindtype c = new ScheduleManagement.MODEL.Remindtype(); c.R_Id = "1"; sch.Remindtype= c; ScheduleManagement.MODEL.Status d = new ScheduleManagement.MODEL.Status(); d.St_Id = "001"; sch.Status = d; sch.S_Voice = txtVoice.Text; sch.S_Announcement = true; sch.S_Cascade = false; mainfrmBllOperation.AddSchedule(sch); MessageBox.Show("添加成功"); ListAllSchedule();//管理区日程绑定 } private void button12_Click(object sender, EventArgs e) { } #region 双击托盘上图标时,显示窗体 /// <summary> /// 将窗体从任务栏点击出来的 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) { if (this.WindowState == FormWindowState.Minimized) { Instance.Show(); Instance.WindowState = FormWindowState.Normal; notifyIcon1.Visible = false; } } #endregion #region 点最小化按钮时,最小化到托盘 private void frm_Main_SizeChanged(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { Instance.Hide(); notifyIcon1.Visible = true; } } #endregion private void frm_Main_FormClosing(object sender, FormClosingEventArgs e) { frm_ClosePoint closepoint = new frm_ClosePoint(); if (closepoint.ShowDialog() == DialogResult.OK)//login.ShowDialog()会进行阻塞,主窗体等待login返回DialogResult结果 { //Environment.Exit(Environment.ExitCode);//退出程序 e.Cancel = true; } //return; } private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); } } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.UI/frm_Main.cs
C#
mpl11
16,438
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace ScheduleManagement.UI { public partial class frm_ClosePoint : Form { private int Flag = 0; public frm_ClosePoint() { InitializeComponent(); } private void ClosePoint_Load(object sender, EventArgs e) { this.MaximizeBox = false; this.MinimizeBox = false; } /// <summary> /// 确定退出按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOK_Click(object sender, EventArgs e) { if (rdoExit.Checked) { Flag = 1; } else { Flag = 2; } this.Close(); } /// <summary> /// 取消按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnNO_Click(object sender, EventArgs e) { this.Close(); } private void frm_ClosePoint_FormClosing(object sender, FormClosingEventArgs e) { if (Flag == 1) { this.DialogResult = DialogResult.Cancel;//如果选择直接退出,关闭整个程序 } else if (Flag == 2) { //选择最小化到系统托盘处,最小化窗口 frm_Main.Instance.WindowState = FormWindowState.Minimized; frm_Main.Instance.notifyIcon1.Visible = true; this.DialogResult = DialogResult.OK; } else { this.DialogResult = DialogResult.OK; } } } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.UI/frm_ClosePoint.cs
C#
mpl11
1,998
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace ScheduleManagement.UI { public partial class frm_Login : Form { public frm_Login() { InitializeComponent(); } //实例化登陆处理类 ScheduleManagement.BLL.Login_Bll loginOperation = new ScheduleManagement.BLL.Login_Bll(); //实例化用户信息操作类 ScheduleManagement.BLL.User_BLL userOperation = new ScheduleManagement.BLL.User_BLL(); //权限等级 int Changepermission = 1;//1为普通用户,2为管理员,3为超级管理员 //初始化登陆窗体 private void frm_Login_Load(object sender, EventArgs e) { ListUserName();//列出用户名 txtPassWord.PasswordChar = '*'; txtDelAdminpsw.PasswordChar = '*'; txtDelPsw.PasswordChar = '*'; cboUserName.MaxLength = 10;//用户名最大字符数为10 txtAddUserName.MaxLength = 10; txtPassWord.MaxLength = 30;//密码最大字符数为30 txtAddPsw.MaxLength = 30; txtAddPswCheck.MaxLength = 30; pnlDelAdminCheck.Visible = false; pnlDelchangeAdmin.Visible = false; btnDelChangeOK.Enabled = false; cboDelChangeUser.DropDownStyle=ComboBoxStyle.DropDownList;//只能从下拉列表框中选择,不能编辑 cboDelUser.DropDownStyle = ComboBoxStyle.DropDownList; } //在用户下拉列表中显示最后登陆过的用户 private void ListUserName() { //调用BLL层处理请求 SqlDataReader dr=loginOperation.List(); cboUserName.Items.Clear();//添加前先把原来的数据清空 cboDelUser.Items.Clear(); while(dr.Read()) { cboUserName.Items.Add(dr[0]); cboDelUser.Items.Add(dr[0]); } cboUserName.Text = cboUserName.Items[0].ToString();//用户名默认为最近登录的 } //检查当前选择用户是否为记住密码 private void cboUserName_SelectedIndexChanged(object sender, EventArgs e) { string username = cboUserName.SelectedItem.ToString(); txtPassWord.Text = loginOperation.IsRemember(username); } //重置 private void btnReset_Click(object sender, EventArgs e) { cboUserName.Text = ""; txtPassWord.Text = ""; } //退出 private void btnExit_Click(object sender, EventArgs e) { this.Close(); } //登陆 private void btnLogin_Click(object sender, EventArgs e) { ScheduleManagement.MODEL.Users.U_Name = cboUserName.Text.Trim();//用户名去除两边空格 ScheduleManagement.MODEL.Users.U_Password = txtPassWord.Text; int chkstate = (int)chkRemember.CheckState; try { if (loginOperation.CheckUser(chkstate)) { //读取用户Id及权限 SetUserInfo(); this.DialogResult = DialogResult.OK;//些时登陆成功,返回父窗体 DialogResult.OK,构造主窗体frmMain } } catch (Exception ex) { MessageBox.Show(ex.Message, "出错信息框", MessageBoxButtons.OK, MessageBoxIcon.Information); cboUserName.Focus();//用户列表框获得焦点 } } //读取用户Id及权限 private void SetUserInfo() { loginOperation.SetUserInfo(); } //输入用户名时进行检测 private void cboUserName_TextChanged(object sender, EventArgs e) { string username = cboUserName.Text.ToString(); string tempPassword = loginOperation.IsRemember(username); if (tempPassword.Equals(string.Empty)) chkRemember.Checked = false; else chkRemember.Checked = true; txtPassWord.Text = tempPassword; } //添加用户 private void btnAddUser_Click(object sender, EventArgs e) { try { string username = txtAddUserName.Text.Trim();//用户名两端不能有空格 string psw = txtAddPsw.Text; string pswcheck = txtAddPswCheck.Text; if (userOperation.Adduser(username, psw, pswcheck)) { MessageBox.Show("添加用户成功","添加成功",MessageBoxButtons.OK); tbpLogin.Show();//返回登陆标签 ListUserName();//刷新用户名列表 } } catch (Exception ex) { MessageBox.Show(ex.Message, "出错信息框", MessageBoxButtons.OK, MessageBoxIcon.Information); cboUserName.Focus();//用户列表框获得焦点 } } //删除用户 private void btnDelUser_Click(object sender, EventArgs e) { ScheduleManagement.MODEL.Users.U_Name = cboDelUser.Text.Trim(); ScheduleManagement.MODEL.Users.U_Password = txtDelPsw.Text; int i; try { i = userOperation.CheckUser();//获取用户权限 if (i == 1) { userOperation.Deluser();//普通用户删除 MessageBox.Show("删除用户成功", "删除成功", MessageBoxButtons.OK); ListUserName(); txtDelPsw.Text = ""; cboDelUser.Text = ""; txtDelAdminpsw.Text = ""; } else if (i == 2) { Changepermission = 2; pnlDelUser.Visible = false; pnlDelAdminCheck.Visible = true; lblDelAdmininfo.Text = "此用户为系统管理员,请输入管理员密码:"; } else if (i == 3) { Changepermission = 3; pnlDelUser.Visible = false; pnlDelAdminCheck.Visible = true; lblDelAdmininfo.Text = "此为系统超级管理员,请输入超级管理员密码:"; } else { MessageBox.Show("用户名或密码错误,请重新输入!"); txtDelPsw.Focus(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "出错信息框", MessageBoxButtons.OK, MessageBoxIcon.Information); cboDelUser.Focus();//用户列表框获得焦点 } } //确认管理员密码 private void btnDelAdminCheck_Click(object sender, EventArgs e) { ScheduleManagement.MODEL.Admininfo.A_Password = txtDelAdminpsw.Text; ScheduleManagement.MODEL.Users.U_Name = cboDelUser.Text; ScheduleManagement.MODEL.Users.U_Password = txtDelPsw.Text; if (userOperation.CheckAdmin()) { if (Changepermission == 2) { userOperation.Deluser(); MessageBox.Show("删除用户成功", "删除成功", MessageBoxButtons.OK); ListUserName(); txtDelPsw.Text = ""; pnlDelAdminCheck.Visible = false; txtDelAdminpsw.Text = ""; cboDelUser.Text = ""; pnlDelUser.Visible = true; } else if (Changepermission == 3) { if (cboDelUser.Items.Count > 1) { pnlDelchangeAdmin.Visible = true; pnlDelAdminCheck.Visible = false; foreach (string temp in cboDelUser.Items) { if (temp != ScheduleManagement.MODEL.Users.U_Name) { cboDelChangeUser.Items.Add(temp); } } } else { MessageBox.Show("当前系统只有一个用户,不能删除超级管理员", "删除操作失败", MessageBoxButtons.OK); Changepermission = 1; } //userOperation.Deluser(userinfo); //MessageBox.Show("删除用户成功", "删除成功", MessageBoxButtons.OK); //ListUserName(); } } else { MessageBox.Show("输入的管理密码不正确", "删除操作失败", MessageBoxButtons.OK); } } //取消确认管理员密码 private void btnDelCancel_Click(object sender, EventArgs e) { pnlDelUser.Visible = true; pnlDelAdminCheck.Visible = false; Changepermission = 1; } //确认删除超级管理员 private void btnDelChangeOK_Click(object sender, EventArgs e) { ScheduleManagement.MODEL.Users.U_Name = cboDelUser.Text; string username = cboDelChangeUser.SelectedItem.ToString(); userOperation.ChangeAdmin(username); userOperation.Deluser(); MessageBox.Show("删除用户成功", "删除成功", MessageBoxButtons.OK); ListUserName(); txtDelPsw.Text = ""; cboDelUser.Text = ""; txtDelAdminpsw.Text = ""; pnlDelAdminCheck.Visible = false; pnlDelchangeAdmin.Visible = false; cboDelChangeUser.Text = ""; cboDelChangeUser.Items.Clear(); pnlDelUser.Visible = true; } //取消超级管理员权限转移 private void btnDelChangeCancel_Click(object sender, EventArgs e) { pnlDelUser.Visible = true; pnlDelchangeAdmin.Visible = false; Changepermission = 1; } //选择用户(超级管理员权限转移) private void cboDelChangeUser_SelectedIndexChanged(object sender, EventArgs e) { btnDelChangeOK.Enabled = true; } } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.UI/frm_Login.cs
C#
mpl11
11,035
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // 有关程序集的常规信息通过下列属性集 // 控制。更改这些属性值可修改 // 与程序集关联的信息。 [assembly: AssemblyTitle("ScheduleManagement.UI")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("微软中国")] [assembly: AssemblyProduct("ScheduleManagement.UI")] [assembly: AssemblyCopyright("版权所有 (C) 微软中国 2011")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // 将 ComVisible 设置为 false 使此程序集中的类型 // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, // 则将该类型上的 ComVisible 属性设置为 true。 [assembly: ComVisible(false)] // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID [assembly: Guid("299def24-c66b-4663-b93a-748a2dbe123b")] // 程序集的版本信息由下面四个值组成: // // 主版本 // 次版本 // 内部版本号 // 修订号 // // 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值, // 方法是按如下所示使用“*”: [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.UI/Properties/AssemblyInfo.cs
C#
mpl11
1,361
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace ScheduleManagement.UI { public partial class ClosePoint : Form { public ClosePoint() { InitializeComponent(); } /// <summary> /// 选择按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ClosePoint_Load(object sender, EventArgs e) { //当用户选中某个退出事件 string Exit = ((RadioButton)sender).Text;//选择的按钮 } /// <summary> /// 确定退出按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOK_Click(object sender, EventArgs e) { if (rdoExit.Checked) { Application.Exit();//如果选择直接退出,关闭整个程序 } else { #region 源代码 //选择最小化到系统托盘处,最小化窗口 //this.Close(); //frm_Main frm_main = new frm_Main(); //this.WindowState = FormWindowState.Minimized; //this.notifyIcon1.Visible = true; #endregion //this.notifyIcon.Visible = false; this.Close(); this.Dispose(); Application.Exit(); } } #region 私有方法 /// <summary> /// 隐藏主窗体 /// </summary> private void Hidefrm_Main() { this.Hide(); } /// <summary> /// 显示主窗体 /// </summary> private void Showfrm_Main() { this.Show(); this.WindowState = FormWindowState.Normal; this.Activate(); } #endregion /// <summary> /// 取消按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnNO_Click(object sender, EventArgs e) { frm_Main frm_main = new frm_Main(); frm_main.Show(); this.Close();//关闭此退出窗口 } #region 双击托盘上图标时,显示窗体 /// <summary> /// 将窗体从任务栏点击出来的 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) { if (this.WindowState == FormWindowState.Normal) { this.WindowState = FormWindowState.Minimized; Hidefrm_Main(); } else if (this.WindowState == FormWindowState.Minimized) { Showfrm_Main(); } } #endregion #region 点最小化按钮时,最小化到托盘 //private void frm_Main_SizeChanged(object sender, EventArgs e) //{ // if (this.WindowState == FormWindowState.Minimized) // { // Hidefrm_Main(); // } //} #endregion #region 窗体关闭时最小化到托盘 //private void frm_Main_FormClosing(object sender, FormClosingEventArgs e) //{ // e.Cancel = true; // Hidefrm_Main(); //} #endregion //private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) //{ // this.WindowState = FormWindowState.Normal; // this.Visible = true; //} } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.UI/ClosePoint.cs
C#
mpl11
4,092
using System; using System.Collections.Generic; using System.Text; namespace ScheduleManagement.MODEL { /// <summary> /// 级联日程信息表实体类 /// </summary> public class Cascadeinfo { private System.Int32 c_Id; private System.Int32 c_Up_s_Id; private System.Int32 c_Down_s_Id; private System.Int32 c_Parallel_s_Id; #region public System.Int32 C_Id { set { c_Id = value; } get { return c_Id; } } public System.Int32 C_Up_s_Id { set { c_Up_s_Id = value; } get { return c_Up_s_Id; } } public System.Int32 C_Down_s_Id { set { c_Down_s_Id = value; } get { return c_Down_s_Id; } } public System.Int32 C_Parallel_s_Id { set { c_Parallel_s_Id = value; } get { return c_Parallel_s_Id; } } #endregion private Schedule schedule; public Schedule Schedule { set { schedule = value; } get { return schedule; } } } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.MODEL/Cascadeinfo_Model.cs
C#
mpl11
1,194
using System; using System.Collections.Generic; using System.Text; namespace ScheduleManagement.MODEL { public class Scheduletype { private System.String stp_Id; private System.String stp_Type; #region public System.String Stp_Id { set { stp_Id = value; } get { return stp_Id; } } public System.String Stp_Type { set { stp_Type = value; } get { return stp_Type; } } #endregion } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.MODEL/Scheduletype_Model.cs
C#
mpl11
554
using System; using System.Collections.Generic; using System.Text; namespace ScheduleManagement.MODEL { /// <summary> /// 用户表实体类 /// </summary> public class Users { private static int u_Id; private static string u_Name; private static string u_Password; private static DateTime u_Registrationtime; private static int ch_Id; #region public static int U_Id { set { Users.u_Id = value; } get { return Users.u_Id; } } public static string U_Name { set { Users.u_Name = value; } get { return Users.u_Name; } } public static string U_Password { set { Users.u_Password = value; } get { return Users.u_Password; } } public static DateTime U_Registrationtime { set { u_Registrationtime = value; } get { return u_Registrationtime; } } public static int Ch_Id { set { Users.ch_Id = value; } get { return Users.ch_Id; } } #endregion } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.MODEL/Users_Model.cs
C#
mpl11
1,215
using System; using System.Collections.Generic; using System.Text; namespace ScheduleManagement.MODEL { /// <summary> /// 日程表实体类 /// </summary> public class Schedule { private System.Int32 s_Id; private System.String s_Quality; private System.String s_Content; private System.DateTime s_Createtime; private System.DateTime s_Executetime; private System.DateTime s_Finishtime; private System.Boolean s_Announcement; private System.Boolean s_Cascade; private System.String s_Voice; private System.String s_Note; #region public System.Int32 S_Id { set { s_Id = value; } get { return s_Id; } } public System.String S_Quality { set { s_Quality = value; } get { return s_Quality; } } public System.String S_Content { set { s_Content = value; } get { return s_Content; } } public System.DateTime S_Createtime { set { s_Createtime = value; } get { return s_Createtime; } } public System.DateTime S_Executetime { set { s_Executetime = value; } get { return s_Executetime; } } public System.DateTime S_Finishtime { set { s_Finishtime = value; } get { return s_Finishtime; } } public System.Boolean S_Announcement { set { s_Announcement = value; } get { return s_Announcement; } } public System.Boolean S_Cascade { set { s_Cascade = value; } get { return s_Cascade; } } public System.String S_Voice { set { s_Voice = value; } get { return s_Voice; } } public System.String S_Note { set { s_Note = value; } get { return s_Note; } } #endregion private Remindtype remindtype; public Remindtype Remindtype { set { remindtype = value; } get { return remindtype; } } private Status status; public Status Status { set { status = value; } get { return status; } } private Users users; public Users Users { set { users = value; } get { return users; } } private Schedulequality schedulequality; public Schedulequality Schedulequality { set { schedulequality = value; } get { return schedulequality; } } private Scheduletype scheduletype; public Scheduletype Scheduletype { set { scheduletype = value; } get { return scheduletype; } } } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.MODEL/Schedule_Model.cs
C#
mpl11
3,051
using System; using System.Collections.Generic; using System.Text; namespace ScheduleManagement.MODEL { /// <summary> /// 提醒类型实体类 /// </summary> public class Remindtype { private System.String r_Id; private System.String r_Type; #region public System.String R_Id { set { r_Id = value; } get { return r_Id; } } public System.String R_Type { set { r_Type = value; } get { return r_Type; } } #endregion } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.MODEL/Remindtype_Model.cs
C#
mpl11
605
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // 有关程序集的常规信息通过下列属性集 // 控制。更改这些属性值可修改 // 与程序集关联的信息。 [assembly: AssemblyTitle("ScheduleManagement.MODEL")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("微软中国")] [assembly: AssemblyProduct("ScheduleManagement.MODEL")] [assembly: AssemblyCopyright("版权所有 (C) 微软中国 2011")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // 将 ComVisible 设置为 false 使此程序集中的类型 // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, // 则将该类型上的 ComVisible 属性设置为 true。 [assembly: ComVisible(false)] // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID [assembly: Guid("5896a04b-480c-422b-b704-1b9721e2dcfe")] // 程序集的版本信息由下面四个值组成: // // 主版本 // 次版本 // 内部版本号 // 修订号 // // 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值, // 方法是按如下所示使用“*”: [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.MODEL/Properties/AssemblyInfo.cs
C#
mpl11
1,367
using System; using System.Collections.Generic; using System.Text; namespace ScheduleManagement.MODEL { /// <summary> /// 日程属性表实体类 /// </summary> public class Schedulequality { private System.String sq_Id; private System.String sq_Type; private System.String sq_Icon; private System.String sq_Color; #region public System.String Sq_Id { set { sq_Id = value; } get { return sq_Id; } } public System.String Sq_Type { set { sq_Type = value; } get { return sq_Type; } } public System.String Sq_Icon { set { sq_Icon = value; } get { return sq_Icon; } } public System.String Sq_Color { set { sq_Color = value; } get { return sq_Color; } } #endregion } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.MODEL/Schedulequality_Model.cs
C#
mpl11
979
using System; using System.Collections.Generic; using System.Text; namespace ScheduleManagement.MODEL { /// <summary> /// 管理员信息表实体类 /// </summary> public class Admininfo { private static System.Int32 a_Id; private static System.String a_Password; #region public static System.Int32 A_Id { set { a_Id = value; } get { return a_Id; } } public static System.String A_Password { set { a_Password = value; } get { return a_Password; } } #endregion //private static Users users; //public static Users Users //{ // set { users = value; } // get { return users; } //} } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.MODEL/Admininfo_Model.cs
C#
mpl11
833
using System; using System.Collections.Generic; using System.Text; namespace ScheduleManagement.MODEL { /// <summary> /// 日程状态表实体类 /// </summary> public class Status { private System.String st_Id; private System.String st_Status; #region public System.String St_Id { set { st_Id = value; } get { return st_Id; } } public System.String St_Status { set { st_Status = value; } get { return st_Status; } } #endregion } }
10ata3-crriculumdesign-schedulemanagementsystem
trunk/日程管理系统/ScheduleManagement/ScheduleManagement.MODEL/Status_Model.cs
C#
mpl11
620
# ########## Project setup ########## PROJECT(ProSonic) CMAKE_MINIMUM_REQUIRED(VERSION 2.4.5) if(COMMAND cmake_policy) cmake_policy(SET CMP0003 OLD) endif(COMMAND cmake_policy) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel" FORCE) endif() if(NOT PROSONIC_INSTALL_PREFIX) if(WIN32) set(PROSONIC_INSTALL_PREFIX "C:/ProSonic" CACHE PATH "PROSONIC_INSTALL_PREFIX: Install path prefix, prepended onto install directories." FORCE) else(WIN32) set(PROSONIC_INSTALL_PREFIX "/usr/local/prosonic" CACHE PATH "PROSONIC_INSTALL_PREFIX: Install path prefix, prepended onto install directories." FORCE) endif(WIN32) endif(NOT PROSONIC_INSTALL_PREFIX) set(CMAKE_INSTALL_PREFIX "${PROSONIC_INSTALL_PREFIX}" CACHE INTERNAL "Prefix prepended to install directories" FORCE) option(PROSONIC_BUILD_DEV_TOOLS "Build game development tools along with engine" False) option(PROSONIC_INSTALL_EXAMPLE_DATA "Install example game data to run with engine" True) # ######### General setup ########## INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/") IF(WIN32) IF(MINGW) SET(DIRECTX_LIBRARIES "-ldinput -lddraw -ldxguid -lwinmm -ldsound" CACHE STRING "DirectX libraries needed to build project") SET(CMAKE_CXX_FLAGS "-DALLEGRO_STATICLINK -fexpensive-optimizations -march=i586 -mmmx -msse") SET(CMAKE_C_FLAGS "-DALLEGRO_STATICLINK -funroll-loops -funswitch-loops -w -fexpensive-optimizations -march=i586 -mmmx -msse") ENDIF(MINGW) IF(MSVC) SET(DIRECTX_LIBRARIES "dinput.lib ddraw.lib dxguid.lib winmm.lib dsound.lib" CACHE STRING "DirectX libraries needed to build project") SET(CMAKE_CXX_FLAGS "/DALLEGRO_STATICLINK /arch SSE") SET(CMAKE_C_FLAGS "/DALLEGRO_STATICLINK /w /arch SSE") ENDIF(MSVC) ELSE(WIN32) SET(ALLEGRO_CONFIG "allegro-config" CACHE STRING "Path to allegro-config script") SET(CMAKE_CXX_FLAGS "-fexpensive-optimizations -march=i586 -mmmx -msse") SET(CMAKE_C_FLAGS "-w -funroll-loops -funswitch-loops -fexpensive-optimizations -march=i586 -mmmx -msse") ENDIF(WIN32) FIND_PACKAGE(Allegro REQUIRED) INCLUDE_DIRECTORIES(${ALLEGRO_INCLUDE_DIRS}) IF(WIN32) IF(MINGW) LINK_LIBRARIES("-mwindows") ENDIF(MINGW) IF(MSVC) LINK_LIBRARIES("/SUBSYSTEM:WINDOWS") ENDIF(MSVC) LINK_LIBRARIES(${ALLEGRO_LIBRARIES}) LINK_LIBRARIES(${DIRECTX_LIBRARIES}) ELSE(WIN32) EXEC_PROGRAM(${ALLEGRO_CONFIG} ARGS --libs OUTPUT_VARIABLE ALLEGRO_CONFIG_LIBS RETURN_VALUE ret ) LINK_LIBRARIES(${ALLEGRO_CONFIG_LIBS}) ENDIF(WIN32) find_package(HAWKNL REQUIRED) include_directories(${HAWKNL_INCLUDE_DIR}) LINK_LIBRARIES(${HAWKNL_LIBRARY}) find_package(ZLIB REQUIRED) include_directories(${ZLIB_INCLUDE_DIRS}) LINK_LIBRARIES(${ZLIB_LIBRARIES}) add_subdirectory(Source/Engine) if(PROSONIC_BUILD_DEV_TOOLS) add_subdirectory(Source/Tools/scriptcompiler) add_subdirectory(Source/Tools/spritecompiler) add_subdirectory(Source/Tools/pzfcompiler) add_subdirectory(Source/Tools/gmv2psd) add_subdirectory(Source/Tools/limp) endif(PROSONIC_BUILD_DEV_TOOLS) if(PROSONIC_INSTALL_EXAMPLE_DATA) install(FILES ${CMAKE_SOURCE_DIR}/Data/Engine/*.* DESTINATION ${CMAKE_INSTALL_PREFIX}) endif(PROSONIC_INSTALL_EXAMPLE_DATA)
001tomclark-research-check
CMakeLists.txt
CMake
gpl2
3,378
# Locate hawkNL # This module defines # HAWKNL_LIBRARY # HAWKNL_FOUND, if false, do not try to link to cal3d # HAWKNL_INCLUDE_DIR, where to find the headers # # $HAWKNL_DIR is an environment variable that would # correspond to the ./configure --prefix=$HAWKNL_DIR # # Created by David Guthrie. Based on code by Robert Osfield FIND_PATH(HAWKNL_INCLUDE_DIR nl.h ${HAWKNL_DIR}/include $ENV{HAWKNL_DIR}/include $ENV{HAWKNL_DIR} ~/Library/Frameworks /Library/Frameworks /usr/local/include /usr/local/include/hawknl /usr/include /usr/include/hawknl /sw/include # Fink /opt/local/include # DarwinPorts /opt/csw/include # Blastwave /opt/include [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/include /usr/freeware/include ) MACRO(FIND_HAWKNL_LIBRARY MYLIBRARY MYLIBRARYNAMES) FIND_LIBRARY(${MYLIBRARY} NAMES ${MYLIBRARYNAMES} PATHS ${HAWKNL_DIR}/lib $ENV{HAWKNL_DIR}/lib $ENV{HAWKNL_DIR} ~/Library/Frameworks /Library/Frameworks /usr/local/lib /usr/lib /sw/lib /opt/local/lib /opt/csw/lib /opt/lib [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/lib /usr/freeware/lib64 ) ENDMACRO(FIND_HAWKNL_LIBRARY MYLIBRARY MYLIBRARYNAMES) SET(NL_RELEASE_STATIC_LIB_NAMES NLstatic NL nl) SET(NL_DEBUG_STATIC_LIB_NAMES NLstaticD NLD nld) FIND_HAWKNL_LIBRARY(HAWKNL_LIBRARY "${NL_RELEASE_STATIC_LIB_NAMES}") FIND_HAWKNL_LIBRARY(HAWKNL_LIBRARY_DEBUG "${NL_DEBUG_STATIC_LIB_NAMES}") SET(HAWKNL_FOUND "NO") IF(HAWKNL_LIBRARY AND HAWKNL_INCLUDE_DIR) SET(HAWKNL_FOUND "YES") ENDIF(HAWKNL_LIBRARY AND HAWKNL_INCLUDE_DIR)
001tomclark-research-check
CMakeModules/FindHAWKNL.cmake
CMake
gpl2
1,729
# - Try to find Allegro # Once done this will define # # ALLEGRO_FOUND - system has Allegro # ALLEGRO_INCLUDE_DIRS - the Allegro include directory # ALLEGRO_LIBRARIES - Link these to use Allegro # ALLEGRO_DEFINITIONS - Compiler switches required for using Allegro # # Copyright (c) 2008 Olof Naessen <olof.naessen@gmail.com> # # Redistribution and use is allowed according to the terms of the New # BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. # if (ALLEGRO_LIBRARIES AND ALLEGRO_INCLUDE_DIRS) # in cache already set(ALLEGRO_FOUND TRUE) else (ALLEGRO_LIBRARIES AND ALLEGRO_INCLUDE_DIRS) find_path(ALLEGRO_INCLUDE_DIR NAMES allegro.h PATHS /usr/include /usr/local/include /opt/local/include /sw/include PATH_SUFFIXES allegro ) find_library(ALLEG_LIBRARY NAMES alleg_unsharable alleg PATHS /usr/lib /usr/local/lib /opt/local/lib /sw/lib ) set(ALLEGRO_INCLUDE_DIRS ${ALLEGRO_INCLUDE_DIR} ) set(ALLEGRO_LIBRARIES ${ALLEG_LIBRARY} ) if (ALLEGRO_INCLUDE_DIRS AND ALLEGRO_LIBRARIES) set(ALLEGRO_FOUND TRUE) endif (ALLEGRO_INCLUDE_DIRS AND ALLEGRO_LIBRARIES) if (ALLEGRO_FOUND) if (NOT Allegro_FIND_QUIETLY) message(STATUS "Found Allegro: ${ALLEGRO_LIBRARIES}") endif (NOT Allegro_FIND_QUIETLY) else (ALLEGRO_FOUND) if (Allegro_FIND_REQUIRED) message(FATAL_ERROR "Could not find Allegro") endif (Allegro_FIND_REQUIRED) endif (ALLEGRO_FOUND) # show the ALLEGRO_INCLUDE_DIRS and ALLEGRO_LIBRARIES variables only in the advanced view mark_as_advanced(ALLEGRO_INCLUDE_DIRS ALLEGRO_LIBRARIES) endif (ALLEGRO_LIBRARIES AND ALLEGRO_INCLUDE_DIRS)
001tomclark-research-check
CMakeModules/FindAllegro.cmake
CMake
gpl2
1,744
// gmv2psd v1.00 // Written by Damian Grove #include <stdio.h> #include <stdlib.h> FILE *in; FILE *out; int i; int size; int main(int argc, char *argv[]){ // Check to see if command line used properly if(argc != 3){ printf("USAGE: gmv2psd [in.gmv] [out.psd]\n"); system("PAUSE"); return 0; } // Open GMV file in = fopen(argv[1], "rb"); // Get the size of the GMV file fseek(in, 0, SEEK_END); size = (ftell(in) - 0x40) / 3; rewind(in); // Verify the header info fread(&i, 4, 1, in); // "Gens" if(i != 0x736E6547){ fclose(in); printf("ERROR: Invalid GMV file!\n"); system("PAUSE"); return 0; } fread(&i, 4, 1, in); // " Mov" if(i != 0x766F4D20){ fclose(in); printf("ERROR: Invalid GMV file!\n"); system("PAUSE"); return 0; } fread(&i, 2, 1, in); // "ie" if((i & 0xFFFF) != 0x6569){ fclose(in); printf("ERROR: Invalid GMV file!\n"); system("PAUSE"); return 0; } // Create PSD file out = fopen(argv[2], "wb"); // Write PSD header i = 0; fwrite(&i, 2, 1, out); fwrite(&size, 2, 1, out); fwrite(&i, 2, 1, out); // Convert demo data fseek(in, 0x40, SEEK_SET); while(size > 0){ fread(&i, 3, 1, in); i ^= 0xFFFFFF; i = (i & 0x80) | ((i & 0x60) >> 1) | ((i & 0x10) << 2) | (i & 0xF); fwrite(&i, 1, 1, out); size--; } // Close files i = ftell(out); fclose(in); fclose(out); printf("GMV data successfully converted to PSD!\nBytes written: %i\n", i); system("PAUSE"); return 0; }
001tomclark-research-check
Source/Tools/gmv2psd/main.c
C
gpl2
1,541
# ########## gmv2psd executable ########## # Sources: SET(gmv2psd_executable_SRCS main.c ) # Headers: SET(gmv2psd_executable_HDRS ) # actual target: ADD_EXECUTABLE(gmv2psd ${gmv2psd_executable_SRCS}) # add install target: INSTALL(TARGETS gmv2psd DESTINATION bin)
001tomclark-research-check
Source/Tools/gmv2psd/CMakeLists.txt
CMake
gpl2
272
#include <stdio.h> #include <allegro.h> #define LABEL_SPRITES 1 #define LABEL_ANIMS 2 #define RETURN_EOF -1 #define RETURN_ERROR -2 #define RETURN_COMMENT -3 #define RETURN_M -4 #define RETURN_M_END -5 BITMAP *bmp; FILE *txt; FILE *psf; short sprite_count; short anim_count; short start_x; short start_y; short size_x; short size_y; char orientation; // used to track 'm', 'f', and 'r' values typedef struct{ char p; // palette color char r; // red char g; // green char b; // blue } SPRITE_SHEET; SPRITE_SHEET *sheet; typedef struct{ short size_x_left; short size_x_right; short size_y_top; short size_y_bottom; } SPRITE_DATA; SPRITE_DATA *sprite; short *anim; int FindValue(){ int i; short label[5]; orientation = 0; label[0] = getc(txt); while(label[0] == 0x20 || label[0] == 0x9) label[0] = getc(txt); if(label[0] == RETURN_EOF) return RETURN_EOF; if(label[0] == '#') return RETURN_COMMENT; for(i=0; i < 5; i++){ if(label[i] >= '0' && label[i] <= '9'){ label[i] -= '0'; if(orientation) return RETURN_ERROR; } else if(label[i] >= 'A' && label[i] <= 'F'){ label[i] -= 'A'; label[i] += 10; if(orientation) return RETURN_ERROR; } /*else if(label[i] >= 'a' && label[i] <= 'f'){ label[i] -= 'a'; label[i] += 10; }*/ else if(label[i] == ',' || label[i] == 0xD || label[i] == 0xA){ label[i] = -1; break; } else if(label[i] == 'm'){ orientation = 1; i--; } else if(label[i] == 'f'){ orientation = 2; i--; } else if(label[i] == 'r'){ orientation = 3; i--; } else return RETURN_ERROR; label[i+1] = getc(txt); } if(i == 5) return RETURN_ERROR; if(label[0] == -1) return 0; if(label[1] == -1) return label[0]; if(label[2] == -1) return (label[0] << 4) + label[1]; if(label[3] == -1) return (label[0] << 8) + (label[1] << 4) + label[2]; return (label[0] << 12) + (label[1] << 8) + (label[2] << 4) + label[3]; } int FindSub(){ int i; char label[5]; label[0] = getc(txt); while(label[0] == 0x20 || label[0] == 0xD || label[0] == 0xA || label[0] == 0x9) label[0] = getc(txt); if(label[0] == RETURN_EOF) return RETURN_EOF; if(label[0] == '#') return RETURN_COMMENT; if(label[0] == '&') return RETURN_M; for(i=0; i < 5; i++){ if(label[i] >= '0' && label[i] <= '9') label[i] -= '0'; else if(label[i] >= 'A' && label[i] <= 'F'){ label[i] -= 'A'; label[i] += 10; } /*else if(label[i] >= 'a' && label[i] <= 'f'){ label[i] -= 'a'; label[i] += 10; }*/ else if(label[i] == ':'){ label[i] = -1; break; } else return RETURN_ERROR; label[i+1] = getc(txt); } if(i == 5) return RETURN_ERROR; if(label[0] == -1) return 0; if(label[1] == -1) return label[0]; if(label[2] == -1) return (label[0] << 4) + label[1]; if(label[3] == -1) return (label[0] << 8) + (label[1] << 4) + label[2]; return (label[0] << 12) + (label[1] << 8) + (label[2] << 4) + label[3]; } int FindLabel(){ char label[9]; label[0] = getc(txt); while(label[0] == 0x20 || label[0] == 0xD || label[0] == 0xA || label[0] == 0x9){ label[0] = getc(txt); } if(label[0] == RETURN_EOF) return RETURN_EOF; if(label[0] == '#') return RETURN_COMMENT; if(label[0] == 'S'){ // S label[1] = getc(txt); // P label[2] = getc(txt); // R label[3] = getc(txt); // I label[4] = getc(txt); // T label[5] = getc(txt); // E label[6] = getc(txt); // S label[7] = getc(txt); // : label[8] = '\0'; // \0 if(strcmp(label, "SPRITES:") == 0) return LABEL_SPRITES; } else if(label[0] == 'A'){ // A label[1] = getc(txt); // N label[2] = getc(txt); // I label[3] = getc(txt); // M label[4] = getc(txt); // S label[5] = getc(txt); // : label[6] = '\0'; // \0 if(strcmp(label, "ANIMS:") == 0) return LABEL_ANIMS; } return RETURN_ERROR; } FindMacro(){ char label[4]; label[0] = getc(txt); label[1] = getc(txt); label[2] = getc(txt); if(label[0] == 'E' && label[1] == 'N' && label[2] == 'D'){ label[3] = getc(txt); while(label[3] == 0x20 || label[3] == 0x9) label[3] = getc(txt); if(label[3] == 0xD || label[3] == 0xA) return RETURN_M_END; } return RETURN_ERROR; } int main(int argc, char **argv){ int l; int b; int anim_size = 0; // We MUST initialize this with a value int v[256]; int v1; int v2; int v3; int v4; int x; int y; char filename[256]; allegro_init(); if(argc < 2){ allegro_message("Must run from the command prompt or run dialog:\n\n" "\"SPRITE COMPILER\" \"[file without extension]\""); allegro_exit(); return 0; } set_color_depth(24); strcpy(filename, argv[1]); strcat(filename, ".txt"); txt = fopen(filename, "rb"); if(!txt){ allegro_message("Could not open \"%s\"", filename); allegro_exit(); return 0; } strcpy(filename, argv[1]); strcat(filename, ".bmp"); bmp = load_bitmap(filename, NULL); if(!bmp){ allegro_message("Could not open \"%s\"", filename); fclose(txt); allegro_exit(); return 0; } strcpy(filename, argv[1]); strcat(filename, ".psf"); psf = fopen(filename, "w+b"); if(!psf){ allegro_message("Could not create \"%s\"", filename); fclose(txt); destroy_bitmap(bmp); allegro_exit(); return 0; } while(l != RETURN_EOF){ l = FindLabel(); while(l == RETURN_COMMENT){ b = 0; while(b != 0xA && b != 0xD) b = getc(txt); l = FindLabel(); } if(l == LABEL_SPRITES){ sprite_count = FindValue(); sprite = realloc(sprite, sprite_count << 3); l = FindSub(); while(l == RETURN_COMMENT){ b = 0; while(b != 0xA && b != 0xD) b = getc(txt); l = FindSub(); } while(l != RETURN_M){ v1 = FindValue(); v3 = FindValue(); v2 = FindValue(); v4 = FindValue(); if(v2 > 0) v2 += (v1-1); if(v4 > 0) v4 += (v3-1); sprite[l].size_x_left = v1 + ((orientation & 1) << 15); sprite[l].size_x_right = v2; sprite[l].size_y_top = v3 + ((orientation & 2) << 14); sprite[l].size_y_bottom = v4; l = FindSub(); while(l == RETURN_COMMENT){ b = 0; while(b != 0xA && b != 0xD) b = getc(txt); l = FindSub(); } } if(l == RETURN_M){ l = FindMacro(); if(l == RETURN_ERROR) allegro_message("Invalid macro!"); //else if(l == RETURN_M_END) // break; } } else if(l == LABEL_ANIMS){ anim_count = FindValue(); //sprite = realloc(sprite, sprite_count << 3); l = FindSub(); while(l == RETURN_COMMENT){ b = 0; while(b != 0xA && b != 0xD) b = getc(txt); l = FindSub(); } while(l != RETURN_M){ for(b=0; b < 256; b++) v[b] = 0; v[0] = FindValue(); if(v[0] > 255){ allegro_message("Animation speed cannot exceed 0xFF!"); free(sprite); free(anim); fclose(psf); fclose(txt); destroy_bitmap(bmp); allegro_exit(); return 0; } for(b=1; v[b-1] != RETURN_COMMENT; b++){ if(b > 255){ allegro_message("Animation 0x%X is too long!", l); free(sprite); free(anim); fclose(psf); fclose(txt); destroy_bitmap(bmp); allegro_exit(); return 0; } v[b] = FindValue(); } if(b < 2){ allegro_message("No speed specified for animation 0x%X!", l); free(sprite); free(anim); fclose(psf); fclose(txt); destroy_bitmap(bmp); allegro_exit(); return 0; } b--; anim_size += b; anim = realloc(anim, anim_size << 1); anim[anim_size - b] = b-1 + (v[0] << 8); for(x=1; x < b; x++) anim[anim_size - b + x] = v[x]; l = FindSub(); while(l == RETURN_COMMENT){ b = 0; while(b != 0xA && b != 0xD) b = getc(txt); l = FindSub(); } } if(l == RETURN_M){ l = FindMacro(); if(l == RETURN_ERROR) allegro_message("Invalid macro!"); //else if(l == RETURN_M_END) // break; } } } fwrite(&sprite_count, 2, 1, psf); fwrite(&anim_count, 2, 1, psf); fwrite(&bmp->w, 2, 1, psf); fwrite(&bmp->h, 2, 1, psf); for(b=0; b < sprite_count; b++){ fwrite(&sprite[b].size_x_left, 2, 1, psf); fwrite(&sprite[b].size_x_right, 2, 1, psf); fwrite(&sprite[b].size_y_top, 2, 1, psf); fwrite(&sprite[b].size_y_bottom, 2, 1, psf); } for(b=0; b < anim_size; b++) fwrite(&anim[b], 2, 1, psf); for(y=0; y < bmp->h; y++){ for(x=0; x < bmp->w; x++){ /*v1 = 0; v2 = bmp->line[y][x*3] >> 2; v3 = bmp->line[y][(x*3)+1] >> 2; v4 = bmp->line[y][(x*3)+2] >> 2; if(v2 == 0x3F && v3 == 0 && v4 == 0x3F){ v2 = 0xFF; v3 = 0xFF; v4 = 0xFF; } fwrite(&v1, 1, 1, psf); fwrite(&v2, 1, 1, psf); fwrite(&v3, 1, 1, psf); fwrite(&v4, 1, 1, psf);*/ v1 = bmp->line[y][x*3] >> 3; v2 = bmp->line[y][(x*3)+1] >> 2; v3 = bmp->line[y][(x*3)+2] >> 3; v4 = (v1 << 11) | (v2 << 5) | v3; //v4 = (v4 << 8) | (v4 >> 8); fwrite(&v4, 2, 1, psf); } } allegro_message("Sprite sheet \"%s\" successfully created!", filename); fclose(psf); fclose(txt); destroy_bitmap(bmp); allegro_exit(); return 0; } END_OF_MAIN();
001tomclark-research-check
Source/Tools/spritecompiler/main.c
C
gpl2
9,631
# ########## General Setup ############## IF(WIN32) target_link_libraries(spritecompiler "-mwindows" ${ALLEGRO_LIBRARIES} ${DIRECTX_LIBRARIES}) ELSE(WIN32) target_link_libraries(spritecompiler ${ALLEGRO_CONFIG_LIBS}) ENDIF(WIN32) # ########## Resource compilation ######## IF(WIN32) # Only Windows target needs resource compilation # And MinGW is the only one that needs an explicit compile step IF(MINGW) IF(CMAKE_CROSSCOMPILING) ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Sprite_Compiler_resource.obj COMMAND i686-pc-mingw32-windres -I${CMAKE_CURRENT_SOURCE_DIR} -o ${CMAKE_CURRENT_BINARY_DIR}/Sprite_Compiler_resource.obj -i${CMAKE_CURRENT_SOURCE_DIR}/Sprite_Compiler.rc DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Sprite_Compiler.rc ) ENDIF(CMAKE_CROSSCOMPILING) IF(NOT CMAKE_CROSSCOMPILING) ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Sprite_Compiler_resource.obj COMMAND windres -I${CMAKE_CURRENT_SOURCE_DIR} -o ${CMAKE_CURRENT_BINARY_DIR}/Sprite_Compiler_resource.obj -i${CMAKE_CURRENT_SOURCE_DIR}/Sprite_Compiler.rc DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Sprite_Compiler.rc ) ENDIF(NOT CMAKE_CROSSCOMPILING) ENDIF(MINGW) ENDIF(WIN32) # ########## spritecompiler executable ########## # Sources: SET(spritecompiler_executable_SRCS main.c ) IF(WIN32) # Headers: SET(spritecompiler_executable_HDRS Sprite_Compiler_rc.h ) ELSE(WIN32) # Headers: SET(spritecompiler_executable_HDRS ) ENDIF(WIN32) # MSVC can natively handle Windows RC files IF(MSVC) SET(spritecompiler_executable_SRCS ${spritecompiler_executable_SRCS} Sprite_Compiler.rc ) ENDIF(MSVC) # actual target: IF(WIN32) IF(MINGW) ADD_EXECUTABLE(spritecompiler ${spritecompiler_executable_SRCS} Sprite_Compiler_resource.obj) ELSE(MINGW) ADD_EXECUTABLE(spritecompiler ${spritecompiler_executable_SRCS}) ENDIF(MINGW) ELSE(WIN32) ADD_EXECUTABLE(spritecompiler ${spritecompiler_executable_SRCS}) ENDIF(WIN32) # add install target: INSTALL(TARGETS spritecompiler DESTINATION bin)
001tomclark-research-check
Source/Tools/spritecompiler/CMakeLists.txt
CMake
gpl2
2,097
#include <stdio.h> #include <stdlib.h> #include <string.h> // needed for strcpy() #include <ctype.h> // needed for isdigit() /* TODO LIST: - Clean up script compiler - Support arrays with variable subscripts - Add music and sound functionality support - Support sprites and animations - Setup objects to have states - Add move/stop, float/grounded, spawn/destroy functionality to objects */ // This is for the new scripting format #define NUM_INTERNAL_GVARS 91 #define NUM_INTERNAL_OVARS 24 #define NUM_INTERNAL_PVARS 90 #define NUM_PREFIXES 4 #define NUM_KEYWORDS 28 #define NUM_OPERATORS 14 #define NUM_CONDITIONS 6 char *internal_gvars[NUM_INTERNAL_GVARS] = { "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "mouse_z_previous", "camera_mode", "fade_count", "edit_mode", "edit_selector", "edit_clipboard", "smart_mix", "advance_frame", "Game_paused", "DemoCount", "DemoPosition", "DemoFadeDelay", "zone", "act", "stage", "demo", "demo_mode", "frame_skip", "draw_frame", "screen_resolution_x", "screen_resolution_y", "screen_padding_x", "screen_padding_y", "screen_offset_x", "screen_offset_y", "screen_frame_x", "screen_frame_y", "screen_buffer_x", "screen_buffer_y", "screen_scale_x", "screen_scale_y", "screen_double_x", "screen_double_y", "screen_interlace_x", "screen_interlace_y", "vsync_enable", "close_button_pressed", "number_of_objects_in_memory", "ticCounter60L", "fps", "show_fps", "ticCounterL", "ticCounterR", "ticCounter60R", "ticUpdated", "waitCounter", "frames", "num_of_players", "num_of_frames", "frame", "Level_Inactive_flag", "Timer_frames", "Debug_object", "Debug_placement_mode", "Debug_mode_flag", "Emerald_count", "Continue_count", "Time_Over_flag", "Timer_frames", "Timer_minute_word", "Timer_minute", "Timer_second", "Timer_millisecond", "titlecard_sequence_end", "key", "key_shifts", "prompt", "full_screen", "audio_volume", "show_version", "show_watermark", "Update_HUD_lives", "Update_HUD_rings", "Update_HUD_timer", "Update_HUD_score", }; char *internal_ovars[NUM_INTERNAL_OVARS] = { "o.user", "o.static_node", "o.htag", "o.ltag", "o.type", "o.routine", "o.status", "o.x_pos", "o.y_pos", "o.render_flags", "o.width_pixels", "o.priority", "o.subtype", "o.objoff_32", "o.objoff_34", "o.anim_frame_duration", "o.anim_frame", "o.anim", "o.x_pos_pre", "o.y_pos_pre", "o.x_vel", "o.y_vel", "o.x_radius", "o.y_radius", }; char *internal_pvars[NUM_INTERNAL_PVARS] = { "p.character", "p.sidekick", "p.CtrlInput", "p.render_flags", "p.art_tile", "p.x_pos", "p.x_pos_pre", "p.y_pos", "p.y_pos_pre", "p.x_vel", "p.y_vel", "p.inertia", "p.x_radius", "p.y_radius", "p.priority", "p.anim_frame_duration", "p.anim_frame", "p.anim", "p.next_anim", "p.status", "p.routine", "p.routine_secondary", "p.angle", "p.flip_angle", "p.air_left", "p.flip_turned", "p.obj_control", "p.status_secondary", "p.flips_remaining", "p.flip_speed", "p.move_lock", "p.invulnerable_time", "p.invincibility_time", "p.speedshoes_time", "p.next_tilt", "p.tilt", "p.stick_to_convex", "p.spindash_flag", "p.spindash_counter", "p.jumping", "p.interact", "p.layer", "p.layer_plus", "p.Sonic_top_speed", "p.Sonic_acceleration", "p.Sonic_deceleration", "p.Ctrl_Held", "p.Ctrl_Press", "p.Ctrl_Held_Logical", "p.Ctrl_Press_Logical", "p.width_pixels", "p.Sonic_Look_delay_counter", // "Sonic_Stat_Record_Buf[128]", // "Sonic_Pos_Record_Buf[128]", "p.Camera_X_pos", "p.Camera_Y_pos", "p.Camera_Z_pos", "p.Camera_Max_Y_pos", "p.Camera_Min_X_pos", "p.Camera_Max_X_pos", "p.Camera_Min_Y_pos", "p.Camera_Max_Y_pos_now", "p.Camera_X_pos_coarse", "p.Sonic_Pos_Record_Index", "p.Camera_Y_pos_bias", "p.Ring_count", "p.Score", "p.Life_count", "p.Extra_life_flags", "p.Last_star_pole_hit", "p.Saved_Last_star_pole_hit", "p.Saved_x_pos", "p.Saved_y_pos", "p.Saved_Ring_count", "p.Saved_Timer", "p.Saved_art_tile", "p.Saved_layer", "p.Saved_Camera_X_pos", "p.Saved_Camera_Y_pos", "p.Saved_Water_Level", "p.Saved_Extra_life_flags", "p.Saved_Extra_life_flags_2P", "p.Saved_Camera_Max_Y_pos", "p.Collision_addr", "p.ram_EEB0", "p.ram_EEB2", "p.ram_EEBE", "p.ram_EED0", "p.ram_F65C", "p.ram_F768", "p.ram_F76A", "p.ram_F7C7", }; char *prefixes[NUM_PREFIXES] = { "player", // array "object", // array "p", "o", }; char *keywords[NUM_KEYWORDS] = { "//", "/*", "include", "define", "object", "endobject", "if", "elseif", "else", "endif", "break", "function", "endfunction", "playfm", "playpcm", "resetsound", "textout", "drawsprite", "animate", "destroy", "return", "counterout", "fadeoutfm", "move", "spawn", "rest", "setgfxmode", "startzone", }; char *operators[NUM_OPERATORS] = { "~", // 0 Bitwise NOT (one operand only) "++", // 1 Increase (one operand only) "--", // 2 Decrease (one operand only) "=", // 3 Assign "+", // 4 Add "-", // 5 Subtract "*", // 6 Multiply "/", // 7 Divide "%", // 8 Modulus "<<", // 9 Bitwise shift left ">>", // 10 Bitwise shift right "&", // 11 Bitwise AND "|", // 12 Bitwise OR "^", // 13 Bitwise XOR }; char *conditions[NUM_CONDITIONS] = { "==", // Equal ">", // Greater "<", // Less ">=", // Greater or equal "<=", // Less or equal "!=", // Not equal }; unsigned short num_labels; char *label; int *label_value; // Stuff for storing the scripts FILE *file_script; char *script[256]; char *script_bytecode; char *script_bytecode_index; int script_bytecode_size; int script_bytecode_index_size; // Stuff for holding keywords, labels, etc. char text_buffer[64]; char string_cmp1[64]; char string_cmp2[64]; char string_cmp3[64]; // Stuff for keeping track of the script position int text_pos[256]; short line_number; // Stuff for storing general information read from the script int byte_value; char return_type; char array_found; char text_length; unsigned int ptr_offset; // used to offset pointers unsigned char scope_file; unsigned char scope_if; unsigned char scope_object; unsigned char scope_function; typedef struct{ unsigned int ptr_list[256]; // ptr_list[255] is used for 'endif' unsigned char ptr_type[256]; // 6 for "if", 7 for "elseif", 8 for "else" unsigned char num_branches; } type_if; type_if *if_section; char load_script(char *filename, ...){ int filesize; printf("Opening \"%s\"...\n", filename); file_script = fopen(filename, "r+b"); // UPC = User Programmable Code if(!file_script) return 0; scope_file++; text_pos[scope_file] = 0; fseek(file_script, 0, SEEK_END); filesize = ftell(file_script); filesize += 2; rewind(file_script); script[scope_file] = (char *)malloc(filesize); filesize -= 2; // These will only allocate on the first file loaded if(!script_bytecode){ script_bytecode = (char *)malloc(1); script_bytecode[0] = 0; } if(!label){ label = (char *)malloc(64); label[0] = 0; } if(!label_value){ label_value = (int *)malloc(4); label_value[0] = 0; } if(!if_section){ if_section = (type_if *)malloc(1); } fread(script[scope_file], 1, filesize, file_script); script[scope_file][filesize] = 0xA; // new line script[scope_file][filesize+1] = 0; // terminating character fclose(file_script); return 1; } char save_script(){ short i = 0; char header[] = { 'P', 'R', 'O', 'C', 'O', 'D', 'E', 0 }; file_script = fopen("game.pcs", "wb"); if(!file_script){ printf("ERROR: There was an error while trying to create the PCS file.\n"); return 0; } if(script_bytecode_size > 0){ // "PROCODE" and a byte for the script version fwrite(header, 1, 8, file_script); // Bytecode header containing pointers to various chunks of code fwrite(&script_bytecode_size, 1, 4, file_script); // size of script fwrite(script_bytecode_index, 1, script_bytecode_index_size, file_script); // Word to terminate the header fwrite(&i, 1, 2, file_script); // Script fwrite(script_bytecode, 1, script_bytecode_size, file_script); } fclose(file_script); return 1; } char free_current_script(){ if(script[scope_file]) free(script[scope_file]); scope_file--; printf("Script closed.\n"); return 1; } char free_script(){ short i; for(i=0; i < 256; i++) if(script[i]) free(script[i]); if(script_bytecode) free(script_bytecode); if(script_bytecode_index) free(script_bytecode_index); if(label) free(label); if(label_value) free(label_value); if(if_section) free(if_section); return 1; } char testchar_seperator(char ch){ // test for space, tab, and carriage if(ch == ' ' || ch == 0x9 || ch == 0xD) return ch; // test for new line if(ch == 0xA){ line_number++; return ch; } if(ch == '[') return ch; if(ch == ']') return ch; // no seperator found return 0; } char testchar_newline(char ch){ if(ch == 0xA){ line_number++; return 1; } // new line not found return 0; } char testchar_legalchar(char ch){ if( (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || (ch == '.') //|| ch == '[' || ch == ']' || ch == '"' || ch == '_' || ch == '/' || ch == '*' || ch == '%' || ch == '+' || ch == '-' || ch == '&' || ch == '|' || ch == '^' || ch == '~' || ch == '=' || ch == '>' || ch == '<' || ch == '!') return ch; return 0; } char write_char_bytecode(char ch){ script_bytecode_size++; script_bytecode = (char *)realloc(script_bytecode, script_bytecode_size); script_bytecode[script_bytecode_size-1] = ch; return 0; } char write_short_bytecode(short w){ script_bytecode_size += 2; script_bytecode = (char *)realloc(script_bytecode, script_bytecode_size); *(short *)(&script_bytecode[script_bytecode_size-2]) = w; return 0; } char write_long_bytecode(int lw){ script_bytecode_size += 4; script_bytecode = (char *)realloc(script_bytecode, script_bytecode_size); *(int *)(&script_bytecode[script_bytecode_size-4]) = lw; return 0; } char write_bytecode_index(char ch1, char ch2, int lw){ if(ch1 != 0){ // object lookup script_bytecode_index_size += 5; script_bytecode_index = (char *)realloc(script_bytecode_index, script_bytecode_index_size); script_bytecode_index[script_bytecode_index_size-5] = ch1; } else{ // function lookup script_bytecode_index_size += 6; script_bytecode_index = (char *)realloc(script_bytecode_index, script_bytecode_index_size); script_bytecode_index[script_bytecode_index_size-6] = ch1; script_bytecode_index[script_bytecode_index_size-5] = ch2; } // pointer *(int *)(&script_bytecode_index[script_bytecode_index_size-4]) = lw; return 0; } char upper_to_lower(char *str){ int i; for(i=0; i < 64; i++){ if(str[i] >= 'A' && str[i] <= 'Z') str[i] += 0x20; } return 1; } char read_keyword(){ int i; byte_value = -1; // loop until a legal character is found while(testchar_legalchar(script[scope_file][text_pos[scope_file]]) == 0){ text_pos[scope_file]++; if(script[scope_file][text_pos[scope_file]] == 0) return 0; // RETURN: end of script found } i = 0; // loop until an illegal character is found while(testchar_legalchar(script[scope_file][text_pos[scope_file]])){ if(i == 63) return -1; // RETURN: 63 character word limit exceeded text_buffer[i] = script[scope_file][text_pos[scope_file]]; text_pos[scope_file]++; i++; } array_found = (script[scope_file][text_pos[scope_file]] == '['); text_buffer[i] = 0; // add terminator to string for(i=0; i < NUM_KEYWORDS; i++){ strcpy(string_cmp1, text_buffer); strcpy(string_cmp2, keywords[i]); upper_to_lower(string_cmp1); upper_to_lower(string_cmp2); if(strcmp(string_cmp1, string_cmp2) == 0){ byte_value = i; return 1; // RETURN: keyword match found } } return -2; // RETURN: invalid keyword } char read_operator(){ int i; byte_value = -1; while(testchar_legalchar(script[scope_file][text_pos[scope_file]]) == 0){ text_pos[scope_file]++; if(script[scope_file][text_pos[scope_file]] == 0xA) // new line found line_number++; else if(script[scope_file][text_pos[scope_file]] == 0) return 0; // RETURN: end of script found } i = 0; while(testchar_legalchar(script[scope_file][text_pos[scope_file]])){ if(i == 2) return -1; // RETURN: invalid operator text_buffer[i] = script[scope_file][text_pos[scope_file]]; text_pos[scope_file]++; i++; } text_buffer[i] = 0; // add terminator to string for(i=0; i < NUM_OPERATORS; i++){ strcpy(string_cmp1, text_buffer); strcpy(string_cmp2, operators[i]); upper_to_lower(string_cmp1); upper_to_lower(string_cmp2); if(strcmp(string_cmp1, string_cmp2) == 0){ byte_value = i; return 1; // RETURN: operator match found } } return -2; // RETURN: invalid operator } char read_logic_operator(){ int i; byte_value = -1; while(testchar_legalchar(script[scope_file][text_pos[scope_file]]) == 0){ text_pos[scope_file]++; if(script[scope_file][text_pos[scope_file]] == 0xA) // new line found line_number++; else if(script[scope_file][text_pos[scope_file]] == 0) return 0; // RETURN: end of script found } i = 0; while(testchar_legalchar(script[scope_file][text_pos[scope_file]])){ if(i == 2) return -1; // RETURN: invalid operator text_buffer[i] = script[scope_file][text_pos[scope_file]]; text_pos[scope_file]++; i++; } text_buffer[i] = 0; // add terminator to string for(i=0; i < NUM_CONDITIONS; i++){ strcpy(string_cmp1, text_buffer); strcpy(string_cmp2, conditions[i]); upper_to_lower(string_cmp1); upper_to_lower(string_cmp2); if(strcmp(string_cmp1, string_cmp2) == 0){ byte_value = i; return 1; // RETURN: operator match found } } return -2; // RETURN: invalid operator } char read_label(){ int i; byte_value = -1; while(testchar_legalchar(script[scope_file][text_pos[scope_file]]) == 0){ text_pos[scope_file]++; if(script[scope_file][text_pos[scope_file]] == 0xA) // new line found line_number++; else if(script[scope_file][text_pos[scope_file]] == 0) return 0; // RETURN: end of script found } label = (char *)realloc(label, 64 + ((int)num_labels<<6)); i = 0; while(testchar_seperator(script[scope_file][text_pos[scope_file]]) == 0){ label[((int)num_labels<<6) + i] = script[scope_file][text_pos[scope_file]]; text_pos[scope_file]++; i++; } label[((int)num_labels<<6) + i] = 0; for(i=0; i < num_labels; i++){ strcpy(string_cmp1, &label[((int)num_labels)<<6]); strcpy(string_cmp2, &label[i<<6]); upper_to_lower(string_cmp1); upper_to_lower(string_cmp2); if(strcmp(string_cmp1, string_cmp2) == 0){ return -1; // RETURN: label already defined } } num_labels++; return 1; // RETURN: label successfully read } char read_string(){ int i; byte_value = -1; while(testchar_legalchar(script[scope_file][text_pos[scope_file]]) == 0){ text_pos[scope_file]++; if(script[scope_file][text_pos[scope_file]] == 0) return 0; // RETURN: end of script found } if(script[scope_file][text_pos[scope_file]] != '"') return -2; // RETURN: invalid string text_pos[scope_file]++; i = 0; while(script[scope_file][text_pos[scope_file]] != '"'){ if(i == 63) return -1; // RETURN: 63 character word limit exceeded text_buffer[i] = script[scope_file][text_pos[scope_file]]; text_pos[scope_file]++; i++; } text_pos[scope_file]++; text_buffer[i] = 0; // add terminator to string return 1; // RETURN: string successfully read } char read_array(){ int i; byte_value = -1; while(testchar_legalchar(script[scope_file][text_pos[scope_file]]) == 0){ text_pos[scope_file]++; if(script[scope_file][text_pos[scope_file]] == 0xA) // new line found line_number++; else if(script[scope_file][text_pos[scope_file]] == 0) return 0; // RETURN: end of script found } i = 0; while(script[scope_file][text_pos[scope_file]] != ']'){ text_buffer[i] = script[scope_file][text_pos[scope_file]]; text_pos[scope_file]++; if(text_buffer[i] == 0x20 || text_buffer[i] == 0x9 || text_buffer[i] == 0xA || text_buffer[i] == 0xD) text_buffer[i] = 0; if(text_buffer[i] == 0) return 0; // RETURN: end of script found else if(i == 63) return -3; // RETURN: 63 character limit exceeded i++; } text_buffer[i] = 0; for(i=0; i < 64; i++){ if(text_buffer[i] == 0){ text_length = i; // save length of text i = 63; } } return 1; } char read_number(){ int i; byte_value = -1; while(testchar_legalchar(script[scope_file][text_pos[scope_file]]) == 0){ text_pos[scope_file]++; if(script[scope_file][text_pos[scope_file]] == 0xA) // new line found line_number++; else if(script[scope_file][text_pos[scope_file]] == 0) return 0; // RETURN: end of script found } i = 0; while(testchar_seperator(script[scope_file][text_pos[scope_file]]) == 0){ text_buffer[i] = script[scope_file][text_pos[scope_file]]; text_pos[scope_file]++; i++; } array_found = (script[scope_file][text_pos[scope_file]] == '['); text_buffer[i] = 0; text_length = i; // save length of text if(array_found) return 5; for(i=0; i < NUM_KEYWORDS; i++){ strcpy(string_cmp1, text_buffer); strcpy(string_cmp2, keywords[i]); upper_to_lower(string_cmp1); upper_to_lower(string_cmp2); if(strcmp(string_cmp1, string_cmp2) == 0){ return -1; // RETURN: same name as existing keyword } } for(i=0; i < NUM_INTERNAL_GVARS; i++){ strcpy(string_cmp1, text_buffer); strcpy(string_cmp2, internal_gvars[i]); upper_to_lower(string_cmp1); upper_to_lower(string_cmp2); if(strcmp(string_cmp1, string_cmp2) == 0){ byte_value = i; return 1; // RETURN: GVAR match found } } for(i=0; i < NUM_INTERNAL_OVARS; i++){ strcpy(string_cmp1, text_buffer); strcpy(string_cmp2, internal_ovars[i]); upper_to_lower(string_cmp1); upper_to_lower(string_cmp2); if(strcmp(string_cmp1, string_cmp2) == 0){ byte_value = i; return 10; // RETURN: OVAR match found } } for(i=0; i < NUM_INTERNAL_PVARS; i++){ strcpy(string_cmp1, text_buffer); strcpy(string_cmp2, internal_pvars[i]); upper_to_lower(string_cmp1); upper_to_lower(string_cmp2); if(strcmp(string_cmp1, string_cmp2) == 0){ byte_value = i; return 2; // RETURN: PVAR match found } } for(i=0; i < num_labels; i++){ strcpy(string_cmp1, text_buffer); strcpy(string_cmp2, &label[i<<6]); upper_to_lower(string_cmp1); upper_to_lower(string_cmp2); if(strcmp(string_cmp1, string_cmp2) == 0){ byte_value = i; return 3; // RETURN: LABEL match found } } if(isdigit(text_buffer[0]) == 0 && text_buffer[0] != '-') return -2; // RETURN: invalid number for(i=1; i < text_length; i++){ if(isdigit(text_buffer[i]) == 0) return -2; // RETURN: invalid number } byte_value = atol(text_buffer); return 4; // RETURN: number read } char get_variable(){ switch(read_number()){ case -2: printf("ERROR: invalid number.\n"); return_type = -2; return 0; case -1: printf("ERROR: same name as existing keyword.\n"); return_type = -1; return 0; case 0: printf("End of script found.\n"); return_type = 0; return 0; case 1: printf("GVAR match found for '%s'.\n", text_buffer); return_type = 1; break; case 10: printf("OVAR match found for '%s'.\n", text_buffer); return_type = 10; break; case 2: printf("PVAR match found for '%s'.\n", text_buffer); return_type = 2; break; case 3: return_type = 3; case 4: printf("ERROR: must use a variable.\n"); return_type = 4; return 0; case 5: // Array found return_type = 5; return 5; } return 1; } char define_label(){ switch(read_label()){ case -1: printf("ERROR: label already defined.\n"); return_type = -1; return 0; case 0: printf("End of script found.\n"); return_type = 0; return 0; case 1: printf("New label defined.\n"); return_type = 1; break; } return 1; } char get_constant(){ switch(read_number()){ case -2: printf("ERROR: invalid number.\n"); return_type = -2; return 0; case -1: printf("ERROR: same name as existing keyword.\n"); return_type = -1; return 0; case 0: printf("End of script found.\n"); return_type = 0; return 0; case 1: printf("ERROR: must use a constant.\n"); return_type = 1; return 0; case 2: printf("ERROR: must use a constant.\n"); return_type = 2; return 0; case 3: printf("LABEL match found with value of '%i'.\n", label_value[byte_value]); return_type = 3; break; case 4: printf("Number '%i' read.\n", byte_value); return_type = 4; break; } return 1; } char get_number(){ switch(read_number()){ case -2: printf("ERROR: invalid number.\n"); return_type = -2; return 0; case -1: printf("ERROR: same name as existing keyword.\n"); return_type = -1; return 0; case 0: printf("End of script found.\n"); return_type = 0; return 0; case 1: printf("GVAR match found for '%s'.\n", text_buffer); return_type = 1; break; case 10: printf("OVAR match found for '%s'.\n", text_buffer); return_type = 10; break; case 2: printf("PVAR match found for '%s'.\n", text_buffer); return_type = 2; break; case 3: printf("LABEL match found with value of '%i'.\n", label_value[byte_value]); return_type = 3; break; case 4: printf("Number '%i' read.\n", byte_value); return_type = 4; break; } return 1; } char get_operator(){ switch(read_operator()){ case -2: return_type = -2; case -1: printf("ERROR: invalid operator.\n"); return_type = -1; return 0; case 0: printf("End of script found.\n"); return_type = 0; return 0; case 1: printf("Operator match found for '%s'.\n", text_buffer); return_type = 1; break; } return 1; } char get_logic_operator(){ switch(read_logic_operator()){ case -2: return_type = -2; case -1: printf("ERROR: invalid logic operator.\n"); return_type = -1; return 0; case 0: printf("End of script found.\n"); return_type = 0; return 0; case 1: printf("Logic operator match found for '%s'.\n", text_buffer); return_type = 1; break; } return 1; } char get_keyword(){ switch(read_keyword()){ case -2: //printf("ERROR: '%s' is an invalid keyword.\n", text_buffer); return_type = -2; return 0; case -1: printf("ERROR: 63 character word limit exceeded.\n"); return_type = -1; return 0; case 0: printf("End of script found.\n"); return_type = 0; return 0; case 1: printf("Keyword match found for '%s'.\n", text_buffer); return_type = 1; break; } return 1; } /*char get_array(){ switch(read_array()){ case -2: printf("ERROR: invalid number.\n"); return_type = -2; return 0; case -1: printf("ERROR: same name as existing keyword.\n"); return_type = -1; return 0; case 0: printf("End of script found.\n"); return_type = 0; return 0; case 1: printf("GVAR match found for '%s'.\n", text_buffer); return_type = 1; break; case 10: printf("OVAR match found for '%s'.\n", text_buffer); return_type = 10; break; case 2: printf("PVAR match found for '%s'.\n", text_buffer); return_type = 2; break; case 3: printf("LABEL match found with value of '%i'.\n", label_value[byte_value]); return_type = 3; break; case 4: printf("Number '%i' read.\n", byte_value); return_type = 4; break; } return 1; }*/ /* char read_array(int c){ // START OF ARRAY DETECTION CODE if(script[scope_file][text_pos[scope_file]] == '['){ text_pos[scope_file]++; strcpy(string_cmp3, string_cmp1); // backup string if(!get_number()){ return -1; } if(return_type == 3) // label used byte_value = label_value[byte_value]; if(script[scope_file][text_pos[scope_file]] == ']'){ text_pos[scope_file]++; if(c + byte_value < NUM_INTERNAL_OVARS){ byte_value += c; strcpy(string_cmp1, string_cmp3); strcpy(string_cmp2, internal_ovars[c]); if(strcmp(string_cmp1, string_cmp2) != 0){ printf("ERROR: Subscript value is too big for array.\n"); return -1; } } else{ printf("ERROR: Subscript value is too big for array.\n"); return -1; } } else{ printf("ERROR: Invalid subscript in array.\n"); return -1; } } // END OF ARRAY DETECTION CODE return 1; } */ char interpret_number(){ int c; for(c=0; c < NUM_INTERNAL_GVARS; c++){ strcpy(string_cmp1, internal_gvars[c]); upper_to_lower(string_cmp1); if(strcmp(text_buffer, string_cmp1) == 0){ write_char_bytecode(1 + array_found); write_short_bytecode(c + 0x800); return_type = 1; return return_type; } } for(c=0; c < NUM_INTERNAL_OVARS; c++){ strcpy(string_cmp1, internal_ovars[c]); upper_to_lower(string_cmp1); if(strcmp(text_buffer, string_cmp1) == 0){ write_char_bytecode(1 + array_found); write_short_bytecode(c + 0x100); return_type = 10; return return_type; } } for(c=0; c < NUM_INTERNAL_PVARS; c++){ strcpy(string_cmp1, internal_pvars[c]); upper_to_lower(string_cmp1); if(strcmp(text_buffer, string_cmp1) == 0){ write_char_bytecode(1 + array_found); write_short_bytecode(c); return_type = 2; return return_type; } } if(!array_found){ // check for constants if it's not an array for(c=0; c < num_labels; c++){ strcpy(string_cmp1, &label[c<<6]); upper_to_lower(string_cmp1); if(strcmp(text_buffer, string_cmp1) == 0){ write_char_bytecode(0); write_long_bytecode(label_value[c]); return_type = 3; return return_type; } } if(isdigit(text_buffer[0]) == 0 && text_buffer[0] != '-'){ return_type = -2; return return_type; // RETURN: invalid number } for(c=1; c < text_length; c++){ if(isdigit(text_buffer[c]) == 0){ return_type = -2; return return_type; // RETURN: invalid number } } } else{ return_type = -2; return return_type; // RETURN: invalid number } write_char_bytecode(0); write_long_bytecode(atol(text_buffer)); return_type = 4; return return_type; // RETURN: number read } char handle_number(char size){ if(!get_number()){ return -1; } if(return_type == 1){ // GVAR variable byte_value += 0x800; write_char_bytecode(1); write_short_bytecode(byte_value); } else if(return_type == 10){ // OVAR variable byte_value += 0x100; write_char_bytecode(1); write_short_bytecode(byte_value); } else if(return_type == 2){ // PVAR variable write_char_bytecode(1); write_short_bytecode(byte_value); } else{ // constant if(return_type == 3) // label byte_value = label_value[byte_value]; write_char_bytecode(0); switch(size){ case 1: write_char_bytecode(byte_value); break; case 2: write_short_bytecode(byte_value); break; case 4: write_long_bytecode(byte_value); } } return 1; } char compile_script(){ int c; array_found = 0; if(!get_keyword()){ // check for end of script if(return_type == 0){ free_current_script(); return 0; } if(return_type == -2 && (scope_object != 0 || scope_function != 0)){ write_char_bytecode(0); // this is an assignment upper_to_lower(text_buffer); if(!interpret_number()){ printf("ERROR: '%s' is an invalid keyword.\n", text_buffer); free_current_script(); return 0; // assignment statement not found } if(array_found){ // found '[' in the string array_found = 0; if(read_array()){ upper_to_lower(text_buffer); if(!interpret_number()){ printf("ERROR: '%s' is an invalid number.\n", text_buffer); free_current_script(); return 0; } } else{ printf("ERROR: '%s' is an invalid array.\n", text_buffer); free_current_script(); return 0; } } /*else{ if(!get_number()){ free_current_script(); return 0; } upper_to_lower(text_buffer); if(!interpret_number()){ printf("ERROR: '%s' is an invalid number.\n", text_buffer); free_current_script(); return 0; } }*/ if(!get_operator()){ free_current_script(); return 0; } write_char_bytecode(byte_value); if(byte_value >= 3){ // another operand is required if(!get_number()){ free_current_script(); return 0; } upper_to_lower(text_buffer); if(!interpret_number()){ printf("ERROR: '%s' is an invalid keyword.\n", text_buffer); free_current_script(); return 0; // assignment statement not found } if(array_found){ // found '[' in the string array_found = 0; if(read_array()){ upper_to_lower(text_buffer); if(!interpret_number()){ printf("ERROR: '%s' is an invalid number.\n", text_buffer); free_current_script(); return 0; } } else{ printf("ERROR: '%s' is an invalid array.\n", text_buffer); free_current_script(); return 0; } } /*else{ if(!get_number()){ free_current_script(); return 0; } upper_to_lower(text_buffer); if(!interpret_number()){ printf("ERROR: '%s' is an invalid number.\n", text_buffer); free_current_script(); return 0; } }*/ } return 1; } else{ printf("ERROR: '%s' is an invalid keyword.\n", text_buffer); free_current_script(); return 0; } /* // check for assignment statement if(return_type == -2 && (scope_object != 0 || scope_function != 0)){ // invalid keyword for(c=0; c < NUM_INTERNAL_GVARS; c++){ strcpy(string_cmp1, text_buffer); strcpy(string_cmp2, internal_gvars[c]); upper_to_lower(string_cmp1); upper_to_lower(string_cmp2); if(strcmp(string_cmp1, string_cmp2) == 0){ write_char_bytecode(0); // this is an assignment byte_value = c; byte_value += 0x800; write_short_bytecode(byte_value); // this is an assignment if(!get_operator()){ free_current_script(); return 0; } write_char_bytecode(byte_value); if(byte_value >= 3){ // another operand is required if(!get_number()){ free_current_script(); return 0; } if(return_type == 1){ // GVAR variable byte_value += 0x800; write_char_bytecode(1); write_short_bytecode(byte_value); } else if(return_type == 10){ // OVAR variable //if(!read_array(byte_value)){ free_current_script(); return 0; } byte_value += 0x100; write_char_bytecode(1); write_short_bytecode(byte_value); } else if(return_type == 2){ // PVAR variable write_char_bytecode(1); write_short_bytecode(byte_value); } else{ // constant if(return_type == 3) // label byte_value = label_value[byte_value]; write_char_bytecode(0); write_long_bytecode(byte_value); } } return 1; } } for(c=0; c < NUM_INTERNAL_OVARS; c++){ strcpy(string_cmp1, text_buffer); strcpy(string_cmp2, internal_ovars[c]); upper_to_lower(string_cmp1); upper_to_lower(string_cmp2); if(strcmp(string_cmp1, string_cmp2) == 0){ write_char_bytecode(0); // this is an assignment byte_value = c; //if(!read_array(byte_value)){ free_current_script(); return 0; } byte_value += 0x100; write_short_bytecode(byte_value); // this is an assignment if(!get_operator()){ free_current_script(); return 0; } write_char_bytecode(byte_value); if(byte_value >= 3){ // another operand is required if(!get_number()){ free_current_script(); return 0; } if(return_type == 1){ // GVAR variable byte_value += 0x800; write_char_bytecode(1); write_short_bytecode(byte_value); } else if(return_type == 10){ // OVAR variable //if(!read_array(byte_value)){ free_current_script(); return 0; } byte_value += 0x100; write_char_bytecode(1); write_short_bytecode(byte_value); } else if(return_type == 2){ // PVAR variable write_char_bytecode(1); write_short_bytecode(byte_value); } else{ // constant if(return_type == 3) // label byte_value = label_value[byte_value]; write_char_bytecode(0); write_long_bytecode(byte_value); } } return 1; } } for(c=0; c < NUM_INTERNAL_PVARS; c++){ strcpy(string_cmp1, text_buffer); strcpy(string_cmp2, internal_pvars[c]); upper_to_lower(string_cmp1); upper_to_lower(string_cmp2); if(strcmp(string_cmp1, string_cmp2) == 0){ write_char_bytecode(0); // this is an assignment byte_value = c; write_short_bytecode(byte_value); // this is an assignment if(!get_operator()){ free_current_script(); return 0; } write_char_bytecode(byte_value); if(byte_value >= 3){ if(!get_number()){ free_current_script(); return 0; } if(return_type == 1){ // GVAR variable byte_value += 0x800; write_char_bytecode(1); write_short_bytecode(byte_value); } else if(return_type == 10){ // OVAR variable //if(!read_array(byte_value)){ free_current_script(); return 0; } byte_value += 0x100; write_char_bytecode(1); write_short_bytecode(byte_value); } else if(return_type == 2){ // PVAR variable write_char_bytecode(1); write_short_bytecode(byte_value); } else{ // constant if(return_type == 3) // label byte_value = label_value[byte_value]; write_char_bytecode(0); write_long_bytecode(byte_value); } } return 1; } } printf("ERROR: '%s' is an invalid keyword.\n", text_buffer); free_current_script(); return 0; // assignment statement not found } else{ printf("ERROR: '%s' is an invalid keyword.\n", text_buffer); free_current_script(); return 0; }*/ } switch(byte_value){ case 0: // "//" while(testchar_newline(script[scope_file][text_pos[scope_file]]) == 0) text_pos[scope_file]++; break; case 1: // "/*" while(byte_value != 0){ while(script[scope_file][text_pos[scope_file]] != '*'){ if(script[scope_file][text_pos[scope_file]] == 0){ free_current_script(); return 0; // RETURN: end of script found } text_pos[scope_file]++; } if(script[scope_file][text_pos[scope_file]+1] == '/'){ text_pos[scope_file] += 2; byte_value = 0; } else text_pos[scope_file]++; } break; case 2: // "include" if(scope_object != 0){ printf("ERROR: cannot use '%s' inside an object definition.\n", text_buffer); free_current_script(); return 0; } if(scope_function != 0){ printf("ERROR: cannot use '%s' inside a function definition.\n", text_buffer); free_current_script(); return 0; } if(scope_file == 255){ printf("ERROR: too many \"include\" levels.\n"); free_current_script(); return 0; } if(!read_string()){ free_current_script(); return 0; } load_script(text_buffer); printf("Script loaded.\n"); while(compile_script()); printf("Script compiled.\n"); break; case 3: // "define" if(scope_object != 0){ printf("ERROR: cannot use '%s' inside an object definition.\n", text_buffer); free_current_script(); return 0; } if(scope_function != 0){ printf("ERROR: cannot use '%s' inside a function definition.\n", text_buffer); free_current_script(); return 0; } if(num_labels == 65535){ printf("ERROR: too many constants defined.\n"); free_current_script(); return 0; } if(!define_label()){ free_current_script(); return 0; } if(!get_constant()){ free_current_script(); return 0; } label_value = (int *)realloc(label_value, (int)num_labels<<2); if(return_type == 3) // label byte_value = label_value[byte_value]; label_value[num_labels-1] = byte_value; break; case 4: // "object" if(scope_object != 0){ printf("ERROR: cannot define an object within another.\n"); free_current_script(); return 0; } if(scope_function != 0){ printf("ERROR: cannot define an object within a function.\n"); free_current_script(); return 0; } scope_object = 1; ptr_offset = script_bytecode_size; if(!get_constant()){ free_current_script(); return 0; } if(return_type == 3) // label byte_value = label_value[byte_value]; if(byte_value < 1 || byte_value > 255){ printf("ERROR: object value must be between 1 and 255.\n"); free_current_script(); return 0; } write_bytecode_index(byte_value, 0, script_bytecode_size); break; case 5: // "endobject" if(scope_object != 1){ printf("ERROR: no 'object' definition found.\n"); free_current_script(); return 0; } if(scope_if != 0){ printf("ERROR: cannot use 'endobject' within an 'if' statement.\n"); free_current_script(); return 0; } scope_object = 0; write_char_bytecode(10); // "return" break; case 6: // "if" scope_if++; if(scope_if == 255){ printf("ERROR: too many 'if' levels.\n"); free_current_script(); return 0; } if_section = (type_if *)realloc(if_section, scope_if * sizeof(type_if)); if_section[scope_if-1].num_branches = 0; if_section[scope_if-1].ptr_list[0] = script_bytecode_size; if_section[scope_if-1].ptr_type[0] = byte_value; // "if" write_char_bytecode(byte_value); write_long_bytecode(0); // next branch ptr write_long_bytecode(0); // endif ptr //////////// Conidition //////////// if(!handle_number(4)){ free_current_script(); return 0; } if(!get_logic_operator()){ free_current_script(); return 0; } write_char_bytecode(byte_value); if(!handle_number(4)){ free_current_script(); return 0; } break; case 7: // "elseif" if_section[scope_if-1].num_branches++; if(scope_if == 0){ printf("ERROR: cannot use %s outside an if section.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(10); // insert "break" // Save script address if_section[scope_if-1].ptr_list[if_section[scope_if-1].num_branches] = script_bytecode_size; if_section[scope_if-1].ptr_type[if_section[scope_if-1].num_branches] = byte_value; // "elseif" write_char_bytecode(byte_value); write_long_bytecode(0); // reserve space for pointer //////////// Conidition //////////// if(!handle_number(4)){ free_current_script(); return 0; } if(!get_logic_operator()){ free_current_script(); return 0; } write_char_bytecode(byte_value); if(!handle_number(4)){ free_current_script(); return 0; } break; case 8: // "else" if_section[scope_if-1].num_branches++; if(scope_if == 0){ printf("ERROR: cannot use %s outside an if section.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(10); // insert "break" // Save script address if_section[scope_if-1].ptr_list[if_section[scope_if-1].num_branches] = script_bytecode_size; if_section[scope_if-1].ptr_type[if_section[scope_if-1].num_branches] = byte_value; // "else" break; case 9: // "endif" if_section[scope_if-1].num_branches++; if(scope_if == 0){ printf("ERROR: cannot use %s outside an if section.\n", text_buffer); free_current_script(); return 0; } if(if_section[scope_if-1].ptr_type[if_section[scope_if-1].num_branches-1] != 0x8) // not "else" write_char_bytecode(10); // insert "break" // Save script address if_section[scope_if-1].ptr_list[if_section[scope_if-1].num_branches] = script_bytecode_size; *(int *)(&script_bytecode[if_section[scope_if-1].ptr_list[0]+5]) = script_bytecode_size - ptr_offset; for(c=0; c < if_section[scope_if-1].num_branches; c++){ if(if_section[scope_if-1].ptr_type[c] != 8){ // not type "else" *(int *)(&script_bytecode[if_section[scope_if-1].ptr_list[c]+1]) = if_section[scope_if-1].ptr_list[c+1] - ptr_offset; } } scope_if--; break; case 10: // "break" if(scope_object != 1){ printf("ERROR: cannot use '%s' outside an object definition.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(byte_value); break; case 11: // "function" if(scope_function != 0){ printf("ERROR: cannot define a function within another.\n"); free_current_script(); return 0; } if(scope_object != 0){ printf("ERROR: cannot define a function within an object.\n"); free_current_script(); return 0; } scope_function = 1; ptr_offset = script_bytecode_size; if(!get_constant()){ free_current_script(); return 0; } if(return_type == 3) // label byte_value = label_value[byte_value]; if(byte_value < 1 || byte_value > 255){ printf("ERROR: function value must be between 1 and 255.\n"); free_current_script(); return 0; } write_bytecode_index(0, byte_value, script_bytecode_size); break; case 12: // "endfunction" if(scope_function != 1){ printf("ERROR: no 'function' definition found.\n"); free_current_script(); return 0; } if(scope_if != 0){ printf("ERROR: cannot use 'endfunction' within an 'if' statement.\n"); free_current_script(); return 0; } scope_function = 0; write_char_bytecode(10); // "return" break; case 13: // "playbgm" if(scope_object == 0 && scope_function == 0){ printf("ERROR: cannot use '%s' outside a function or object.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(byte_value); // music if(!handle_number(2)){ free_current_script(); return 0; } // buffer if(!handle_number(1)){ free_current_script(); return 0; } // mix if(!handle_number(1)){ free_current_script(); return 0; } break; case 14: // "playsfx" if(scope_object == 0 && scope_function == 0){ printf("ERROR: cannot use '%s' outside a function or object.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(byte_value); // sound if(!handle_number(2)){ free_current_script(); return 0; } // buffer if(!handle_number(1)){ free_current_script(); return 0; } // mix if(!handle_number(1)){ free_current_script(); return 0; } break; case 15: // "resetsound" if(scope_object == 0 && scope_function == 0){ printf("ERROR: cannot use '%s' outside a function or object.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(byte_value); break; case 16: // "textout" if(scope_object == 0 && scope_function == 0){ printf("ERROR: cannot use '%s' outside a function or object.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(byte_value); // X position if(!handle_number(2)){ free_current_script(); return 0; } // Y position if(!handle_number(2)){ free_current_script(); return 0; } // Color if(!handle_number(1)){ free_current_script(); return 0; } // String if(!read_string()){ free_current_script(); return 0; } for(c=0; c < 64; c++){ write_char_bytecode(text_buffer[c]); if(text_buffer[c] == 0) c = 64; } break; case 17: // "drawsprite" if(scope_object == 0){ printf("ERROR: cannot use '%s' outside an object.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(byte_value); // Layer if(!handle_number(1)){ free_current_script(); return 0; } // Drawing flags if(!handle_number(1)){ free_current_script(); return 0; } // Translucency if(!handle_number(1)){ free_current_script(); return 0; } // X position if(!handle_number(2)){ free_current_script(); return 0; } // Y position if(!handle_number(2)){ free_current_script(); return 0; } break; case 18: // "animate" if(scope_object == 0){ printf("ERROR: cannot use '%s' outside an object.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(byte_value); // Layer if(!handle_number(1)){ free_current_script(); return 0; } // Drawing flags if(!handle_number(1)){ free_current_script(); return 0; } // Translucency if(!handle_number(1)){ free_current_script(); return 0; } // X position if(!handle_number(2)){ free_current_script(); return 0; } // Y position if(!handle_number(2)){ free_current_script(); return 0; } break; case 19: // "destroy" if(scope_object == 0){ printf("ERROR: cannot use '%s' outside an object.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(byte_value); break; case 20: // "return" if(scope_object == 0 && scope_function == 0){ printf("ERROR: cannot use '%s' outside a function or object.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(byte_value); break; case 21: // "counterout" if(scope_object == 0 && scope_function == 0){ printf("ERROR: cannot use '%s' outside a function or object.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(byte_value); // Type if(!handle_number(1)){ free_current_script(); return 0; } // Fill if(!handle_number(1)){ free_current_script(); return 0; } // Number if(!handle_number(4)){ free_current_script(); return 0; } // X position if(!handle_number(2)){ free_current_script(); return 0; } // Y position if(!handle_number(2)){ free_current_script(); return 0; } break; case 22: // "fadeoutfm" if(scope_object == 0 && scope_function == 0){ printf("ERROR: cannot use '%s' outside a function or object.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(byte_value); // buffer if(!handle_number(1)){ free_current_script(); return 0; } break; case 23: // "move" if(scope_object == 0){ printf("ERROR: cannot use '%s' outside an object.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(byte_value); break; case 24: // "spawn" if(scope_object == 0 && scope_function == 0){ printf("ERROR: cannot use '%s' outside a function or object.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(byte_value); // type if(!handle_number(1)){ free_current_script(); return 0; } // subtype if(!handle_number(1)){ free_current_script(); return 0; } // high tag if(!handle_number(1)){ free_current_script(); return 0; } // low tag if(!handle_number(1)){ free_current_script(); return 0; } // x position if(!handle_number(2)){ free_current_script(); return 0; } // y position if(!handle_number(2)){ free_current_script(); return 0; } break; case 25: // "rest" if(scope_object == 0 && scope_function == 0){ printf("ERROR: cannot use '%s' outside a function or object.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(byte_value); // milliseconds if(!handle_number(2)){ free_current_script(); return 0; } break; case 26: // "setgfxmode" if(scope_object == 0 && scope_function == 0){ printf("ERROR: cannot use '%s' outside a function or object.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(byte_value); // res_x if(!handle_number(2)){ free_current_script(); return 0; } // res_y if(!handle_number(2)){ free_current_script(); return 0; } // pad_x if(!handle_number(2)){ free_current_script(); return 0; } // pad_y if(!handle_number(2)){ free_current_script(); return 0; } // dbl_x if(!handle_number(2)){ free_current_script(); return 0; } // dbl_y if(!handle_number(2)){ free_current_script(); return 0; } // full if(!handle_number(1)){ free_current_script(); return 0; } break; case 27: // "startzone" if(scope_object == 0 && scope_function == 0){ printf("ERROR: cannot use '%s' outside a function or object.\n", text_buffer); free_current_script(); return 0; } write_char_bytecode(byte_value); // zone if(!handle_number(1)){ free_current_script(); return 0; } // act if(!handle_number(1)){ free_current_script(); return 0; } // stage if(!handle_number(1)){ free_current_script(); return 0; } break; } return 1; // continue reading script } int main(){ printf("ProSonic Script Compiler\nCompile: %s\nCopyright(c) Damian Grove, 2009\n\n", __DATE__); scope_file = 0xFF; // 'scope_file' will get increased by 1, making it 0. load_script("game.txt"); printf("Script loaded.\n"); while(compile_script()); printf("Script compiled.\n"); save_script(); printf("Script saved.\n"); free_script(); printf("Script closed.\n"); system("PAUSE"); return 0; }
001tomclark-research-check
Source/Tools/scriptcompiler/main.c
C
gpl2
50,972
# ########## scriptcompiler executable ########## # Sources: SET(scriptcompiler_executable_SRCS main.c ) # Headers: SET(scriptcompiler_executable_HDRS ) # actual target: ADD_EXECUTABLE(scriptcompiler ${scriptcompiler_executable_SRCS}) # add install target: INSTALL(TARGETS scriptcompiler DESTINATION bin)
001tomclark-research-check
Source/Tools/scriptcompiler/CMakeLists.txt
CMake
gpl2
314
#include <stdio.h> #include <stdlib.h> #include "zone.h" ZONE zone; int main(int argc, char *argv[]) { printf("CompileZone(&zone, \"ZONE.TXT\")\n"); CompileZone(&zone, "ZONE.TXT"); //printf("LoadZone(&zone, \"cpz.pzf\")\n"); //LoadZone(&zone, "james.pzf"); printf("SaveZone(&zone, \"copy_cpz.pzf\")\n"); SaveZone(&zone, "output.pzf"); return 0; }
001tomclark-research-check
Source/Tools/pzfcompiler/main.c
C
gpl2
381
# ########## pzfcompiler executable ########## # Sources: SET(pzfcompiler_executable_SRCS main.c zone.c ) # Headers: SET(pzfcompiler_executable_HDRS zone.h ) # actual target: ADD_EXECUTABLE(pzfcompiler ${pzfcompiler_executable_SRCS}) # add install target: INSTALL(TARGETS pzfcompiler DESTINATION bin)
001tomclark-research-check
Source/Tools/pzfcompiler/CMakeLists.txt
CMake
gpl2
318
/***************************************************************************** * ______ * / _ \ _ __ ______ * / /_ / / / //__ / / _ \ * / ____ / / / / / / / * / / / / / /_ / / * /_ / /_ / \ _____ / * ______ * / ____ / ______ _ __ _ ______ * / /___ / _ \ / //_ \ /_ / / _ \ * _\___ \ / / / / / / / / / / / / /_ / * / /_ / / / /_ / / / / / / / / / /____ * \______ / \ _____ / /_ / /_ / /_ / \ ______/ * * * ProSonic Engine * Created by Damian Grove * * Compiled with DJGPP - GCC 2.952 (DOS) / Dev-C++ 4.9.9.2 (Windows) * Libraries used: * - Allegro - 3.9.34 http://www.talula.demon.co.uk/allegro/ * - DUMB - 0.9.3 http://dumb.sourceforge.net/ * - AllegroOgg - 1.0.3 http://nekros.freeshell.org/delirium/ * ****************************************************************************** * * NAME: ProSonic - Read/write zone data * * FILE: zone.c * * DESCRIPTION: * All PZF and zone related functions go here. * *****************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <errno.h> // Required for ENOMEM since "allegro.h" isn't included #include "zone.h" void ClearZone(ZONE *z) { int n; if((int)(size_t)z->Act != ENOMEM) free(z->Act); if((int)(size_t)z->OSC != ENOMEM) free(z->OSC); if((int)(size_t)z->BATT != ENOMEM) free(z->BATT); if((int)(size_t)z->BDAT != ENOMEM) free(z->BDAT); if((int)(size_t)z->BLOCK != ENOMEM) free(z->BLOCK); if((int)(size_t)z->BMAP != ENOMEM) free(z->BMAP); if((int)(size_t)z->BSOL != ENOMEM) free(z->BSOL); if((int)(size_t)z->OBJ != ENOMEM) free(z->OBJ); if((int)(size_t)z->TMAP != ENOMEM) free(z->TMAP); if((int)(size_t)z->WMAP != ENOMEM) free(z->WMAP); if((int)(size_t)z->CCYC != ENOMEM) free(z->CCYC); if((int)(size_t)z->FILTERDISTORTION != ENOMEM) free(z->FILTERDISTORTION); if((int)(size_t)z->FILTERCOMPOSITE != ENOMEM) free(z->FILTERCOMPOSITE); if((int)(size_t)z->OSC != ENOMEM) free(z->OSC); if((int)(size_t)z->BATT != ENOMEM) free(z->BATT); if((int)(size_t)z->BDAT != ENOMEM) free(z->BDAT); if((int)(size_t)z->BLOCK != ENOMEM) free(z->BLOCK); if((int)(size_t)z->BMAP != ENOMEM) free(z->BMAP); if((int)(size_t)z->BSOL != ENOMEM) free(z->BSOL); if((int)(size_t)z->OBJ != ENOMEM) free(z->OBJ); if((int)(size_t)z->TMAP != ENOMEM) free(z->TMAP); if((int)(size_t)z->WMAP != ENOMEM) free(z->WMAP); if((int)(size_t)z->CCYC != ENOMEM) free(z->CCYC); if((int)(size_t)z->FILTERDISTORTION != ENOMEM) free(z->FILTERDISTORTION); if((int)(size_t)z->FILTERCOMPOSITE != ENOMEM) free(z->FILTERCOMPOSITE); z->OSC_FileCount = 0; z->BATT_FileCount = 0; z->BDAT_FileCount = 0; z->BLOCK_FileCount = 0; z->BMAP_FileCount = 0; z->BSOL_FileCount = 0; z->OBJ_FileCount = 0; z->TMAP_FileCount = 0; z->WMAP_FileCount = 0; z->CCYC_FileCount = 0; z->FILTERDISTORTION_FileCount = 0; z->FILTERCOMPOSITE_FileCount = 0; } void DeleteZone(ZONE *z) { ClearZone(z); free(z); } // READ WORD // int ReadWord(ZONE *z, const char *string, ...) { for(a=0; a<24; a++) item[a] = 0; for(a=0; a<24; a++){ c = ftell(txt_file); if(c < filesize_zone){ fread(&item[a], 1, 1, txt_file); } else{ item[a] = '\0'; a = 32; printf("* EOF *\n"); return 255; } printf("%c", item[a]);//////////////////// if(item[a] == ' ' || item[a] == 0x9 || item[a] == 0xA || item[a] == 0xD) { if(a == 0) a--; if(a > 0){ printf("ERROR 1: Invalid item \"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\"\n", item[0], item[1], item[2], item[3], item[4], item[5], item[6], item[7], item[8], item[9], item[10], item[11], item[12], item[13], item[14], item[15], item[16], item[17], item[18], item[19], item[20], item[21], item[22], item[23]); fclose(txt_file); free(z); return 1; } } else { if(item[a] == ':'){ item[a] = '\0'; printf("----");//////////// a = 32; } else if(a == 23){ printf("ERROR 2: Invalid item \"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\"\n", item[0], item[1], item[2], item[3], item[4], item[5], item[6], item[7], item[8], item[9], item[10], item[11], item[12], item[13], item[14], item[15], item[16], item[17], item[18], item[19], item[20], item[21], item[22], item[23]); fclose(txt_file); free(z); return 2; } } } b = 0; if(strcmp(&string[0], "ZONE.TXT") == 0) { if(strcmp(&item[0], "ZONENAME1") == 0) b = 1; else if(strcmp(&item[0], "ZONENAME2") == 0) b = 2; else if(strcmp(&item[0], "ACTS") == 0) b = 3; else if(strcmp(&item[0], "STAGE1A") == 0) b = 0x10; else if(strcmp(&item[0], "STAGE1B") == 0) b = 0x11; else if(strcmp(&item[0], "STAGE1C") == 0) b = 0x12; else if(strcmp(&item[0], "STAGE1D") == 0) b = 0x13; else if(strcmp(&item[0], "STAGE2A") == 0) b = 0x20; else if(strcmp(&item[0], "STAGE2B") == 0) b = 0x21; else if(strcmp(&item[0], "STAGE2C") == 0) b = 0x22; else if(strcmp(&item[0], "STAGE2D") == 0) b = 0x23; else if(strcmp(&item[0], "STAGE3A") == 0) b = 0x30; else if(strcmp(&item[0], "STAGE3B") == 0) b = 0x31; else if(strcmp(&item[0], "STAGE3C") == 0) b = 0x32; else if(strcmp(&item[0], "STAGE3D") == 0) b = 0x33; else if(strcmp(&item[0], "STAGE4A") == 0) b = 0x40; else if(strcmp(&item[0], "STAGE4B") == 0) b = 0x41; else if(strcmp(&item[0], "STAGE4C") == 0) b = 0x42; else if(strcmp(&item[0], "STAGE4D") == 0) b = 0x43; else if(strcmp(&item[0], "STAGE5A") == 0) b = 0x50; else if(strcmp(&item[0], "STAGE5B") == 0) b = 0x51; else if(strcmp(&item[0], "STAGE5C") == 0) b = 0x52; else if(strcmp(&item[0], "STAGE5D") == 0) b = 0x53; else if(strcmp(&item[0], "STAGE6A") == 0) b = 0x60; else if(strcmp(&item[0], "STAGE6B") == 0) b = 0x61; else if(strcmp(&item[0], "STAGE6C") == 0) b = 0x62; else if(strcmp(&item[0], "STAGE6D") == 0) b = 0x63; else if(strcmp(&item[0], "STAGE7A") == 0) b = 0x70; else if(strcmp(&item[0], "STAGE7B") == 0) b = 0x71; else if(strcmp(&item[0], "STAGE7C") == 0) b = 0x72; else if(strcmp(&item[0], "STAGE7D") == 0) b = 0x73; else if(strcmp(&item[0], "STAGE8A") == 0) b = 0x80; else if(strcmp(&item[0], "STAGE8B") == 0) b = 0x81; else if(strcmp(&item[0], "STAGE8C") == 0) b = 0x82; else if(strcmp(&item[0], "STAGE8D") == 0) b = 0x83; } else if(strcmp(&string[0], "INDEX.TXT") == 0) { if(strcmp(&item[0], "FILES") == 0) b = 0x200; else if(item[0] == '0' && item[1] == '\0') b = 0x201; else if(strtol(&item[0], NULL, 10) < 256 && strtol(&item[0], NULL, 10) > 0) b = strtol(&item[0], NULL, 10) + 0x201; } else { if(strcmp(&item[0], "NAME") == 0) b = 0x100; else if(strcmp(&item[0], "ACTNUMBER") == 0) b = 0x101; else if(strcmp(&item[0], "MUSICREGULAR") == 0) b = 0x102; else if(strcmp(&item[0], "MUSICALTERNATIVE") == 0) b = 0x103; else if(strcmp(&item[0], "OPENINGSCRIPT") == 0) b = 0x104; else if(strcmp(&item[0], "CLOSINGSCRIPT") == 0) b = 0x105; else if(strcmp(&item[0], "ACTIVESCRIPT") == 0) b = 0x106; else if(strcmp(&item[0], "WATERENABLE") == 0) b = 0x107; else if(strcmp(&item[0], "WRAPPOINT") == 0) b = 0x108; else if(strcmp(&item[0], "ABOVEWATERFILTERL") == 0) b = 0x109; else if(strcmp(&item[0], "BELOWWATERFILTERL") == 0) b = 0x10A; else if(strcmp(&item[0], "ABOVEWATERFILTERSPEED") == 0) b = 0x10B; else if(strcmp(&item[0], "BELOWWATERFILTERSPEED") == 0) b = 0x10C; else if(strcmp(&item[0], "CLEARBACKGROUND") == 0) b = 0x10D; // PLACE HOLDER FOR 0x10E else if(strcmp(&item[0], "PALETTE") == 0) b = 0x10F; else if(strcmp(&item[0], "COLORCYCLER") == 0) b = 0x110; else if(strcmp(&item[0], "WATERMAP") == 0) b = 0x111; else if(strcmp(&item[0], "BLOCKMAP") == 0) b = 0x112; else if(strcmp(&item[0], "BLOCKART") == 0) b = 0x113; else if(strcmp(&item[0], "BLOCKDATA") == 0) b = 0x114; else if(strcmp(&item[0], "BLOCKATTRIBUTES") == 0) b = 0x115; else if(strcmp(&item[0], "BLOCKSOLIDITY") == 0) b = 0x116; else if(strcmp(&item[0], "TILEMAP") == 0) b = 0x117; else if(strcmp(&item[0], "OBJECTLAYOUT") == 0) b = 0x118; else if(strcmp(&item[0], "WATERHEIGHT") == 0) b = 0x119; else if(strcmp(&item[0], "LEVELXL") == 0) b = 0x11A; else if(strcmp(&item[0], "LEVELXR") == 0) b = 0x11B; else if(strcmp(&item[0], "LEVELYT") == 0) b = 0x11C; else if(strcmp(&item[0], "LEVELYB") == 0) b = 0x11D; else if(strcmp(&item[0], "START0X") == 0) b = 0x11E; else if(strcmp(&item[0], "START0Y") == 0) b = 0x11F; else if(strcmp(&item[0], "START1X") == 0) b = 0x120; else if(strcmp(&item[0], "START1Y") == 0) b = 0x121; else if(strcmp(&item[0], "START2X") == 0) b = 0x122; else if(strcmp(&item[0], "START2Y") == 0) b = 0x123; else if(strcmp(&item[0], "START3X") == 0) b = 0x124; else if(strcmp(&item[0], "START3Y") == 0) b = 0x125; else if(strcmp(&item[0], "START4X") == 0) b = 0x126; else if(strcmp(&item[0], "START4Y") == 0) b = 0x127; else if(strcmp(&item[0], "START5X") == 0) b = 0x128; else if(strcmp(&item[0], "START5Y") == 0) b = 0x129; else if(strcmp(&item[0], "START6X") == 0) b = 0x12A; else if(strcmp(&item[0], "START6Y") == 0) b = 0x12B; else if(strcmp(&item[0], "START7X") == 0) b = 0x12C; else if(strcmp(&item[0], "START7Y") == 0) b = 0x12D; else if(strcmp(&item[0], "START8X") == 0) b = 0x12E; else if(strcmp(&item[0], "START8Y") == 0) b = 0x12F; else if(strcmp(&item[0], "START9X") == 0) b = 0x130; else if(strcmp(&item[0], "START9Y") == 0) b = 0x131; else if(strcmp(&item[0], "STARTAX") == 0) b = 0x132; else if(strcmp(&item[0], "STARTAY") == 0) b = 0x133; else if(strcmp(&item[0], "STARTBX") == 0) b = 0x134; else if(strcmp(&item[0], "STARTBY") == 0) b = 0x135; else if(strcmp(&item[0], "STARTCX") == 0) b = 0x136; else if(strcmp(&item[0], "STARTCY") == 0) b = 0x137; else if(strcmp(&item[0], "STARTDX") == 0) b = 0x138; else if(strcmp(&item[0], "STARTDY") == 0) b = 0x139; else if(strcmp(&item[0], "STARTEX") == 0) b = 0x13A; else if(strcmp(&item[0], "STARTEY") == 0) b = 0x13B; else if(strcmp(&item[0], "STARTFX") == 0) b = 0x13C; else if(strcmp(&item[0], "STARTFY") == 0) b = 0x13D; } if(b == 0){ printf("ERROR 3: Invalid item \"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\"\n", item[0], item[1], item[2], item[3], item[4], item[5], item[6], item[7], item[8], item[9], item[10], item[11], item[12], item[13], item[14], item[15], item[16], item[17], item[18], item[19], item[20], item[21], item[22], item[23]); fclose(txt_file); free(z); return 3; } if(z->Act_FileCount == 0 && b >= 10){ printf("ERROR 4: \"%s\" defined before \"ACTS\"\n", &item[0]); fclose(txt_file); free(z); return 4; } printf("%i\n", b); return 0; } int ReadText(ZONE *z, const char *string, ...) { // READ TEXT // for(a=0; a<24; a++) item[a] = 0; for(a=0; a<24; a++){ c = ftell(txt_file); while(a == 0 && c < filesize_zone && item[0] != '"') fread(&item[0], 1, 1, txt_file); if(c < filesize_zone) fread(&item[a], 1, 1, txt_file); else{ item[a] = '\0'; a = 32; return 255; } printf("%c", item[a]);/////////////////// if(a > 0 && item[a] == '"'){ item[a] = '\0'; a = 32; printf("----\n");//////////// return 0; } } return 0; } int ReadVar(ZONE *z, const char *string, ...) { // READ VARIABLE // for(a=0; a<24; a++) item[a] = 0; for(a=0; a<11; a++){ c = ftell(txt_file); if(c < filesize_zone) fread(&item[a], 1, 1, txt_file); else{ item[a] = '\0'; a = 32; endoffile = 1; } if(item[a] == ' ' || item[a] == 0x9 || item[a] == 0xA || item[a] == 0xD) { if(a == 0) a--; else if(a == 2 && (item[1] == 'x' || item[1] == 'X')){ printf("ERROR 5: Invalid value\n"); fclose(txt_file); free(z); return 5; } else if(a > 0){ item[a] = '\0'; a = 32; } } else { if(item[a] < '0' || item[a] > '9'){ if(a == 1){ if(item[0] != '0' || (item[1] != 'x' && item[1] != 'X')){ printf("ERROR 6: Invalid value\n"); fclose(txt_file); free(z); return 6; } } else if(a == 0){ printf("ERROR 7: Invalid value\n"); fclose(txt_file); free(z); return 6; } else if(a > 1 && (item[a] < 'A' || (item[a] > 'F' && item[a] < 'a') || item[a] > 'f')){ //else if(item[a] != 'x' && item[a] != 'X'){ printf("ERROR 8: Invalid value\n"); fclose(txt_file); free(z); return 7; } } } } if(item[0] == '0' && (item[1] == 'x' || item[1] == 'X')) d = strtol(&item[2], NULL, 16); else d = strtol(&item[0], NULL, 10); if(endoffile == 1){ endoffile = 0; return 255; } printf("VALUE = %i\n", d); return 0; } int ReadFloatVar(ZONE *z, const char *string, ...) { // READ VARIABLE // for(a=0; a<24; a++) item[a] = 0; for(a=0; a<11; a++){ c = ftell(txt_file); if(c < filesize_zone) fread(&item[a], 1, 1, txt_file); else{ item[a] = '\0'; a = 32; endoffile = 1; } if(item[a] == ' ' || item[a] == 0x9 || item[a] == 0xA || item[a] == 0xD) { if(a == 0) a--; else if(a == 2 && (item[1] == 'x' || item[1] == 'X')){ printf("ERROR 5: Invalid value\n"); fclose(txt_file); free(z); return 5; } else if(a > 0){ item[a] = '\0'; a = 32; } } else { if(item[a] < '0' || item[a] > '9'){ if(a != 1){ printf("ERROR 6: Invalid value\n"); fclose(txt_file); free(z); return 6; } else if(item[a] != '.'){ printf("ERROR 7: Invalid value\n"); fclose(txt_file); free(z); return 7; } } } } f = strtof(&item[0], NULL); if(endoffile == 1){ endoffile = 0; return 255; } printf("VALUE = %f\n", f); return 0; } int CreateZone(ZONE *z) { //z = malloc(1); z->OSC = 0; z->BATT = 0; z->BDAT = 0; z->BLOCK = 0; z->BMAP = 0; z->BSOL = 0; z->OBJ = 0; z->PAL = 0; z->TMAP = 0; z->WMAP = 0; z->CCYC = 0; z->FILTERDISTORTION = 0; z->FILTERCOMPOSITE = 0; return 0; } int CompileZone(ZONE *z, const char *string, ...) { int e; //CreateZone(z); //z = malloc(1); z->Act = 0; z->OSC_SizeTable = 0; z->BATT_SizeTable = 0; z->BDAT_SizeTable = 0; z->BLOCK_SizeTable = 0; z->BMAP_SizeTable = 0; z->BSOL_SizeTable = 0; z->OBJ_SizeTable = 0; z->PAL_SizeTable = 0; z->TMAP_SizeTable = 0; z->WMAP_SizeTable = 0; z->CCYC_SizeTable = 0; z->FILTERDISTORTION_SizeTable = 0; z->FILTERCOMPOSITE_SizeTable = 0; z->OSC_AddressTable = 0; z->BATT_AddressTable = 0; z->BDAT_AddressTable = 0; z->BLOCK_AddressTable = 0; z->BMAP_AddressTable = 0; z->BSOL_AddressTable = 0; z->OBJ_AddressTable = 0; z->PAL_AddressTable = 0; z->TMAP_AddressTable = 0; z->WMAP_AddressTable = 0; z->CCYC_AddressTable = 0; z->FILTERDISTORTION_AddressTable = 0; z->FILTERCOMPOSITE_AddressTable = 0; z->OSC = 0; z->BATT = 0; z->BDAT = 0; z->BLOCK = 0; z->BMAP = 0; z->BSOL = 0; z->OBJ = 0; z->PAL = 0; z->TMAP = 0; z->WMAP = 0; z->CCYC = 0; z->FILTERDISTORTION = 0; z->FILTERCOMPOSITE = 0; txt_file = fopen("ZONE.TXT", "r+b"); fseek(txt_file, 0, SEEK_END); filesize_zone = ftell(txt_file); rewind(txt_file); ////////////// // ZONE.TXT // ////////////// a = 0; b = 0; c = 0; d = 0; while(ReadWord(z, "ZONE.TXT") != 255){ // b = d (b is the item, d is the value) if(b == 1 || b == 2){ // TEXT e = ReadText(z, "ZONE.TXT"); if(e == 255){ printf("DONE!\n"); //free(z); fclose(txt_file); return 0; } else if(b == 1){ for(a=0; a<20; a++) z->LevelName1[a] = item[a]; } else{ for(a=0; a<20; a++) z->LevelName2[a] = item[a]; } } else if(b > 2){ // VARIABLE if(ReadVar(z, "ZONE.TXT") == 255){ printf("DONE!\n"); //free(z); fclose(txt_file); return 0; } else{ if(b == 3){ z->Act_FileCount = d; z->Act = realloc(z->Act, sizeof(ACT) * z->Act_FileCount); } else{ if(b&3 == 0) a = 0xE; else if(b&3 == 1) a = 0xD; else if(b&3 == 2) a = 0xB; else a = 0x7; z->Act[(b>>4)-1].IncludedStages &= a; z->Act[(b>>4)-1].IncludedStages += (d << (b&3)); } } } else{ printf("1: Cannot compile because of an error in \"ZONE.TXT\"\n"); free(z); fclose(txt_file); return 1; } } fclose(txt_file); ///////////////// // STAGExx.TXT // ///////////////// strcpy(&filename[0], ".\\ACTa\\STAGEc.TXT"); for(a1=0; a1 < z->Act_FileCount; a1++){ filename[5] = '1' + a1; for(c1=0; c1<4; c1++){ filename[12] = 'A' + c1; if(fopen(&filename[0], "r+b") != 0 && (z->Act[a1].IncludedStages >> c1) & 1 == 1){ txt_file = fopen(&filename[0], "r+b"); printf("%s\n", &filename[0]); fseek(txt_file, 0, SEEK_END); filesize_zone = ftell(txt_file); rewind(txt_file); while(ReadWord(z, &filename[0]) != 255){ // b = d (b is the item, d is the value) switch(b){ case 0x100: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].Name = d; break; case 0x101: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].ActNumber = d; break; case 0x102: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].MusicRegular = d; break; case 0x103: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].MusicAlternate = d; break; case 0x104: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].OpeningScript = d; break; case 0x105: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].ClosingScript = d; break; case 0x106: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].ActiveScript = d; break; case 0x107: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].WaterEnable = d; break; case 0x108: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].WrapPoint = d; break; case 0x109: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].AboveWaterFilterL = d; break; case 0x10A: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].BelowWaterFilterL = d; break; case 0x10B: ReadFloatVar(z, &filename[0]); z->Act[a1].Stage[c1].AboveWaterFilterSpeed = f; break; case 0x10C: ReadFloatVar(z, &filename[0]); z->Act[a1].Stage[c1].BelowWaterFilterSpeed = f; break; case 0x10D: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].ClearBackground = d; break; // PLACE HOLDER FOR 0x10E case 0x10F: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].Palette = d; break; case 0x110: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].ColorCycle = d; break; case 0x111: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].WaterMap = d; break; case 0x112: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].BlockMap = d; break; case 0x113: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].BlockArt = d; break; case 0x114: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].BlockData = d; break; case 0x115: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].BlockAttributes = d; break; case 0x116: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].BlockSolidity = d; break; case 0x117: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].TileMap = d; break; case 0x118: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].ObjectLayout = d; break; case 0x119: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].WaterHeight = d; break; case 0x11A: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].LevelXL = d; break; case 0x11B: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].LevelXR = d; break; case 0x11C: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].LevelYT = d; break; case 0x11D: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].LevelYB = d; break; case 0x11E: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartX[0] = d; break; case 0x11F: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartY[0] = d; break; case 0x120: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartX[1] = d; break; case 0x121: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartY[1] = d; break; case 0x122: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartX[2] = d; break; case 0x123: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartY[2] = d; break; case 0x124: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartX[3] = d; break; case 0x125: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartY[3] = d; break; case 0x126: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartX[4] = d; break; case 0x127: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartY[4] = d; break; case 0x128: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartX[5] = d; break; case 0x129: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartY[5] = d; break; case 0x12A: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartX[6] = d; break; case 0x12B: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartY[6] = d; break; case 0x12C: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartX[7] = d; break; case 0x12D: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartY[7] = d; break; case 0x12E: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartX[8] = d; break; case 0x12F: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartY[8] = d; break; case 0x130: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartX[9] = d; break; case 0x131: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartY[9] = d; break; case 0x132: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartX[10] = d; break; case 0x133: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartY[10] = d; break; case 0x134: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartX[11] = d; break; case 0x135: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartY[11] = d; break; case 0x136: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartX[12] = d; break; case 0x137: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartY[12] = d; break; case 0x138: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartX[13] = d; break; case 0x139: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartY[13] = d; break; case 0x13A: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartX[14] = d; break; case 0x13B: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartY[14] = d; break; case 0x13C: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartX[15] = d; break; case 0x13D: ReadVar(z, &filename[0]); z->Act[a1].Stage[c1].StartY[15] = d; break; default: printf("1: Cannot compile because of an error in \"STAGExx.TXT\"\n"); free(z); fclose(txt_file); return 1; } } fclose(txt_file); } } } /////////////// // INDEX.TXT // /////////////// c1 = 0; for(a1=0; a1<13; a1++){ switch(a1){ case 0: strcpy(&filename[0], ".\\OSC\\INDEX.TXT"); strcpy(&path[0], ".\\OSC\\"); printf("case %i\n", a1); break; case 1: strcpy(&filename[0], ".\\BATT\\INDEX.TXT"); strcpy(&path[0], ".\\BATT\\"); printf("case %i\n", a1); break; case 2: strcpy(&filename[0], ".\\BDAT\\INDEX.TXT"); strcpy(&path[0], ".\\BDAT\\"); printf("case %i\n", a1); break; case 3: strcpy(&filename[0], ".\\BLOCK\\INDEX.TXT"); strcpy(&path[0], ".\\BLOCK\\"); printf("case %i\n", a1); break; case 4: strcpy(&filename[0], ".\\BMAP\\INDEX.TXT"); strcpy(&path[0], ".\\BMAP\\"); printf("case %i\n", a1); break; case 5: strcpy(&filename[0], ".\\BSOL\\INDEX.TXT"); strcpy(&path[0], ".\\BSOL\\"); printf("case %i\n", a1); break; case 6: strcpy(&filename[0], ".\\OBJ\\INDEX.TXT"); strcpy(&path[0], ".\\OBJ\\"); printf("case %i\n", a1); break; case 7: strcpy(&filename[0], ".\\PAL\\INDEX.TXT"); strcpy(&path[0], ".\\PAL\\"); printf("case %i\n", a1); break; case 8: strcpy(&filename[0], ".\\TMAP\\INDEX.TXT"); strcpy(&path[0], ".\\TMAP\\"); printf("case %i\n", a1); break; case 9: strcpy(&filename[0], ".\\WMAP\\INDEX.TXT"); strcpy(&path[0], ".\\WMAP\\"); printf("case %i\n", a1); break; case 10: strcpy(&filename[0], ".\\CCYC\\INDEX.TXT"); strcpy(&path[0], ".\\CCYC\\"); printf("case %i\n", a1); break; case 11: strcpy(&filename[0], ".\\FILTERDISTORTION\\INDEX.TXT"); strcpy(&path[0], ".\\FILTERDISTORTION\\"); printf("case %i\n", a1); break; default: strcpy(&filename[0], ".\\FILTERCOMPOSITE\\INDEX.TXT"); strcpy(&path[0], ".\\FILTERCOMPOSITE\\"); printf("case %i\n", a1); } txt_file = fopen(&filename[0], "r+b"); fseek(txt_file, 0, SEEK_END); filesize_zone = ftell(txt_file); rewind(txt_file); while(ReadWord(z, "INDEX.TXT") != 255){ // b = d (b is the item, d is the value) if(b > 0x200){ // FILE NAMES printf("text\n"); e = ReadText(z, "INDEX.TXT"); if(e == 255){ printf("DONE!\n"); //free(z); fclose(txt_file); return 0; } else{ for(c=0; c < 24; c++) filename[c] = 0; strcpy(&filename[0], &path[0]); strcat(&filename[0], &item[0]); txt_data = fopen(&filename[0], "r+b"); if(txt_data == NULL) printf("ERROR: CANNOT OPEN DATA FILE!\n"); fseek(txt_data, 0, SEEK_END); c = ftell(txt_data); //filesize_zone = ftell(txt_file); rewind(txt_data); switch(a1){ case 0: printf(" case %i\n", a1); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->OSC = realloc(z->OSC, c1 + c); for(a=0; a<c; a++) fread(&z->OSC[c1+a], 1, 1, txt_data); z->OSC_SizeTable[(b-1) & 0xFF] = c; z->OSC_AddressTable[(b-1) & 0xFF] = c1; c1 += c; break; case 1: printf(" case %i\n", a1); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->BATT = realloc(z->BATT, c1 + c); for(a=0; a<c; a++) fread(&z->BATT[c1+a], 1, 1, txt_data); z->BATT_SizeTable[(b-1) & 0xFF] = c; z->BATT_AddressTable[(b-1) & 0xFF] = c1; c1 += c; break; case 2: printf(" case %i\n", a1); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->BDAT = realloc(z->BDAT, c1 + c); for(a=0; a<c; a++) fread(&z->BDAT[c1+a], 1, 1, txt_data); z->BDAT_SizeTable[(b-1) & 0xFF] = c; z->BDAT_AddressTable[(b-1) & 0xFF] = c1; c1 += c; break; case 3: printf(" case %i\n", a1); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->BLOCK = realloc(z->BLOCK, c1 + c); for(a=0; a<c; a++) fread(&z->BLOCK[c1+a], 1, 1, txt_data); z->BLOCK_SizeTable[(b-1) & 0xFF] = c; z->BLOCK_AddressTable[(b-1) & 0xFF] = c1; c1 += c; break; case 4: printf(" case %i\n", a1); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->BMAP = realloc(z->BMAP, c1 + c); for(a=0; a<c; a++) fread(&z->BMAP[c1+a], 1, 1, txt_data); z->BMAP_SizeTable[(b-1) & 0xFF] = c; z->BMAP_AddressTable[(b-1) & 0xFF] = c1; c1 += c; break; case 5: printf(" case %i\n", a1); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->BSOL = realloc(z->BSOL, c1 + c); for(a=0; a<c; a++) fread(&z->BSOL[c1+a], 1, 1, txt_data); z->BSOL_SizeTable[(b-1) & 0xFF] = c; z->BSOL_AddressTable[(b-1) & 0xFF] = c1; c1 += c; break; case 6: printf(" case %i\n", a1); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->OBJ = realloc(z->OBJ, c1 + c); for(a=0; a<c; a++) fread(&z->OBJ[c1+a], 1, 1, txt_data); z->OBJ_SizeTable[(b-1) & 0xFF] = c; z->OBJ_AddressTable[(b-1) & 0xFF] = c1; c1 += c; break; case 7: printf(" case %i\n", a1); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->PAL = realloc(z->PAL, c1 + c); for(a=0; a<c; a++) fread(&z->PAL[c1+a], 1, 1, txt_data); z->PAL_SizeTable[(b-1) & 0xFF] = c; z->PAL_AddressTable[(b-1) & 0xFF] = c1; c1 += c; break; case 8: printf(" case %i\n", a1); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->TMAP = realloc(z->TMAP, c1 + c); for(a=0; a<c; a++) fread(&z->TMAP[c1+a], 1, 1, txt_data); z->TMAP_SizeTable[(b-1) & 0xFF] = c; z->TMAP_AddressTable[(b-1) & 0xFF] = c1; c1 += c; break; case 9: printf(" case %i\n", a1); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->WMAP = realloc(z->WMAP, c1 + c); for(a=0; a<c; a++) fread(&z->WMAP[c1+a], 1, 1, txt_data); z->WMAP_SizeTable[(b-1) & 0xFF] = c; z->WMAP_AddressTable[(b-1) & 0xFF] = c1; c1 += c; break; case 10: printf(" case %i\n", a1); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->CCYC = realloc(z->CCYC, c1 + c); for(a=0; a<c; a++) fread(&z->CCYC[c1+a], 1, 1, txt_data); z->CCYC_SizeTable[(b-1) & 0xFF] = c; z->CCYC_AddressTable[(b-1) & 0xFF] = c1; c1 += c; break; case 11: printf(" case %i\n", a1); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->FILTERDISTORTION = realloc(z->FILTERDISTORTION, c1 + c); for(a=0; a<c; a++) fread(&z->FILTERDISTORTION[c1+a], 1, 1, txt_data); z->FILTERDISTORTION_SizeTable[(b-1) & 0xFF] = c; z->FILTERDISTORTION_AddressTable[(b-1) & 0xFF] = c1; c1 += c; break; default: printf(" case %i\n", a1); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->FILTERCOMPOSITE = realloc(z->FILTERCOMPOSITE, c1 + c); for(a=0; a<c; a++) fread(&z->FILTERCOMPOSITE[c1+a], 1, 1, txt_data); z->FILTERCOMPOSITE_SizeTable[(b-1) & 0xFF] = c; z->FILTERCOMPOSITE_AddressTable[(b-1) & 0xFF] = c1; c1 += c; break; } printf("\n\n========================================\n\n"); close(txt_data); } } else if(b == 0x200){ // NUMBER OF FILES printf("var\n"); if(ReadVar(z, "INDEX.TXT") == 255){ printf("DONE!\n"); //free(z); fclose(txt_file); return 0; } else{ switch(a1){ case 0: z->OSC_FileCount = d; z->OSC_SizeTable = realloc(z->OSC_SizeTable, d << 2); z->OSC_AddressTable = realloc(z->OSC_AddressTable, d << 2); c1 = 0; break; case 1: z->BATT_FileCount = d; z->BATT_SizeTable = realloc(z->BATT_SizeTable, d << 2); z->BATT_AddressTable = realloc(z->BATT_AddressTable, d << 2); c1 = 0; break; case 2: z->BDAT_FileCount = d; z->BDAT_SizeTable = realloc(z->BDAT_SizeTable, d << 2); z->BDAT_AddressTable = realloc(z->BDAT_AddressTable, d << 2); c1 = 0; break; case 3: z->BLOCK_FileCount = d; z->BLOCK_SizeTable = realloc(z->BLOCK_SizeTable, d << 2); z->BLOCK_AddressTable = realloc(z->BLOCK_AddressTable, d << 2); c1 = 0; break; case 4: z->BMAP_FileCount = d; z->BMAP_SizeTable = realloc(z->BMAP_SizeTable, d << 2); z->BMAP_AddressTable = realloc(z->BMAP_AddressTable, d << 2); c1 = 0; break; case 5: z->BSOL_FileCount = d; z->BSOL_SizeTable = realloc(z->BSOL_SizeTable, d << 2); z->BSOL_AddressTable = realloc(z->BSOL_AddressTable, d << 2); c1 = 0; break; case 6: z->OBJ_FileCount = d; z->OBJ_SizeTable = realloc(z->OBJ_SizeTable, d << 2); z->OBJ_AddressTable = realloc(z->OBJ_AddressTable, d << 2); c1 = 0; break; case 7: z->PAL_FileCount = d; z->PAL_SizeTable = realloc(z->PAL_SizeTable, d << 2); z->PAL_AddressTable = realloc(z->PAL_AddressTable, d << 2); c1 = 0; break; case 8: z->TMAP_FileCount = d; z->TMAP_SizeTable = realloc(z->TMAP_SizeTable, d << 2); z->TMAP_AddressTable = realloc(z->TMAP_AddressTable, d << 2); c1 = 0; break; case 9: z->WMAP_FileCount = d; z->WMAP_SizeTable = realloc(z->WMAP_SizeTable, d << 2); z->WMAP_AddressTable = realloc(z->WMAP_AddressTable, d << 2); c1 = 0; break; case 10: z->CCYC_FileCount = d; z->CCYC_SizeTable = realloc(z->CCYC_SizeTable, d << 2); z->CCYC_AddressTable = realloc(z->CCYC_AddressTable, d << 2); c1 = 0; break; case 11: z->FILTERDISTORTION_FileCount = d; z->FILTERDISTORTION_SizeTable = realloc(z->FILTERDISTORTION_SizeTable, d << 2); z->FILTERDISTORTION_AddressTable = realloc(z->FILTERDISTORTION_AddressTable, d << 2); c1 = 0; break; default: z->FILTERCOMPOSITE_FileCount = d; z->FILTERCOMPOSITE_SizeTable = realloc(z->FILTERCOMPOSITE_SizeTable, d << 2); z->FILTERCOMPOSITE_AddressTable = realloc(z->FILTERCOMPOSITE_AddressTable, d << 2); c1 = 0; } } } else{ printf("1: Cannot compile because of an error in \"INDEX.TXT\"\n"); free(z); fclose(txt_file); return 1; } } fclose(txt_file); } return 0; } int LoadZone(ZONE *z, const char *string, ...) { int a = 0; int b = 0; int c = 0; int d = 0; int x[2]; long filesize; FILE *pzf; pzf = fopen(string, "r+b"); fseek(pzf, 0, SEEK_END); filesize = ftell(pzf); fseek(pzf, 0, SEEK_SET); if(filesize >= 109){ fread(&a, 1, 1, pzf); // P fread(&b, 1, 1, pzf); // Z fread(&c, 1, 1, pzf); // F fread(&d, 1, 1, pzf); // version } else return 1; if(a!='P' || b!='Z' || c!='F' || d>0) return 2; // Create an instance of a ZONE //z = malloc(1); ClearZone(z); z->Act = 0; z->OSC_SizeTable = 0; z->BATT_SizeTable = 0; z->BDAT_SizeTable = 0; z->BLOCK_SizeTable = 0; z->BMAP_SizeTable = 0; z->BSOL_SizeTable = 0; z->OBJ_SizeTable = 0; z->PAL_SizeTable = 0; z->TMAP_SizeTable = 0; z->WMAP_SizeTable = 0; z->CCYC_SizeTable = 0; z->FILTERDISTORTION_SizeTable = 0; z->FILTERCOMPOSITE_SizeTable = 0; z->OSC_AddressTable = 0; z->BATT_AddressTable = 0; z->BDAT_AddressTable = 0; z->BLOCK_AddressTable = 0; z->BMAP_AddressTable = 0; z->BSOL_AddressTable = 0; z->OBJ_AddressTable = 0; z->PAL_AddressTable = 0; z->TMAP_AddressTable = 0; z->WMAP_AddressTable = 0; z->CCYC_AddressTable = 0; z->FILTERDISTORTION_AddressTable = 0; z->FILTERCOMPOSITE_AddressTable = 0; z->OSC = 0; z->BATT = 0; z->BDAT = 0; z->BLOCK = 0; z->BMAP = 0; z->BSOL = 0; z->OBJ = 0; z->PAL = 0; z->TMAP = 0; z->WMAP = 0; z->CCYC = 0; z->FILTERDISTORTION = 0; z->FILTERCOMPOSITE = 0; fread(&z->LevelName1, 1, 20, pzf); fread(&z->LevelName2, 1, 20, pzf); fread(&(z->Act_FileCount), 1, 1, pzf); fread(&(z->OSC_FileCount), 1, 1, pzf); fread(&(z->BATT_FileCount), 1, 1, pzf); fread(&(z->BDAT_FileCount), 1, 1, pzf); fread(&(z->BLOCK_FileCount), 1, 1, pzf); fread(&(z->BMAP_FileCount), 1, 1, pzf); fread(&(z->BSOL_FileCount), 1, 1, pzf); fread(&(z->OBJ_FileCount), 1, 1, pzf); fread(&(z->PAL_FileCount), 1, 1, pzf); fread(&(z->TMAP_FileCount), 1, 1, pzf); fread(&(z->WMAP_FileCount), 1, 1, pzf); fread(&(z->CCYC_FileCount), 1, 1, pzf); fread(&(z->FILTERDISTORTION_FileCount), 1, 1, pzf); fread(&(z->FILTERCOMPOSITE_FileCount), 1, 1, pzf); //////////////////// // READ ACT FILES // //////////////////// z->Act = malloc(sizeof(ACT) * z->Act_FileCount); fread(&a, 4, 1, pzf); // Read "Act" table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->Act_FileCount; b++){ x[1] = ftell(pzf); fread(&c, 1, 1, pzf); // Read IncludedStages z->Act[b].IncludedStages = c; // Write IncludedStages fread(&a, 4, 1, pzf); // Read stage address fseek(pzf, a, SEEK_SET); // Jump to address for(c=0; c<4; c++){ switch(c){ case 0: a = (z->Act[b].IncludedStages & 1); break; case 1: a = ((z->Act[b].IncludedStages >> 1) & 1); break; case 2: a = ((z->Act[b].IncludedStages >> 2) & 1); break; default: a = ((z->Act[b].IncludedStages >> 3) & 1); } if(a == 1){ fread(&(z->Act[b].Stage[c].Name), 1, 1, pzf); fread(&(z->Act[b].Stage[c].ActNumber), 1, 1, pzf); fread(&(z->Act[b].Stage[c].MusicRegular), 1, 1, pzf); fread(&(z->Act[b].Stage[c].MusicAlternate), 1, 1, pzf); fread(&(z->Act[b].Stage[c].OpeningScript), 1, 1, pzf); fread(&(z->Act[b].Stage[c].ClosingScript), 1, 1, pzf); fread(&(z->Act[b].Stage[c].ActiveScript), 1, 1, pzf); fread(&(z->Act[b].Stage[c].WaterEnable), 1, 1, pzf); fread(&(z->Act[b].Stage[c].WrapPoint), 2, 1, pzf); fread(&(z->Act[b].Stage[c].AboveWaterFilterL), 1, 1, pzf); fread(&(z->Act[b].Stage[c].BelowWaterFilterL), 1, 1, pzf); fread(&(z->Act[b].Stage[c].AboveWaterFilterSpeed), 4, 1, pzf); fread(&(z->Act[b].Stage[c].BelowWaterFilterSpeed), 4, 1, pzf); fread(&(z->Act[b].Stage[c].ClearBackground), 1, 1, pzf); // PLACE HOLDER FOR 0x10E fread(&(z->Act[b].Stage[c].Palette), 1, 1, pzf); fread(&(z->Act[b].Stage[c].ColorCycle), 1, 1, pzf); fread(&(z->Act[b].Stage[c].WaterMap), 1, 1, pzf); fread(&(z->Act[b].Stage[c].BlockMap), 1, 1, pzf); fread(&(z->Act[b].Stage[c].BlockArt), 1, 1, pzf); fread(&(z->Act[b].Stage[c].BlockData), 1, 1, pzf); fread(&(z->Act[b].Stage[c].BlockAttributes), 1, 1, pzf); fread(&(z->Act[b].Stage[c].BlockSolidity), 1, 1, pzf); fread(&(z->Act[b].Stage[c].TileMap), 1, 1, pzf); fread(&(z->Act[b].Stage[c].ObjectLayout), 1, 1, pzf); fread(&(z->Act[b].Stage[c].WaterHeight), 2, 1, pzf); fread(&(z->Act[b].Stage[c].LevelXL), 2, 1, pzf); fread(&(z->Act[b].Stage[c].LevelXR), 2, 1, pzf); fread(&(z->Act[b].Stage[c].LevelYT), 2, 1, pzf); fread(&(z->Act[b].Stage[c].LevelYB), 2, 1, pzf); fread(&(z->Act[b].Stage[c].StartX[0]), 2, 16, pzf); fread(&(z->Act[b].Stage[c].StartY[0]), 2, 16, pzf); } } fseek(pzf, x[1] + 4, SEEK_SET); // Set it up to read the next act } //////////////////// // READ OSC FILES // //////////////////// fseek(pzf, x[0], SEEK_SET); z->OSC_SizeTable = malloc(z->OSC_FileCount << 2); z->OSC_AddressTable = malloc(z->OSC_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->OSC_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->OSC_AddressTable[b] = filesize_data; z->OSC_SizeTable[b] = d; filesize_data += d; z->OSC = realloc(z->OSC, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address for(c=0; c < d; c++){ fread(&a, 1, 1, pzf); z->OSC[z->OSC_AddressTable[b] + c] = a; } fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////// // READ BATT FILES // ///////////////////// fseek(pzf, x[0], SEEK_SET); z->BATT_SizeTable = malloc(z->BATT_FileCount << 2); z->BATT_AddressTable = malloc(z->BATT_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->BATT_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->BATT_AddressTable[b] = filesize_data; z->BATT_SizeTable[b] = d; filesize_data += d; z->BATT = realloc(z->BATT, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address for(c=0; c < d; c++){ fread(&a, 1, 1, pzf); z->BATT[z->BATT_AddressTable[b] + c] = a; } fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////// // READ BDAT FILES // ///////////////////// fseek(pzf, x[0], SEEK_SET); z->BDAT_SizeTable = malloc(z->BDAT_FileCount << 2); z->BDAT_AddressTable = malloc(z->BDAT_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->BDAT_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->BDAT_AddressTable[b] = filesize_data; z->BDAT_SizeTable[b] = d; filesize_data += d; z->BDAT = realloc(z->BDAT, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address for(c=0; c < d; c++){ fread(&a, 1, 1, pzf); z->BDAT[z->BDAT_AddressTable[b] + c] = a; } fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ////////////////////// // READ BLOCK FILES // ////////////////////// fseek(pzf, x[0], SEEK_SET); z->BLOCK_SizeTable = malloc(z->BLOCK_FileCount << 2); z->BLOCK_AddressTable = malloc(z->BLOCK_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->BLOCK_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->BLOCK_AddressTable[b] = filesize_data; z->BLOCK_SizeTable[b] = d; filesize_data += d; z->BLOCK = realloc(z->BLOCK, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address for(c=0; c < d; c++){ fread(&a, 1, 1, pzf); z->BLOCK[z->BLOCK_AddressTable[b] + c] = a; } fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////// // READ BMAP FILES // ///////////////////// fseek(pzf, x[0], SEEK_SET); z->BMAP_SizeTable = malloc(z->BMAP_FileCount << 2); z->BMAP_AddressTable = malloc(z->BMAP_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->BMAP_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->BMAP_AddressTable[b] = filesize_data; z->BMAP_SizeTable[b] = d; filesize_data += d; z->BMAP = realloc(z->BMAP, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address for(c=0; c < d; c++){ fread(&a, 1, 1, pzf); z->BMAP[z->BMAP_AddressTable[b] + c] = a; } fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////// // READ BSOL FILES // ///////////////////// fseek(pzf, x[0], SEEK_SET); z->BSOL_SizeTable = malloc(z->BSOL_FileCount << 2); z->BSOL_AddressTable = malloc(z->BSOL_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->BSOL_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->BSOL_AddressTable[b] = filesize_data; z->BSOL_SizeTable[b] = d; filesize_data += d; z->BSOL = realloc(z->BSOL, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address for(c=0; c < d; c++){ fread(&a, 1, 1, pzf); z->BSOL[z->BSOL_AddressTable[b] + c] = a; } fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } //////////////////// // READ OBJ FILES // //////////////////// fseek(pzf, x[0], SEEK_SET); z->OBJ_SizeTable = malloc(z->OBJ_FileCount << 2); z->OBJ_AddressTable = malloc(z->OBJ_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->OBJ_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->OBJ_AddressTable[b] = filesize_data; z->OBJ_SizeTable[b] = d; filesize_data += d; z->OBJ = realloc(z->OBJ, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address for(c=0; c < d; c++){ fread(&a, 1, 1, pzf); z->OBJ[z->OBJ_AddressTable[b] + c] = a; } fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } //////////////////// // READ PAL FILES // //////////////////// fseek(pzf, x[0], SEEK_SET); z->PAL_SizeTable = malloc(z->PAL_FileCount << 2); z->PAL_AddressTable = malloc(z->PAL_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->PAL_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->PAL_AddressTable[b] = filesize_data; z->PAL_SizeTable[b] = d; filesize_data += d; z->PAL = realloc(z->PAL, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address for(c=0; c < d; c++){ fread(&a, 1, 1, pzf); z->PAL[z->PAL_AddressTable[b] + c] = a; } fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////// // READ TMAP FILES // ///////////////////// fseek(pzf, x[0], SEEK_SET); z->TMAP_SizeTable = malloc(z->TMAP_FileCount << 2); z->TMAP_AddressTable = malloc(z->TMAP_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->TMAP_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->TMAP_AddressTable[b] = filesize_data; z->TMAP_SizeTable[b] = d; filesize_data += d; z->TMAP = realloc(z->TMAP, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address for(c=0; c < d; c++){ fread(&a, 1, 1, pzf); z->TMAP[z->TMAP_AddressTable[b] + c] = a; } fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////// // READ WMAP FILES // ///////////////////// fseek(pzf, x[0], SEEK_SET); z->WMAP_SizeTable = malloc(z->WMAP_FileCount << 2); z->WMAP_AddressTable = malloc(z->WMAP_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->WMAP_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->WMAP_AddressTable[b] = filesize_data; z->WMAP_SizeTable[b] = d; filesize_data += d; z->WMAP = realloc(z->WMAP, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address for(c=0; c < d; c++){ fread(&a, 1, 1, pzf); z->WMAP[z->WMAP_AddressTable[b] + c] = a; } fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////// // READ CCYC FILES // ///////////////////// fseek(pzf, x[0], SEEK_SET); z->CCYC_SizeTable = malloc(z->CCYC_FileCount << 2); z->CCYC_AddressTable = malloc(z->CCYC_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->CCYC_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->CCYC_AddressTable[b] = filesize_data; z->CCYC_SizeTable[b] = d; filesize_data += d; z->CCYC = realloc(z->CCYC, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address for(c=0; c < d; c++){ fread(&a, 1, 1, pzf); z->CCYC[z->CCYC_AddressTable[b] + c] = a; } fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////////////////// // READ FILTERDISTORTION FILES // ///////////////////////////////// fseek(pzf, x[0], SEEK_SET); z->FILTERDISTORTION_SizeTable = malloc(z->FILTERDISTORTION_FileCount << 2); z->FILTERDISTORTION_AddressTable = malloc(z->FILTERDISTORTION_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->FILTERDISTORTION_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->FILTERDISTORTION_AddressTable[b] = filesize_data; z->FILTERDISTORTION_SizeTable[b] = d; filesize_data += d; z->FILTERDISTORTION = realloc(z->FILTERDISTORTION, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address for(c=0; c < d; c++){ fread(&a, 1, 1, pzf); z->FILTERDISTORTION[z->FILTERDISTORTION_AddressTable[b] + c] = a; } fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////////////////// // READ FILTERCOMPOSITE FILES // ///////////////////////////////// fseek(pzf, x[0], SEEK_SET); z->FILTERCOMPOSITE_SizeTable = malloc(z->FILTERCOMPOSITE_FileCount << 2); z->FILTERCOMPOSITE_AddressTable = malloc(z->FILTERCOMPOSITE_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->FILTERCOMPOSITE_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->FILTERCOMPOSITE_AddressTable[b] = filesize_data; z->FILTERCOMPOSITE_SizeTable[b] = d; filesize_data += d; z->FILTERCOMPOSITE = realloc(z->FILTERCOMPOSITE, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address for(c=0; c < d; c++){ fread(&a, 1, 1, pzf); z->FILTERCOMPOSITE[z->FILTERCOMPOSITE_AddressTable[b] + c] = a; } fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } fclose(pzf); return 0; } int SaveZone(ZONE *z, const char *string, ...) { int x[13]; int y[256]; long filesize; FILE *pzf; a = 0; b = 0; c = 0; d = 0; //if(pzf == ENOMEM) pzf = fopen(string, "wb"); a = 'P'; b = 'Z'; c = 'F'; d = 0; // version fwrite(&a, 1, 1, pzf); fwrite(&b, 1, 1, pzf); fwrite(&c, 1, 1, pzf); fwrite(&d, 1, 1, pzf); fwrite(&z->LevelName1, 1, 20, pzf); fwrite(&z->LevelName2, 1, 20, pzf); a = 0; fwrite(&z->Act_FileCount, 1, 1, pzf); fwrite(&z->OSC_FileCount, 1, 1, pzf); fwrite(&z->BATT_FileCount, 1, 1, pzf); fwrite(&z->BDAT_FileCount, 1, 1, pzf); fwrite(&z->BLOCK_FileCount, 1, 1, pzf); fwrite(&z->BMAP_FileCount, 1, 1, pzf); fwrite(&z->BSOL_FileCount, 1, 1, pzf); fwrite(&z->OBJ_FileCount, 1, 1, pzf); fwrite(&z->PAL_FileCount, 1, 1, pzf); fwrite(&z->TMAP_FileCount, 1, 1, pzf); fwrite(&z->WMAP_FileCount, 1, 1, pzf); fwrite(&z->CCYC_FileCount, 1, 1, pzf); fwrite(&z->FILTERDISTORTION_FileCount, 1, 1, pzf); fwrite(&z->FILTERCOMPOSITE_FileCount, 1, 1, pzf); x[0] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[1] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[2] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[3] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[4] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[5] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[6] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[7] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[8] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[9] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[10] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[11] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[12] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[13] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); ///////////////////// // WRITE ACT FILES // ///////////////////// a = ftell(pzf); // save the table address fseek(pzf, x[0], SEEK_SET); // go back to table pointer fwrite(&a, 4, 1, pzf); // write address value to pointer fseek(pzf, a, SEEK_SET); // go back to the table a = 0; // Setup the act file table for(b=0; b < z->Act_FileCount; b++){ fwrite(&z->Act[b].IncludedStages, 1, 1, pzf); y[b] = ftell(pzf); fwrite(&a, 4, 1, pzf); } // Write the act files for(b=0; b < z->Act_FileCount; b++){ a = ftell(pzf); // save the act file address fseek(pzf, y[b], SEEK_SET); // go back to the act table fwrite(&a, 4, 1, pzf); // write address value to act file fseek(pzf, a, SEEK_SET); // go back to the act file for(c=0; c<4; c++){ switch(c){ case 0: a = (z->Act[b].IncludedStages & 1); break; case 1: a = ((z->Act[b].IncludedStages >> 1) & 1); break; case 2: a = ((z->Act[b].IncludedStages >> 2) & 1); break; default: a = ((z->Act[b].IncludedStages >> 3) & 1); } if(a == 1){ fwrite(&(z->Act[b].Stage[c].Name), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].ActNumber), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].MusicRegular), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].MusicAlternate), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].OpeningScript), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].ClosingScript), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].ActiveScript), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].WaterEnable), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].WrapPoint), 2, 1, pzf); fwrite(&(z->Act[b].Stage[c].AboveWaterFilterL), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].BelowWaterFilterL), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].AboveWaterFilterSpeed), 4, 1, pzf); fwrite(&(z->Act[b].Stage[c].BelowWaterFilterSpeed), 4, 1, pzf); fwrite(&(z->Act[b].Stage[c].ClearBackground), 1, 1, pzf); // PLACE HOLDER FOR 0x10E fwrite(&(z->Act[b].Stage[c].Palette), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].ColorCycle), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].WaterMap), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].BlockMap), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].BlockArt), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].BlockData), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].BlockAttributes), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].BlockSolidity), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].TileMap), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].ObjectLayout), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].WaterHeight), 2, 1, pzf); fwrite(&(z->Act[b].Stage[c].LevelXL), 2, 1, pzf); fwrite(&(z->Act[b].Stage[c].LevelXR), 2, 1, pzf); fwrite(&(z->Act[b].Stage[c].LevelYT), 2, 1, pzf); fwrite(&(z->Act[b].Stage[c].LevelYB), 2, 1, pzf); fwrite(&(z->Act[b].Stage[c].StartX[0]), 2, 16, pzf); fwrite(&(z->Act[b].Stage[c].StartY[0]), 2, 16, pzf); } } } ///////////////////// // WRITE OSC FILES // ///////////////////// a = ftell(pzf); fseek(pzf, x[1], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->OSC_FileCount; b++){ fwrite(&z->OSC_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->OSC_FileCount; b++){ a = ftell(pzf); // save the OSC file address fseek(pzf, y[b], SEEK_SET); // go back to the OSC table fwrite(&a, 4, 1, pzf); // write address to OSC file fseek(pzf, a, SEEK_SET); // go back to the OSC file a = z->OSC_AddressTable[b]; // Write file for(c=0; c < z->OSC_SizeTable[b]; c++) fwrite(&z->OSC[a+c], 1, 1, pzf); } ////////////////////// // WRITE BATT FILES // ////////////////////// a = ftell(pzf); fseek(pzf, x[2], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->BATT_FileCount; b++){ fwrite(&z->BATT_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->BATT_FileCount; b++){ a = ftell(pzf); // save the BATT file address fseek(pzf, y[b], SEEK_SET); // go back to the BATT table fwrite(&a, 4, 1, pzf); // write address to BATT file fseek(pzf, a, SEEK_SET); // go back to the BATT file a = z->BATT_AddressTable[b]; // Write file for(c=0; c < z->BATT_SizeTable[b]; c++) fwrite(&z->BATT[a+c], 1, 1, pzf); } ////////////////////// // WRITE BDAT FILES // ////////////////////// a = ftell(pzf); fseek(pzf, x[3], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->BDAT_FileCount; b++){ fwrite(&z->BDAT_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->BDAT_FileCount; b++){ a = ftell(pzf); // save the BDAT file address fseek(pzf, y[b], SEEK_SET); // go back to the BDAT table fwrite(&a, 4, 1, pzf); // write address to BDAT file fseek(pzf, a, SEEK_SET); // go back to the BDAT file a = z->BDAT_AddressTable[b]; // Write file for(c=0; c < z->BDAT_SizeTable[b]; c++) fwrite(&z->BDAT[a+c], 1, 1, pzf); } /////////////////////// // WRITE BLOCK FILES // /////////////////////// a = ftell(pzf); fseek(pzf, x[4], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->BLOCK_FileCount; b++){ fwrite(&z->BLOCK_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->BLOCK_FileCount; b++){ a = ftell(pzf); // save the BLOCK file address fseek(pzf, y[b], SEEK_SET); // go back to the BLOCK table fwrite(&a, 4, 1, pzf); // write address to BLOCK file fseek(pzf, a, SEEK_SET); // go back to the BLOCK file a = z->BLOCK_AddressTable[b]; // Write file for(c=0; c < z->BLOCK_SizeTable[b]; c++) fwrite(&z->BLOCK[a+c], 1, 1, pzf); } ////////////////////// // WRITE BMAP FILES // ////////////////////// a = ftell(pzf); fseek(pzf, x[5], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->BMAP_FileCount; b++){ fwrite(&z->BMAP_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->BMAP_FileCount; b++){ a = ftell(pzf); // save the BMAP file address fseek(pzf, y[b], SEEK_SET); // go back to the BMAP table fwrite(&a, 4, 1, pzf); // write address to BMAP file fseek(pzf, a, SEEK_SET); // go back to the BMAP file a = z->BMAP_AddressTable[b]; // Write file for(c=0; c < z->BMAP_SizeTable[b]; c++) fwrite(&z->BMAP[a+c], 1, 1, pzf); } ////////////////////// // WRITE BSOL FILES // ////////////////////// a = ftell(pzf); fseek(pzf, x[6], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->BSOL_FileCount; b++){ fwrite(&z->BSOL_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->BSOL_FileCount; b++){ a = ftell(pzf); // save the BSOL file address fseek(pzf, y[b], SEEK_SET); // go back to the BSOL table fwrite(&a, 4, 1, pzf); // write address to BSOL file fseek(pzf, a, SEEK_SET); // go back to the BSOL file a = z->BSOL_AddressTable[b]; // Write file for(c=0; c < z->BSOL_SizeTable[b]; c++) fwrite(&z->BSOL[a+c], 1, 1, pzf); } ///////////////////// // WRITE OBJ FILES // ///////////////////// a = ftell(pzf); fseek(pzf, x[7], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->OBJ_FileCount; b++){ fwrite(&z->OBJ_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->OBJ_FileCount; b++){ a = ftell(pzf); // save the OBJ file address fseek(pzf, y[b], SEEK_SET); // go back to the OBJ table fwrite(&a, 4, 1, pzf); // write address to OBJ file fseek(pzf, a, SEEK_SET); // go back to the OBJ file a = z->OBJ_AddressTable[b]; // Write file for(c=0; c < z->OBJ_SizeTable[b]; c++) fwrite(&z->OBJ[a+c], 1, 1, pzf); } ///////////////////// // WRITE PAL FILES // ///////////////////// a = ftell(pzf); fseek(pzf, x[8], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->PAL_FileCount; b++){ fwrite(&z->PAL_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->PAL_FileCount; b++){ a = ftell(pzf); // save the PAL file address fseek(pzf, y[b], SEEK_SET); // go back to the PAL table fwrite(&a, 4, 1, pzf); // write address to PAL file fseek(pzf, a, SEEK_SET); // go back to the PAL file a = z->PAL_AddressTable[b]; // Write file for(c=0; c < z->PAL_SizeTable[b]; c++) fwrite(&z->PAL[a+c], 1, 1, pzf); } ////////////////////// // WRITE TMAP FILES // ////////////////////// a = ftell(pzf); fseek(pzf, x[9], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->TMAP_FileCount; b++){ fwrite(&z->TMAP_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->TMAP_FileCount; b++){ a = ftell(pzf); // save the TMAP file address fseek(pzf, y[b], SEEK_SET); // go back to the TMAP table fwrite(&a, 4, 1, pzf); // write address to TMAP file fseek(pzf, a, SEEK_SET); // go back to the TMAP file a = z->TMAP_AddressTable[b]; // Write file for(c=0; c < z->TMAP_SizeTable[b]; c++) fwrite(&z->TMAP[a+c], 1, 1, pzf); } ////////////////////// // WRITE WMAP FILES // ////////////////////// a = ftell(pzf); fseek(pzf, x[10], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->WMAP_FileCount; b++){ fwrite(&z->WMAP_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->WMAP_FileCount; b++){ a = ftell(pzf); // save the WMAP file address fseek(pzf, y[b], SEEK_SET); // go back to the WMAP table fwrite(&a, 4, 1, pzf); // write address to WMAP file fseek(pzf, a, SEEK_SET); // go back to the WMAP file a = z->WMAP_AddressTable[b]; // Write file for(c=0; c < z->WMAP_SizeTable[b]; c++) fwrite(&z->WMAP[a+c], 1, 1, pzf); } ////////////////////// // WRITE CCYC FILES // ////////////////////// a = ftell(pzf); fseek(pzf, x[11], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->CCYC_FileCount; b++){ fwrite(&z->CCYC_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->CCYC_FileCount; b++){ a = ftell(pzf); // save the CCYC file address fseek(pzf, y[b], SEEK_SET); // go back to the CCYC table fwrite(&a, 4, 1, pzf); // write address to CCYC file fseek(pzf, a, SEEK_SET); // go back to the CCYC file a = z->CCYC_AddressTable[b]; // Write file for(c=0; c < z->CCYC_SizeTable[b]; c++) fwrite(&z->CCYC[a+c], 1, 1, pzf); } ////////////////////////////////// // WRITE FILTERDISTORTION FILES // ////////////////////////////////// a = ftell(pzf); fseek(pzf, x[12], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->FILTERDISTORTION_FileCount; b++){ fwrite(&z->FILTERDISTORTION_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->FILTERDISTORTION_FileCount; b++){ a = ftell(pzf); // save the FILTERDISTORTION file address fseek(pzf, y[b], SEEK_SET); // go back to the FILTERDISTORTION table fwrite(&a, 4, 1, pzf); // write address to FILTERDISTORTION file fseek(pzf, a, SEEK_SET); // go back to the FILTERDISTORTION file a = z->FILTERDISTORTION_AddressTable[b]; // Write file for(c=0; c < z->FILTERDISTORTION_SizeTable[b]; c++) fwrite(&z->FILTERDISTORTION[a+c], 1, 1, pzf); } ///////////////////////////////// // WRITE FILTERCOMPOSITE FILES // ///////////////////////////////// a = ftell(pzf); fseek(pzf, x[13], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->FILTERCOMPOSITE_FileCount; b++){ fwrite(&z->FILTERCOMPOSITE_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->FILTERCOMPOSITE_FileCount; b++){ a = ftell(pzf); // save the FILTERCOMPOSITE file address fseek(pzf, y[b], SEEK_SET); // go back to the FILTERCOMPOSITE table fwrite(&a, 4, 1, pzf); // write address to FILTERCOMPOSITE file fseek(pzf, a, SEEK_SET); // go back to the FILTERCOMPOSITE file a = z->FILTERCOMPOSITE_AddressTable[b]; // Write file for(c=0; c < z->FILTERCOMPOSITE_SizeTable[b]; c++) fwrite(&z->FILTERCOMPOSITE[a+c], 1, 1, pzf); } fclose(pzf); return 0; }
001tomclark-research-check
Source/Tools/pzfcompiler/zone.c
C
gpl2
69,939
/***************************************************************************** SONIC PZF LIBRARY Copyright(c) Damian Grove, 2006 "zone.h" ------------------------------------------------------------------------ The ProSonic hierarchy works like this: ZONE (e.g. Palmtree Panic Zone) \ \__ ACT (e.g. Act 1) \ \__ STAGE (e.g. Present) MAXIMUM NUMBER OF ZONES 256 MAXIMUM NUMBER OF ACTS 8 MAXIMUM NUMBER OF STAGES 4 ------------------------------------------------------------------------ The PZF format is designed to support 256 zones so game designers will never run out of room to add levels to their games. Although 8 acts seems high, it was picked over a 4 act limit since Knuckles' Chaotix makes use of 5. To ensure better compatibility, the 4 act limit was dropped in favor of the 8 act limit. Stages are different in that the game designer doesn't actually tell ProSonic how many there are. Instead there are a total of 4 stage 'slots' that allow the player to choose which slots to use. The 4 slots are A, B, C, and D. This was done to ensure better compatibility with Sonic CD. Since the third act of every zone in Sonic CD only has 2 future stages (which are C and D), it would only make sense to allow ProSonic to do the same thing. ------------------------------------------------------------------------ FILE DATA FORMAT: All sizes and addresses are stored in little-endian format. z->TYPE_FileCount = 1; z->TYPE [ INT_0 Address to file 0 (from TYPE[0]) INT_1 Size of file 0 (in bytes) FILE_0[INT_1] ] z->TYPE_FileCount = 2; z->TYPE [ INT_0 Address to file 0 (from TYPE[0]) INT_1 Address to file 1 (from TYPE[0]) INT_2 Size of file 0 (in bytes) INT_3 Size of file 1 (in bytes) FILE_0[INT_2] FILE_1[INT_3] ] z->TYPE_FileCount = 3; z->TYPE [ INT_0 Address to file 0 (from TYPE[0]) INT_1 Address to file 1 (from TYPE[0]) INT_2 Address to file 2 (from TYPE[0]) INT_3 Size of file 0 (in bytes) INT_4 Size of file 1 (in bytes) INT_5 Size of file 2 (in bytes) FILE_0[INT_3] FILE_1[INT_4] FILE_2[INT_5] ] ... *****************************************************************************/ char item[24]; int a; int b; int c; int d; float f; int a1; int c1; int endoffile; long filesize_zone; long filesize_stagea; long filesize_stageb; long filesize_stagec; long filesize_staged; int filesize_data; char filename[256]; char path[256]; FILE *txt_file; FILE *txt_data; /////////// // STAGE // /////////// typedef struct // Previously called a "TIMEZONE" { char Name; char ActNumber; char MusicRegular; char MusicAlternate; char OpeningScript; char ClosingScript; char ActiveScript; char WaterEnable; short WrapPoint; char AboveWaterFilterL; char BelowWaterFilterL; float AboveWaterFilterSpeed; float BelowWaterFilterSpeed; char ClearBackground; //char BelowWaterFilterB; char Palette; char ColorCycle; char WaterMap; char BlockMap; char BlockArt; char BlockData; char BlockAttributes; char BlockSolidity; char TileMap; char ObjectLayout; short WaterHeight; short LevelXL; short LevelXR; short LevelYT; short LevelYB; short StartX[16]; short StartY[16]; } STAGE; ///////// // ACT // ///////// typedef struct { char IncludedStages; // (bits: 0000DCBA) STAGE Stage[4]; } ACT; ////////// // ZONE // ////////// typedef struct { char Act_FileCount; ACT *Act; char LevelName1[20]; char LevelName2[20]; unsigned char OSC_FileCount; unsigned char BATT_FileCount; unsigned char BDAT_FileCount; unsigned char BLOCK_FileCount; unsigned char BMAP_FileCount; unsigned char BSOL_FileCount; unsigned char OBJ_FileCount; unsigned char PAL_FileCount; unsigned char TMAP_FileCount; unsigned char WMAP_FileCount; unsigned char CCYC_FileCount; unsigned char FILTERDISTORTION_FileCount; unsigned char FILTERCOMPOSITE_FileCount; unsigned int *OSC_SizeTable; unsigned int *BATT_SizeTable; unsigned int *BDAT_SizeTable; unsigned int *BLOCK_SizeTable; unsigned int *BMAP_SizeTable; unsigned int *BSOL_SizeTable; unsigned int *OBJ_SizeTable; unsigned int *PAL_SizeTable; unsigned int *TMAP_SizeTable; unsigned int *WMAP_SizeTable; unsigned int *CCYC_SizeTable; unsigned int *FILTERDISTORTION_SizeTable; unsigned int *FILTERCOMPOSITE_SizeTable; unsigned int *OSC_AddressTable; unsigned int *BATT_AddressTable; unsigned int *BDAT_AddressTable; unsigned int *BLOCK_AddressTable; unsigned int *BMAP_AddressTable; unsigned int *BSOL_AddressTable; unsigned int *OBJ_AddressTable; unsigned int *PAL_AddressTable; unsigned int *TMAP_AddressTable; unsigned int *WMAP_AddressTable; unsigned int *CCYC_AddressTable; unsigned int *FILTERDISTORTION_AddressTable; unsigned int *FILTERCOMPOSITE_AddressTable; unsigned char *OSC; unsigned char *BATT; unsigned char *BDAT; unsigned char *BLOCK; unsigned char *BMAP; unsigned char *BSOL; unsigned char *OBJ; unsigned char *PAL; unsigned char *TMAP; unsigned char *WMAP; unsigned char *CCYC; unsigned char *FILTERDISTORTION; unsigned char *FILTERCOMPOSITE; } ZONE; // Needed by CompileZone() int ReadWord(ZONE *z, const char *string, ...); int ReadText(ZONE *z, const char *string, ...); int ReadVar(ZONE *z, const char *string, ...); int ReadFloatVar(ZONE *z, const char *string, ...); void ClearZone(ZONE *z); void DeleteZone(ZONE *z); int CreateZone(ZONE *z); int CompileZone(ZONE *z, const char *string, ...); int LoadZone(ZONE *z, const char *string, ...); int SaveZone(ZONE *z, const char *string, ...);
001tomclark-research-check
Source/Tools/pzfcompiler/zone.h
C
gpl2
5,825
# ########## limp executable ########## # Sources: SET(limp_executable_SRCS limp.c ) # Headers: SET(limp_executable_HDRS ) # actual target: ADD_EXECUTABLE(limp ${limp_executable_SRCS}) # add install target: INSTALL(TARGETS limp DESTINATION bin)
001tomclark-research-check
Source/Tools/limp/CMakeLists.txt
CMake
gpl2
254
/***************************************************************************** * ______ * / _ \ _ __ ______ * / /_ / / / //__ / / _ \ * / ____ / / / / / / / * / / / / / /_ / / * /_ / /_ / \ _____ / * ______ * / ____ / ______ _ __ _ ______ * / /___ / _ \ / //_ \ /_ / / _ \ * _\___ \ / / / / / / / / / / / / /_ / * / /_ / / / /_ / / / / / / / / / /____ * \______ / \ _____ / /_ / /_ / /_ / \ ______/ * * LIMP * * * ProSonic Engine * Created by Damian Grove * * Programmed in C * Compiled with DJGPP - GCC 2.952 * Libraries used: * - Allegro - 3.9.34 http://www.talula.demon.co.uk/allegro/ * - DUMB - 0.9.3 http://dumb.sourceforge.net/ * *****************************************************************************/ #include <stdio.h> #include <string.h> // TO-DO LIST: // - Update HEADER code // - Might need to update BMAP (to incorporate the "plane" bit) // Sonic the Hedgehog #define S1_TILES 0x2478 #define S1_MAP 0xC878 #define S1_BLOCKS 0xD478 #define S1_SOLIDITY 0x0 // ? #define S1_RINGS 0x0 // ? not stored in S1 RAM #define S1_PALETTE 0x11F78 #define S1_WPALETTE 0x11E78 // Sonic the Hedgehog 2 (commercial) #define S2_TILES 0x2478 #define S2_MAP 0xA478 #define S2_BLOCKS 0xB478 #define S2_SOLIDITY 0xFA78 #define S2_RINGS 0x10C80 #define S2_PALETTE 0x11F78 #define S2_WPALETTE 0x11478 // Sonic the Hedgehog 2 (1998 beta) #define S2B_TILES 0x2478 #define S2B_MAP 0xA478 #define S2B_BLOCKS 0xB478 #define S2B_SOLIDITY 0xF478 // different from S2 #define S2B_RINGS 0x10C80 // making assumption here -- never actually tested! #define S2B_PALETTE 0x11F78 #define S2B_WPALETTE 0x11FF8 // Sonic the Hedgehog 2 (2006 beta) // HAVEN'T RESEARCHED THIS YET!! #define SPRITES 0x12478 #define VALUE_ZONE 0x12288 #define VALUE_ACT 0x12289 int TILES; int MAP; int BLOCKS; int SOLIDITY; int RINGS; int PALETTE; // Regular palette int WPALETTE; // Underwater palette enum SonicGame { SONIC1, SONIC2, SONIC2BETA }; int Game = SONIC2; // Make this user-selectable in the future enum DrawProperty { NORMAL, MIRROR, FLIP, ROTATE }; unsigned char Byte1; unsigned char Byte2; unsigned char Byte3; unsigned char Byte4; unsigned short Word1; unsigned short Word2; unsigned short Word3; unsigned short Word4; unsigned short Word5; unsigned int DWord1; unsigned int DWord2; int test1; int test2; int Block; int Tile; char priority[0x400]; //int CreateHeader(); // PZF file header int CreateBATT(); int CreateBLOCK(); int CreateBMAP(); int CreateBSOL(); int CreateOBJ(); int CreatePAL(); int CreateTMAP(); char nameSavestate[128]; char nameROM[128]; char ZonePrefix[6]; // We include space for 2 extra bytes to detect prefix errors char BMAPName[13]; char TMAPName[13]; char PALName[13]; char OBJName[13]; char BSOLName[13]; char BATTName[13]; char BDATName[13]; char BLOCKName[13]; FILE *gssSavestate; // Genecyst savestate FILE *binROM; // Sega Genesis ROM FILE *datLimp2; // Collision data taken from the Sonic 2 ROM FILE *pzfHeader; // PZF file header to be created FILE *datBlockSlope; FILE *datBlockData; FILE *datBlocks; FILE *datBlockMap; FILE *datBlockSolid; FILE *datObjects; FILE *datPalette; FILE *datTileMap; char PaletteData[192]; int main() { printf("LIMP\nProSonic level importer!\n\n"); printf("Type the name of the savestate you wish to use: "); fgets(nameSavestate, 128, stdin); nameSavestate[strlen(nameSavestate) - 1] = '\0'; if(fopen(nameSavestate, "rb") == NULL){ printf("\n\nERROR 1: Cannot open file"); return 0; } printf("Type the name of the ROM you wish to use: "); fgets(nameROM, 128, stdin); nameROM[strlen(nameROM) - 1] = '\0'; if(fopen(nameROM, "rb") == NULL){ printf("\n\nERROR 2: Cannot open file"); return 0; } printf("Type the zone prefix you want to use: "); fgets(ZonePrefix, 6, stdin); printf("\n"); if(strlen(ZonePrefix) > 4) { printf("\n\nERROR 3: Prefix cannot exceed 3 characters"); return 0; } else { ZonePrefix[strlen(ZonePrefix) - 1] = '\0'; strcpy(BMAPName, ZonePrefix); strcat(BMAPName, "BMAP.DAT"); strcpy(TMAPName, ZonePrefix); strcat(TMAPName, "TMAP.DAT"); strcpy(BSOLName, ZonePrefix); strcat(BSOLName, "BSOL.DAT"); strcpy(BATTName, ZonePrefix); strcat(BATTName, "BATT.DAT"); strcpy(BDATName, ZonePrefix); strcat(BDATName, "BDAT.DAT"); strcpy(OBJName, ZonePrefix); strcat(OBJName, "OBJ.DAT"); strcpy(PALName, ZonePrefix); strcat(PALName, "PAL.DAT"); strcpy(BLOCKName, ZonePrefix); strcat(BLOCKName, "BLOCK.DAT"); } switch(Game) { case SONIC1: TILES = S1_TILES; MAP = S1_MAP; BLOCKS = S1_BLOCKS; SOLIDITY = S1_SOLIDITY; RINGS = S1_RINGS; PALETTE = S1_PALETTE; WPALETTE = S1_WPALETTE; break; case SONIC2: TILES = S2_TILES; MAP = S2_MAP; BLOCKS = S2_BLOCKS; SOLIDITY = S2_SOLIDITY; RINGS = S2_RINGS; PALETTE = S2_PALETTE; WPALETTE = S2_WPALETTE; break; case SONIC2BETA: TILES = S2B_TILES; MAP = S2B_MAP; BLOCKS = S2B_BLOCKS; SOLIDITY = S2B_SOLIDITY; RINGS = S2B_RINGS; PALETTE = S2B_PALETTE; WPALETTE = S2B_WPALETTE; break; } gssSavestate = fopen(nameSavestate, "rb"); binROM = fopen(nameROM, "rb"); datLimp2 = fopen("Limp2.dat", "rb"); // For Sonic 2 //pzfHeader = fopen("HEADER.DAT", "w+b"); datBlockSlope = fopen(BATTName, "w+b"); datBlocks = fopen(BLOCKName, "w+b"); datBlockMap = fopen(BMAPName, "w+b"); datBlockSolid = fopen(BSOLName, "w+b"); datBlockData = fopen(BDATName, "w+b"); datObjects = fopen(OBJName, "w+b"); datPalette = fopen(PALName, "w+b"); datTileMap = fopen(TMAPName, "w+b"); //CreateHeader(); //printf("\n- PZF file header created"); CreatePAL(); printf("\n- Palette data created"); CreateBLOCK(); printf("\n- Block data created"); CreateBMAP(); if(Game == SONIC1) CreateBMAP(); // Do twice for Sonic 1 printf("\n- Block-map data created"); CreateTMAP(); printf("\n- Tile-map data created"); CreateBSOL(); printf("\n- Block solidity data created"); CreateOBJ(); printf("\n- Object layout data created"); fclose(gssSavestate); fclose(binROM); //fclose(pzfHeader); fclose(datBlockSlope); fclose(datBlocks); fclose(datBlockMap); fclose(datBlockSolid); fclose(datBlockData); fclose(datObjects); fclose(datPalette); fclose(datTileMap); printf("\n\nFinished!"); return 0; } /*int CreateHeader() { char TempFiller = 0; // temporary variable to use for unused ones char TimeZoneCount = 1; // 1-4 char ActCount = 1; // 1-8 char TileSize; // 0 - 32, 1 - 64, 2 - 128, 3 - 256 char LevelName1[] = "UNTITLED "; char LevelName2[] = "UNTITLED "; short PlayerStartX1; short PlayerStartY1; short PlayerStartX2; // unused short PlayerStartY2; // unused short PlayerStartX3; // unused short PlayerStartY3; // unused short PlayerStartX4; // unused short PlayerStartY4; // unused short PlayerStartX5; // unused short PlayerStartY5; // unused short PlayerStartX6; // unused short PlayerStartY6; // unused short PlayerStartX7; // unused short PlayerStartY7; // unused short PlayerStartX8; // unused short PlayerStartY8; // unused short LevelSizeXL; // X size from left short LevelSizeXR; // X size to right short LevelSizeYT; // Y size from top short LevelSizeYB; // Y size to bottom short WaterHeight; char TileColumns; // unused char TileRows; // unused char WaterEnable; char Song1P; char Song2P; //short FilterDimL; // Top filter dimension for plane L //short FilterDimH; // Top filter dimension for plane H //short FilterDimB; // Top filter dimension for plane B //char FilterSpeedTL; // Top filter plane L speed //char FilterSpeedH~~~ finish this stuff later... // char pzfNamePAL[] = "PALETTE 1 "; char pzfNameWMAP[] = "WATER MAP 1 "; char pzfNameBMAP[] = "BLOCK MAP 1 "; char pzfNameBLOCK[] = "BLOCK ART 1 "; char pzfNameBDAT[] = "BLOCK PLANES 1 "; char pzfNameBATT[] = "SLOPE TABLE 1 "; char pzfNameBSOL[] = "SOLIDITY 1 "; char pzfNameTMAP[] = "TILE MAP 1 "; char pzfNameFILTER[] = "FILTER 1 "; char pzfNameOBJ[] = "OBJECT MAP 1 "; // Temporary stuff if(Game == SONIC1) TileSize = 3; // 256x256 else TileSize = 2; // 128x128 Byte1 = 'P'; fwrite(&Byte1, sizeof(char), 1, pzfHeader); Byte1 = 'Z'; fwrite(&Byte1, sizeof(char), 1, pzfHeader); Byte1 = 'F'; fwrite(&Byte1, sizeof(char), 1, pzfHeader); Byte1 = (TimeZoneCount << 4) + ActCount; fwrite(&Byte1, sizeof(char), 1, pzfHeader); fwrite(&TileSize, sizeof(char), 1, pzfHeader); fwrite(&Byte1, sizeof(char), 1, pzfHeader); fwrite(&Byte1, sizeof(char), 1, pzfHeader); fwrite(&Byte1, sizeof(char), 1, pzfHeader); for(Byte1 = 0; Byte1 < 16; Byte1++) fwrite(&LevelName1[Byte1], sizeof(char), 1, pzfHeader); for(Byte1 = 0; Byte1 < 16; Byte1++) fwrite(&LevelName2[Byte1], sizeof(char), 1, pzfHeader); fseek(gssSavestate, 0xD480, SEEK_SET); fread(&PlayerStartX1, sizeof(short), 1, gssSavestate); fwrite(&PlayerStartX1, sizeof(short), 1, pzfHeader); fseek(gssSavestate, 0xD484, SEEK_SET); fread(&PlayerStartY1, sizeof(short), 1, gssSavestate); fwrite(&PlayerStartY1, sizeof(short), 1, pzfHeader); fwrite(&PlayerStartX2, sizeof(short), 1, pzfHeader); fwrite(&PlayerStartY2, sizeof(short), 1, pzfHeader); fwrite(&PlayerStartX3, sizeof(short), 1, pzfHeader); fwrite(&PlayerStartY3, sizeof(short), 1, pzfHeader); fwrite(&PlayerStartX4, sizeof(short), 1, pzfHeader); fwrite(&PlayerStartY4, sizeof(short), 1, pzfHeader); fwrite(&PlayerStartX5, sizeof(short), 1, pzfHeader); fwrite(&PlayerStartY5, sizeof(short), 1, pzfHeader); fwrite(&PlayerStartX6, sizeof(short), 1, pzfHeader); fwrite(&PlayerStartY6, sizeof(short), 1, pzfHeader); fwrite(&PlayerStartX7, sizeof(short), 1, pzfHeader); fwrite(&PlayerStartY7, sizeof(short), 1, pzfHeader); fwrite(&PlayerStartX8, sizeof(short), 1, pzfHeader); fwrite(&PlayerStartY8, sizeof(short), 1, pzfHeader); fseek(gssSavestate, 0x11338, SEEK_SET); fread(&LevelSizeXL, sizeof(short), 1, gssSavestate); fread(&LevelSizeXR, sizeof(short), 1, gssSavestate); fread(&LevelSizeYT, sizeof(short), 1, gssSavestate); fread(&LevelSizeYB, sizeof(short), 1, gssSavestate); fwrite(&LevelSizeXL, sizeof(short), 1, pzfHeader); fwrite(&LevelSizeXR, sizeof(short), 1, pzfHeader); fwrite(&LevelSizeYT, sizeof(short), 1, pzfHeader); fwrite(&LevelSizeYB, sizeof(short), 1, pzfHeader); fseek(gssSavestate, 0x11AC0, SEEK_SET); fread(&WaterHeight, sizeof(short), 1, gssSavestate); fwrite(&WaterHeight, sizeof(short), 1, pzfHeader); fwrite(&TileColumns, sizeof(char), 1, pzfHeader); fwrite(&TileRows, sizeof(char), 1, pzfHeader); fseek(gssSavestate, 0x11AC4, SEEK_SET); fread(&WaterEnable, sizeof(char), 1, gssSavestate); fwrite(&WaterEnable, sizeof(char), 1, pzfHeader); fwrite(&Song1P, sizeof(char), 1, pzfHeader); fwrite(&Song2P, sizeof(char), 1, pzfHeader); fwrite(&Byte1, sizeof(char), 1, pzfHeader); fwrite(&Byte1, sizeof(char), 1, pzfHeader); for(Byte1 = 0; Byte1 < 33; Byte1++) fwrite(&TempFiller, sizeof(char), 1, pzfHeader); Byte1 = 0x11; fwrite(&Byte1, sizeof(char), 1, pzfHeader); Byte1 = 1; fwrite(&Byte1, sizeof(char), 1, pzfHeader); fwrite(&Byte1, sizeof(char), 1, pzfHeader); fwrite(&Byte1, sizeof(char), 1, pzfHeader); fwrite(&Byte1, sizeof(char), 1, pzfHeader); fwrite(&Byte1, sizeof(char), 1, pzfHeader); fwrite(&Byte1, sizeof(char), 1, pzfHeader); fwrite(&Byte1, sizeof(char), 1, pzfHeader); fwrite(&Byte1, sizeof(char), 1, pzfHeader); fwrite(&Byte1, sizeof(char), 1, pzfHeader); fwrite(&Byte1, sizeof(char), 1, pzfHeader); for(Byte1 = 0; Byte1 < 16; Byte1++) fwrite(&pzfNamePAL[Byte1], sizeof(char), 1, pzfHeader); for(Byte1 = 0; Byte1 < 16; Byte1++) fwrite(&pzfNameWMAP[Byte1], sizeof(char), 1, pzfHeader); for(Byte1 = 0; Byte1 < 16; Byte1++) fwrite(&pzfNameBMAP[Byte1], sizeof(char), 1, pzfHeader); for(Byte1 = 0; Byte1 < 16; Byte1++) fwrite(&pzfNameBLOCK[Byte1], sizeof(char), 1, pzfHeader); for(Byte1 = 0; Byte1 < 16; Byte1++) fwrite(&pzfNameBDAT[Byte1], sizeof(char), 1, pzfHeader); for(Byte1 = 0; Byte1 < 16; Byte1++) fwrite(&pzfNameBATT[Byte1], sizeof(char), 1, pzfHeader); for(Byte1 = 0; Byte1 < 16; Byte1++) fwrite(&pzfNameBSOL[Byte1], sizeof(char), 1, pzfHeader); for(Byte1 = 0; Byte1 < 16; Byte1++) fwrite(&pzfNameTMAP[Byte1], sizeof(char), 1, pzfHeader); for(Byte1 = 0; Byte1 < 16; Byte1++) fwrite(&pzfNameFILTER[Byte1], sizeof(char), 1, pzfHeader); for(Byte1 = 0; Byte1 < 16; Byte1++) fwrite(&pzfNameOBJ[Byte1], sizeof(char), 1, pzfHeader); return 0; }*/ int CreateBLOCK() { short Sprite; char Draw; char Palette; unsigned short ColorTransparent = 0xF81F; Block = 1024; fwrite(&Block, 2, 1, datBlocks); for(Block = 0; Block < 1024; Block++) { fseek(gssSavestate, BLOCKS + (Block << 3), SEEK_SET); fread(&Word1, 2, 1, gssSavestate); fread(&Word2, 2, 1, gssSavestate); fread(&Word3, 2, 1, gssSavestate); fread(&Word4, 2, 1, gssSavestate); Word1 = (Word1 << 8) + (Word1 >> 8); Word2 = (Word2 << 8) + (Word2 >> 8); Word3 = (Word3 << 8) + (Word3 >> 8); Word4 = (Word4 << 8) + (Word4 >> 8); priority[Block] = (Word1>>15)+(Word2>>15)+(Word3>>15)+(Word4>>15); Byte1 = (Word1 >> 15) + ((Word2 >> 15) << 1) + ((Word3 >> 15) << 2) + ((Word4 >> 15) << 3); fwrite(&Byte1, 1, 1, datBlockData); for(test1 = 0; test1 < 4; test1++) { if(test1 == 0){ Sprite = Word1 & 0x7FF; Draw = (Word1 >> 11) & 3; Palette = (Word1 >> 13) & 3; } else if(test1 == 1){ Sprite = Word2 & 0x7FF; Draw = (Word2 >> 11) & 3; Palette = (Word2 >> 13) & 3; } else if(test1 == 2){ Sprite = Word3 & 0x7FF; Draw = (Word3 >> 11) & 3; Palette = (Word3 >> 13) & 3; } else{ Sprite = Word4 & 0x7FF; Draw = (Word4 >> 11) & 3; Palette = (Word4 >> 13) & 3; } if(Draw == NORMAL) { fseek(gssSavestate, SPRITES + (Sprite << 5), SEEK_SET); for(test2 = 0; test2 < 8; test2++) { // PIXEL 1 & 2 fread(&Byte1, 1, 1, gssSavestate); Byte2 = (Byte1 >> 4) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } Byte2 = (Byte1 & 0xF) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } // PIXEL 3 & 4 fread(&Byte1, 1, 1, gssSavestate); Byte2 = (Byte1 >> 4) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } Byte2 = (Byte1 & 0xF) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } // PIXEL 5 & 6 fread(&Byte1, 1, 1, gssSavestate); Byte2 = (Byte1 >> 4) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } Byte2 = (Byte1 & 0xF) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } // PIXEL 7 & 8 fread(&Byte1, 1, 1, gssSavestate); Byte2 = (Byte1 >> 4) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } Byte2 = (Byte1 & 0xF) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } fseek(datBlocks, 16, SEEK_CUR); } } else if(Draw == MIRROR) { fseek(gssSavestate, SPRITES + (Sprite << 5) + 3, SEEK_SET); for(test2 = 0; test2 < 8; test2++) { // PIXEL 1 & 2 fread(&Byte1, 1, 1, gssSavestate); Byte2 = (Byte1 & 0xF) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } Byte2 = (Byte1 >> 4) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } // PIXEL 3 & 4 fseek(gssSavestate, -2, SEEK_CUR); fread(&Byte1, 1, 1, gssSavestate); Byte2 = (Byte1 & 0xF) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } Byte2 = (Byte1 >> 4) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } // PIXEL 5 & 6 fseek(gssSavestate, -2, SEEK_CUR); fread(&Byte1, 1, 1, gssSavestate); Byte2 = (Byte1 & 0xF) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } Byte2 = (Byte1 >> 4) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } // PIXEL 7 & 8 fseek(gssSavestate, -2, SEEK_CUR); fread(&Byte1, 1, 1, gssSavestate); Byte2 = (Byte1 & 0xF) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } Byte2 = (Byte1 >> 4) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } fseek(datBlocks, 16, SEEK_CUR); fseek(gssSavestate, 6, SEEK_CUR); } } else if(Draw == FLIP) { fseek(gssSavestate, SPRITES + (Sprite << 5) + 28, SEEK_SET); for(test2 = 0; test2 < 8; test2++) { // PIXEL 1 & 2 fread(&Byte1, 1, 1, gssSavestate); Byte2 = (Byte1 >> 4) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } Byte2 = (Byte1 & 0xF) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } // PIXEL 3 & 4 fread(&Byte1, 1, 1, gssSavestate); Byte2 = (Byte1 >> 4) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } Byte2 = (Byte1 & 0xF) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } // PIXEL 5 & 6 fread(&Byte1, 1, 1, gssSavestate); Byte2 = (Byte1 >> 4) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } Byte2 = (Byte1 & 0xF) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } // PIXEL 7 & 8 fread(&Byte1, 1, 1, gssSavestate); Byte2 = (Byte1 >> 4) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } Byte2 = (Byte1 & 0xF) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } fseek(datBlocks, 16, SEEK_CUR); fseek(gssSavestate, -8, SEEK_CUR); } } else if(Draw == ROTATE) { fseek(gssSavestate, SPRITES + (Sprite << 5) + 31, SEEK_SET); for(test2 = 0; test2 < 8; test2++) { // PIXEL 1 & 2 fread(&Byte1, 1, 1, gssSavestate); Byte2 = (Byte1 & 0xF) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } Byte2 = (Byte1 >> 4) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } // PIXEL 3 & 4 fseek(gssSavestate, -2, SEEK_CUR); fread(&Byte1, 1, 1, gssSavestate); Byte2 = (Byte1 & 0xF) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } Byte2 = (Byte1 >> 4) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } // PIXEL 5 & 6 fseek(gssSavestate, -2, SEEK_CUR); fread(&Byte1, 1, 1, gssSavestate); Byte2 = (Byte1 & 0xF) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } Byte2 = (Byte1 >> 4) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } // PIXEL 7 & 8 fseek(gssSavestate, -2, SEEK_CUR); fread(&Byte1, 1, 1, gssSavestate); Byte2 = (Byte1 & 0xF) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } Byte2 = (Byte1 >> 4) + (Palette << 4); if(Byte2 == 0x10 || Byte2 == 0x20 || Byte2 == 0x30 || Byte2 == 0) Byte2 = 0xFF; if(Byte2 != 0xFF){ Word5 = ((PaletteData[Byte2 * 3] >> 1) << 11) | (PaletteData[(Byte2 * 3) + 1] << 5) | (PaletteData[(Byte2 * 3) + 2] >> 1); fwrite(&Word5, 2, 1, datBlocks); } else{ fwrite(&ColorTransparent, 2, 1, datBlocks); } fseek(datBlocks, 16, SEEK_CUR); fseek(gssSavestate, -2, SEEK_CUR); } } if(test1 == 0) fseek(datBlocks, -240, SEEK_CUR); else if(test1 == 1) fseek(datBlocks, -16, SEEK_CUR); else if(test1 == 2) fseek(datBlocks, -240, SEEK_CUR); else if(test1 == 3) fseek(datBlocks, -16, SEEK_CUR); } } return 0; } int CreatePAL() { /*char Header[0x83] = { 0x0A, 0x05, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x48, 0x00, 0x80, 0x80, 0xFF, 0x10, 0x08, 0x00, 0x10, 0x4A, 0x08, 0x18, 0x08, 0x00, 0x18, 0x39, 0x29, 0x21, 0x10, 0x00, 0x21, 0x10, 0x08, 0x21, 0x18, 0x08, 0x29, 0x10, 0x00, 0x29, 0x18, 0x00, 0x29, 0x18, 0x08, 0x29, 0x21, 0x18, 0x31, 0x18, 0x00, 0x31, 0x21, 0x08, 0x31, 0x29, 0x18, 0x39, 0x18, 0x00, 0x00, 0x01, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5E, 0x00, 0x0C };*/ //for(test1 = 0; test1 < 0x83; test1++) // fwrite(&Header[test1], sizeof(char), 1, datPalette); fseek(gssSavestate, PALETTE, SEEK_SET); Byte4 = 0; for(test1 = 0; test1 < 2; test1++) { // Color 0 fseek(gssSavestate, 64, SEEK_CUR); // move to color 0 of third palette fread(&Word1, sizeof(Word1), 1, gssSavestate); fseek(gssSavestate, -64, SEEK_CUR); // move to color 1 of first palette Byte1 = ((Word1 >> 4) & 0xE0) >> 2; // Red Byte2 = ((Word1 >> 8) & 0xE0) >> 2; // Green Byte3 = (Word1 & 0xE) << 2; // Blue fwrite(&Byte1, sizeof(Byte1), 1, datPalette); fwrite(&Byte2, sizeof(Byte2), 1, datPalette); fwrite(&Byte3, sizeof(Byte3), 1, datPalette); // Colors 1-63 for(test2 = 1; test2 < 64; test2++) { fread(&Word1, sizeof(Word1), 1, gssSavestate); Byte1 = ((Word1 >> 4) & 0xE0) >> 2; // Red Byte2 = ((Word1 >> 8) & 0xE0) >> 2; // Green Byte3 = (Word1 & 0xE) << 2; // Blue fwrite(&Byte1, sizeof(Byte1), 1, datPalette); fwrite(&Byte2, sizeof(Byte2), 1, datPalette); fwrite(&Byte3, sizeof(Byte3), 1, datPalette); if(test1 == 0){ PaletteData[test2 * 3] = Byte1; PaletteData[(test2 * 3) + 1] = Byte2; PaletteData[(test2 * 3) + 2] = Byte3; } } // Write 64 blank colors for(test2 = 0; test2 < 64; test2++) { fwrite(&Byte4, sizeof(Byte4), 1, datPalette); fwrite(&Byte4, sizeof(Byte4), 1, datPalette); fwrite(&Byte4, sizeof(Byte4), 1, datPalette); } fseek(gssSavestate, WPALETTE, SEEK_SET); } // Fix transparency color PaletteData[0] = PaletteData[96]; PaletteData[1] = PaletteData[97]; PaletteData[2] = PaletteData[98]; return 0; } int CreateBMAP() { int Size; // ======================================= // Sonic 1 engine format // --------------------------------------- // _BPfm_bb bbbbbbbb // _NMFE_98 76543210 // ======================================= // ======================================= // Sonic 2 engine format // --------------------------------------- // __BPfmbb bbbbbbbb // __NMFE98 76543210 // ======================================= // ======================================= // ProSonic engine format // --------------------------------------- // //uuuuuuup BPtttttt fmbbbbbb bbbbbbbb // //VUTSRQPO NMLKJIHG FEDCBA98 76543210 // ttttttuu uuuLbpBP fmNNNNNN NNNNNNNN // (NOTE: little-endian!!) // ======================================= fseek(gssSavestate, TILES, SEEK_SET); Byte4 = 0; Size = 16384; if(Game == SONIC1){ Byte1 = 3; // 256x256 (32 << 3) fwrite(&Byte1, sizeof(Byte1), 1, datBlockMap); } else{ Byte1 = 2; // 128x128 (32 << 2) fwrite(&Byte1, sizeof(Byte1), 1, datBlockMap); } if(Game == SONIC1) { Word1 = 0; for(test1 = 0; test1 < 256; test1++) fwrite(&Word1, sizeof(Word2), 1, datBlockMap); Size -= 256; } for(test1 = 0; test1 < Size; test1++) { fread(&Byte1, sizeof(Byte1), 1, gssSavestate); fread(&Byte2, sizeof(Byte2), 1, gssSavestate); Word1 = (short)((Byte1 << 8) + Byte2); //Word1 = ((Word1 >> 8) & 255) + ((Word1 << 8) & 255); // Byte swap //Word2 = Word1 & 0x3FF; // Block DWord1 = Word1 & 0x3FF; // 11 1111 1111 (b) //printf("%04X ", DWord1); //system("pause"); if(Game == SONIC1){ ////DWord1 += (int)(Word1 & 0x1800) << 3; // 1 1000 0000 0000 (f and m) ////DWord1 += (int)(Word1 & 0x6000) << 9; // 110 0000 0000 0000 (B and P) DWord1 += (int)(Word1 & 0x7800) << 3; // NEW CODE FOR NEW FORMAT! DWord1 += (int)(Word1 & 0x6000) << 5; // NEW CODE FOR NEW FORMAT! (copy BP to bp) } else{ ////DWord1 += (int)(Word1 & 0xC00) << 4; // 1100 0000 0000 (f and m) //DWord1 += (int)(Word1 & 0x3000) << 10; // 11 0000 0000 0000 (B and P) ////DWord1 += (int)(Word1 & 0x2000) << 10; // 11 0000 0000 0000 (B and P) ////DWord1 += (int)(Word1 & 0x4000) << 8; // 11 0000 0000 0000 (B and P) DWord1 += (int)(Word1 & 0xFC00) << 4; // NEW CODE FOR NEW FORMAT! } DWord1 += (int)((int)(priority[Word1 & 0x3FF] > 0)<<20); Byte1 = (DWord1 & 0xFF); fwrite(&Byte1, sizeof(Byte1), 1, datBlockMap); Byte1 = ((DWord1 >> 8) & 0xFF); fwrite(&Byte1, sizeof(Byte1), 1, datBlockMap); Byte1 = ((DWord1 >> 16) & 0xFF); fwrite(&Byte1, sizeof(Byte1), 1, datBlockMap); Byte1 = (DWord1 >> 24); fwrite(&Byte1, sizeof(Byte1), 1, datBlockMap); } if(Game == SONIC1) { Word1 = 0; Size = 16384; for(test1 = 0; test1 < Size; test1++) fwrite(&Word1, sizeof(Word2), 1, datBlockMap); } return 0; } int CreateTMAP() { int Size; fseek(gssSavestate, MAP, SEEK_SET); if(Game == SONIC1){ Size = 1024; Byte1 = 0x3F; Byte2 = 0x7; fwrite(&Byte1, sizeof(Byte1), 1, datTileMap); fwrite(&Byte2, sizeof(Byte2), 1, datTileMap); } else{ Size = 4096; Byte1 = 0x7F; Byte2 = 0xF; fwrite(&Byte1, sizeof(Byte1), 1, datTileMap); fwrite(&Byte2, sizeof(Byte2), 1, datTileMap); } Byte2 = 0; for(test1 = 0; test1 < Size; test1++) { fread(&Byte1, sizeof(Byte1), 1, gssSavestate); fwrite(&Byte1, sizeof(Byte1), 1, datTileMap); fwrite(&Byte2, sizeof(Byte2), 1, datTileMap); } return 0; } int CreateBSOL() { // Side 0 fseek(gssSavestate, SOLIDITY, SEEK_SET); for(test1 = 0; test1 < 1024; test1++) { fread(&Byte1, sizeof(Byte1), 1, gssSavestate); fseek(datLimp2, Byte1, SEEK_SET); fread(&Byte2, sizeof(Byte2), 1, datLimp2); fwrite(&Byte2, sizeof(Byte2), 1, datBlockSlope); // Floor fseek(datLimp2, (Byte1 << 4) + 0x100, SEEK_SET); for(test2 = 0; test2 < 16; test2++) { fread(&Byte2, sizeof(Byte2), 1, datLimp2); //Byte2 = 0x10 - Byte2; //if(Byte2 > 0x10) // Byte2 += 224; fwrite(&Byte2, sizeof(Byte2), 1, datBlockSolid); } // Wall fseek(datLimp2, (Byte1 << 4) + 0x1100, SEEK_SET); for(test2 = 0; test2 < 16; test2++) { fread(&Byte2, sizeof(Byte2), 1, datLimp2); //Byte2 = 0x10 - Byte2; //if(Byte2 > 0x10) // Byte2 += 224; fwrite(&Byte2, sizeof(Byte2), 1, datBlockSolid); } } // Side 1 fseek(gssSavestate, SOLIDITY + 0x300, SEEK_SET); for(test1 = 0; test1 < 1024; test1++) { fread(&Byte1, sizeof(Byte1), 1, gssSavestate); fseek(datLimp2, Byte1, SEEK_SET); fread(&Byte2, sizeof(Byte2), 1, datLimp2); fwrite(&Byte2, sizeof(Byte2), 1, datBlockSlope); // Floor fseek(datLimp2, (Byte1 << 4) + 0x100, SEEK_SET); for(test2 = 0; test2 < 16; test2++) { fread(&Byte2, sizeof(Byte2), 1, datLimp2); //Byte2 = 0x10 - Byte2; //if(Byte2 > 0x10) // Byte2 += 224; fwrite(&Byte2, sizeof(Byte2), 1, datBlockSolid); } // Wall fseek(datLimp2, (Byte1 << 4) + 0x1100, SEEK_SET); for(test2 = 0; test2 < 16; test2++) { fread(&Byte2, sizeof(Byte2), 1, datLimp2); //Byte2 = 0x10 - Byte2; //if(Byte2 > 0x10) // Byte2 += 224; fwrite(&Byte2, sizeof(Byte2), 1, datBlockSolid); } } return 0; } int CreateOBJ() // FIX ME!! { fseek(gssSavestate, VALUE_ZONE, SEEK_SET); fread(&Byte1, sizeof(Byte1), 1, gssSavestate); fread(&Byte2, sizeof(Byte2), 1, gssSavestate); fseek(binROM, 0xE6800 + (Byte1 << 2) + (Byte2 << 1), SEEK_SET); fread(&Word1, sizeof(Word1), 1, binROM); Word1 = (Word1 >> 8) + (Word1 << 8); fseek(binROM, 0xE6800 + Word1, SEEK_SET); fseek(gssSavestate, RINGS, SEEK_SET); DWord1 = 0; DWord2 = 0; Word1 = 0x25; // Little-endian form of '0x2500' (Ring object) while(DWord1 < 0xFFFF0000 && DWord2 < 0xFFFF0000 && Game != SONIC1) // Temporary solution for Sonic 1 { if(DWord1 < 0xFFFF0000){ fread(&DWord1, sizeof(DWord1), 1, gssSavestate); // Endian conversion DWord1 = ((DWord1 & 0xFF000000) >> 24) + ((DWord1 & 0xFF0000) >> 8) + ((DWord1 & 0xFF00) << 8) + ((DWord1 & 0xFF) << 24); DWord1 &= 0xFFFF0FFF; } if(DWord2 < 0xFFFF0000){ fread(&DWord2, sizeof(DWord2), 1, binROM); // Endian conversion DWord2 = ((DWord2 & 0xFF000000) >> 24) + ((DWord2 & 0xFF0000) >> 8) + ((DWord2 & 0xFF00) << 8) + ((DWord2 & 0xFF) << 24); DWord2 &= 0xFFFF0FFF; } while(DWord2 < DWord1){ fread(&Word4, sizeof(Word4), 1, binROM); //if((Word4 & 0xFF) == 3){ // Endian conversion DWord2 = ((DWord2 & 0xFF000000) >> 24) + ((DWord2 & 0xFF0000) >> 8) + ((DWord2 & 0xFF00) << 8) + ((DWord2 & 0xFF) << 24); fwrite(&DWord2, sizeof(DWord2), 1, datObjects); //Word4 += 8; // Lower byte is currently 3, so add 8 to make it 0xB fwrite(&Word4, sizeof(Word4), 1, datObjects); Word1 = 0x25; fwrite(&Word1, sizeof(Word1), 1, datObjects); //} /*else if((Word4 & 0xFF) == 0x11){/////// this code might not be needed ////////////// // Endian conversion DWord2 = ((DWord2 & 0xFF000000) >> 24) + ((DWord2 & 0xFF0000) >> 8) + ((DWord2 & 0xFF00) << 8) + ((DWord2 & 0xFF) << 24); fwrite(&DWord2, sizeof(DWord2), 1, datObjects); //Word4 += 8; // Lower byte is currently 3, so add 8 to make it 0xB fwrite(&Word4, sizeof(Word4), 1, datObjects); Word1 = 0x10; fwrite(&Word1, sizeof(Word1), 1, datObjects); }*/ fread(&DWord2, sizeof(DWord2), 1, binROM); // Endian conversion DWord2 = ((DWord2 & 0xFF000000) >> 24) + ((DWord2 & 0xFF0000) >> 8) + ((DWord2 & 0xFF00) << 8) + ((DWord2 & 0xFF) << 24); } if(DWord2 < 0xFFFF0000) fseek(binROM, -4, SEEK_CUR); // Endian conversion DWord1 = ((DWord1 & 0xFF000000) >> 24) + ((DWord1 & 0xFF0000) >> 8) + ((DWord1 & 0xFF00) << 8) + ((DWord1 & 0xFF) << 24); fwrite(&DWord1, sizeof(DWord1), 1, datObjects); fwrite(&Word1, sizeof(Word1), 1, datObjects); Word1 = 0; fwrite(&Word1, sizeof(Word1), 1, datObjects); Word1 = 0x25; fseek(gssSavestate, 2, SEEK_CUR); // Endian conversion DWord1 = ((DWord1 & 0xFF000000) >> 24) + ((DWord1 & 0xFF0000) >> 8) + ((DWord1 & 0xFF00) << 8) + ((DWord1 & 0xFF) << 24); } //fseek(datObjects, -2, SEEK_CUR); //Word1 = 0; //fwrite(&Word1, sizeof(Word1), 1, datObjects); //fwrite(&Word1, sizeof(Word1), 1, datObjects); //Byte1 = 0; //fseek(datObjects, 0x17FF, SEEK_SET); //fwrite(&Byte1, sizeof(Byte1), 1, datObjects); return 0; }
001tomclark-research-check
Source/Tools/limp/limp.c
C
gpl2
41,897
// Networking #ifndef ALLEGRO_DOS #define NET_TYPE_OFFLINE 0 #define NET_TYPE_SERVER 1 #define NET_TYPE_CLIENT 2 #define COMMAND_QUIT 1 int check_commands(char *string); void serverside_setup(); void clientside_setup(); NLsocket game_socket[4]; // all connected client ports NLsocket sock_server; // server port NLsocket sock_client; // current client port NLint prosonicnet; // group NLbyte ip_input[17]; NLushort port; NLaddress addr_server; NLaddress addr_client; int net_type; char net_id[4]; char incoming_type; char incoming_sender; char talk_outgoing[64]; char talk_incoming[64]; char player_number; #endif
001tomclark-research-check
Source/Engine/network.h
C
gpl2
657
////////////////////////////// // ProSonic Engine // // Written by Damian Grove // ////////////////////////////// // TO-DO LIST: // // - Create working MMF-like scripting language // - Create working background layer // - Create configuration file // - Allow sprite/animation and sound files to be loaded by external list // - Allow block art to be animated // - Get water working // - Add object layout editor // - *** Make the engine faster *** // BUGS: // // - Fix block editor // - Fix collision editor // NOTE: // // Look into optimizing draw.c by keeping track of X and Y screen drawing position // TEST: // // CPU 700 MHz Celeron // RAM 128 MB // OS TinyXP rev 09 // DATE 07/02/2009 // FPS RATES (with vsync off) // 256 x 192: 45 // 320 x 200: 38 // 320 x 224: 35 // 400 x 300: 23 // 512 x 384: 15 // 640 x 480: 10 // 800 x 600: 07 // GOAL: Get 932x700 running 60 fps on P4 machine // Frame rate as of 08/05/2009 -- 37 fps #include <stdio.h> #include <stdlib.h> // used for exit() #include <string.h> #include <math.h> #include <allegro.h> #ifndef ALLEGRO_DOS #include <nl.h> #endif //#include <winalleg.h> //#include <windows.h> #include "zlib.h" #include "draw.h" #include "tools.h" #include "mouse.h" #include "strings.h" #include "error.h" #include "menus.h" #include "objects.h" #include "sprites.h" #include "m68k.h" #include "obj01.h" #include "script.h" #include "network.h" #include "ym2612.h" #include "psg.h" void TicUpdate(void) // runs every 1/60 seconds { ticUpdated = 1; if(!Game_paused){ ticCounterR++; ticCounter60R++; if(ticCounter60R >= 60){ ticCounter60R = 0; fps = ticCounter60L; ticCounter60L = 0; } } #ifdef ENABLE_MOUSE if(waitCounter > 0) waitCounter--; #endif } END_OF_FUNCTION(TicUpdate); #ifndef ALLEGRO_DOS void close_button_handler(void){ close_button_pressed = TRUE; } END_OF_FUNCTION(close_button_handler); #endif void quit(int e){ #ifdef ALLEGRO_DOS set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); system("CLS"); #endif if(e != 0){ switch(e){ case ERROR_OBJECT_BUFFER: allegro_message("%s", STR_ERR_OBJECT_BUFFER); break; case ERROR_DIVIDE_ZERO: allegro_message("%s", STR_ERR_DIVIDE_ZERO); break; case ERROR_INIT_SCREEN: allegro_message("%s", STR_ERR_INIT_SCREEN); break; case ERROR_NO_DEMO_FILES: allegro_message("%s", STR_ERR_NO_DEMO_FILES); break; default: allegro_message("%s", STR_ERR_UNKNOWN); } } if(program_filename) free(program_filename); #ifdef AUDIO_REC_ENABLED i = ftell(pcm_out) - 8; fseek(pcm_out, 0x4, SEEK_SET); fwrite(&i, 4, 1, pcm_out); i -= 0x24; fseek(pcm_out, 0x28, SEEK_SET); fwrite(&i, 4, 1, pcm_out); fclose(pcm_out); #endif remove_timer(); // needed to prevent crashes stop_audio_stream(stream); YM2612_End(); if(fm_data) free(fm_data); if(pcm_data) free(pcm_data); #ifdef ENABLE_SRAM_LOG_ANALYSIS if(SRAMFile != NULL) fclose(SRAMFile); #endif if(DemoFile != NULL) fclose(DemoFile); for(i=0; i<4; i++){ if(LayerB[i]) destroy_bitmap(LayerB[i]); if(LayerL[i]) destroy_bitmap(LayerL[i]); if(LayerH[i]) destroy_bitmap(LayerH[i]); if(LayerSH[i]) destroy_bitmap(LayerSH[i]); } if(LayerM) destroy_bitmap(LayerM); DeleteZone(&z); if(COMPILED_MAP) free(COMPILED_MAP); if(COMPILED_BACKMAP) free(COMPILED_BACKMAP); if(titlecard_data) free(titlecard_data); if(demodata) free(demodata); if(script) free(script); if(obj_script) free(obj_script); if(Objects) free(Objects); ClearSprites(); if(message) free(message); if(message_time) free(message_time); #ifndef ALLEGRO_DOS if(prosonicnet) nlGroupDestroy(prosonicnet); if(sock_server != NL_INVALID) nlClose(sock_server); if(sock_client != NL_INVALID) nlClose(sock_client); if(game_socket[0] != NL_INVALID) nlClose(game_socket[0]); if(game_socket[1] != NL_INVALID) nlClose(game_socket[1]); if(game_socket[2] != NL_INVALID) nlClose(game_socket[2]); if(game_socket[3] != NL_INVALID) nlClose(game_socket[3]); nlShutdown(); #endif if(e == 0){ set_config_int(config_section[num_of_frames-1], "digi_card", digi_card); set_config_int(config_section[num_of_frames-1], "audio_volume", audio_volume); set_config_int(config_section[num_of_frames-1], "smart_mix", smart_mix); set_config_int(config_section[num_of_frames-1], "vsync_enable", vsync_enable); set_config_int(config_section[num_of_frames-1], "frame_skip", frame_skip); set_config_int(config_section[num_of_frames-1], "screen_resolution_x", screen_resolution_x); set_config_int(config_section[num_of_frames-1], "screen_resolution_y", screen_resolution_y); set_config_int(config_section[num_of_frames-1], "screen_padding_x", screen_padding_x); set_config_int(config_section[num_of_frames-1], "screen_padding_y", screen_padding_y); set_config_int(config_section[num_of_frames-1], "screen_double_x", screen_double_x); set_config_int(config_section[num_of_frames-1], "screen_double_y", screen_double_y); set_config_int(config_section[num_of_frames-1], "full_screen", full_screen); for(i=0; i < 4; i++){ set_config_int(config_section[i], "bind_up", key_bind[i].bind_up); set_config_int(config_section[i], "bind_down", key_bind[i].bind_down); set_config_int(config_section[i], "bind_left", key_bind[i].bind_left); set_config_int(config_section[i], "bind_right", key_bind[i].bind_right); set_config_int(config_section[i], "bind_b", key_bind[i].bind_b); set_config_int(config_section[i], "bind_c", key_bind[i].bind_c); set_config_int(config_section[i], "bind_a", key_bind[i].bind_a); set_config_int(config_section[i], "bind_start", key_bind[i].bind_start); } } allegro_exit(); exit(1); } ////////// START ---- * NETWORK STUFF * ////////// // Move all network code into a seperate file in the future // #ifndef ALLEGRO_DOS void GetNetworkData(){ unsigned char type; unsigned char sender; unsigned char ready; if(net_type == 2){ // client //allegro_message("GetNetworkData() -- client"); type = 0; while(type != 0xFF){ i = nlRead(sock_client, &type, 1); if(i > 0){ switch(type){ case 0x01: n = 0; while(n != 1){ n = nlRead(sock_client, &sender, 1); if(key[KEY_ESC]) quit(0); } n = 0; while(n != 63){ n = nlRead(sock_client, talk_incoming, 63); if(key[KEY_ESC]) quit(0); } allegro_message("CLIENT INCOMING: %s", talk_incoming); break; case 0xFF: nlRead(sock_client, &sender, 1); break; } //allegro_message("GetNetworkData() -- client\ntype = %i\nsender = %i", type, sender); } if(key[KEY_7]) allegro_message("GetNetworkData() -- client"); if(key[KEY_ESC]) quit(0); } } else if(net_type == 1){ // server //allegro_message("GetNetworkData() -- server"); i = 1; type = 0; while(i > 0){ i = nlRead(game_socket[0], &type, 1); if(i > 0){ switch(type){ case 1: n = 0; while(n != 1){ n = nlRead(game_socket[0], &sender, 1); if(key[KEY_ESC]) quit(0); } n = 0; while(n != 63){ n = nlRead(game_socket[0], talk_incoming, 63); if(key[KEY_ESC]) quit(0); } allegro_message("SERVER INCOMING: %s", talk_incoming); break; } //allegro_message("GetNetworkData() -- server\ntype = %i\nsender = %i", type, sender); } if(key[KEY_7]) allegro_message("GetNetworkData() -- server"); if(key[KEY_ESC]) quit(0); } } } void ManageNetwork(){ int sock; unsigned char type; unsigned char sender; unsigned char ready = 1; //allegro_message("ManageNetwork()"); while(ready != 0x3){ for(sock=0; sock < 2; sock++){ i = 1; type = 0; while(i > 0){ i = nlRead(game_socket[sock], &type, 1); if(i > 0){ switch(type){ case 0x01: n = 0; while(n != 1){ n = nlRead(game_socket[sock], &sender, 1); if(key[KEY_ESC]) quit(0); } n = 0; while(n != 63){ n = nlRead(game_socket[sock], talk_incoming, 63); if(key[KEY_ESC]) quit(0); } allegro_message("type = 0x%02X\nsender = 0x%02X\ntalk_incoming = %s", type, sender, talk_incoming); if(sender == 0){ // Relay message from player 1 to player 2 n = 0; while(n != 1){ n = nlWrite(game_socket[1], &type, 1); if(key[KEY_ESC]) quit(0); } n = 0; while(n != 1){ n = nlWrite(game_socket[1], &sender, 1); if(key[KEY_ESC]) quit(0); } n = 0; while(n != 63){ n = nlWrite(game_socket[1], talk_incoming, 63); if(key[KEY_ESC]) quit(0); } } else if(sender == 1){ // Relay message from player 2 to player 1 n = 0; while(n != 1){ n = nlWrite(game_socket[0], &type, 1); if(key[KEY_ESC]) quit(0); } n = 0; while(n != 1){ n = nlWrite(game_socket[0], &sender, 1); if(key[KEY_ESC]) quit(0); } n = 0; while(n != 63){ n = nlWrite(game_socket[0], talk_incoming, 63); if(key[KEY_ESC]) quit(0); } } break; case 0xFF: n = 0; while(n != 1){ n = nlRead(game_socket[sock], &sender, 1); if(key[KEY_ESC]) quit(0); } ready |= (1 << sender); break; } //allegro_message("ManageNetwork()\ntype = %i\nsender = %i", type, sender); } if(key[KEY_7]) allegro_message("ManageNetwork()"); if(key[KEY_ESC]) quit(0); } } } i = 0xFF; n = 0; while(n != 1){ n = nlWrite(prosonicnet, &i, 1); if(key[KEY_ESC]) quit(0); } n = 0; while(n != 1){ n = nlWrite(prosonicnet, &net_id[0], 1); if(key[KEY_ESC]) quit(0); } } int check_commands(char *string){ if(string[0] != '/') return 0; for(i=1; i<64; i++){ if(string[i] >= 'a' && string[i] <= 'z') string[i] -= 0x20; // convert to uppercase } if(strcmp("/QUIT\n", string) == 0) return 1; return 0; } int open_socket(NLsocket *s, short local_port, short net_port, const char *net_ip, ...){ *s = nlOpen(local_port, NL_RELIABLE); if(*s == NL_INVALID){ allegro_message("ERROR: Invalid socket!\n"); nlClose(*s); return 1; } nlGetAddrFromName(net_ip, &addr_client); nlSetAddrPort(&addr_client, net_port); if(nlConnect(*s, &addr_client) == NL_FALSE){ i = nlGetError(); switch(i){ case NL_INVALID_SOCKET: allegro_message("NL_INVALID_SOCKET\n"); nlClose(*s); return; case NL_NULL_POINTER: allegro_message("NL_NULL_POINTER\n"); nlClose(*s); return; case NL_SYSTEM_ERROR: allegro_message("NL_SYSTEM_ERROR: %s\n", nlGetSystemErrorStr(nlGetSystemError())); nlClose(*s); return; case NL_CON_REFUSED: allegro_message("NL_CON_REFUSED\n"); nlClose(*s); return; case NL_WRONG_TYPE: allegro_message("NL_WRONG_TYPE\n"); nlClose(*s); return; default: allegro_message("ERROR i = 0x%X\n", i); //system("PAUSE"); } return 1; } return 0; } void serverside_setup(){ sock_server = nlOpen(port, NL_RELIABLE); if(sock_server == NL_INVALID){ allegro_message("ERROR: Invalid socket!\n"); nlClose(sock_server); return; } if(nlListen(sock_server) == NL_FALSE){ allegro_message("ERROR: Unable to listen!\n"); nlClose(sock_server); return; } prosonicnet = nlGroupCreate(); if(prosonicnet == NL_INVALID){ allegro_message("ERROR: Unable to create group!\n"); nlClose(sock_server); return; } //printf("Listening...\n"); i=0; while(i==0){ game_socket[1] = nlAcceptConnection(sock_server); if(game_socket[1] == NL_INVALID){ i = nlGetError(); switch(i){ case NL_NOT_LISTEN: allegro_message("NL_NOT_LISTEN\n"); nlClose(sock_server); return; case NL_NO_PENDING: /* allegro_message("NL_NO_PENDING\n");*/ break; case NL_WRONG_TYPE: allegro_message("NL_WRONG_TYPE\n"); nlClose(sock_server); return; default: allegro_message("ERROR i = 0x%X\n", i); //system("PAUSE"); } i = 0; // continue loop } else{ // Verify network connection and ProSonic version strcpy(talk_outgoing, "PROSONIC\n"); strcat(talk_outgoing, __DATE__); strcat(talk_outgoing, "\n"); strcat(talk_outgoing, __TIME__); nlWrite(game_socket[1], talk_outgoing, 30); i = 0; while(i == 0){ i = nlRead(game_socket[1], talk_incoming, 30); if(i == 30){ if(strcmp(talk_incoming, talk_outgoing) != 0){ allegro_message("ERROR: Client has incompatible version"); nlClose(game_socket[1]); return; } } else if(i != 0){ allegro_message("ERROR: Unexpected data recieved"); nlClose(game_socket[1]); return; } } for(i=0; i<64; i++) talk_incoming[i] = 0; for(i=0; i<64; i++) talk_outgoing[i] = 0; if(open_socket(&game_socket[0], 0, 727, "127.0.0.1") == 0){ //nlGroupAddSocket(prosonicnet, game_socket[0]); nlGroupAddSocket(prosonicnet, game_socket[1]); net_id[0] = 0; allegro_message("Connection successful!"); } else{ nlClose(game_socket[1]); return; } } } } void clientside_setup(){ sock_client = nlOpen(0, NL_RELIABLE); if(sock_client == NL_INVALID){ allegro_message("ERROR: Invalid socket!\n"); nlClose(sock_client); return; } prosonicnet = nlGroupCreate(); if(prosonicnet == NL_INVALID){ allegro_message("ERROR: Unable to create group!\n"); nlClose(sock_client); return; } nlGetAddrFromName(ip_input, &addr_client); nlSetAddrPort(&addr_client, port); //printf("Connecting...\n"); i=0; while(i==0){ if(nlConnect(sock_client, &addr_client) == NL_FALSE){ i = nlGetError(); switch(i){ case NL_INVALID_SOCKET: allegro_message("NL_INVALID_SOCKET\n"); nlClose(sock_client); return; case NL_NULL_POINTER: allegro_message("NL_NULL_POINTER\n"); nlClose(sock_client); return; case NL_SYSTEM_ERROR: allegro_message("NL_SYSTEM_ERROR: %s\n", nlGetSystemErrorStr(nlGetSystemError())); nlClose(sock_client); return; case NL_CON_REFUSED: allegro_message("NL_CON_REFUSED\n"); nlClose(sock_client); return; case NL_WRONG_TYPE: allegro_message("NL_WRONG_TYPE\n"); nlClose(sock_client); return; default: allegro_message("ERROR i = 0x%X\n", i); //system("PAUSE"); } i = 0; // continue loop } else{ // Verify network connection and ProSonic version strcpy(talk_outgoing, "PROSONIC\n"); strcat(talk_outgoing, __DATE__); strcat(talk_outgoing, "\n"); strcat(talk_outgoing, __TIME__); while(i==0){ i = nlRead(sock_client, talk_incoming, 30); if(i == 30){ if(strcmp(talk_incoming, talk_outgoing) != 0){ nlWrite(sock_client, talk_outgoing, 30); allegro_message("ERROR: Incompatible version"); nlClose(sock_client); return; } } else if(i != 0){ nlWrite(sock_client, talk_outgoing, 31); allegro_message("ERROR: Unexpected data recieved"); nlClose(sock_client); return; } } nlWrite(sock_client, talk_outgoing, 30); for(i=0; i<64; i++) talk_incoming[i] = 0; for(i=0; i<64; i++) talk_outgoing[i] = 0; nlGroupAddSocket(prosonicnet, sock_client); net_id[0] = 1; allegro_message("Connection successful!"); } } } #endif ////////// END ---- * NETWORK STUFF * ////////// ////////// START ---- * SOUND STUFF * ////////// // Move all sound code into a seperate file in the future // void ResetSound(){ fm_data_pos[0] = 0; fm_data_pos[1] = 0; fm_data_pos[2] = 0; fm_data_pos[3] = 0; pcm_data_pos[0][0] = 0; pcm_data_pos[1][0] = 0; pcm_data_pos[0][1] = 0; pcm_data_pos[1][1] = 0; pcm_data_pos[0][2] = 0; pcm_data_pos[1][2] = 0; pcm_data_pos[0][3] = 0; pcm_data_pos[1][3] = 0; } char PauseSound(){ short *temp; // This code will clear the buffer if the game is paused if(Game_paused && advance_frame == 0){ temp = (short*) get_audio_stream_buffer(stream); if(temp){ for( i = 0 ; i < 1470 ; i++ ) temp[i] = 0x8000; free_audio_stream_buffer(stream); } return 1; } return 0; } FUNCINLINE void ProcessSound(){ short *temp; short byte1=0; short byte2=0; short byte3=0; short byte4=0; double v; int audio_buffer_1[2][735]; int audio_buffer_2[2][735]; int audio_buffer_3[2][735]; int audio_buffer_4[2][735]; //int audio_buffer_1_used = (pcm_data_poll[0][0] || pcm_data_poll[1][0]); //int audio_buffer_2_used = (pcm_data_poll[0][1] || pcm_data_poll[1][1]); //int audio_buffer_3_used = (pcm_data_poll[0][2] || pcm_data_poll[1][2]); //int audio_buffer_4_used = (pcm_data_poll[0][3] || pcm_data_poll[1][3]); pcm_data_poll[0][0] = 0; pcm_data_poll[1][0] = 0; if(PauseSound()) return; // Voice 1 (BGM) RestoreYM2612(0); RestorePSG(0); if(!fm_data_pos[0]) StreamPCM(0, &pcm_data_pos[0][0], &pcm_data_pos[1][0], &pcm_data_poll[0][0], &pcm_data_poll[1][0], audio_buffer_1[0], audio_buffer_1[1]); else{ StreamFM(0, &fm_data_pos[0], audio_buffer_1[0], audio_buffer_1[1]); BackupYM2612(0); BackupPSG(0); } // Voice 2 RestoreYM2612(1); RestorePSG(1); if(!fm_data_pos[1]) StreamPCM(1, &pcm_data_pos[0][1], &pcm_data_pos[1][1], &pcm_data_poll[0][1], &pcm_data_poll[1][1], audio_buffer_2[0], audio_buffer_2[1]); else{ StreamFM(1, &fm_data_pos[1], audio_buffer_2[0], audio_buffer_2[1]); BackupYM2612(1); BackupPSG(1); } // Voice 3 RestoreYM2612(2); RestorePSG(2); if(!fm_data_pos[2]) StreamPCM(2, &pcm_data_pos[0][2], &pcm_data_pos[1][2], &pcm_data_poll[0][2], &pcm_data_poll[1][2], audio_buffer_3[0], audio_buffer_3[1]); else{ StreamFM(2, &fm_data_pos[2], audio_buffer_3[0], audio_buffer_3[1]); BackupYM2612(2); BackupPSG(2); } // Voice 4 RestoreYM2612(3); RestorePSG(3); if(!fm_data_pos[3]) StreamPCM(3, &pcm_data_pos[0][3], &pcm_data_pos[1][3], &pcm_data_poll[0][3], &pcm_data_poll[1][3], audio_buffer_4[0], audio_buffer_4[1]); else{ StreamFM(3, &fm_data_pos[3], audio_buffer_4[0], audio_buffer_4[1]); BackupYM2612(3); BackupPSG(3); } temp = (short*) get_audio_stream_buffer(stream); if(temp) { for( i = 0 ; i < 1470 ; i++ ){ byte1 = (short)(audio_buffer_1[i&1][i>>1]); byte2 = (short)(audio_buffer_2[i&1][i>>1]); byte3 = (short)(audio_buffer_3[i&1][i>>1]); byte4 = (short)(audio_buffer_4[i&1][i>>1]); byte1 *= ((float)(audio_volume+1) / 32); byte2 *= ((float)(audio_volume+1) / 32); byte3 *= ((float)(audio_volume+1) / 32); byte4 *= ((float)(audio_volume+1) / 32); if(smart_mix){ n = byte1 + byte2 + byte3 + byte4; //if(abs(n) > audio_peak) // audio_peak = n; // Compression level 0 if(n < 32768 && n > -32769){ mix_volume = 0; audio_compression = 0x10; } // Compression level 1 else if(n < 65536 && n > -65537){ mix_volume = -6.020600; audio_compression = 0x25; } // Compression level 2 else{ mix_volume = -9.542425; audio_compression = 0x3E; } // COMPRESSOR if(audio_compression != 0x10){ byte1 ^= 0x8000; v = byte1; if(v < 0) v = pow(10, (log10(-v / 32767) * (float)((float)audio_compression / 16))) * -32767; else if(v > 0) v = pow(10, (log10(v / 32767) * (float)((float)audio_compression / 16))) * 32767; byte1 = v; byte1 ^= 0x8000; byte2 ^= 0x8000; v = byte2; if(v < 0) v = pow(10, (log10(-v / 32767) * (float)((float)audio_compression / 16))) * -32767; else if(v > 0) v = pow(10, (log10(v / 32767) * (float)((float)audio_compression / 16))) * 32767; byte2 = v; byte2 ^= 0x8000; byte3 ^= 0x8000; v = byte3; if(v < 0) v = pow(10, (log10(-v / 32767) * (float)((float)audio_compression / 16))) * -32767; else if(v > 0) v = pow(10, (log10(v / 32767) * (float)((float)audio_compression / 16))) * 32767; byte3 = v; byte3 ^= 0x8000; byte4 ^= 0x8000; v = byte4; if(v < 0) v = pow(10, (log10(-v / 32767) * (float)((float)audio_compression / 16))) * -32767; else if(v > 0) v = pow(10, (log10(v / 32767) * (float)((float)audio_compression / 16))) * 32767; byte4 = v; byte4 ^= 0x8000; } // MIXER if(mix_volume != 0){ v = byte1; if(v < 0) v = pow(10, log10(-v / 32767) + (mix_volume / 20)) * -32767; else if(v > 0) v = pow(10, log10(v / 32767) + (mix_volume / 20)) * 32767; byte1 = v; v = byte2; if(v < 0) v = pow(10, log10(-v / 32767) + (mix_volume / 20)) * -32767; else if(v > 0) v = pow(10, log10(v / 32767) + (mix_volume / 20)) * 32767; byte2 = v; v = byte3; if(v < 0) v = pow(10, log10(-v / 32767) + (mix_volume / 20)) * -32767; else if(v > 0) v = pow(10, log10(v / 32767) + (mix_volume / 20)) * 32767; byte3 = v; v = byte4; if(v < 0) v = pow(10, log10(-v / 32767) + (mix_volume / 20)) * -32767; else if(v > 0) v = pow(10, log10(v / 32767) + (mix_volume / 20)) * 32767; byte4 = v; } } // Write the mix to the audio stream temp[i] = (int)(byte1 + byte2 + byte3 + byte4)^0x8000; } #ifdef AUDIO_REC_ENABLED RecordPCM(temp); #endif free_audio_stream_buffer(stream); } if(fm_fade_out[0]) fm_fader[0]++; if(fm_fade_out[1]) fm_fader[1]++; if(fm_fade_out[2]) fm_fader[2]++; if(fm_fade_out[3]) fm_fader[3]++; if(fm_fader[0] == 160){ PlayFM(0, 0, 0); } if(fm_fader[1] == 160){ PlayFM(0, 1, 0); } if(fm_fader[2] == 160){ PlayFM(0, 2, 0); } if(fm_fader[3] == 160){ PlayFM(0, 3, 0); } } FUNCINLINE void FadeOutFM(char buffer){ fm_fade_out[buffer] = 1; } void LoadFM(unsigned char file, const char *string, char type, char dac, char repeat){ char vgm_header[4]; gzFile *gzf; int gzc_buffer_size; int gzu_buffer_size; char *gzc_buffer; char *gzu_buffer; #ifdef ALLEGRO_DOS allegro_message("Loading FM file \"%s\"...\n", string); #endif if(string[0] == '\0'){ fm_data_type[file] = -1; fm_data_dac[file] = 0; fm_data_repeat[file] = 0; fm_data_address[file] = 0; fm_size += 4; if(fm_data == 0) fm_data = (char *)malloc(fm_size); else fm_data = (char *)realloc(fm_data, fm_size); } else{ ym_log_file = fopen(string, "rb"); if(ym_log_file == NULL){ allegro_message("Could not open file \"%s\"...\n", string); return; } fm_data_type[file] = type; fm_data_dac[file] = dac; fm_data_repeat[file] = repeat; fm_data_address[file] = fm_size; if(type == FM_TYPE_VGM){ // Read the header to see if it's compressed or not vgm_header[0] = getc(ym_log_file); vgm_header[1] = getc(ym_log_file); vgm_header[2] = getc(ym_log_file); vgm_header[3] = '\0'; } if(type == FM_TYPE_VGM && strcmp(vgm_header, "Vgm") != 0){ // The VGM file is compressed, so we must decompress it fseek(ym_log_file, 0, SEEK_END); gzc_buffer_size = ftell(ym_log_file); // record size of GZ file rewind(ym_log_file); gzc_buffer = (char *)malloc(gzc_buffer_size); fread(gzc_buffer, 1, gzc_buffer_size, ym_log_file); fclose(ym_log_file); n = gzc_buffer_size * 10; // guess at size of VGM file gzu_buffer_size = 0; gzu_buffer = (char *)malloc(n); gzf = gzopen(string, "rb"); i = gzread(gzf, gzu_buffer, n); gzu_buffer_size += i; while(i == n){ // As long as there's more to read, we keep resizing and reading gzu_buffer = (char *)realloc(gzu_buffer, gzu_buffer_size + i); i = gzread(gzf, &gzu_buffer[gzu_buffer_size], n); gzu_buffer_size += i; } gzclose(gzf); free(gzc_buffer); fm_size += (gzu_buffer_size+4); if(fm_data == 0) fm_data = (char *)malloc(fm_size); else fm_data = (char *)realloc(fm_data, fm_size); for(i=0; i < gzu_buffer_size; i++) fm_data[fm_offset+i] = gzu_buffer[i]; free(gzu_buffer); } else{ // The file is either a GYM, or an uncompressed VGM fseek(ym_log_file, 0, SEEK_END); fm_size += (ftell(ym_log_file)+4); if(fm_data == 0) fm_data = (char *)malloc(fm_size); else fm_data = (char *)realloc(fm_data, fm_size); rewind(ym_log_file); fread(&fm_data[fm_offset], 1, fm_size-4-fm_offset, ym_log_file); fclose(ym_log_file); } } fm_offset = fm_size-4; fm_data[fm_offset] = 0xFF; fm_data[fm_offset+1] = 'E'; fm_data[fm_offset+2] = 'O'; fm_data[fm_offset+3] = 'F'; fm_offset += 4; } void LoadPCM(unsigned char file, const char *string, char stereo, char repeat){ #ifdef ALLEGRO_DOS allegro_message("Loading PCM file \"%s\"...\n", string); #endif if(string[0] == '\0'){ pcm_data_address[file] = 0; pcm_data_format_stereo[file] = 0; pcm_data_repeat[file] = 0; pcm_size += 4; if(pcm_data == 0) pcm_data = (char *)malloc(pcm_size); else pcm_data = (char *)realloc(pcm_data, pcm_size); } else{ ym_log_file = fopen(string, "rb"); if(ym_log_file == NULL){ allegro_message("Could not open file \"%s\"...\n", string); return; } pcm_data_address[file] = pcm_size; pcm_data_format_stereo[file] = stereo; pcm_data_repeat[file] = repeat; fseek(ym_log_file, 0, SEEK_END); pcm_size += (ftell(ym_log_file)+4); if(pcm_data == 0) pcm_data = (char *)malloc(pcm_size); else pcm_data = (char *)realloc(pcm_data, pcm_size); rewind(ym_log_file); fread(&pcm_data[pcm_offset], 1, pcm_size-4-pcm_offset, ym_log_file); fclose(ym_log_file); } pcm_offset = pcm_size-4; pcm_data[pcm_offset] = 0xFF; pcm_data[pcm_offset+1] = 'E'; pcm_data[pcm_offset+2] = 'O'; pcm_data[pcm_offset+3] = 'F'; pcm_offset += 4; } void PlayFM(short sound, char buffer, char mix){ fm_fader[buffer] = 0; fm_fade_out[buffer] = 0; fm_reset[buffer] = 1; fm_track_number[buffer] = sound; fm_data_pos[buffer] = fm_data_address[sound]; fm_data_pos_start[buffer] = fm_data_address[sound]; fm_data_ch_repeat[buffer] = fm_data_repeat[sound]; fm_data_ch_type[buffer] = fm_data_type[sound]; if(fm_data_ch_type[buffer]){ // VGM file fm_data_pos_loop[buffer] = fm_data[fm_data_pos[buffer] + 0x1C] + (fm_data[fm_data_pos[buffer] + 0x1D] << 8) + (fm_data[fm_data_pos[buffer] + 0x1E] << 16) + (fm_data[fm_data_pos[buffer] + 0x1F] << 24); fm_data_pos[buffer] += 0x40; } } void PlayPCM(short sound, char buffer, char mix){ if(buffer < 0){ switch(mix){ case 1: // LEFT if(pcm_data_poll[0][1]){ if(pcm_data_poll[0][2]){ if(pcm_data_poll[0][3]){ pcm_data_pos[0][1] = pcm_data_address[sound] + 0x2C; pcm_data_poll[0][1] = sound; pcm_data_ch_repeat[0][1] = pcm_data_repeat[sound]; pcm_data_pos_start[0][1] = pcm_data_address[sound]; pcm_data_ch_format_stereo[0][1] = pcm_data_format_stereo[sound]; } else{ pcm_data_pos[0][3] = pcm_data_address[sound] + 0x2C; pcm_data_poll[0][3] = sound; pcm_data_ch_repeat[0][3] = pcm_data_repeat[sound]; pcm_data_pos_start[0][3] = pcm_data_address[sound]; pcm_data_ch_format_stereo[0][3] = pcm_data_format_stereo[sound]; } } else{ pcm_data_pos[0][2] = pcm_data_address[sound] + 0x2C; pcm_data_poll[0][2] = sound; pcm_data_ch_repeat[0][2] = pcm_data_repeat[sound]; pcm_data_pos_start[0][2] = pcm_data_address[sound]; pcm_data_ch_format_stereo[0][2] = pcm_data_format_stereo[sound]; } } else{ pcm_data_pos[0][1] = pcm_data_address[sound] + 0x2C; pcm_data_poll[0][1] = sound; pcm_data_ch_repeat[0][1] = pcm_data_repeat[sound]; pcm_data_pos_start[0][1] = pcm_data_address[sound]; pcm_data_ch_format_stereo[0][1] = pcm_data_format_stereo[sound]; } break; case 2: // RIGHT if(pcm_data_poll[1][1]){ if(pcm_data_poll[1][2]){ if(pcm_data_poll[1][2]){ pcm_data_pos[1][1] = pcm_data_address[sound] + 0x2C; pcm_data_poll[1][1] = sound; pcm_data_ch_repeat[1][1] = pcm_data_repeat[sound]; pcm_data_pos_start[1][1] = pcm_data_address[sound]; pcm_data_ch_format_stereo[1][1] = pcm_data_format_stereo[sound]; } else{ pcm_data_pos[1][3] = pcm_data_address[sound] + 0x2C; pcm_data_poll[1][3] = sound; pcm_data_ch_repeat[1][3] = pcm_data_repeat[sound]; pcm_data_pos_start[1][3] = pcm_data_address[sound]; pcm_data_ch_format_stereo[1][3] = pcm_data_format_stereo[sound]; } } else{ pcm_data_pos[1][2] = pcm_data_address[sound] + 0x2C; pcm_data_poll[1][2] = sound; pcm_data_ch_repeat[1][2] = pcm_data_repeat[sound]; pcm_data_pos_start[1][2] = pcm_data_address[sound]; pcm_data_ch_format_stereo[1][2] = pcm_data_format_stereo[sound]; } } else{ pcm_data_pos[1][1] = pcm_data_address[sound] + 0x2C; pcm_data_poll[1][1] = sound; pcm_data_ch_repeat[1][1] = pcm_data_repeat[sound]; pcm_data_pos_start[1][1] = pcm_data_address[sound]; pcm_data_ch_format_stereo[1][1] = pcm_data_format_stereo[sound]; } break; default: // STEREO if(pcm_data_poll[0][1] | pcm_data_poll[1][1]){ if(pcm_data_poll[0][2] | pcm_data_poll[1][2]){ if(pcm_data_poll[0][3] | pcm_data_poll[1][3]){ pcm_data_pos[0][1] = pcm_data_address[sound] + 0x2C; pcm_data_pos[1][1] = pcm_data_address[sound] + 0x2C; pcm_data_poll[0][1] = sound; pcm_data_poll[1][1] = sound; pcm_data_ch_repeat[0][1] = pcm_data_repeat[sound]; pcm_data_ch_repeat[1][1] = pcm_data_repeat[sound]; pcm_data_pos_start[0][1] = pcm_data_address[sound]; pcm_data_pos_start[1][1] = pcm_data_address[sound]; pcm_data_ch_format_stereo[0][1] = pcm_data_format_stereo[sound]; pcm_data_ch_format_stereo[1][1] = pcm_data_format_stereo[sound]; } else{ pcm_data_pos[0][3] = pcm_data_address[sound] + 0x2C; pcm_data_pos[1][3] = pcm_data_address[sound] + 0x2C; pcm_data_poll[0][3] = sound; pcm_data_poll[1][3] = sound; pcm_data_ch_repeat[0][3] = pcm_data_repeat[sound]; pcm_data_ch_repeat[1][3] = pcm_data_repeat[sound]; pcm_data_pos_start[0][3] = pcm_data_address[sound]; pcm_data_pos_start[1][3] = pcm_data_address[sound]; pcm_data_ch_format_stereo[0][3] = pcm_data_format_stereo[sound]; pcm_data_ch_format_stereo[1][3] = pcm_data_format_stereo[sound]; } } else{ pcm_data_pos[0][2] = pcm_data_address[sound] + 0x2C; pcm_data_pos[1][2] = pcm_data_address[sound] + 0x2C; pcm_data_poll[0][2] = sound; pcm_data_poll[1][2] = sound; pcm_data_ch_repeat[0][2] = pcm_data_repeat[sound]; pcm_data_ch_repeat[1][2] = pcm_data_repeat[sound]; pcm_data_pos_start[0][2] = pcm_data_address[sound]; pcm_data_pos_start[1][2] = pcm_data_address[sound]; pcm_data_ch_format_stereo[0][2] = pcm_data_format_stereo[sound]; pcm_data_ch_format_stereo[1][2] = pcm_data_format_stereo[sound]; } } else{ pcm_data_pos[0][1] = pcm_data_address[sound] + 0x2C; pcm_data_pos[1][1] = pcm_data_address[sound] + 0x2C; pcm_data_poll[0][1] = sound; pcm_data_poll[1][1] = sound; pcm_data_ch_repeat[0][1] = pcm_data_repeat[sound]; pcm_data_ch_repeat[1][1] = pcm_data_repeat[sound]; pcm_data_pos_start[0][1] = pcm_data_address[sound]; pcm_data_pos_start[1][1] = pcm_data_address[sound]; pcm_data_ch_format_stereo[0][1] = pcm_data_format_stereo[sound]; pcm_data_ch_format_stereo[1][1] = pcm_data_format_stereo[sound]; } } } else{ switch(mix){ case 1: pcm_data_pos[0][buffer] = pcm_data_address[sound] + 0x2C; pcm_data_poll[0][buffer] = sound; pcm_data_ch_repeat[0][buffer] = pcm_data_repeat[sound]; pcm_data_pos_start[0][buffer] = pcm_data_address[sound]; pcm_data_ch_format_stereo[0][buffer] = pcm_data_format_stereo[sound]; break; case 2: pcm_data_pos[1][buffer] = pcm_data_address[sound] + 0x2C; pcm_data_poll[1][buffer] = sound; pcm_data_ch_repeat[1][buffer] = pcm_data_repeat[sound]; pcm_data_pos_start[1][buffer] = pcm_data_address[sound]; pcm_data_ch_format_stereo[1][buffer] = pcm_data_format_stereo[sound]; break; default: pcm_data_pos[0][buffer] = pcm_data_address[sound] + 0x2C; pcm_data_pos[1][buffer] = pcm_data_address[sound] + 0x2C; pcm_data_poll[0][buffer] = sound; pcm_data_poll[1][buffer] = sound; pcm_data_ch_repeat[0][buffer] = pcm_data_repeat[sound]; pcm_data_ch_repeat[1][buffer] = pcm_data_repeat[sound]; pcm_data_pos_start[0][buffer] = pcm_data_address[sound]; pcm_data_pos_start[1][buffer] = pcm_data_address[sound]; pcm_data_ch_format_stereo[0][buffer] = pcm_data_format_stereo[sound]; pcm_data_ch_format_stereo[1][buffer] = pcm_data_format_stereo[sound]; } } } #ifdef AUDIO_REC_ENABLED void RecordPCM(short *sample_data){ int i; short sample1; short sample2; for(i=0; i < 735; i++){ sample1 = sample_data[i<<1] ^ 0x8000; sample2 = sample_data[(i<<1)+1] ^ 0x8000; fwrite(&sample1, 2, 1, pcm_out); fwrite(&sample2, 2, 1, pcm_out); } } #endif void StreamPCM(char ch, int *pos_left, int *pos_right, unsigned short *poll_left, unsigned short *poll_right, int *buffer_left, int *buffer_right){ int position_left; int position_right; position_left = *pos_left; position_right = *pos_right; for(i=0; i < 735; i++){ // LEFT STEREO if(pcm_data[position_left] == 0xFF && pcm_data[position_left+1] == 'E' && pcm_data[position_left+2] == 'O' && pcm_data[position_left+3] == 'F'){ if(pcm_data_ch_repeat[0][ch]){ position_left = pcm_data_pos_start[0][ch] + 0x2C; buffer_left[i] = pcm_data[position_left] + (pcm_data[position_left+1] << 8); position_left += (2 << pcm_data_ch_format_stereo[0][ch]); } else{ *poll_left = 0; buffer_left[i] = 0; // little optimization to write the end of the buffer with zeros if(position_left == position_right){ *poll_right = 0; while(i < 735){ buffer_left[i] = 0; buffer_right[i] = 0; i++; } } } } else{ buffer_left[i] = pcm_data[position_left] + (pcm_data[position_left+1] << 8); position_left += (2 << pcm_data_ch_format_stereo[0][ch]); } // RIGHT STEREO if(pcm_data[position_right] == 0xFF && pcm_data[position_right+1] == 'E' && pcm_data[position_right+2] == 'O' && pcm_data[position_right+3] == 'F'){ if(pcm_data_ch_repeat[1][ch]){ position_right = pcm_data_pos_start[1][ch] + 0x2C; buffer_right[i] = pcm_data[position_right] + (pcm_data[position_right+1] << 8); position_right += (2 << pcm_data_ch_format_stereo[1][ch]); } else{ *poll_right = 0; buffer_right[i] = 0; } } else{ buffer_right[i] = pcm_data[position_right+(2*pcm_data_ch_format_stereo[1][ch])] + (pcm_data[position_right+1+(2*pcm_data_ch_format_stereo[1][ch])] << 8); position_right += (2 << pcm_data_ch_format_stereo[1][ch]); } } *pos_left = position_left; *pos_right = position_right; } void StreamFM(char ch, int *pos, int *buffer_left, int *buffer_right){ int position; short byte; //FILE *bgm; //FILE *sfx; int tempbuf[2][735]; int *tempbufptr[2]; int tempdac; //int sound_vol; int i; char n; tempbufptr[0] = tempbuf[0]; tempbufptr[1] = tempbuf[1]; memset(tempbuf, 0, 2*735*sizeof(int)); // Erase tempbuf position = *pos; if(bgm_enable){ return; } if(fm_reset[ch] == 1){ fm_reset[ch] = 0; // Silence YM2612 and PSG YM2612_Write(0, 0x28); YM2612_Write(1, 0x00); // Channel 1 YM2612_Write(1, 0x01); // Channel 2 YM2612_Write(1, 0x02); // Channel 3 YM2612_Write(1, 0x04); // Channel 4 YM2612_Write(1, 0x05); // Channel 5 YM2612_Write(1, 0x06); // Channel 6 PSG_Write(0x9F); // Channel 1 PSG_Write(0xBF); // Channel 2 PSG_Write(0xDF); // Channel 3 PSG_Write(0xFF); // Channel 4 (noise) // Set DAC enable bit according to the track setting YM2612_Write(0, 0x2B); YM2612_Write(1, fm_data_dac[fm_track_number[ch]]); } if(fm_fade_out[ch]){ if(fm_fader[ch] == 0){ BackupVolume(); // PSG for(i=0; i < 6; i++){ BackupTL(i); // YM2612 YM2612_Write(0, 0x2B); YM2612_Write(1, 0); } } else if(fm_fader[ch] >> 2){ FadeVolumePSG(fm_fader[ch] >> 2); for(i=0; i < 6; i++){ n = GetALG(i); switch(n){ case 7: FadeVolumeYM2612(i, 0, fm_fader[ch] >> 2); case 6: case 5: FadeVolumeYM2612(i, 2, fm_fader[ch] >> 2); case 4: FadeVolumeYM2612(i, 1, fm_fader[ch] >> 2); case 3: case 2: case 1: case 0: FadeVolumeYM2612(i, 3, fm_fader[ch] >> 2); } } } } if(fm_data_ch_type[ch] == FM_TYPE_VGM){ // VGM file i=0; while(i < 735){ if(fm_data_wait[ch] > 0){ while(fm_data_wait[ch] > 0 && i < 735){ fm_data_wait[ch]--; PSG_Update(tempbufptr, 1); YM2612_Update(tempbufptr, 1); tempdac = (signed short)(fm_data_sample[ch]<<8); *tempbufptr[0] = (float)(*tempbufptr[0]) * FM_VOLUME; *tempbufptr[1] = (float)(*tempbufptr[1]) * FM_VOLUME; tempdac = (float)(tempdac) * DAC_VOLUME * GetDAC(ch); *tempbufptr[0] += tempdac; *tempbufptr[1] += tempdac; tempbufptr[0]++; tempbufptr[1]++; i++; } } else{ byte = fm_data[position]; switch(byte){ case 0x4F: // Game Gear PSG stereo // we simply ignore this position += 2; break; case 0x50: // PSG write PSG_Write(fm_data[position+1]); position += 2; break; case 0x52: // YM2612 port 0 write if(fm_data[position+1] == 0x2A){ // Write to the DAC fm_data_sample[ch] = (fm_data[position+2]^0x80); } else{ YM2612_Write(0, fm_data[position+1]); YM2612_Write(1, fm_data[position+2]); } position += 3; break; case 0x53: // YM2612 port 1 write YM2612_Write(2, fm_data[position+1]); YM2612_Write(3, fm_data[position+2]); position += 3; break; case 0x61: // Wait n samples (16-bit) fm_data_wait[ch] = fm_data[position+1] + (fm_data[position+2] << 8); position += 3; break; case 0x62: // Wait 735 samples fm_data_wait[ch] = 735; position++; break; case 0x63: // Wait 882 samples fm_data_wait[ch] = 882; position++; break; case 0x66: // EOF if(fm_data_ch_repeat[ch]){ if(fm_data_pos_loop[ch] != 0){ position = fm_data_pos_start[ch] + fm_data_pos_loop[ch] + 0x1C; fm_data_pos_dac[ch] = fm_data_address_dac[ch]; } else position = fm_data_pos_start[ch] + 0x40; i++; } else{ position = 0; fm_data_ch_type[ch] = -1; for(; i < 735; i++){ tempbuf[0][i] = 0; tempbuf[1][i] = 0; } } break; case 0x67: // Initialize data block fm_data_address_dac[ch] = position + 7; position += (7 + fm_data[position+3] + (fm_data[position+4] << 8) + (fm_data[position+5] << 16) + (fm_data[position+6] << 24)); fm_data_pos_dac[ch] = fm_data_address_dac[ch]; break; case 0xE0: // Data block seek fm_data_pos_dac[ch] = fm_data_address_dac[ch] + fm_data[position+1] + (fm_data[position+2] << 8) + (fm_data[position+3] << 16) + (fm_data[position+4] << 24); position += 5; break; default: if(byte >= 0x70 && byte < 0x80){ // Wait n+1 samples (4-bit) fm_data_wait[ch] = (byte & 0xF) + 1; position++; break; } if(byte >= 0x80 && byte < 0x90){ // YM2612 DAC write / wait n samples (4-bit) fm_data_sample[ch] = (fm_data[fm_data_pos_dac[ch]]^0x80); fm_data_pos_dac[ch]++; fm_data_wait[ch] = (byte & 0xF); position++; break; } allegro_message("ERROR: Unsupported VGM data 0x%02X found at 0x%06X", byte, position); i++; rest(250); position++; } } } for(i=0; i < 735; i++){ buffer_left[i] = tempbuf[0][i]; buffer_right[i] = tempbuf[1][i]; } } else if(fm_data_ch_type[ch] == FM_TYPE_GYM){ // GYM file byte = fm_data[position]; position++; if(byte == 0xFF && fm_data[position] == 'E' && fm_data[position+1] == 'O' && fm_data[position+2] == 'F'){ if(fm_data_ch_repeat[ch]){ for(i = 255; i >= 0; i--){ if(position+3 == fm_data_address[i+1]){ position = fm_data_address[i]; i = 0; } } byte = fm_data[position]; position++; } else{ position = 0; fm_data_ch_type[ch] = -1; for(i=0; i < 735; i++){ tempbuf[0][i] = 0; tempbuf[1][i] = 0; } } } while(byte > 0){ switch(byte){ case 1: YM2612_Write(0, fm_data[position]); YM2612_Write(1, fm_data[position+1]); position += 2; break; case 2: YM2612_Write(2, fm_data[position]); YM2612_Write(3, fm_data[position+1]); position += 2; break; case 3: PSG_Write(fm_data[position]); position++; } byte = fm_data[position]; position++; } PSG_Update(tempbufptr, 735); YM2612_Update(tempbufptr, 735); for(i=0; i < 735; i++){ buffer_left[i] = (float)(tempbuf[0][i]) * FM_VOLUME; buffer_right[i] = (float)(tempbuf[1][i]) * FM_VOLUME; } } else{ for(i=0; i < 735; i++){ buffer_left[i] = 0; buffer_right[i] = 0; } return; } *pos = position; } ////////// END ---- * SOUND STUFF * ////////// void LoadScripts(){ FILE *file_procode; int script_end; // used for PROCODE scripts short data_counter; // used for PROCODE scripts short data_order[256+8]; // used for PROCODE scripts char game_pc_file[1451]; free(script); script_size = 0; for(i=0; i < 256; i++) obj_script_size[i] = 0; //////////// MOTOROLA FILES //////////// //LoadBinary(0x03, "pswap.bin"); // * LoadBinary(0x06, "cscrew.bin"); // Emerald Hill / Metropolis LoadBinary(0x0D, "signpost.bin"); // * LoadBinary(0x11, "bridge.bin"); // Emerald Hill / Hidden Palace LoadBinary(0x1B, "speed.bin"); // Chemical Plant //LoadBinary(0x1E, "spintube.bin"); // Chemical Plant //LoadBinary(0x25, "ring.bin"); // * LoadBinary(0x3F, "fan.bin"); // Oil Ocean LoadBinary(0x79, "starpost.bin"); // * //////////// PROCODE FILES //////////// // This is code that can be used for a "static" executable //file_procode = fopen(program_filename, "rb"); //fseek(file_procode, -1451, SEEK_END); #ifdef ALLEGRO_DOS allegro_message("Loading ProCode script file \"game.pcs\"...\n"); #endif file_procode = fopen("game.pcs", "rb"); if(file_procode == NULL){ allegro_message("Could not open file \"game.pcs\". Program closing...\n"); quit(0); } fread(&i, 4, 1, file_procode); fread(&n, 4, 1, file_procode); // add checks for "PROCODE" string // add checks for version byte data_counter = 0; fread(&script_end, 4, 1, file_procode); while(data_counter >= 0){ data_order[data_counter] = 0; // DO NOT DELETE THIS LINE! data_order[data_counter] = getc(file_procode); if(data_order[data_counter] != 0){ // pointer for an object fread(&i, 4, 1, file_procode); obj_script_type[data_order[data_counter]] = SCRIPT_TYPE_PROCODE; obj_script_start[data_order[data_counter]] = script_size + i; // set size for previous object if(data_counter > 0){ if(data_order[data_counter-1] > 255){ game_script_size[data_order[data_counter-1] >> 8] = obj_script_start[data_order[data_counter]] - game_script_start[data_order[data_counter-1] >> 8]; } else{ obj_script_size[data_order[data_counter-1]] = obj_script_start[data_order[data_counter]] - obj_script_start[data_order[data_counter-1]]; } } data_counter++; } else{ // pointer for a generic function data_order[data_counter] = getc(file_procode); data_order[data_counter] <<= 8; if(data_order[data_counter] == 0){ // end of header game_script_start[data_order[data_counter] >> 8] = script_size + script_end; // set size for previous object if(data_counter > 0){ if(data_order[data_counter-1] > 255){ game_script_size[data_order[data_counter-1] >> 8] = game_script_start[data_order[data_counter] >> 8] - game_script_start[data_order[data_counter-1] >> 8]; } else{ obj_script_size[data_order[data_counter-1]] = game_script_start[data_order[data_counter] >> 8] - obj_script_start[data_order[data_counter-1]]; } } data_counter = -1; } else{ fread(&i, 4, 1, file_procode); game_script_start[data_order[data_counter] >> 8] = script_size + i; // set size for previous object if(data_counter > 0){ if(data_order[data_counter-1] > 255){ game_script_size[data_order[data_counter-1] >> 8] = game_script_start[data_order[data_counter] >> 8] - game_script_start[data_order[data_counter-1] >> 8]; } else{ obj_script_size[data_order[data_counter-1]] = game_script_start[data_order[data_counter] >> 8] - obj_script_start[data_order[data_counter-1]]; } } data_counter++; } } } script = (char*)realloc(script, script_size + script_end); for(i = script_size; i < (script_size + script_end); i++) script[i] = getc(file_procode); fclose(file_procode); script_size = i; internal_gvar_ptrs[0] = (int *)&a0; internal_gvar_ptrs[1] = (int *)&a1; internal_gvar_ptrs[2] = (int *)&a2; internal_gvar_ptrs[3] = (int *)&a3; internal_gvar_ptrs[4] = (int *)&a4; internal_gvar_ptrs[5] = (int *)&a5; internal_gvar_ptrs[6] = (int *)&a6; internal_gvar_ptrs[7] = (int *)&a7; internal_gvar_ptrs[8] = (int *)&d0; internal_gvar_ptrs[9] = (int *)&d1; internal_gvar_ptrs[10] = (int *)&d2; internal_gvar_ptrs[11] = (int *)&d3; internal_gvar_ptrs[12] = (int *)&d4; internal_gvar_ptrs[13] = (int *)&d5; internal_gvar_ptrs[14] = (int *)&d6; internal_gvar_ptrs[15] = (int *)&d7; internal_gvar_ptrs[16] = (int *)&mouse_z_previous; internal_gvar_ptrs[17] = (int *)&camera_mode; internal_gvar_ptrs[18] = (int *)&fade_count; internal_gvar_ptrs[19] = (int *)&edit_mode; internal_gvar_ptrs[20] = (int *)&edit_selector; internal_gvar_ptrs[21] = (int *)&edit_clipboard; internal_gvar_ptrs[22] = (int *)&smart_mix; internal_gvar_ptrs[23] = (int *)&advance_frame; internal_gvar_ptrs[24] = (int *)&Game_paused; internal_gvar_ptrs[25] = (int *)&DemoCount; internal_gvar_ptrs[26] = (int *)&DemoPosition; internal_gvar_ptrs[27] = (int *)&DemoFadeDelay; internal_gvar_ptrs[28] = (int *)&zone; internal_gvar_ptrs[29] = (int *)&act; internal_gvar_ptrs[30] = (int *)&stage; internal_gvar_ptrs[31] = (int *)&demo; internal_gvar_ptrs[32] = (int *)&demo_mode; internal_gvar_ptrs[33] = (int *)&frame_skip; internal_gvar_ptrs[34] = (int *)&draw_frame; internal_gvar_ptrs[35] = (int *)&screen_resolution_x; internal_gvar_ptrs[36] = (int *)&screen_resolution_y; internal_gvar_ptrs[37] = (int *)&screen_padding_x; internal_gvar_ptrs[38] = (int *)&screen_padding_y; internal_gvar_ptrs[39] = (int *)&screen_offset_x; internal_gvar_ptrs[40] = (int *)&screen_offset_y; internal_gvar_ptrs[41] = (int *)&screen_frame_x; internal_gvar_ptrs[42] = (int *)&screen_frame_y; internal_gvar_ptrs[43] = (int *)&screen_buffer_x; internal_gvar_ptrs[44] = (int *)&screen_buffer_y; internal_gvar_ptrs[45] = (int *)&screen_scale_x; internal_gvar_ptrs[46] = (int *)&screen_scale_y; internal_gvar_ptrs[47] = (int *)&screen_double_x; internal_gvar_ptrs[48] = (int *)&screen_double_y; //internal_gvar_ptrs[49] = (int *)&screen_interlace_x; //internal_gvar_ptrs[50] = (int *)&screen_interlace_y; internal_gvar_ptrs[51] = (int *)&vsync_enable; internal_gvar_ptrs[52] = (int *)&close_button_pressed; internal_gvar_ptrs[53] = (int *)&number_of_objects_in_memory; internal_gvar_ptrs[54] = (int *)&ticCounter60L; internal_gvar_ptrs[55] = (int *)&fps; internal_gvar_ptrs[56] = (int *)&show_fps; internal_gvar_ptrs[57] = (int *)&ticCounterL; internal_gvar_ptrs[58] = (int *)&ticCounterR; internal_gvar_ptrs[59] = (int *)&ticCounter60R; internal_gvar_ptrs[60] = (int *)&ticUpdated; internal_gvar_ptrs[61] = (int *)&waitCounter; //internal_gvar_ptrs[62] = (int *)&frames; internal_gvar_ptrs[63] = (int *)&num_of_players; internal_gvar_ptrs[64] = (int *)&num_of_frames; internal_gvar_ptrs[65] = (int *)&frame; internal_gvar_ptrs[66] = (int *)&Level_Inactive_flag; internal_gvar_ptrs[67] = (int *)&Timer_frames; internal_gvar_ptrs[68] = (int *)&Debug_object; internal_gvar_ptrs[69] = (int *)&Debug_placement_mode; internal_gvar_ptrs[70] = (int *)&Debug_mode_flag; internal_gvar_ptrs[71] = (int *)&Emerald_count; internal_gvar_ptrs[72] = (int *)&Continue_count; internal_gvar_ptrs[73] = (int *)&Time_Over_flag; internal_gvar_ptrs[74] = (int *)&Timer_frames; internal_gvar_ptrs[75] = (int *)&Timer_minute_word; internal_gvar_ptrs[76] = (int *)&Timer_minute; internal_gvar_ptrs[77] = (int *)&Timer_second; internal_gvar_ptrs[78] = (int *)&Timer_millisecond; internal_gvar_ptrs[79] = (int *)&titlecard_sequence_end; internal_gvar_ptrs[80] = (int *)key; // already a pointer by itself internal_gvar_ptrs[81] = (int *)&key_shifts; internal_gvar_ptrs[82] = (int *)&prompt; internal_gvar_ptrs[83] = (int *)&full_screen; internal_gvar_ptrs[84] = (int *)&audio_volume; internal_gvar_ptrs[85] = (int *)&show_version; internal_gvar_ptrs[86] = (int *)&show_watermark; internal_gvar_ptrs[87] = (int *)&Update_HUD_lives; internal_gvar_ptrs[88] = (int *)&Update_HUD_rings; internal_gvar_ptrs[89] = (int *)&Update_HUD_timer; internal_gvar_ptrs[90] = (int *)&Update_HUD_score; for(i=0; i < 4; i++){ internal_pvar_ptrs[i][0] = (int *)&player[i].character; internal_pvar_ptrs[i][1] = (int *)&player[i].sidekick; internal_pvar_ptrs[i][2] = (int *)&player[i].CtrlInput; internal_pvar_ptrs[i][3] = (int *)&player[i].render_flags; internal_pvar_ptrs[i][4] = (int *)&player[i].art_tile; internal_pvar_ptrs[i][5] = (int *)&player[i].x_pos; internal_pvar_ptrs[i][6] = (int *)&player[i].x_pos_pre; internal_pvar_ptrs[i][7] = (int *)&player[i].y_pos; internal_pvar_ptrs[i][8] = (int *)&player[i].y_pos_pre; internal_pvar_ptrs[i][9] = (int *)&player[i].x_vel; internal_pvar_ptrs[i][10] = (int *)&player[i].y_vel; internal_pvar_ptrs[i][11] = (int *)&player[i].inertia; internal_pvar_ptrs[i][12] = (int *)&player[i].x_radius; internal_pvar_ptrs[i][13] = (int *)&player[i].y_radius; internal_pvar_ptrs[i][14] = (int *)&player[i].priority; internal_pvar_ptrs[i][15] = (int *)&player[i].anim_frame_duration; internal_pvar_ptrs[i][16] = (int *)&player[i].anim_frame; internal_pvar_ptrs[i][17] = (int *)&player[i].anim; internal_pvar_ptrs[i][18] = (int *)&player[i].next_anim; internal_pvar_ptrs[i][19] = (int *)&player[i].status; internal_pvar_ptrs[i][20] = (int *)&player[i].routine; internal_pvar_ptrs[i][21] = (int *)&player[i].routine_secondary; internal_pvar_ptrs[i][22] = (int *)&player[i].angle; internal_pvar_ptrs[i][23] = (int *)&player[i].flip_angle; internal_pvar_ptrs[i][24] = (int *)&player[i].air_left; internal_pvar_ptrs[i][25] = (int *)&player[i].flip_turned; internal_pvar_ptrs[i][26] = (int *)&player[i].obj_control; internal_pvar_ptrs[i][27] = (int *)&player[i].status_secondary; internal_pvar_ptrs[i][28] = (int *)&player[i].flips_remaining; internal_pvar_ptrs[i][29] = (int *)&player[i].flip_speed; internal_pvar_ptrs[i][30] = (int *)&player[i].move_lock; internal_pvar_ptrs[i][31] = (int *)&player[i].invulnerable_time; internal_pvar_ptrs[i][32] = (int *)&player[i].invincibility_time; internal_pvar_ptrs[i][33] = (int *)&player[i].speedshoes_time; internal_pvar_ptrs[i][34] = (int *)&player[i].next_tilt; internal_pvar_ptrs[i][35] = (int *)&player[i].tilt; internal_pvar_ptrs[i][36] = (int *)&player[i].stick_to_convex; internal_pvar_ptrs[i][37] = (int *)&player[i].spindash_flag; internal_pvar_ptrs[i][38] = (int *)&player[i].spindash_counter; internal_pvar_ptrs[i][39] = (int *)&player[i].jumping; internal_pvar_ptrs[i][40] = (int *)&player[i].interact; internal_pvar_ptrs[i][41] = (int *)&player[i].layer; internal_pvar_ptrs[i][42] = (int *)&player[i].layer_plus; internal_pvar_ptrs[i][43] = (int *)&player[i].Sonic_top_speed; internal_pvar_ptrs[i][44] = (int *)&player[i].Sonic_acceleration; internal_pvar_ptrs[i][45] = (int *)&player[i].Sonic_deceleration; internal_pvar_ptrs[i][46] = (int *)&player[i].Ctrl_Held; internal_pvar_ptrs[i][47] = (int *)&player[i].Ctrl_Press; internal_pvar_ptrs[i][48] = (int *)&player[i].Ctrl_Held_Logical; internal_pvar_ptrs[i][49] = (int *)&player[i].Ctrl_Press_Logical; internal_pvar_ptrs[i][50] = (int *)&player[i].width_pixels; internal_pvar_ptrs[i][51] = (int *)&player[i].Sonic_Look_delay_counter; // Sonic_Stat_Record_Buf[128]; // Sonic_Pos_Record_Buf[128]; internal_pvar_ptrs[i][52] = (int *)&player[i].Camera_X_pos; internal_pvar_ptrs[i][53] = (int *)&player[i].Camera_Y_pos; internal_pvar_ptrs[i][54] = (int *)&player[i].Camera_Z_pos; internal_pvar_ptrs[i][55] = (int *)&player[i].Camera_Max_Y_pos; internal_pvar_ptrs[i][56] = (int *)&player[i].Camera_Min_X_pos; internal_pvar_ptrs[i][57] = (int *)&player[i].Camera_Max_X_pos; internal_pvar_ptrs[i][58] = (int *)&player[i].Camera_Min_Y_pos; internal_pvar_ptrs[i][59] = (int *)&player[i].Camera_Max_Y_pos_now; internal_pvar_ptrs[i][60] = (int *)&player[i].Camera_X_pos_coarse; internal_pvar_ptrs[i][61] = (int *)&player[i].Sonic_Pos_Record_Index; internal_pvar_ptrs[i][62] = (int *)&player[i].Camera_Y_pos_bias; internal_pvar_ptrs[i][63] = (int *)&player[i].Ring_count; internal_pvar_ptrs[i][64] = (int *)&player[i].Score; internal_pvar_ptrs[i][65] = (int *)&player[i].Life_count; internal_pvar_ptrs[i][66] = (int *)&player[i].Extra_life_flags; internal_pvar_ptrs[i][67] = (int *)&player[i].Last_star_pole_hit; internal_pvar_ptrs[i][68] = (int *)&player[i].Saved_Last_star_pole_hit; internal_pvar_ptrs[i][69] = (int *)&player[i].Saved_x_pos; internal_pvar_ptrs[i][70] = (int *)&player[i].Saved_y_pos; internal_pvar_ptrs[i][71] = (int *)&player[i].Saved_Ring_count; internal_pvar_ptrs[i][72] = (int *)&player[i].Saved_Timer; internal_pvar_ptrs[i][73] = (int *)&player[i].Saved_art_tile; internal_pvar_ptrs[i][74] = (int *)&player[i].Saved_layer; internal_pvar_ptrs[i][75] = (int *)&player[i].Saved_Camera_X_pos; internal_pvar_ptrs[i][76] = (int *)&player[i].Saved_Camera_Y_pos; internal_pvar_ptrs[i][77] = (int *)&player[i].Saved_Water_Level; internal_pvar_ptrs[i][78] = (int *)&player[i].Saved_Extra_life_flags; internal_pvar_ptrs[i][79] = (int *)&player[i].Saved_Extra_life_flags_2P; internal_pvar_ptrs[i][80] = (int *)&player[i].Saved_Camera_Max_Y_pos; internal_pvar_ptrs[i][81] = (int *)&player[i].Collision_addr; internal_pvar_ptrs[i][82] = (int *)&player[i].ram_EEB0; internal_pvar_ptrs[i][83] = (int *)&player[i].ram_EEB2; internal_pvar_ptrs[i][84] = (int *)&player[i].ram_EEBE; internal_pvar_ptrs[i][85] = (int *)&player[i].ram_EED0; internal_pvar_ptrs[i][86] = (int *)&player[i].ram_F65C; internal_pvar_ptrs[i][87] = (int *)&player[i].ram_F768; internal_pvar_ptrs[i][88] = (int *)&player[i].ram_F76A; internal_pvar_ptrs[i][89] = (int *)&player[i].ram_F7C7; } internal_gvar_size[0] = sizeof(a0); internal_gvar_size[1] = sizeof(a1); internal_gvar_size[2] = sizeof(a2); internal_gvar_size[3] = sizeof(a3); internal_gvar_size[4] = sizeof(a4); internal_gvar_size[5] = sizeof(a5); internal_gvar_size[6] = sizeof(a6); internal_gvar_size[7] = sizeof(a7); internal_gvar_size[8] = sizeof(d0); internal_gvar_size[9] = sizeof(d1); internal_gvar_size[10] = sizeof(d2); internal_gvar_size[11] = sizeof(d3); internal_gvar_size[12] = sizeof(d4); internal_gvar_size[13] = sizeof(d5); internal_gvar_size[14] = sizeof(d6); internal_gvar_size[15] = sizeof(d7); internal_gvar_size[16] = sizeof(mouse_z_previous); internal_gvar_size[17] = sizeof(camera_mode); internal_gvar_size[18] = sizeof(fade_count); internal_gvar_size[19] = sizeof(edit_mode); internal_gvar_size[20] = sizeof(edit_selector); internal_gvar_size[21] = sizeof(edit_clipboard); internal_gvar_size[22] = sizeof(smart_mix); internal_gvar_size[23] = sizeof(advance_frame); internal_gvar_size[24] = sizeof(Game_paused); internal_gvar_size[25] = sizeof(DemoCount); internal_gvar_size[26] = sizeof(DemoPosition); internal_gvar_size[27] = sizeof(DemoFadeDelay); internal_gvar_size[28] = sizeof(zone); internal_gvar_size[29] = sizeof(act); internal_gvar_size[30] = sizeof(stage); internal_gvar_size[31] = sizeof(demo); internal_gvar_size[32] = sizeof(demo_mode); internal_gvar_size[33] = sizeof(frame_skip); internal_gvar_size[34] = sizeof(draw_frame); internal_gvar_size[35] = sizeof(screen_resolution_x); internal_gvar_size[36] = sizeof(screen_resolution_y); internal_gvar_size[37] = sizeof(screen_padding_x); internal_gvar_size[38] = sizeof(screen_padding_y); internal_gvar_size[39] = sizeof(screen_offset_x); internal_gvar_size[40] = sizeof(screen_offset_y); internal_gvar_size[41] = sizeof(screen_frame_x); internal_gvar_size[42] = sizeof(screen_frame_y); internal_gvar_size[43] = sizeof(screen_buffer_x); internal_gvar_size[44] = sizeof(screen_buffer_y); internal_gvar_size[45] = sizeof(screen_scale_x); internal_gvar_size[46] = sizeof(screen_scale_y); internal_gvar_size[47] = sizeof(screen_double_x); internal_gvar_size[48] = sizeof(screen_double_y); //internal_gvar_size[49] = sizeof(screen_interlace_x); //internal_gvar_size[50] = sizeof(screen_interlace_y); internal_gvar_size[51] = sizeof(vsync_enable); internal_gvar_size[52] = sizeof(close_button_pressed); internal_gvar_size[53] = sizeof(number_of_objects_in_memory); internal_gvar_size[54] = sizeof(ticCounter60L); internal_gvar_size[55] = sizeof(fps); internal_gvar_size[56] = sizeof(show_fps); internal_gvar_size[57] = sizeof(ticCounterL); internal_gvar_size[58] = sizeof(ticCounterR); internal_gvar_size[59] = sizeof(ticCounter60R); internal_gvar_size[60] = sizeof(ticUpdated); internal_gvar_size[61] = sizeof(waitCounter); //internal_gvar_size[62] = sizeof(frames); internal_gvar_size[63] = sizeof(num_of_players); internal_gvar_size[64] = sizeof(num_of_frames); internal_gvar_size[65] = sizeof(frame); internal_gvar_size[66] = sizeof(Level_Inactive_flag); internal_gvar_size[67] = sizeof(Timer_frames); internal_gvar_size[68] = sizeof(Debug_object); internal_gvar_size[69] = sizeof(Debug_placement_mode); internal_gvar_size[70] = sizeof(Debug_mode_flag); internal_gvar_size[71] = sizeof(Emerald_count); internal_gvar_size[72] = sizeof(Continue_count); internal_gvar_size[73] = sizeof(Time_Over_flag); internal_gvar_size[74] = sizeof(Timer_frames); internal_gvar_size[75] = sizeof(Timer_minute_word); internal_gvar_size[76] = sizeof(Timer_minute); internal_gvar_size[77] = sizeof(Timer_second); internal_gvar_size[78] = sizeof(Timer_millisecond); internal_gvar_size[79] = sizeof(titlecard_sequence_end); internal_gvar_size[80] = sizeof(key[0]); internal_gvar_size[81] = sizeof(key_shifts); internal_gvar_size[82] = sizeof(prompt); internal_gvar_size[83] = sizeof(full_screen); internal_gvar_size[84] = sizeof(audio_volume); internal_gvar_size[85] = sizeof(show_version); internal_gvar_size[86] = sizeof(show_watermark); internal_gvar_size[87] = sizeof(Update_HUD_lives); internal_gvar_size[88] = sizeof(Update_HUD_rings); internal_gvar_size[89] = sizeof(Update_HUD_timer); internal_gvar_size[90] = sizeof(Update_HUD_score); internal_ovar_size[0] = 4; internal_ovar_size[1] = 1; internal_ovar_size[2] = 1; internal_ovar_size[3] = 1; internal_ovar_size[4] = 1; internal_ovar_size[5] = 1; internal_ovar_size[6] = 1; internal_ovar_size[7] = 2; internal_ovar_size[8] = 2; internal_ovar_size[9] = 1; internal_ovar_size[10] = 1; internal_ovar_size[11] = 1; internal_ovar_size[12] = 1; internal_ovar_size[13] = 1; internal_ovar_size[14] = 1; internal_ovar_size[15] = 1; internal_ovar_size[16] = 2; internal_ovar_size[17] = 1; internal_ovar_size[18] = 2; internal_ovar_size[19] = 2; internal_ovar_size[20] = 2; internal_ovar_size[21] = 2; internal_ovar_size[22] = 1; internal_ovar_size[23] = 1; internal_pvar_size[0] = sizeof(player[i].character); internal_pvar_size[1] = sizeof(player[i].sidekick); internal_pvar_size[2] = sizeof(player[i].CtrlInput); internal_pvar_size[3] = sizeof(player[i].render_flags); internal_pvar_size[4] = sizeof(player[i].art_tile); internal_pvar_size[5] = sizeof(player[i].x_pos); internal_pvar_size[6] = sizeof(player[i].x_pos_pre); internal_pvar_size[7] = sizeof(player[i].y_pos); internal_pvar_size[8] = sizeof(player[i].y_pos_pre); internal_pvar_size[9] = sizeof(player[i].x_vel); internal_pvar_size[10] = sizeof(player[i].y_vel); internal_pvar_size[11] = sizeof(player[i].inertia); internal_pvar_size[12] = sizeof(player[i].x_radius); internal_pvar_size[13] = sizeof(player[i].y_radius); internal_pvar_size[14] = sizeof(player[i].priority); internal_pvar_size[15] = sizeof(player[i].anim_frame_duration); internal_pvar_size[16] = sizeof(player[i].anim_frame); internal_pvar_size[17] = sizeof(player[i].anim); internal_pvar_size[18] = sizeof(player[i].next_anim); internal_pvar_size[19] = sizeof(player[i].status); internal_pvar_size[20] = sizeof(player[i].routine); internal_pvar_size[21] = sizeof(player[i].routine_secondary); internal_pvar_size[22] = sizeof(player[i].angle); internal_pvar_size[23] = sizeof(player[i].flip_angle); internal_pvar_size[24] = sizeof(player[i].air_left); internal_pvar_size[25] = sizeof(player[i].flip_turned); internal_pvar_size[26] = sizeof(player[i].obj_control); internal_pvar_size[27] = sizeof(player[i].status_secondary); internal_pvar_size[28] = sizeof(player[i].flips_remaining); internal_pvar_size[29] = sizeof(player[i].flip_speed); internal_pvar_size[30] = sizeof(player[i].move_lock); internal_pvar_size[31] = sizeof(player[i].invulnerable_time); internal_pvar_size[32] = sizeof(player[i].invincibility_time); internal_pvar_size[33] = sizeof(player[i].speedshoes_time); internal_pvar_size[34] = sizeof(player[i].next_tilt); internal_pvar_size[35] = sizeof(player[i].tilt); internal_pvar_size[36] = sizeof(player[i].stick_to_convex); internal_pvar_size[37] = sizeof(player[i].spindash_flag); internal_pvar_size[38] = sizeof(player[i].spindash_counter); internal_pvar_size[39] = sizeof(player[i].jumping); internal_pvar_size[40] = sizeof(player[i].interact); internal_pvar_size[41] = sizeof(player[i].layer); internal_pvar_size[42] = sizeof(player[i].layer_plus); internal_pvar_size[43] = sizeof(player[i].Sonic_top_speed); internal_pvar_size[44] = sizeof(player[i].Sonic_acceleration); internal_pvar_size[45] = sizeof(player[i].Sonic_deceleration); internal_pvar_size[46] = sizeof(player[i].Ctrl_Held); internal_pvar_size[47] = sizeof(player[i].Ctrl_Press); internal_pvar_size[48] = sizeof(player[i].Ctrl_Held_Logical); internal_pvar_size[49] = sizeof(player[i].Ctrl_Press_Logical); internal_pvar_size[50] = sizeof(player[i].width_pixels); internal_pvar_size[51] = sizeof(player[i].Sonic_Look_delay_counter); internal_pvar_size[52] = sizeof(player[i].Camera_X_pos); internal_pvar_size[53] = sizeof(player[i].Camera_Y_pos); internal_pvar_size[54] = sizeof(player[i].Camera_Z_pos); internal_pvar_size[55] = sizeof(player[i].Camera_Max_Y_pos); internal_pvar_size[56] = sizeof(player[i].Camera_Min_X_pos); internal_pvar_size[57] = sizeof(player[i].Camera_Max_X_pos); internal_pvar_size[58] = sizeof(player[i].Camera_Min_Y_pos); internal_pvar_size[59] = sizeof(player[i].Camera_Max_Y_pos_now); internal_pvar_size[60] = sizeof(player[i].Camera_X_pos_coarse); internal_pvar_size[61] = sizeof(player[i].Sonic_Pos_Record_Index); internal_pvar_size[62] = sizeof(player[i].Camera_Y_pos_bias); internal_pvar_size[63] = sizeof(player[i].Ring_count); internal_pvar_size[64] = sizeof(player[i].Score); internal_pvar_size[65] = sizeof(player[i].Life_count); internal_pvar_size[66] = sizeof(player[i].Extra_life_flags); internal_pvar_size[67] = sizeof(player[i].Last_star_pole_hit); internal_pvar_size[68] = sizeof(player[i].Saved_Last_star_pole_hit); internal_pvar_size[69] = sizeof(player[i].Saved_x_pos); internal_pvar_size[70] = sizeof(player[i].Saved_y_pos); internal_pvar_size[71] = sizeof(player[i].Saved_Ring_count); internal_pvar_size[72] = sizeof(player[i].Saved_Timer); internal_pvar_size[73] = sizeof(player[i].Saved_art_tile); internal_pvar_size[74] = sizeof(player[i].Saved_layer); internal_pvar_size[75] = sizeof(player[i].Saved_Camera_X_pos); internal_pvar_size[76] = sizeof(player[i].Saved_Camera_Y_pos); internal_pvar_size[77] = sizeof(player[i].Saved_Water_Level); internal_pvar_size[78] = sizeof(player[i].Saved_Extra_life_flags); internal_pvar_size[79] = sizeof(player[i].Saved_Extra_life_flags_2P); internal_pvar_size[80] = sizeof(player[i].Saved_Camera_Max_Y_pos); internal_pvar_size[81] = sizeof(player[i].Collision_addr); internal_pvar_size[82] = sizeof(player[i].ram_EEB0); internal_pvar_size[83] = sizeof(player[i].ram_EEB2); internal_pvar_size[84] = sizeof(player[i].ram_EEBE); internal_pvar_size[85] = sizeof(player[i].ram_EED0); internal_pvar_size[86] = sizeof(player[i].ram_F65C); internal_pvar_size[87] = sizeof(player[i].ram_F768); internal_pvar_size[88] = sizeof(player[i].ram_F76A); internal_pvar_size[89] = sizeof(player[i].ram_F7C7); } #ifdef ENABLE_LOGGING void TabLog(signed char tab){ logtab += tab; if(logtab < 0) logtab = 0; } void WriteLog(const char *string, ...){ if(logline < 100000){ msglog_tabs[logline] = logtab; strncpy(msglog[logline], string, 32); msglog[logline][31] = '\0'; logline++; } } void RamLog(unsigned short addr){ char string[32]; for(i=0; i < 64 && logline < 100000; i += 8){ sprintf( string, "\t%02X, %02X, %02X, %02X, %02X, %02X, %02X, %02X", ram_68k[0xFFFF - addr - i-0], ram_68k[0xFFFF - addr - i-1], ram_68k[0xFFFF - addr - i-2], ram_68k[0xFFFF - addr - i-3], ram_68k[0xFFFF - addr - i-4], ram_68k[0xFFFF - addr - i-5], ram_68k[0xFFFF - addr - i-6], ram_68k[0xFFFF - addr - i-7] ); if(string[0] == '\t'){ strncpy(msglog[logline], string, 32); msglog[logline][31] = '\0'; logline++; } } } void VarLog(short var){ char string[32]; if(logline < 100000){ switch(var){ // 68000 REGISTERS case REG_A0: sprintf(string, "a0 = 0x%08X", a0); break; case REG_A1: sprintf(string, "a1 = 0x%08X", a1); break; case REG_A2: sprintf(string, "a2 = 0x%08X", a2); break; case REG_A3: sprintf(string, "a3 = 0x%08X", a3); break; case REG_A4: sprintf(string, "a4 = 0x%08X", a4); break; case REG_A5: sprintf(string, "a5 = 0x%08X", a5); break; case REG_A6: sprintf(string, "a6 = 0x%08X", a6); break; case REG_A7: sprintf(string, "a7 = 0x%08X", a7); break; case REG_D0: sprintf(string, "d0 = 0x%08X", d0); break; case REG_D1: sprintf(string, "d1 = 0x%08X", d1); break; case REG_D2: sprintf(string, "d2 = 0x%08X", d2); break; case REG_D3: sprintf(string, "d3 = 0x%08X", d3); break; case REG_D4: sprintf(string, "d4 = 0x%08X", d4); break; case REG_D5: sprintf(string, "d5 = 0x%08X", d5); break; case REG_D6: sprintf(string, "d6 = 0x%08X", d6); break; case REG_D7: sprintf(string, "d7 = 0x%08X", d7); break; case REG_PC: sprintf(string, "pc = 0x%08X", pc); break; case REG_SR: sprintf(string, "sr = 0x%08X", sr); break; // VARIABLES case VAR_VAR_TEMP: sprintf(string, "var_temp = 0x%08X", var_temp); break; case VAR_ROUTINE: sprintf(string, "routine = 0x%02X", p->routine); break; case VAR_X_RADIUS: sprintf(string, "x_radius = 0x%02X", p->x_radius); break; case VAR_Y_RADIUS: sprintf(string, "y_radius = 0x%02X", p->y_radius); break; case VAR_X_POS: sprintf(string, "x_pos = 0x%04X", p->x_pos); break; case VAR_X_POS_PRE: sprintf(string, "x_pos_pre = 0x%04X", p->x_pos_pre); break; case VAR_Y_POS: sprintf(string, "y_pos = 0x%04X", p->y_pos); break; case VAR_Y_POS_PRE: sprintf(string, "y_pos_pre = 0x%04X", p->y_pos_pre); break; case VAR_X_VEL: sprintf(string, "x_vel = 0x%04X", p->x_vel); break; case VAR_Y_VEL: sprintf(string, "y_vel = 0x%04X", p->y_vel); break; case VAR_INERTIA: sprintf(string, "inertia = 0x%04X", p->inertia); break; case VAR_STATUS: sprintf(string, "status = 0x%02X", p->status); break; case VAR_ANGLE: sprintf(string, "angle = 0x%02X", p->angle); break; case VAR_ANIM: sprintf(string, "anim = 0x%02X", p->anim); break; case VAR_LAYER: sprintf(string, "layer = 0x%02X", p->layer); break; default: return; } msglog_tabs[logline] = logtab; msglog[logline][0] = '*'; msglog[logline][1] = ' '; strncpy(&msglog[logline][2], string, 30); msglog[logline][31] = '\0'; logline++; } } void RegLog(){ WriteLog("*****************"); VarLog(REG_A0); VarLog(REG_A1); VarLog(REG_A2); VarLog(REG_A3); VarLog(REG_A4); VarLog(REG_A5); VarLog(REG_A6); VarLog(REG_A7); VarLog(REG_D0); VarLog(REG_D1); VarLog(REG_D2); VarLog(REG_D3); VarLog(REG_D4); VarLog(REG_D5); VarLog(REG_D6); VarLog(REG_D7); WriteLog("*****************"); } void DumpLog(const char *string, ...){ int tab_space = 0x20202020; short endofline = 0x0A0D; short logy; char logx; FILE *dump; dump = fopen(string, "w+b"); for(logy=0; logy < logline; logy++){ for(logx=0; logx < msglog_tabs[logy]; logx++) fwrite(&tab_space, 4, 1, dump); for(logx=0; logx < 32; logx++){ if(msglog[logy][logx] == '\0'){ fwrite(&endofline, 2, 1, dump); break; } fwrite(&msglog[logy][logx], 1, 1, dump); } } fclose(dump); } void ResetLog(){ logline = 0; logtab = 0; } #ifdef ENABLE_SRAM_LOG_ANALYSIS void AnalyzeSRAM(){ int i; int problem; unsigned char prosonic_ram[64] = { 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, }; unsigned char ram_skip_table[64] = { // 9 means it should NOT be skipped, but is due to issues 1, 9, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 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, 9, 9, 9 }; unsigned char ram_conversion_table[64] = { 0x00, 0x01, 0x03, 0x02, 0x04, 0x05, 0x06, 0x07, 0x09, 0x08, 0x0B, 0x0A, 0x0D, 0x0C, 0x0F, 0x0E, 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2F, 0x2E, 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x36, 0x37, 0x38, 0x39, 0x3B, 0x3A, 0x3C, 0x3D, 0x3E, 0x3F }; char number_string_conversion[] = "0123456789ABCDEF"; char sram_frame_string[] = "sram_frame[0x00] = 0x00"; char prosonic_ram_string[] = "prosonic_ram[0x00] = 0x00"; prosonic_ram[0x01] = p->render_flags; // bit 1 always off (broken), turn off *(short *)&prosonic_ram[0x02] = p->art_tile; *(short *)&prosonic_ram[0x08] = p->x_pos; *(short *)&prosonic_ram[0x0A] = p->x_pos_pre; *(short *)&prosonic_ram[0x0C] = p->y_pos; *(short *)&prosonic_ram[0x0E] = p->y_pos_pre; *(short *)&prosonic_ram[0x10] = p->x_vel; *(short *)&prosonic_ram[0x12] = p->y_vel; *(short *)&prosonic_ram[0x14] = p->inertia; prosonic_ram[0x16] = p->y_radius; prosonic_ram[0x17] = p->x_radius; prosonic_ram[0x18] = p->priority; prosonic_ram[0x1B] = p->anim_frame; prosonic_ram[0x1C] = p->anim; prosonic_ram[0x1D] = p->next_anim; prosonic_ram[0x1E] = p->anim_frame_duration; prosonic_ram[0x22] = p->status; prosonic_ram[0x24] = p->routine; prosonic_ram[0x25] = p->routine_secondary; prosonic_ram[0x26] = p->angle; prosonic_ram[0x27] = p->flip_angle; prosonic_ram[0x28] = p->air_left; prosonic_ram[0x29] = p->flip_turned; prosonic_ram[0x2A] = p->obj_control; prosonic_ram[0x2B] = p->status_secondary; prosonic_ram[0x2C] = p->flips_remaining; prosonic_ram[0x2D] = p->flip_speed; *(short *)&prosonic_ram[0x2E] = p->move_lock; *(short *)&prosonic_ram[0x30] = p->invulnerable_time; *(short *)&prosonic_ram[0x32] = p->invincibility_time; *(short *)&prosonic_ram[0x34] = p->speedshoes_time; prosonic_ram[0x36] = p->next_tilt; prosonic_ram[0x37] = p->tilt; prosonic_ram[0x38] = p->stick_to_convex; prosonic_ram[0x39] = p->spindash_flag; *(short *)&prosonic_ram[0x3A] = p->spindash_counter; prosonic_ram[0x3C] = p->jumping; prosonic_ram[0x3D] = p->interact; // not yet used, turn off prosonic_ram[0x3E] = p->layer - 4; // not quite right, turn off prosonic_ram[0x3F] = p->layer_plus - 4; // not quite right, turn off problem = 0; for(i=0; i < 64; i++){ if(!ram_skip_table[i]){ n = ram_conversion_table[i]; if(sram_frame[i] != prosonic_ram[n]){ //allegro_message( //"sram_frame[0x%02X] = 0x%02X\nprosonic_ram[0x%02X] = 0x%02X", //i, sram_frame[i], i, prosonic_ram[n]); prosonic_ram_string[0x0F] = number_string_conversion[n >> 4]; prosonic_ram_string[0x10] = number_string_conversion[n & 0xF]; prosonic_ram_string[0x17] = number_string_conversion[prosonic_ram[n] >> 4]; prosonic_ram_string[0x18] = number_string_conversion[prosonic_ram[n] & 0xF]; sram_frame_string[0x0D] = number_string_conversion[i >> 4]; sram_frame_string[0x0E] = number_string_conversion[i & 0xF]; sram_frame_string[0x15] = number_string_conversion[sram_frame[i] >> 4]; sram_frame_string[0x16] = number_string_conversion[sram_frame[i] & 0xF]; WriteLog("\n"); if(!problem){ WriteLog("CALCULATION PROBLEMS:"); WriteLog("\n"); } WriteLog(prosonic_ram_string); WriteLog(sram_frame_string); problem++; } } } if(problem){ DumpLog("obj01.log"); if(problem == 1) allegro_message("A problem was discovered with 1 byte at frame 0x%X. A log file has been dumped.", ticCounterL); else allegro_message("Problems were discovered with %i bytes at frame 0x%X. A log file has been dumped.", problem, ticCounterL); rest(100); } } #endif #endif /* void LoadSavestate(const char *string, ...){ unsigned char ram[64]; int i; FILE *savestate; savestate = fopen(string, "rb"); if(savestate == NULL){ allegro_message("Cannot open savestate \"%s\".", string); return; } fseek(savestate, 0xD478, SEEK_SET); for(i = 0; i < 64; i++) fread(&ram[i], 1, 1, savestate); p->render_flags = ram[1]; p->art_tile = (ram[2] << 8) + ram[3]; p->x_pos = (ram[8] << 8) + ram[9]; p->x_pos_pre = (ram[0xA] << 8) + ram[0xB]; p->y_pos = (ram[0xC] << 8) + ram[0xD]; p->y_pos_pre = (ram[0xE] << 8) + ram[0xF]; p->x_vel = (ram[0x10] << 8) + ram[0x11]; p->y_vel = (ram[0x12] << 8) + ram[0x13]; p->inertia = (ram[0x14] << 8) + ram[0x15]; p->y_radius = ram[0x16]; p->x_radius = ram[0x17]; p->priority = ram[0x18]; p->anim_frame = ram[0x1B]; p->anim = ram[0x1C]; p->next_anim = ram[0x1D]; //p->anim_frame_duration = ram[0x1E]; p->status = ram[0x22]; p->routine = ram[0x24]; p->routine_secondary = ram[0x25]; p->angle = ram[0x26]; p->flip_angle = ram[0x27]; p->air_left = ram[0x28]; p->flip_turned = ram[0x29]; p->obj_control = ram[0x2A]; p->status_secondary = ram[0x2B]; p->flips_remaining = ram[0x2C]; p->flip_speed = ram[0x2D]; p->move_lock = (ram[0x2E] << 8) + ram[0x2F]; p->invulnerable_time = (ram[0x30] << 8) + ram[0x31]; p->invincibility_time = (ram[0x32] << 8) + ram[0x33]; p->speedshoes_time = (ram[0x34] << 8) + ram[0x35]; p->next_tilt = ram[0x36]; p->tilt = ram[0x37]; p->stick_to_convex = ram[0x38]; p->spindash_flag = ram[0x39]; p->spindash_counter = (ram[0x3A] << 8) + ram[0x3B]; p->jumping = ram[0x3C]; p->interact = ram[0x3D]; p->layer = ram[0x3E] + 4; p->layer_plus = ram[0x3F] + 4; fclose(savestate); } */ void FadeRGB(BITMAP *b){ unsigned short x; unsigned short y; int color_r; int color_g; int color_b; int new_color_r; int new_color_g; int new_color_b; if(fade_count < 0){ // Fade to black for(y=0; y < screen_resolution_y; y++){ for(x=16; x < screen_resolution_x+16; x++){ color_r = (unsigned short)(b->line[y][(x<<1)+1]<<8) + (unsigned short)(b->line[y][x<<1]); color_g = (color_r >> 6) & 31; color_b = color_r & 31; color_r >>= 11; // Fade color R if(color_r + fade_count <= 0) new_color_r = 0; else new_color_r = color_r + fade_count; if(new_color_r == 0){ // Fade color G if(color_g + color_r + fade_count <= 0) new_color_g = 0; else new_color_g = color_g + color_r + fade_count; if(new_color_g == 0){ // Fade color B if(color_b + color_g + color_r + fade_count <= 0) new_color_b = 0; else new_color_b = color_b + color_g + color_r + fade_count; } else new_color_b = color_b; } else{ new_color_g = color_g; new_color_b = color_b; } b->line[y][(x<<1)+1] = (new_color_r << 3) + (new_color_g >> 2); b->line[y][x<<1] = (new_color_g << 6) + new_color_b; } } } else{ // Fade to white for(y=0; y < screen_resolution_y; y++){ for(x=16; x < screen_resolution_x+16; x++){ color_r = (unsigned short)(b->line[y][(x<<1)+1]<<8) + (unsigned short)(b->line[y][x<<1]); color_g = (color_r >> 6) & 31; color_b = color_r & 31; color_r >>= 11; // Fade color R if(color_r + fade_count >= 31) new_color_r = 31; else new_color_r = color_r + fade_count; if(new_color_r == 31){ // Fade color G if(color_g + fade_count - (31-color_r) >= 31) new_color_g = 31; else new_color_g = color_g + fade_count - (31-color_r); if(new_color_g == 31){ // Fade color B if(color_b + fade_count - (31-color_r) + (31-color_g) >= 31) new_color_b = 31; else new_color_b = color_b + fade_count - (31-color_r) + (31-color_g); } else new_color_b = color_b; } else{ new_color_g = color_g; new_color_b = color_b; } b->line[y][(x<<1)+1] = (new_color_r << 3) + (new_color_g >> 2); b->line[y][x<<1] = (new_color_g << 6) + new_color_b; } } } } void TitleCard(){ int addr; int tc_size; int i; int n; if(titlecard_sequence_end) return; if(titlecard_counter[0] == 0xFF){ titlecard_file = fopen("tcard.dat", "rb"); if(titlecard_file == NULL){ allegro_message("Could not open file \"tcard.dat\". Program closing...\n"); quit(0); } fseek(titlecard_file, 0, SEEK_END); tc_size = ftell(titlecard_file); rewind(titlecard_file); if(titlecard_data) free(titlecard_data); titlecard_data = (char *)malloc(tc_size); fread(titlecard_data, 1, tc_size, titlecard_file); fclose(titlecard_file); for(i=0; i < titlecard_data[0]; i++){ titlecard_phase[i] = -1; titlecard_counter[i] = 0; titlecard_xpos[i] = (titlecard_data[(i<<3)+5] << 8) + titlecard_data[(i<<3)+6]; titlecard_ypos[i] = (titlecard_data[(i<<3)+7] << 8) + titlecard_data[(i<<3)+8]; } if(titlecard_data[0] > 0) fade_count = titlecard_xpos[0]; Update_HUD_timer = 0; } for(i=0; i < titlecard_data[0]; i++){ if(titlecard_counter[i] != 0xFF){ addr = (titlecard_data[(i<<3)+1] << 8) + titlecard_data[(i<<3)+2]; if(i == 0){ if(titlecard_counter[i] == 0){ titlecard_phase[i]++; titlecard_counter[i] = titlecard_data[addr+(titlecard_phase[i]*2)]; } if(titlecard_counter[i] != 0xFF){ titlecard_counter[i]--; titlecard_xpos[i] += (signed char)titlecard_data[addr+(titlecard_phase[i]*2)+1]; fade_count = titlecard_xpos[i]; } } else{ if(titlecard_counter[i] == 0){ titlecard_phase[i]++; titlecard_counter[i] = titlecard_data[addr+(titlecard_phase[i]*3)]; } if(titlecard_counter[i] != 0xFF){ titlecard_counter[i]--; titlecard_xpos[i] += (signed char)titlecard_data[addr+(titlecard_phase[i]*3)+1]; titlecard_ypos[i] += (signed char)titlecard_data[addr+(titlecard_phase[i]*3)+2]; switch(num_of_frames){ case 1: DrawSprite(&z, LayerB[frame-1], 0x103, titlecard_data[(i<<3)+3], NORMAL, titlecard_data[(i<<3)+4], titlecard_xpos[i]+16, titlecard_ypos[i]); break; case 2: DrawSprite(&z, LayerM, 0x103, titlecard_data[(i<<3)+3], NORMAL, titlecard_data[(i<<3)+4], titlecard_xpos[i]+16, titlecard_ypos[i]); DrawSprite(&z, LayerM, 0x103, titlecard_data[(i<<3)+3], NORMAL, titlecard_data[(i<<3)+4], titlecard_xpos[i]+16, titlecard_ypos[i]); break; case 3: DrawSprite(&z, LayerM, 0x103, titlecard_data[(i<<3)+3], NORMAL, titlecard_data[(i<<3)+4], titlecard_xpos[i]+16, titlecard_ypos[i]); DrawSprite(&z, LayerM, 0x103, titlecard_data[(i<<3)+3], NORMAL, titlecard_data[(i<<3)+4], titlecard_xpos[i]+16, titlecard_ypos[i]); DrawSprite(&z, LayerM, 0x103, titlecard_data[(i<<3)+3], NORMAL, titlecard_data[(i<<3)+4], titlecard_xpos[i]+16, titlecard_ypos[i]); break; case 4: DrawSprite(&z, LayerM, 0x103, titlecard_data[(i<<3)+3], NORMAL, titlecard_data[(i<<3)+4], titlecard_xpos[i]+16, titlecard_ypos[i]); DrawSprite(&z, LayerM, 0x103, titlecard_data[(i<<3)+3], NORMAL, titlecard_data[(i<<3)+4], titlecard_xpos[i]+16, titlecard_ypos[i]); DrawSprite(&z, LayerM, 0x103, titlecard_data[(i<<3)+3], NORMAL, titlecard_data[(i<<3)+4], titlecard_xpos[i]+16, titlecard_ypos[i]); DrawSprite(&z, LayerM, 0x103, titlecard_data[(i<<3)+3], NORMAL, titlecard_data[(i<<3)+4], titlecard_xpos[i]+16, titlecard_ypos[i]); } } } } } n=0; for(i=0; i < titlecard_data[0]; i++) n += titlecard_counter[i]; if(titlecard_data[0] * 0xFF == n){ titlecard_sequence_end = 1; free(titlecard_data); titlecard_data = 0; // DO NOT DELETE ME!! Prevents memory leaks! ticCounterL = 0; Update_HUD_timer = 1; } } void UpdateBlockLayout(ZONE *z){ // This function is used with the editing tools so any changes made to the // level layout will automatically update the COMPILED_MAP array. unsigned short x; unsigned short y; if(!COMPILED_MAP) return; for(y=0; y < blocks_y; y++){ for(x=0; x < blocks_x; x++) COMPILED_MAP[(y * blocks_x) + x] = ReadBlock(z, x<<4, y<<4); } } void CreateBlockLayout(ZONE *z){ // This function maps out all the 16x16 blocks into an array so they can be // quickly referenced without having to read the tile layout. It uses extra // memory, but it provides a performance boost. unsigned short x; unsigned short y; if(COMPILED_MAP) free(COMPILED_MAP); COMPILED_MAP = malloc(blocks_x * blocks_y * 4); for(y=0; y < blocks_y; y++){ for(x=0; x < blocks_x; x++) COMPILED_MAP[(y * blocks_x) + x] = ReadBlock(z, x<<4, y<<4); } if(COMPILED_BACKMAP) free(COMPILED_BACKMAP); COMPILED_BACKMAP = malloc(blocks_x * blocks_y * 2); for(y=0; y < blocks_y; y++){ for(x=0; x < blocks_x; x++) COMPILED_BACKMAP[(y * blocks_x) + x] = ReadBackBlock(z, x<<4, y<<4); } } int ReadBlock(ZONE *z, unsigned short x, unsigned short y){ unsigned short t; unsigned int b; // BMAP FORMAT // ////////uuuuuuus bptttttt fmBBBBBB BBBBBBBB OLD FORMAT! // ttttttuu uuuLbpBP fmNNNNNN NNNNNNNN // (NOTE: little endian!!) // // // (N) block number // (m) mirror // (f) flip // (P) platform (layer 1) // (B) barrier (layer 1) // (p) platform (layer 2) // (b) barrier (layer 2) // (L) plane // (u) undefined // (t) translucency x %= ((z->TMAP[tmap_ptr-2]+1) << (5+tilesize)); y %= ((z->TMAP[tmap_ptr-1]+1) << (5+tilesize)); t = ((x / (32 << tilesize)) + (y / (32 << tilesize) * tiles_x_long)) << 1; t = *(short *)(&z->TMAP[tmap_ptr+t]); b = (((x & ((32 << tilesize) - 1)) >> 4) + (((y & ((32 << tilesize) - 1)) >> 4) * (2 << tilesize))) << 2; b = *(int *)(&z->BMAP[bmap_ptr + b + ((((2 << tilesize) * (2 << tilesize)) << 2) * t)]); return b; } short ReadBackBlock(ZONE *z, unsigned short x, unsigned short y){ unsigned short t; unsigned int b; // BMAP FORMAT // ////////uuuuuuus bptttttt fmBBBBBB BBBBBBBB OLD FORMAT! // ttttttuu uuuLbpBP fmNNNNNN NNNNNNNN // (NOTE: little endian!!) // // // (N) block number // (m) mirror // (f) flip // (P) platform (layer 1) // (B) barrier (layer 1) // (p) platform (layer 2) // (b) barrier (layer 2) // (L) plane // (u) undefined // (t) translucency x %= ((z->TMAP[tmap_ptr-2]+1) << (5+tilesize)); y %= ((z->TMAP[tmap_ptr-1]+1) << (5+tilesize)); x += (blocks_x<<4); t = ((x / (32 << tilesize)) + (y / (32 << tilesize) * tiles_x_long)) << 1; t = *(short *)(&z->TMAP[tmap_ptr+t]); b = (((x & ((32 << tilesize) - 1)) >> 4) + (((y & ((32 << tilesize) - 1)) >> 4) * (2 << tilesize))) << 2; b = *(short *)(&z->BMAP[bmap_ptr + b + ((((2 << tilesize) * (2 << tilesize)) << 2) * t)]); return b; } int Pause(){ if(p->Life_count == 0){ Game_paused = 0; return 0; } if(p->Ctrl_Press & 0x80){ Game_paused ^= 1; return Game_paused; } if(Game_paused){ #ifdef ENABLE_LOGGING if(p->Ctrl_Press & 0x40){ DumpLog("obj01.log"); } #endif if(p->Ctrl_Held & 0x10){ if(p->Ctrl_Press & 0x10) p->Ctrl_Press ^= 0x10; advance_frame ^= 1; return advance_frame ^ 1; } if(p->Ctrl_Press & 0x20){ p->Ctrl_Press ^= 0x20; advance_frame ^= 1; return advance_frame ^ 1; } if(advance_frame == 1) advance_frame = 0; } return Game_paused; } int main(int argc, char **argv) { // Copy program filename i = strlen(argv[0]) + 1; program_filename = (char *)malloc(i); strcpy(program_filename, argv[0]); // Copy IP address #ifndef ALLEGRO_DOS if(argc > 1) strcpy(ip_input, argv[1]); else strcpy(ip_input, "127.0.0.1"); #endif // Required // #ifdef ALLEGRO_DOS printf("Initializing Allegro...\n"); #endif if(allegro_init() != 0){ #ifdef ALLEGRO_DOS printf("Error: allegro_init() has failed!"); #endif return 0; } #ifdef ALLEGRO_DOS allegro_message("Installing keyboard...\n"); #endif if(install_keyboard() != 0){ allegro_message("Error: install_keyboard() has failed!"); allegro_exit(); return 0; } #ifdef ALLEGRO_DOS allegro_message("Installing timer...\n"); #endif if(install_timer() != 0){ allegro_message("Error: install_timer() has failed!"); allegro_exit(); return 0; } #ifndef ALLEGRO_DOS if(nlInit() == NL_FALSE){ allegro_message("Error: nlInit() has failed!"); allegro_exit(); return 0; } nlSelectNetwork(NL_IP); #endif #ifdef ENABLE_MOUSE #ifdef ALLEGRO_DOS allegro_message("Installing mouse...\n"); #endif if(install_mouse() < 0){ // positive numbers and zero both pass allegro_message("Warning: install_mouse() has failed!"); } #endif p = &player[0]; // Just to be safe // for(i=0; i<4; i++){ LayerB[i] = 0; LayerL[i] = 0; LayerH[i] = 0; LayerSH[i] = 0; } LayerM = 0; // Fix for Mac port (must create window before using dialog boxes) #ifndef ALLEGRO_DOS set_color_depth(16); screen_resolution_x = 320; screen_resolution_y = 224; screen_padding_x = 0; screen_padding_y = 16; screen_double_x = 0; screen_double_y = 0; full_screen = 0; screen_offset_x = screen_padding_x >> 1; screen_offset_y = screen_padding_y >> 1; SetGfxModeWindow(); #endif #ifdef ALLEGRO_DOS system("CLS"); allegro_message("\nSelect number of players:\n\n" "Press 1 for single player\n" "Press 2 for two players\n" "Press 3 for three players\n" "Press 4 for four players\n"); #else allegro_message("Click OK, and then select number of players:\n\n" "Press 1 for single player\n" "Press 2 for two players\n" "Press 3 for three players\n" "Press 4 for four players\n"); #endif while(!key[KEY_1] && !key[KEY_2] && !key[KEY_3] && !key[KEY_4]); if(key[KEY_1]) num_of_frames = 1; if(key[KEY_2]) num_of_frames = 2; if(key[KEY_3]) num_of_frames = 3; if(key[KEY_4]) num_of_frames = 4; set_config_file("setup.cfg"); strcpy(config_section[0], "1_player"); strcpy(config_section[1], "2_player"); strcpy(config_section[2], "3_player"); strcpy(config_section[3], "4_player"); #ifdef ALLEGRO_DOS allegro_message("\nReading configuration file...\n"); #endif #ifdef ALLEGRO_LINUX // We want it to default to "DIGI_ESD" on Linux due to issues with PulseAudio digi_card = get_config_int(config_section[num_of_frames-1], "digi_card", DIGI_ESD); #else digi_card = get_config_int(config_section[num_of_frames-1], "digi_card", DIGI_AUTODETECT); #endif audio_volume = get_config_int(config_section[num_of_frames-1], "audio_volume", 0x1F); smart_mix = get_config_int(config_section[num_of_frames-1], "smart_mix", 1); vsync_enable = get_config_int(config_section[num_of_frames-1], "vsync_enable", 0); frame_skip = get_config_int(config_section[num_of_frames-1], "frame_skip", 0); screen_resolution_x = get_config_int(config_section[num_of_frames-1], "screen_resolution_x", 320); screen_resolution_y = get_config_int(config_section[num_of_frames-1], "screen_resolution_y", 224); screen_padding_x = get_config_int(config_section[num_of_frames-1], "screen_padding_x", 0); screen_padding_y = get_config_int(config_section[num_of_frames-1], "screen_padding_y", 16); screen_double_x = get_config_int(config_section[num_of_frames-1], "screen_double_x", 0); screen_double_y = get_config_int(config_section[num_of_frames-1], "screen_double_y", 0); full_screen = get_config_int(config_section[num_of_frames-1], "full_screen", 0); key_bind[0].bind_up = get_config_int(config_section[0], "bind_up", 84); key_bind[0].bind_down = get_config_int(config_section[0], "bind_down", 85); key_bind[0].bind_left = get_config_int(config_section[0], "bind_left", 82); key_bind[0].bind_right = get_config_int(config_section[0], "bind_right", 83); key_bind[0].bind_b = get_config_int(config_section[0], "bind_b", 19); key_bind[0].bind_c = get_config_int(config_section[0], "bind_c", 4); key_bind[0].bind_a = get_config_int(config_section[0], "bind_a", 1); key_bind[0].bind_start = get_config_int(config_section[0], "bind_start", 67); for(i=1; i < 4; i++){ key_bind[i].bind_up = get_config_int(config_section[i], "bind_up", 0); key_bind[i].bind_down = get_config_int(config_section[i], "bind_down", 0); key_bind[i].bind_left = get_config_int(config_section[i], "bind_left", 0); key_bind[i].bind_right = get_config_int(config_section[i], "bind_right", 0); key_bind[i].bind_b = get_config_int(config_section[i], "bind_b", 0); key_bind[i].bind_c = get_config_int(config_section[i], "bind_c", 0); key_bind[i].bind_a = get_config_int(config_section[i], "bind_a", 0); key_bind[i].bind_start = get_config_int(config_section[i], "bind_start", 0); } // Optional // #ifdef ALLEGRO_DOS allegro_message("Installing sound...\n"); #endif if(install_sound(digi_card, MIDI_NONE, NULL) != 0){ allegro_message("Warning: install_sound() has failed!"); #ifdef ALLEGRO_DOS allegro_message("\n"); #endif } set_volume(255, 0); set_volume_per_voice(0); audio_compression = 0x10; // 1:1 ratio //audio_volume = 0x1F; // Initialize network variables #ifndef ALLEGRO_DOS sock_server = NL_INVALID; sock_client = NL_INVALID; game_socket[0] = NL_INVALID; game_socket[1] = NL_INVALID; game_socket[2] = NL_INVALID; game_socket[3] = NL_INVALID; prosonicnet = NL_INVALID; port = 727; #endif num_of_messages = 4; message_time_limit = 10 * 60; // 10 seconds message = (char *)malloc(64 * (num_of_messages+1)); // +1 for overhead message_time = (short *)malloc(2 * (num_of_messages+1)); for(i=0; i <= num_of_messages; i++) message_time[i] = 0; #ifndef ALLEGRO_DOS /*if(num_of_frames > 1){ allegro_message("Select multiplayer mode:\n\n" "Press 0 for offline\n" "Press 1 for netplay (server)\n" "Press 2 for netplay (client)\n"); while(!key[KEY_0] && !key[KEY_1] && !key[KEY_2]); if(key[KEY_0]){ net_type = NET_TYPE_OFFLINE; } else{ if(key[KEY_1]){ net_type = NET_TYPE_SERVER; serverside_setup(); } if(key[KEY_2]){ net_type = NET_TYPE_CLIENT; clientside_setup(); } } }*/ #endif fm_offset = 0; fm_size = 0; fm_data = 0; fm_data_pos[0] = 0; fm_data_pos[1] = 0; fm_data_pos[2] = 0; fm_data_pos[3] = 0; LoadFM(0x00, "", 0, 0, 0); LoadFM(0x01, "ehz.vgz", FM_TYPE_VGM, FM_DAC_ON, FM_REPEAT_ON); LoadFM(0x02, "mcz2.vgz", FM_TYPE_VGM, FM_DAC_ON, FM_REPEAT_ON); LoadFM(0x03, "launch.vgz", FM_TYPE_VGM, FM_DAC_ON, FM_REPEAT_ON); LoadFM(0x04, "crystegg.vgz", FM_TYPE_VGM, FM_DAC_ON, FM_REPEAT_ON); LoadFM(0x1A, "endofact.vgz", FM_TYPE_VGM, FM_DAC_ON, FM_REPEAT_OFF); LoadFM(0x20, "jump.vgz", FM_TYPE_VGM, FM_DAC_OFF, FM_REPEAT_OFF); LoadFM(0x21, "starpost.vgz", FM_TYPE_VGM, FM_DAC_OFF, FM_REPEAT_OFF); LoadFM(0x23, "pain.vgz", FM_TYPE_VGM, FM_DAC_OFF, FM_REPEAT_OFF); LoadFM(0x24, "brake.vgz", FM_TYPE_VGM, FM_DAC_OFF, FM_REPEAT_OFF); LoadFM(0x3C, "blastoff.vgz", FM_TYPE_VGM, FM_DAC_OFF, FM_REPEAT_OFF); LoadFM(0x3E, "spin.vgz", FM_TYPE_VGM, FM_DAC_OFF, FM_REPEAT_OFF); LoadFM(0x4C, "spring.vgz", FM_TYPE_VGM, FM_DAC_OFF, FM_REPEAT_OFF); LoadFM(0x4F, "sign1.vgz", FM_TYPE_VGM, FM_DAC_OFF, FM_REPEAT_OFF); // signpost spin LoadFM(0x53, "starpost.vgz", FM_TYPE_VGM, FM_DAC_OFF, FM_REPEAT_OFF); // signpost spin (2P) LoadFM(0x60, "spindash.vgz", FM_TYPE_VGM, FM_DAC_OFF, FM_REPEAT_OFF); pcm_offset = 0; pcm_size = 0; pcm_data = 0; pcm_data_pos[0][0] = 0; pcm_data_pos[0][1] = 0; pcm_data_pos[0][2] = 0; pcm_data_pos[0][3] = 0; pcm_data_pos[1][0] = 0; pcm_data_pos[1][1] = 0; pcm_data_pos[1][2] = 0; pcm_data_pos[1][3] = 0; LoadPCM(0x00, "", 0, 0); LoadPCM(0x35, "ring.wav", PCM_TYPE_MONO, PCM_REPEAT_OFF); #ifdef ALLEGRO_DOS allegro_message("Initializing YM2612...\n"); #endif YM2612_Init(7670453, 44100, 1 ); #ifdef ALLEGRO_DOS allegro_message("Initializing PSG...\n"); #endif PSG_Init(3579545, 44100); stream = play_audio_stream(735, 16, 1, 44100, 255, 128); if(!stream) quit(0); BackupYM2612(0); BackupYM2612(1); BackupYM2612(2); BackupYM2612(3); BackupPSG(0); BackupPSG(1); BackupPSG(2); BackupPSG(3); mix_volume = 0; #ifdef AUDIO_REC_ENABLED pcm_out = fopen("output.wav", "wb"); i = 0x46464952; // "RIFF" fwrite(&i, 4, 1, pcm_out); i = 0; // reserved for (size - 0x8) fwrite(&i, 4, 1, pcm_out); i = 0x45564157; // "WAVE" fwrite(&i, 4, 1, pcm_out); i = 0x20746D66; // "fmt " fwrite(&i, 4, 1, pcm_out); i = 0x10; fwrite(&i, 4, 1, pcm_out); i = 0x20001; fwrite(&i, 4, 1, pcm_out); i = 0xAC44; fwrite(&i, 4, 1, pcm_out); i = 0x2B110; fwrite(&i, 4, 1, pcm_out); i = 0x100004; fwrite(&i, 4, 1, pcm_out); i = 0x61746164; // "data" fwrite(&i, 4, 1, pcm_out); i = 0; // reserved for (size - 0x2C) fwrite(&i, 4, 1, pcm_out); #endif LoadFont0(); InitLevelSelect(); SpriteTable = 0; // Needed to prevent memory leaks SpriteTableSize = 0; LoadSprite(0x101, "url.psf"); LoadSprite(0x102, "panel.psf"); LoadSprite(0x103, "tcard.psf"); LoadSprite(0x104, "font1.psf"); LoadSprite(0x105, "hud.psf"); LoadSprite(0x00, "sonic.psf"); LoadSprite(0x11, "sonic.psf"); LoadSprite(0x25, "ring.psf"); LoadScripts(); for(i=0; i < 10; i++){ strcpy(demo_file_list[i], "demo"); demo_file_list[i][4] = i + 0x30; strcpy(&demo_file_list[i][5], ".psd"); #ifdef ENABLE_SRAM_LOG_ANALYSIS strcpy(sram_file_list[i], "demo"); sram_file_list[i][4] = i + 0x30; strcpy(&sram_file_list[i][5], ".srm"); #endif } demo_number = 0; demo_mode = 0; DemoPosition = 0; DemoFile = NULL; DemoFadeDelay = 3; // "3" for Sonic 1-2, "1" for Sonic 3 frame = 1; ticCounter60L = 0; // Logic ticCounterR = 0; // Real-time ticCounter60R = 0; // Real-time ticUpdated = 0; LOCK_VARIABLE(ticUpdated); LOCK_VARIABLE(ticCounterR); LOCK_VARIABLE(ticCounter60R); LOCK_VARIABLE(ticCounter60L); LOCK_VARIABLE(fps); LOCK_VARIABLE(waitCounter); LOCK_FUNCTION(TicUpdate); install_int_ex(&TicUpdate, BPS_TO_TIMER(60)); set_color_depth(16); screen_offset_x = screen_padding_x >> 1; screen_offset_y = screen_padding_y >> 1; if(full_screen) SetGfxModeFull(); else SetGfxModeWindow(); #ifdef ENABLE_MOUSE show_mouse(screen); #endif close_button_pressed = FALSE; #ifndef ALLEGRO_DOS LOCK_FUNCTION(close_button_handler); set_close_button_callback(close_button_handler); #endif //LOCK_VARIABLE(fm_data_pos); //LOCK_FUNCTION(StreamFM); //LOCK_FUNCTION(ProcessSound); //install_int_ex(&ProcessSound, BPS_TO_TIMER(60)); fade_count = -96; titlecard_counter[0] = 0xFF; // required to start TitleCard() for(i=0; i < 256; i++){ strcpy(zone_file_list[i], "zone"); zone_file_list[i][4] = (i / 100) + 0x30; zone_file_list[i][5] = ((i / 10) % 10) + 0x30; zone_file_list[i][6] = (i % 10) + 0x30; strcpy(&zone_file_list[i][7], ".pzf"); } CreateZone(&z); zone = 0; act = 0; stage = 0; Level_Inactive_flag = 1; LoadZone(&z, zone_file_list[zone]); InitDraw(&z); AllocateObjects(&z); CreateBlockLayout(&z); strcpy(TextBuffer, "ProSonic - "); strcat(TextBuffer, (&z)->LevelName1); strcat(TextBuffer, " ZONE"); set_window_title(TextBuffer); // SET UP THE CELL DATA num_of_cells = z.FILTERCOMPOSITE[0]; num_of_filters = z.FILTERCOMPOSITE[1]; cells_ptr = *(short *)&z.FILTERCOMPOSITE[2]; filters_ptr = *(short *)&z.FILTERCOMPOSITE[4]; bg_rgb_color = *(short *)&z.FILTERCOMPOSITE[6]; filter_a = z.FILTERCOMPOSITE[8]; filter_b = z.FILTERCOMPOSITE[9]; filter_a_speed = z.FILTERCOMPOSITE[10]; filter_b_speed = z.FILTERCOMPOSITE[11]; cell_data = (CELL*)(&z.FILTERCOMPOSITE[cells_ptr]); for(i=0; i < 4; i++){ player[i].status = 0; player[i].layer = 0x10; player[i].Life_count = 3; player[i].x_pos = z.Act[act].Stage[stage].StartX[0]; player[i].y_pos = z.Act[act].Stage[stage].StartY[0]; player[i].Camera_X_pos = player[i].x_pos - (screen_resolution_x >> 1); player[i].Camera_Y_pos = player[i].y_pos - (screen_resolution_y >> 1); player[i].Camera_Min_X_pos = z.Act[act].Stage[stage].LevelXL; player[i].Camera_Max_X_pos = z.Act[act].Stage[stage].LevelXR; player[i].Camera_Min_Y_pos = z.Act[act].Stage[stage].LevelYT; player[i].Camera_Max_Y_pos = z.Act[act].Stage[stage].LevelYB; player[i].Camera_Max_Y_pos_now = z.Act[act].Stage[stage].LevelYB; player[i].Camera_Y_pos_bias = 0x60; } water_current_height = 0x24C00; water_direction = 1; water_accel = 0; z.Act[act].Stage[stage].WaterEnable = 0; counter_fe74 = 0x80; counter_fe74_direction = 1; counter_fe74_accel = 0; while(!key[KEY_ESC] && !close_button_pressed){ if(demo_number >= 0){ if(demo_mode == 0){ demo_mode = 1; DemoFile = NULL; for(i=0; i < 10; i++){ // search for next existing demo file n = PlayDemo(demo_number); if(n == 0) i = 9; else if(n == -1 && i == 9) quit(ERROR_NO_DEMO_FILES); else{ demo_number++; demo_number %= 10; } } } } for(frame=1; frame <= num_of_frames; frame++){ p = &player[frame-1]; if(show_menu == 0){ if(demo_mode != 1 && titlecard_sequence_end){ p->CtrlInput = 0; if(!typing){ if(key[key_bind[frame-1].bind_up]) p->CtrlInput |= 1; if(key[key_bind[frame-1].bind_down]) p->CtrlInput |= 2; if(key[key_bind[frame-1].bind_left]) p->CtrlInput |= 4; if(key[key_bind[frame-1].bind_right]) p->CtrlInput |= 8; if(key[key_bind[frame-1].bind_b]) p->CtrlInput |= 0x10; if(key[key_bind[frame-1].bind_c]) p->CtrlInput |= 0x20; if(key[key_bind[frame-1].bind_a]) p->CtrlInput |= 0x40; if(key[key_bind[frame-1].bind_start]) p->CtrlInput |= 0x80; } } else p->CtrlInput = 0; if(demo_mode == 1) PlayDemo(demo_number); else if(demo_mode > 1) RecordDemo(9); #ifdef ENABLE_FRAME_CONTROL while(key[KEY_D]); while(!key[KEY_S] && !key[KEY_D]); #endif if(demo_mode == 1 && key[KEY_ENTER]){ DemoPosition = 0; demo_mode = 0; if(demodata) free(demodata); demodata = 0; demo_size = 0; demo_number = -1; zone = 0; act = 0; stage = 0; Level_Inactive_flag = 1; } p->Ctrl_Press = 0; if(p->CtrlInput & 1){ if((p->Ctrl_Held & 1) == 0) p->Ctrl_Press |= 1; p->Ctrl_Held |= 1; } else p->Ctrl_Held &= 0xFE; if(p->CtrlInput & 2){ if((p->Ctrl_Held & 2) == 0) p->Ctrl_Press |= 2; p->Ctrl_Held |= 2; } else p->Ctrl_Held &= 0xFD; if(p->CtrlInput & 4){ if((p->Ctrl_Held & 4) == 0) p->Ctrl_Press |= 4; p->Ctrl_Held |= 4; } else p->Ctrl_Held &= 0xFB; if(p->CtrlInput & 8){ if((p->Ctrl_Held & 8) == 0) p->Ctrl_Press |= 8; p->Ctrl_Held |= 8; } else p->Ctrl_Held &= 0xF7; if(p->CtrlInput & 0x40){ if((p->Ctrl_Held & 0x40) == 0) p->Ctrl_Press |= 0x40; p->Ctrl_Held |= 0x40; } else p->Ctrl_Held &= 0xBF; if(p->CtrlInput & 0x10){ if((p->Ctrl_Held & 0x10) == 0) p->Ctrl_Press |= 0x10; p->Ctrl_Held |= 0x10; } else p->Ctrl_Held &= 0xEF; if(p->CtrlInput & 0x20){ if((p->Ctrl_Held & 0x20) == 0) p->Ctrl_Press |= 0x20; p->Ctrl_Held |= 0x20; } else p->Ctrl_Held &= 0xDF; if(p->CtrlInput & 0x80){ if((p->Ctrl_Held & 0x80) == 0) p->Ctrl_Press |= 0x80; p->Ctrl_Held |= 0x80; } else p->Ctrl_Held &= 0x7F; /*if(key[KEY_0]) LoadSavestate("sonic2.gs0"); else if(key[KEY_1]) LoadSavestate("sonic2.gs1"); else if(key[KEY_2]) LoadSavestate("sonic2.gs2"); else if(key[KEY_3]) LoadSavestate("sonic2.gs3"); else if(key[KEY_4]) LoadSavestate("sonic2.gs4"); else if(key[KEY_5]) LoadSavestate("sonic2.gs5"); else if(key[KEY_6]) LoadSavestate("sonic2.gs6"); else if(key[KEY_7]) LoadSavestate("sonic2.gs7"); else if(key[KEY_8]) LoadSavestate("sonic2.gs8"); else if(key[KEY_9]) LoadSavestate("sonic2.gs9");*/ } if(!typing){ if(key[KEY_M]){ if(key_m_previously_pressed == 0){ show_menu ^= 1; key_m_previously_pressed = 1; } } else key_m_previously_pressed = 0; if(key[KEY_N]){ if(key_n_previously_pressed == 0){ debug_show_object_nodes ^= 1; key_n_previously_pressed = 1; } } else key_n_previously_pressed = 0; } if(frame == 1){ if(prompt){ LoadZonePrompt(); prompt = 0; } if(!typing){ if(key[KEY_SPACE]){ edit_mode++; edit_mode %= 5; #ifdef ENABLE_MOUSE mouse_z_previous = mouse_z; #endif rest(200); } if(key[KEY_0]){ rest(200); show_fps ^= 1; } if(key[KEY_9]){ rest(200); vsync_enable ^= 1; } } } if(frame == 1){ while(ticUpdated == 0); // wait until 'ticUpdated' it 1 ticUpdated = 0; draw_frame = 0; } if(ticCounterR % (frame_skip+1) == 0){ draw_frame = 1; clear_to_color(LayerH[frame-1], MASK_COLOR_16); clear_to_color(LayerSH[frame-1], MASK_COLOR_16); if(num_of_frames > 1 && frame == 1) clear(LayerM); } if(Pause() == 0){ if(camera_mode){ if(p->Ctrl_Held & 1){ p->Camera_Y_pos -= 8; if(key[KEY_LSHIFT] || key[KEY_RSHIFT]) p->Camera_Y_pos -= 8; } else if(p->Ctrl_Held & 2){ p->Camera_Y_pos += 8; if(key[KEY_LSHIFT] || key[KEY_RSHIFT]) p->Camera_Y_pos += 8; } if(p->Ctrl_Held & 4){ p->Camera_X_pos -= 8; if(key[KEY_LSHIFT] || key[KEY_RSHIFT]) p->Camera_X_pos -= 8; } else if(p->Ctrl_Held & 8){ p->Camera_X_pos += 8; if(key[KEY_LSHIFT] || key[KEY_RSHIFT]) p->Camera_X_pos += 8; } if(p->Camera_X_pos < 0) p->Camera_X_pos = 0; if(p->Camera_Y_pos < 0) p->Camera_Y_pos = 0; #ifdef ENABLE_MOUSE player[0].x_pos = player[0].Camera_X_pos + ((mouse_x << screen_scale_x) >> screen_double_x); player[0].y_pos = player[0].Camera_Y_pos + ((mouse_y << screen_scale_y) >> screen_double_y); #endif } else{ if(Update_HUD_timer == 1){ if(Timer_minute == 9 && Timer_second == 59 && Timer_millisecond == 59){ if(!Time_Over_flag){ KillCharacter(); Time_Over_flag = 1; } } else if(frame == 1){ Timer_millisecond++; if(Timer_millisecond == 60){ Timer_millisecond = 0; Timer_second++; if(Timer_second == 60){ Timer_second = 0; Timer_minute++; } } } } else{ if(p->anim == 5) p->anim_frame = 0; } } #ifdef ENABLE_SRAM_LOG_ANALYSIS if(frame == 1 && DemoPosition > 6 && /*ticCounterL >= sram_start && */titlecard_sequence_end) AnalyzeSRAM(); #endif #ifdef ENABLE_LOGGING ResetLog(); #endif RunFunction(1); if(!camera_mode) Obj01(); if(!titlecard_sequence_end){ p->x_vel = 0; p->y_vel = 0; } #ifdef ENABLE_LOGGING #ifndef ENABLE_SRAM_LOG_ANALYSIS DumpLog("obj01.log"); #endif #endif } #ifndef ALLEGRO_DOS if(frame == 1){ if(net_type > 0){ if(net_type == 1) ManageNetwork(); else{ n = 0xFF; i = 0; while(i != 1){ i = nlWrite(prosonicnet, &n, 1); // player ready if(key[KEY_ESC]) quit(0); } i = 0; while(i != 1){ i = nlWrite(prosonicnet, &net_id[0], 1); // who sent it if(key[KEY_ESC]) quit(0); } //allegro_message("client sent data:\ni = %i\nnet_id[0] = %i", i, net_id[0]); } GetNetworkData(); } } #endif if(p->Ctrl_Press & 0x10){ camera_mode ^= 1; if(camera_mode){ p->status = 0; p->routine = 0; p->layer = 0x10; p->x_pos_pre = 0; p->y_pos_pre = 0; p->x_vel = 0; p->y_vel = 0; p->inertia = 0; p->anim = 0; p->anim_frame = 0; p->anim_frame_duration = 0; p->next_anim = 0; p->Camera_Y_pos_bias = 0x60; } } if(camera_mode && frame == 1){ p->x_pos = 0xFFFF; p->y_pos = 0xFFFF; } ManageObjectNodes(&z); RunFunction(2); if(draw_frame){ DrawBackArea(LayerB[frame-1]); DrawPlayArea(LayerL[frame-1], LayerH[frame-1]); } RunFunction(3); if(show_fps) DrawCounter10(LayerSH[frame-1], fps, 8, 0, 2, 1); if(titlecard_sequence_end){ #ifndef ALLEGRO_DOS if(frame == 1){ Talk(); } #endif if(show_version){ #ifdef ALLEGRO_LINUX DrawText(screen_resolution_x - (26 << 3), screen_resolution_y - 32, 0x10, "PROGRAMMED BY DAMIAN GROVE"); DrawText(screen_resolution_x - (27 << 3), screen_resolution_y - 20, 0x10, "LINUX PORT BY KING INUYASHA"); #else #ifdef ALLEGRO_MACOSX DrawText(screen_resolution_x - (26 << 3), screen_resolution_y - 32, 0x10, "PROGRAMMED BY DAMIAN GROVE"); DrawText(screen_resolution_x - (24 << 3), screen_resolution_y - 20, 0x10, "MAC PORT BY CYBERKITSUNE"); #else DrawText(screen_resolution_x - (26 << 3), screen_resolution_y - 20, 0x10, "PROGRAMMED BY DAMIAN GROVE"); #endif #endif DrawText(screen_resolution_x - (11 << 3), screen_resolution_y - 8, 0x10, __DATE__); } if(edit_mode == 0){ // SCORE DrawSprite(&z, LayerSH[frame-1], 0x105, 0x01, NORMAL, 0, 0x10+16, 0x08); DrawSprite(&z, LayerSH[frame-1], 0x105, 0x08, NORMAL, 0, 0x68+16, 0x08); //DrawCounter10(LayerSH[frame-1], p->Score, 0x60, 0x08, 0, 0); // TIME if(Timer_minute == 9){ if(((Timer_second * 60) + Timer_millisecond) & 8) DrawSprite(&z, LayerSH[frame-1], 0x105, 0x03, NORMAL, 0, 0x10+16, 0x18); else DrawSprite(&z, LayerSH[frame-1], 0x105, 0x04, NORMAL, 0, 0x10+16, 0x18); } else DrawSprite(&z, LayerSH[frame-1], 0x105, 0x03, NORMAL, 0, 0x10+16, 0x18); DrawSprite(&z, LayerSH[frame-1], 0x105, 0x07, NORMAL, 0, 0x40+16, 0x18); //DrawCounter10(LayerSH[frame-1], Timer_minute, 0x38, 0x18, 1, 0); //DrawCounter10(LayerSH[frame-1], Timer_second, 0x50, 0x18, 2, 0); // RINGS if(p->Ring_count <= 0){ if(((Timer_second * 60) + Timer_millisecond) & 8) DrawSprite(&z, LayerSH[frame-1], 0x105, 0x05, NORMAL, 0, 0x10+16, 0x28); else DrawSprite(&z, LayerSH[frame-1], 0x105, 0x06, NORMAL, 0, 0x10+16, 0x28); } else DrawSprite(&z, LayerSH[frame-1], 0x105, 0x05, NORMAL, 0, 0x10+16, 0x28); //DrawCounter10(LayerSH[frame-1], p->Ring_count, 0x50, 0x28, 1, 0); // LIVES DrawSprite(&z, LayerSH[frame-1], 0x105, 0x1C, NORMAL, 0, 0x10+16, screen_resolution_y - 24); //DrawCounter10(LayerSH[frame-1], p->Life_count, 0x38, screen_resolution_y - 16, 1, 1); } if(debug_show_object_nodes > 0){ number_of_objects_in_memory = 0; for(i=0; i < (MAX_BUFFER_OBJECTS >> 3); i++){ if(ObjectNodes[0+(i<<3)] < MAX_LEVEL_OBJECTS) number_of_objects_in_memory++; if(ObjectNodes[1+(i<<3)] < MAX_LEVEL_OBJECTS) number_of_objects_in_memory++; if(ObjectNodes[2+(i<<3)] < MAX_LEVEL_OBJECTS) number_of_objects_in_memory++; if(ObjectNodes[3+(i<<3)] < MAX_LEVEL_OBJECTS) number_of_objects_in_memory++; if(ObjectNodes[4+(i<<3)] < MAX_LEVEL_OBJECTS) number_of_objects_in_memory++; if(ObjectNodes[5+(i<<3)] < MAX_LEVEL_OBJECTS) number_of_objects_in_memory++; if(ObjectNodes[6+(i<<3)] < MAX_LEVEL_OBJECTS) number_of_objects_in_memory++; if(ObjectNodes[7+(i<<3)] < MAX_LEVEL_OBJECTS) number_of_objects_in_memory++; } DrawCounter16(LayerH[frame-1], number_of_objects_in_memory, 0, screen_resolution_y-MAX_BUFFER_OBJECTS-16); for(i=0; i < (MAX_BUFFER_OBJECTS >> 3); i++){ DrawCounter16(LayerH[frame-1], ObjectNodes[0+(i<<3)], 0, screen_resolution_y-MAX_BUFFER_OBJECTS+(i<<3)); DrawCounter16(LayerH[frame-1], ObjectNodes[1+(i<<3)], 40, screen_resolution_y-MAX_BUFFER_OBJECTS+(i<<3)); DrawCounter16(LayerH[frame-1], ObjectNodes[2+(i<<3)], 80, screen_resolution_y-MAX_BUFFER_OBJECTS+(i<<3)); DrawCounter16(LayerH[frame-1], ObjectNodes[3+(i<<3)], 120, screen_resolution_y-MAX_BUFFER_OBJECTS+(i<<3)); DrawCounter16(LayerH[frame-1], ObjectNodes[4+(i<<3)], 160, screen_resolution_y-MAX_BUFFER_OBJECTS+(i<<3)); DrawCounter16(LayerH[frame-1], ObjectNodes[5+(i<<3)], 200, screen_resolution_y-MAX_BUFFER_OBJECTS+(i<<3)); DrawCounter16(LayerH[frame-1], ObjectNodes[6+(i<<3)], 240, screen_resolution_y-MAX_BUFFER_OBJECTS+(i<<3)); DrawCounter16(LayerH[frame-1], ObjectNodes[7+(i<<3)], 280, screen_resolution_y-MAX_BUFFER_OBJECTS+(i<<3)); } } // Draw URL in the lower-right portion of the screen if(show_watermark) DrawSprite(&z, LayerL[frame-1], 0x101, 0, NORMAL, 24, screen_resolution_x-147, screen_resolution_y-24); if(show_menu > 0) Menu(); #ifdef ENABLE_MOUSE ShowBlockInfo(&z); #endif } #ifndef ENABLE_FRAME_CONTROL if(digi_card != DIGI_NONE){ if(frame == num_of_frames) ProcessSound(); } #endif if(num_of_frames > 1){ switch(frame){ case 1: if(num_of_frames == 2){ blit(LayerB[frame-1], LayerM, 16, 0, screen_offset_x+16, screen_offset_y >> 1 << screen_double_y, screen_buffer_x-32, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerL[frame-1], LayerM, 16, 0, screen_offset_x+16, screen_offset_y >> 1 << screen_double_y, screen_buffer_x-32, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerH[frame-1], LayerM, 16, 0, screen_offset_x+16, screen_offset_y >> 1 << screen_double_y, screen_buffer_x-32, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerSH[frame-1], LayerM, 16, 0, screen_offset_x+16, screen_offset_y >> 1 << screen_double_y, screen_buffer_x-32, screen_buffer_y >> 1 << screen_double_y); } else{ blit(LayerB[frame-1], LayerM, 8 << screen_double_x, 0, screen_offset_x+16, screen_offset_y >> 1 << screen_double_y, (screen_buffer_x-32) >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerL[frame-1], LayerM, 8 << screen_double_x, 0, screen_offset_x+16, screen_offset_y >> 1 << screen_double_y, (screen_buffer_x-32) >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerH[frame-1], LayerM, 8 << screen_double_x, 0, screen_offset_x+16, screen_offset_y >> 1 << screen_double_y, (screen_buffer_x-32) >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerSH[frame-1], LayerM, 8 << screen_double_x, 0, screen_offset_x+16, screen_offset_y >> 1 << screen_double_y, (screen_buffer_x-32) >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); } break; case 2: if(num_of_frames == 2){ blit(LayerB[frame-1], LayerM, 16, 0, screen_offset_x+16, (((screen_resolution_y + screen_padding_y) >> 1) << screen_double_y) + (screen_padding_y >> 2 << screen_double_y), screen_buffer_x-32, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerL[frame-1], LayerM, 16, 0, screen_offset_x+16, (((screen_resolution_y + screen_padding_y) >> 1) << screen_double_y) + (screen_padding_y >> 2 << screen_double_y), screen_buffer_x-32, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerH[frame-1], LayerM, 16, 0, screen_offset_x+16, (((screen_resolution_y + screen_padding_y) >> 1) << screen_double_y) + (screen_padding_y >> 2 << screen_double_y), screen_buffer_x-32, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerSH[frame-1], LayerM, 16, 0, screen_offset_x+16, (((screen_resolution_y + screen_padding_y) >> 1) << screen_double_y) + (screen_padding_y >> 2 << screen_double_y), screen_buffer_x-32, screen_buffer_y >> 1 << screen_double_y); } else{ blit(LayerB[frame-1], LayerM, 8 << screen_double_x, 0, -((8 << screen_double_x)-16) + (((screen_resolution_x + screen_padding_x) >> 1) << screen_double_x) + (screen_padding_x >> 2 << screen_double_x) + (8 << screen_double_x), screen_offset_y >> 1 << screen_double_y, (screen_buffer_x-32) >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerL[frame-1], LayerM, 8 << screen_double_x, 0, -((8 << screen_double_x)-16) + (((screen_resolution_x + screen_padding_x) >> 1) << screen_double_x) + (screen_padding_x >> 2 << screen_double_x) + (8 << screen_double_x), screen_offset_y >> 1 << screen_double_y, (screen_buffer_x-32) >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerH[frame-1], LayerM, 8 << screen_double_x, 0, -((8 << screen_double_x)-16) + (((screen_resolution_x + screen_padding_x) >> 1) << screen_double_x) + (screen_padding_x >> 2 << screen_double_x) + (8 << screen_double_x), screen_offset_y >> 1 << screen_double_y, (screen_buffer_x-32) >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerSH[frame-1], LayerM, 8 << screen_double_x, 0, -((8 << screen_double_x)-16) + (((screen_resolution_x + screen_padding_x) >> 1) << screen_double_x) + (screen_padding_x >> 2 << screen_double_x) + (8 << screen_double_x), screen_offset_y >> 1 << screen_double_y, (screen_buffer_x-32) >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); } break; case 3: blit(LayerB[frame-1], LayerM, 8 << screen_double_x, 0, screen_offset_x+16, (((screen_resolution_y + screen_padding_y) >> 1) << screen_double_y) + (screen_padding_y >> 2 << screen_double_y), (screen_buffer_x-32) >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerL[frame-1], LayerM, 8 << screen_double_x, 0, screen_offset_x+16, (((screen_resolution_y + screen_padding_y) >> 1) << screen_double_y) + (screen_padding_y >> 2 << screen_double_y), (screen_buffer_x-32) >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerH[frame-1], LayerM, 8 << screen_double_x, 0, screen_offset_x+16, (((screen_resolution_y + screen_padding_y) >> 1) << screen_double_y) + (screen_padding_y >> 2 << screen_double_y), (screen_buffer_x-32) >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerSH[frame-1], LayerM, 8 << screen_double_x, 0, screen_offset_x+16, (((screen_resolution_y + screen_padding_y) >> 1) << screen_double_y) + (screen_padding_y >> 2 << screen_double_y), (screen_buffer_x-32) >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); break; case 4: blit(LayerB[frame-1], LayerM, 8 << screen_double_x, 0, -((8 << screen_double_x)-16) + (((screen_resolution_x + screen_padding_x) >> 1) << screen_double_x) + (screen_padding_x >> 2 << screen_double_x) + (8 << screen_double_x), (((screen_resolution_y + screen_padding_y) >> 1) << screen_double_y) + (screen_padding_y >> 2 << screen_double_y), (screen_buffer_x-32) >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerL[frame-1], LayerM, 8 << screen_double_x, 0, -((8 << screen_double_x)-16) + (((screen_resolution_x + screen_padding_x) >> 1) << screen_double_x) + (screen_padding_x >> 2 << screen_double_x) + (8 << screen_double_x), (((screen_resolution_y + screen_padding_y) >> 1) << screen_double_y) + (screen_padding_y >> 2 << screen_double_y), (screen_buffer_x-32) >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerH[frame-1], LayerM, 8 << screen_double_x, 0, -((8 << screen_double_x)-16) + (((screen_resolution_x + screen_padding_x) >> 1) << screen_double_x) + (screen_padding_x >> 2 << screen_double_x) + (8 << screen_double_x), (((screen_resolution_y + screen_padding_y) >> 1) << screen_double_y) + (screen_padding_y >> 2 << screen_double_y), (screen_buffer_x-32) >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); masked_blit(LayerSH[frame-1], LayerM, 8 << screen_double_x, 0, -((8 << screen_double_x)-16) + (((screen_resolution_x + screen_padding_x) >> 1) << screen_double_x) + (screen_padding_x >> 2 << screen_double_x) + (8 << screen_double_x), (((screen_resolution_y + screen_padding_y) >> 1) << screen_double_y) + (screen_padding_y >> 2 << screen_double_y), (screen_buffer_x-32) >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); } if(frame == num_of_frames){ if(fade_count != 0) FadeRGB(LayerM); TitleCard(); if(vsync_enable) vsync(); #ifndef ALLEGRO_DOS acquire_screen(); // used for "set_display_switch_mode()" #endif if(screen_double_x && num_of_frames == 2) stretch_blit(LayerM, screen, 16, 0, screen_resolution_x+screen_padding_x, (screen_resolution_y+screen_padding_y) << screen_double_y, 0, 0, (screen_resolution_x+screen_padding_x) << screen_double_x, (screen_resolution_y+screen_padding_y) << screen_double_y); else blit(LayerM, screen, 16, 0, 0, 0, (screen_resolution_x+screen_padding_x) << screen_double_x, (screen_resolution_y+screen_padding_y) << screen_double_y); #ifndef ALLEGRO_DOS release_screen(); // used for "set_display_switch_mode()" #endif } } else{ masked_blit(LayerL[frame-1], LayerB[frame-1], 16, 0, 16, 0, screen_buffer_x-32, screen_buffer_y); masked_blit(LayerH[frame-1], LayerB[frame-1], 16, 0, 16, 0, screen_buffer_x-32, screen_buffer_y); masked_blit(LayerSH[frame-1], LayerB[frame-1], 16, 0, 16, 0, screen_buffer_x-32, screen_buffer_y); if(fade_count != 0) FadeRGB(LayerB[frame-1]); TitleCard(); if(vsync_enable) vsync(); #ifndef ALLEGRO_DOS acquire_screen(); // used for "set_display_switch_mode()" #endif if(screen_double_x || screen_double_y) stretch_blit(LayerB[frame-1], screen, 16, 0, screen_resolution_x, screen_resolution_y, screen_offset_x << screen_double_x, screen_offset_y << screen_double_y, screen_resolution_x << screen_double_x, screen_resolution_y << screen_double_y); else blit(LayerB[frame-1], screen, 16, 0, screen_offset_x, screen_offset_y, screen_resolution_x, screen_resolution_y); #ifndef ALLEGRO_DOS release_screen(); // used for "set_display_switch_mode()" #endif } if(frame == 1){ // shouldn't this be "frame == num_of_frames"?? // Water movement if(water_direction == 1 && water_accel == 63){ water_accel = 63; water_direction = 0; } else if(water_direction == 0 && water_accel == -63){ water_accel = -63; water_direction = 1; } if(water_direction == 0) water_accel--; else water_accel++; water_current_height += water_accel; // Counter FE74 if(counter_fe74_direction == 1 && counter_fe74_accel == 0xB0){ counter_fe74_accel = 0xB0; counter_fe74_direction = 0; } else if(counter_fe74_direction == 0 && counter_fe74_accel == -0xB0){ counter_fe74_accel = -0xB0; counter_fe74_direction = 1; } if(counter_fe74_direction == 0) counter_fe74_accel -= 8; else counter_fe74_accel += 8; counter_fe74 += counter_fe74_accel; } if(Level_Inactive_flag && frame == num_of_frames){ if(fade_count == -96){ if(zone) unlisted_zone = 0; ResetSound(); Level_Inactive_flag = 0; LoadZone(&z, zone_file_list[zone + (unlisted_zone * 256)]); InitDraw(&z); AllocateObjects(&z); CreateBlockLayout(&z); strcpy(TextBuffer, "ProSonic - "); strcat(TextBuffer, z.LevelName1); strcat(TextBuffer, " ZONE"); set_window_title(TextBuffer); // SET UP THE CELL DATA num_of_cells = z.FILTERCOMPOSITE[0]; num_of_filters = z.FILTERCOMPOSITE[1]; cells_ptr = *(short *)&z.FILTERCOMPOSITE[2]; filters_ptr = *(short *)&z.FILTERCOMPOSITE[4]; bg_rgb_color = *(short *)&z.FILTERCOMPOSITE[6]; filter_a = z.FILTERCOMPOSITE[8]; filter_b = z.FILTERCOMPOSITE[9]; filter_a_speed = z.FILTERCOMPOSITE[10]; filter_b_speed = z.FILTERCOMPOSITE[11]; cell_data = (CELL*)(&z.FILTERCOMPOSITE[cells_ptr]); for(i=0; i < num_of_frames; i++){ n = player[i].Life_count; d0 = player[i].Saved_Last_star_pole_hit; d1 = player[i].Saved_x_pos; d2 = player[i].Saved_y_pos; d3 = player[i].Saved_Ring_count; d4 = player[i].Saved_Timer; d5 = player[i].Saved_art_tile; d6 = player[i].Saved_layer; d7 = player[i].Saved_Camera_X_pos; a0 = player[i].Saved_Camera_Y_pos; a1 = player[i].Saved_Water_Level; a2 = player[i].Saved_Extra_life_flags; a3 = player[i].Saved_Extra_life_flags_2P; a4 = player[i].Saved_Camera_Max_Y_pos; /* player[i] = init_player; /*/ player[i].status = 0; player[i].routine = 0; player[i].layer = 0x10; player[i].x_pos_pre = 0; player[i].y_pos_pre = 0; player[i].x_vel = 0; player[i].y_vel = 0; player[i].inertia = 0; player[i].anim = 0; player[i].anim_frame = 0; player[i].anim_frame_duration = 0; player[i].next_anim = 0; //*/ player[i].Life_count = n; player[i].Saved_Last_star_pole_hit = d0; player[i].Saved_x_pos = d1; player[i].Saved_y_pos = d2; player[i].Saved_Ring_count = d3; player[i].Saved_Timer = d4; player[i].Saved_art_tile = d5; player[i].Saved_layer = d6; player[i].Saved_Camera_X_pos = d7; player[i].Saved_Camera_Y_pos = a0; player[i].Saved_Water_Level = a1; player[i].Saved_Extra_life_flags = a2; player[i].Saved_Extra_life_flags_2P = a3; player[i].Saved_Camera_Max_Y_pos = a4; //if(player[i].Saved_x_pos != 0){ // player[i].x_pos = player[i].Saved_x_pos; // player[i].y_pos = player[i].Saved_y_pos; //} //else{ player[i].x_pos = z.Act[act].Stage[stage].StartX[0]; player[i].y_pos = z.Act[act].Stage[stage].StartY[0]; //} player[i].Camera_X_pos = player[i].x_pos - (screen_resolution_x >> 1); player[i].Camera_Y_pos = player[i].y_pos - (screen_resolution_y >> 1) + 0x10; player[i].Camera_Min_X_pos = z.Act[act].Stage[stage].LevelXL; player[i].Camera_Max_X_pos = z.Act[act].Stage[stage].LevelXR; player[i].Camera_Min_Y_pos = z.Act[act].Stage[stage].LevelYT; player[i].Camera_Max_Y_pos = z.Act[act].Stage[stage].LevelYB; player[i].Camera_Max_Y_pos_now = z.Act[act].Stage[stage].LevelYB; player[i].Camera_Y_pos_bias = 0x60; player[i].render_flags |= 0x80; player[i].Ring_count = 0; } Timer_minute = 0; Timer_second = 0; Timer_millisecond = 0; water_accel = 0; water_direction = 1; counter_fe74_accel = 0; counter_fe74_direction = 1; counter_fe74 = 0x80; Game_paused = 0; titlecard_sequence_end = 0; RunFunction(4); } else{ FadeOutFM(0); fade_count -= 4; } } if(!Game_paused && frame == num_of_frames){ ticCounter60L++; ticCounterL++; } } }//END KEY_ESC quit(ERROR_NULL); return 0; // Not really needed, this just stops the compiler from complaining ;) } END_OF_MAIN()
001tomclark-research-check
Source/Engine/main.c
C
gpl2
128,964
#define SCRIPT_TYPE_PROCODE 0 #define SCRIPT_TYPE_MOTOROLA 1 char addr_literal; // When this is TRUE, calc_effective_address() will copy // address values without conversions. This value will be // set to zero once calc_effective_address() has finished. char ea_big_endian; //void pro_call(int target); void pro_call(short data, unsigned short NodeNumber); void pro_jump(short data, unsigned short NodeNumber); void DataIn(); void DataOut(); //void SlopeObject(int target); unsigned char *script; // collection of all scripts unsigned int script_size; unsigned char *obj_script; // individual script (object OR function) signed int script_pos; // used to track in 'obj_script' unsigned char obj_script_type[256]; // 0 = Procode; 1 = Motorola unsigned int obj_script_start[256]; unsigned int obj_script_size[256]; // These are for generic game functions unsigned int game_script_start[8]; unsigned int game_script_size[8]; void RunScript(unsigned short NodeNumber); void RunFunction(unsigned char function); void LoadBinary(unsigned char o, const char *filename); #define NUM_INTERNAL_GVARS 91 // generic variables #define NUM_INTERNAL_OVARS 24 // object variables #define NUM_INTERNAL_PVARS 90 // player variables // #define NUM_KEYWORDS 11 // #define NUM_OPERATORS 14 // #define NUM_CONDITIONS 6 int *internal_gvar_ptrs[NUM_INTERNAL_GVARS]; int *internal_ovar_ptrs[NUM_INTERNAL_OVARS]; int *internal_pvar_ptrs[4][NUM_INTERNAL_PVARS]; char internal_gvar_size[NUM_INTERNAL_GVARS]; char internal_ovar_size[NUM_INTERNAL_OVARS]; char internal_pvar_size[NUM_INTERNAL_PVARS]; int break_ptr[256]; unsigned char if_scope;
001tomclark-research-check
Source/Engine/script.h
C
gpl2
1,715
#ifndef DRAW_H #define DRAW_H #include "structs.h" #include "common.h" #ifdef __cplusplus extern "C"{ #endif int InitDraw(ZONE *z); FUNCINLINE void DrawPlayArea(BITMAP *l, BITMAP *h); FUNCINLINE void DrawBackArea(BITMAP *b); FUNCINLINE void SetGfxModeWindow(); FUNCINLINE void SetGfxModeFull(); void SetGfxMode(short res_x, short res_y, short pad_x, short pad_y, short dbl_x, short dbl_y, char full); //unsigned short ColorSolid16; PALETTE pal; #ifdef __cplusplus } #endif #endif
001tomclark-research-check
Source/Engine/draw.h
C
gpl2
528
#ifndef MENUS_H #define MENUS_H #include "structs.h" #include "text.h" #ifdef __cplusplus extern "C"{ #endif char menu_column_size; char menu_column_count; signed char menu_selection; // item (zone) signed char menu_sub_selection; // row (act) char menu_timer1; // repeat delay (UP) char menu_timer2; // repeat delay (DOWN) char menu_timer3; // repeat stop (LEFT) char menu_timer4; // repeat stop (RIGHT) char show_menu; typedef struct{ char type; // 0 for acts, 1 for sound test char var_size; // used for "TYPE 1" 0 for char, 1 for short, 3 for float char *var_ptr8; // used for "TYPE 1" short *var_ptr16; // used for "TYPE 1" int *var_ptr32; // NOT USED AT ALL!! float *var_ptr32f; // used for "TYPE 1" float min_value; // used for "TYPE 1" float max_value; // used for "TYPE 1" char value_digits; // used for "TYPE 1" short offset_x; short offset_y; char columns; char string[8][8]; // [column][character] e.g. "STAGE 1" // CURRENTLY, ONLY [0][x] WORKS!! } MENU_ITEM_SUB; typedef struct{ short offset_x; short offset_y; char show; char rows; char string[20]; // e.g. "EMERALD HILL" MENU_ITEM_SUB row[8]; } MENU_ITEM; MENU_ITEM selection_menu[14]; void Menu(); void InitLevelSelect(); #ifdef __cplusplus } #endif #endif
001tomclark-research-check
Source/Engine/menus.h
C
gpl2
1,384
#define BYTE 1 #define WORD 2 #define LONG 4 //#define MOTOROLA_STACK_SIZE 32 // measured in long words // ==================================================== // REPLACE THESE EVENTUALLY WITH REG_A AND REG_D ARRAYS // ==================================================== // Motorola 68000 address registers volatile int a0, a1, a2, a3, a4, a5, a6, a7; // Motorola 68000 data registers volatile int d0, d1, d2, d3, d4, d5, d6, d7; // ==================================================== // Address and data registers unsigned int reg_a[8]; unsigned int reg_d[8]; unsigned int imm; unsigned int ea; enum script_type{ NEW, MOTOROLA }; unsigned char ram_68k[0x10000]; //int stack_68k[MOTOROLA_STACK_SIZE]; int swap_endian(char s, unsigned int v); int calc_effective_address(char size, char mode, char r); int read_script(char size, char type); //volatile char increment; // Misc registers int pc; short sr; // lower byte is CCR register char cc_x; char cc_n; char cc_z; char cc_v; char cc_c; //char ccr; #define CCR_C 0x01 #define CCR_V 0x02 #define CCR_Z 0x04 #define CCR_N 0x08 #define CCR_X 0x10 // Motorola 68000 flags //char flag_c; //char flag_z; void op_add(short data); void op_addi(short data); void op_addq(short data); void op_and(short data); void op_andi(short data); void op_bcc(short data); void op_bchg(short data); void op_bclr(short data); void op_bset(short data); void op_btst(short data); void op_clr(short data); void op_cmp(short data); void op_cmpi(short data); void op_eor(short data); void op_eori(short data); void op_jmp(short data); void op_lea(short data); void op_lsd(short data); void op_move(short data); void op_movem(short data); void op_moveq(short data); void op_neg(short data);
001tomclark-research-check
Source/Engine/m68k.h
C
gpl2
1,807
# ########## General Setup ############## target_link_libraries(ProSonic ${LIBS}) # ########## Resource compilation ######## IF(WIN32) # Only Windows target needs resource compilation # And MinGW is the only one that needs an explicit compile step IF(MINGW) IF(CMAKE_CROSSCOMPILING) ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/DrawScreen_resource.obj COMMAND i686-pc-mingw32-windres -I${CMAKE_CURRENT_SOURCE_DIR} -o ${CMAKE_CURRENT_BINARY_DIR}/DrawScreen_resource.obj -i${CMAKE_CURRENT_SOURCE_DIR}/DrawScreen.rc DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/DrawScreen.rc ) ENDIF(CMAKE_CROSSCOMPILING) IF(NOT CMAKE_CROSSCOMPILING) ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/DrawScreen_resource.obj COMMAND windres -I${CMAKE_CURRENT_SOURCE_DIR} -o ${CMAKE_CURRENT_BINARY_DIR}/DrawScreen_resource.obj -i${CMAKE_CURRENT_SOURCE_DIR}/DrawScreen.rc DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/DrawScreen.rc ) ENDIF(NOT CMAKE_CROSSCOMPILING) ENDIF(MINGW) ENDIF(WIN32) # ########## Engine executable ########## # Sources: SET(Engine_executable_SRCS demo.c draw.c DrawScreen.rc m68k.c main.c menus.c obj01.c objects.c psg.c script.c script2.c sprites.c text.c tools.c ym2612.c zone.c ) # Headers: SET(Engine_executable_HDRS common.h draw.h error.h m68k.h menus.h mouse.h network.h obj01.h objects.h psg.h script.h sprites.h strings.h structs.h text.h tools.h ym2612.h zone.h ) IF(WIN32) SET(Engine_executable_HDRS ${Engine_executable_HDRS} DrawScreen_rc.h ) ENDIF(WIN32) # MSVC can natively handle Windows RC files IF(MSVC) SET(Engine_executable_SRCS ${Engine_executable_SRCS} DrawScreen.rc ) ENDIF(MSVC) # actual target: IF(WIN32) IF(MINGW) ADD_EXECUTABLE(ProSonic ${Engine_executable_SRCS} DrawScreen_resource.obj) ELSE(MINGW) ADD_EXECUTABLE(ProSonic ${Engine_executable_SRCS}) ENDIF(MINGW) ELSE(WIN32) ADD_EXECUTABLE(ProSonic ${Engine_executable_SRCS}) ENDIF(WIN32) # add install target: INSTALL(TARGETS ProSonic DESTINATION bin)
001tomclark-research-check
Source/Engine/CMakeLists.txt
CMake
gpl2
2,213
#ifndef STRINGS_H #define STRINGS_H #ifdef __cplusplus extern "C"{ #endif #define STR_ERR_UNKNOWN "ERROR: An unknown error has occured." #define STR_ERR_OBJECT_BUFFER "ERROR: Object buffer is full." #define STR_ERR_DIVIDE_ZERO "ERROR: Division by zero." #define STR_ERR_INIT_SCREEN "ERROR: Could not initialize screen." #define STR_ERR_NO_DEMO_FILES "ERROR: No demo files found." #define STR_MSG_PZF_DUMPED "PZF data dumped." #define STR_MSG_OPEN_FILE "ENTER THE NAME OF THE FILE TO LOAD:" #define STR_MSG_REUSE_BLOCKS "REUSE EXISTING BLOCKS ON IMPORT *** Y OR N:" #ifdef __cplusplus } #endif #endif
001tomclark-research-check
Source/Engine/strings.h
C
gpl2
673
/***************************************************************************** * ______ * / _ \ _ __ ______ * / /_ / / / //__ / / _ \ * / ____ / / / / / / / * / / / / / /_ / / * /_ / /_ / \ _____ / * ______ * / ____ / ______ _ __ _ ______ * / /___ / _ \ / //_ \ /_ / / _ \ * _\___ \ / / / / / / / / / / / / /_ / * / /_ / / / /_ / / / / / / / / / /____ * \______ / \ _____ / /_ / /_ / /_ / \ ______/ * * * ProSonic Engine * Created by Damian Grove * * Compiled with DJGPP - GCC 2.952 (DOS) / Dev-C++ 4.9.9.2 (Windows) * Libraries used: * - Allegro - 3.9.34 http://www.talula.demon.co.uk/allegro/ * - DUMB - 0.9.3 http://dumb.sourceforge.net/ * - AllegroOgg - 1.0.3 http://nekros.freeshell.org/delirium/ * ****************************************************************************** * * NAME: ProSonic - Read/write zone data * * FILE: zone.c * * DESCRIPTION: * All PZF and zone related functions go here. * *****************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> // Required for ENOMEM since "allegro.h" isn't included #include "zone.h" // #define PZF_COMPILE_INCLUDED void ClearZone(ZONE *z) { if(z){ if(z->Act) free(z->Act); z->Act = 0; if(z->OSC) free(z->OSC); if(z->BATT) free(z->BATT); if(z->BDAT) free(z->BDAT); if(z->BLOCK) free(z->BLOCK); if(z->BMAP) free(z->BMAP); if(z->BSOL) free(z->BSOL); if(z->OBJ) free(z->OBJ); if(z->TMAP) free(z->TMAP); if(z->WMAP) free(z->WMAP); if(z->CCYC) free(z->CCYC); if(z->FILTERDISTORTION) free(z->FILTERDISTORTION); if(z->FILTERCOMPOSITE) free(z->FILTERCOMPOSITE); z->OSC = 0; z->BATT = 0; z->BDAT = 0; z->BLOCK = 0; z->BMAP = 0; z->BSOL = 0; z->OBJ = 0; z->TMAP = 0; z->WMAP = 0; z->CCYC = 0; z->FILTERDISTORTION = 0; z->FILTERCOMPOSITE = 0; if(z->OSC_SizeTable) free(z->OSC_SizeTable); if(z->BATT_SizeTable) free(z->BATT_SizeTable); if(z->BDAT_SizeTable) free(z->BDAT_SizeTable); if(z->BLOCK_SizeTable) free(z->BLOCK_SizeTable); if(z->BMAP_SizeTable) free(z->BMAP_SizeTable); if(z->BSOL_SizeTable) free(z->BSOL_SizeTable); if(z->OBJ_SizeTable) free(z->OBJ_SizeTable); if(z->TMAP_SizeTable) free(z->TMAP_SizeTable); if(z->WMAP_SizeTable) free(z->WMAP_SizeTable); if(z->CCYC_SizeTable) free(z->CCYC_SizeTable); if(z->FILTERDISTORTION_SizeTable) free(z->FILTERDISTORTION_SizeTable); if(z->FILTERCOMPOSITE_SizeTable) free(z->FILTERCOMPOSITE_SizeTable); z->OSC_SizeTable = 0; z->BATT_SizeTable = 0; z->BDAT_SizeTable = 0; z->BLOCK_SizeTable = 0; z->BMAP_SizeTable = 0; z->BSOL_SizeTable = 0; z->OBJ_SizeTable = 0; z->TMAP_SizeTable = 0; z->WMAP_SizeTable = 0; z->CCYC_SizeTable = 0; z->FILTERDISTORTION_SizeTable = 0; z->FILTERCOMPOSITE_SizeTable = 0; if(z->OSC_AddressTable) free(z->OSC_AddressTable); if(z->BATT_AddressTable) free(z->BATT_AddressTable); if(z->BDAT_AddressTable) free(z->BDAT_AddressTable); if(z->BLOCK_AddressTable) free(z->BLOCK_AddressTable); if(z->BMAP_AddressTable) free(z->BMAP_AddressTable); if(z->BSOL_AddressTable) free(z->BSOL_AddressTable); if(z->OBJ_AddressTable) free(z->OBJ_AddressTable); if(z->TMAP_AddressTable) free(z->TMAP_AddressTable); if(z->WMAP_AddressTable) free(z->WMAP_AddressTable); if(z->CCYC_AddressTable) free(z->CCYC_AddressTable); if(z->FILTERDISTORTION_AddressTable) free(z->FILTERDISTORTION_AddressTable); if(z->FILTERCOMPOSITE_AddressTable) free(z->FILTERCOMPOSITE_AddressTable); z->OSC_AddressTable = 0; z->BATT_AddressTable = 0; z->BDAT_AddressTable = 0; z->BLOCK_AddressTable = 0; z->BMAP_AddressTable = 0; z->BSOL_AddressTable = 0; z->OBJ_AddressTable = 0; z->TMAP_AddressTable = 0; z->WMAP_AddressTable = 0; z->CCYC_AddressTable = 0; z->FILTERDISTORTION_AddressTable = 0; z->FILTERCOMPOSITE_AddressTable = 0; z->OSC_FileCount = 0; z->BATT_FileCount = 0; z->BDAT_FileCount = 0; z->BLOCK_FileCount = 0; z->BMAP_FileCount = 0; z->BSOL_FileCount = 0; z->OBJ_FileCount = 0; z->TMAP_FileCount = 0; z->WMAP_FileCount = 0; z->CCYC_FileCount = 0; z->FILTERDISTORTION_FileCount = 0; z->FILTERCOMPOSITE_FileCount = 0; } } void DeleteZone(ZONE *z) { if(z){ ClearZone(z); free(z); z = 0; } } #ifdef PZF_COMPILE_INCLUDED // READ WORD // int ReadWord(ZONE *z, const char *string, ...) { for(a=0; a<24; a++) item[a] = 0; for(a=0; a<24; a++){ c = ftell(txt_file); if(c < filesize_zone){ fread(&item[a], 1, 1, txt_file); } else{ item[a] = '\0'; a = 32; printf("* EOF *\n"); return 255; } printf("%c", item[a]);//////////////////// if(item[a] == ' ' || item[a] == 0x9 || item[a] == 0xA || item[a] == 0xD) { if(a == 0) a--; if(a > 0){ printf("ERROR 1: Invalid item \"%s\"\n", item); fclose(txt_file); free(z); return 1; } } else { if(item[a] == ':'){ item[a] = '\0'; printf("----");//////////// a = 32; } else if(a == 23){ printf("ERROR 2: Invalid item \"%s\"\n", item); fclose(txt_file); free(z); return 2; } } } b = 0; if(strcmp(&string[0], "ZONE.TXT") == 0) { if(strcmp(&item[0], "ZONENAME1") == 0) b = 1; else if(strcmp(&item[0], "ZONENAME2") == 0) b = 2; else if(strcmp(&item[0], "ACTS") == 0) b = 3; else if(strcmp(&item[0], "STAGE1A") == 0) b = 0x10; else if(strcmp(&item[0], "STAGE1B") == 0) b = 0x11; else if(strcmp(&item[0], "STAGE1C") == 0) b = 0x12; else if(strcmp(&item[0], "STAGE1D") == 0) b = 0x13; else if(strcmp(&item[0], "STAGE2A") == 0) b = 0x20; else if(strcmp(&item[0], "STAGE2B") == 0) b = 0x21; else if(strcmp(&item[0], "STAGE2C") == 0) b = 0x22; else if(strcmp(&item[0], "STAGE2D") == 0) b = 0x23; else if(strcmp(&item[0], "STAGE3A") == 0) b = 0x30; else if(strcmp(&item[0], "STAGE3B") == 0) b = 0x31; else if(strcmp(&item[0], "STAGE3C") == 0) b = 0x32; else if(strcmp(&item[0], "STAGE3D") == 0) b = 0x33; else if(strcmp(&item[0], "STAGE4A") == 0) b = 0x40; else if(strcmp(&item[0], "STAGE4B") == 0) b = 0x41; else if(strcmp(&item[0], "STAGE4C") == 0) b = 0x42; else if(strcmp(&item[0], "STAGE4D") == 0) b = 0x43; else if(strcmp(&item[0], "STAGE5A") == 0) b = 0x50; else if(strcmp(&item[0], "STAGE5B") == 0) b = 0x51; else if(strcmp(&item[0], "STAGE5C") == 0) b = 0x52; else if(strcmp(&item[0], "STAGE5D") == 0) b = 0x53; else if(strcmp(&item[0], "STAGE6A") == 0) b = 0x60; else if(strcmp(&item[0], "STAGE6B") == 0) b = 0x61; else if(strcmp(&item[0], "STAGE6C") == 0) b = 0x62; else if(strcmp(&item[0], "STAGE6D") == 0) b = 0x63; else if(strcmp(&item[0], "STAGE7A") == 0) b = 0x70; else if(strcmp(&item[0], "STAGE7B") == 0) b = 0x71; else if(strcmp(&item[0], "STAGE7C") == 0) b = 0x72; else if(strcmp(&item[0], "STAGE7D") == 0) b = 0x73; else if(strcmp(&item[0], "STAGE8A") == 0) b = 0x80; else if(strcmp(&item[0], "STAGE8B") == 0) b = 0x81; else if(strcmp(&item[0], "STAGE8C") == 0) b = 0x82; else if(strcmp(&item[0], "STAGE8D") == 0) b = 0x83; } else if(strcmp(&string[0], "INDEX.TXT") == 0) { if(strcmp(&item[0], "FILES") == 0) b = 0x200; else if(item[0] == '0' && item[1] == '\0') b = 0x201; else if(strtol(&item[0], NULL, 10) < 256 && strtol(&item[0], NULL, 10) > 0) b = strtol(&item[0], NULL, 10) + 0x201; } else { if(strcmp(&item[0], "NAME") == 0) b = 0x100; else if(strcmp(&item[0], "ACTNUMBER") == 0) b = 0x101; else if(strcmp(&item[0], "MUSICREGULAR") == 0) b = 0x102; else if(strcmp(&item[0], "MUSICALTERNATIVE") == 0) b = 0x103; else if(strcmp(&item[0], "OPENINGSCRIPT") == 0) b = 0x104; else if(strcmp(&item[0], "CLOSINGSCRIPT") == 0) b = 0x105; else if(strcmp(&item[0], "ACTIVESCRIPT") == 0) b = 0x106; else if(strcmp(&item[0], "WATERENABLE") == 0) b = 0x107; else if(strcmp(&item[0], "WRAPPOINT") == 0) b = 0x108; else if(strcmp(&item[0], "ABOVEWATERFILTERL") == 0) b = 0x109; else if(strcmp(&item[0], "BELOWWATERFILTERL") == 0) b = 0x10A; else if(strcmp(&item[0], "ABOVEWATERFILTERSPEED") == 0) b = 0x10B; else if(strcmp(&item[0], "BELOWWATERFILTERSPEED") == 0) b = 0x10C; else if(strcmp(&item[0], "CLEARBACKGROUND") == 0) b = 0x10D; // PLACE HOLDER FOR 0x10E else if(strcmp(&item[0], "PALETTE") == 0) b = 0x10F; else if(strcmp(&item[0], "COLORCYCLER") == 0) b = 0x110; else if(strcmp(&item[0], "WATERMAP") == 0) b = 0x111; else if(strcmp(&item[0], "BLOCKMAP") == 0) b = 0x112; else if(strcmp(&item[0], "BLOCKART") == 0) b = 0x113; else if(strcmp(&item[0], "BLOCKDATA") == 0) b = 0x114; else if(strcmp(&item[0], "BLOCKATTRIBUTES") == 0) b = 0x115; else if(strcmp(&item[0], "BLOCKSOLIDITY") == 0) b = 0x116; else if(strcmp(&item[0], "TILEMAP") == 0) b = 0x117; else if(strcmp(&item[0], "OBJECTLAYOUT") == 0) b = 0x118; else if(strcmp(&item[0], "WATERHEIGHT") == 0) b = 0x119; else if(strcmp(&item[0], "LEVELXL") == 0) b = 0x11A; else if(strcmp(&item[0], "LEVELXR") == 0) b = 0x11B; else if(strcmp(&item[0], "LEVELYT") == 0) b = 0x11C; else if(strcmp(&item[0], "LEVELYB") == 0) b = 0x11D; else if(strcmp(&item[0], "START0X") == 0) b = 0x11E; else if(strcmp(&item[0], "START0Y") == 0) b = 0x11F; else if(strcmp(&item[0], "START1X") == 0) b = 0x120; else if(strcmp(&item[0], "START1Y") == 0) b = 0x121; else if(strcmp(&item[0], "START2X") == 0) b = 0x122; else if(strcmp(&item[0], "START2Y") == 0) b = 0x123; else if(strcmp(&item[0], "START3X") == 0) b = 0x124; else if(strcmp(&item[0], "START3Y") == 0) b = 0x125; else if(strcmp(&item[0], "START4X") == 0) b = 0x126; else if(strcmp(&item[0], "START4Y") == 0) b = 0x127; else if(strcmp(&item[0], "START5X") == 0) b = 0x128; else if(strcmp(&item[0], "START5Y") == 0) b = 0x129; else if(strcmp(&item[0], "START6X") == 0) b = 0x12A; else if(strcmp(&item[0], "START6Y") == 0) b = 0x12B; else if(strcmp(&item[0], "START7X") == 0) b = 0x12C; else if(strcmp(&item[0], "START7Y") == 0) b = 0x12D; else if(strcmp(&item[0], "START8X") == 0) b = 0x12E; else if(strcmp(&item[0], "START8Y") == 0) b = 0x12F; else if(strcmp(&item[0], "START9X") == 0) b = 0x130; else if(strcmp(&item[0], "START9Y") == 0) b = 0x131; else if(strcmp(&item[0], "STARTAX") == 0) b = 0x132; else if(strcmp(&item[0], "STARTAY") == 0) b = 0x133; else if(strcmp(&item[0], "STARTBX") == 0) b = 0x134; else if(strcmp(&item[0], "STARTBY") == 0) b = 0x135; else if(strcmp(&item[0], "STARTCX") == 0) b = 0x136; else if(strcmp(&item[0], "STARTCY") == 0) b = 0x137; else if(strcmp(&item[0], "STARTDX") == 0) b = 0x138; else if(strcmp(&item[0], "STARTDY") == 0) b = 0x139; else if(strcmp(&item[0], "STARTEX") == 0) b = 0x13A; else if(strcmp(&item[0], "STARTEY") == 0) b = 0x13B; else if(strcmp(&item[0], "STARTFX") == 0) b = 0x13C; else if(strcmp(&item[0], "STARTFY") == 0) b = 0x13D; } if(b == 0){ printf("ERROR 3: Invalid item \"%s\"\n", item); fclose(txt_file); free(z); return 3; } if(z->Act_FileCount == 0 && b >= 10){ printf("ERROR 4: \"%s\" defined before \"ACTS\"\n", &item[0]); fclose(txt_file); free(z); return 4; } printf("%i\n", b); return 0; } int ReadText(ZONE *z, const char *string, ...) { // READ TEXT // for(a=0; a<24; a++) item[a] = 0; for(a=0; a<24; a++){ c = ftell(txt_file); while(a == 0 && c < filesize_zone && item[0] != '"') fread(&item[0], 1, 1, txt_file); if(c < filesize_zone) fread(&item[a], 1, 1, txt_file); else{ item[a] = '\0'; a = 32; return 255; } printf("%c", item[a]);/////////////////// if(a > 0 && item[a] == '"'){ item[a] = '\0'; a = 32; printf("----\n");//////////// return 0; } } return 0; } int ReadVar(ZONE *z, const char *string, ...) { // READ VARIABLE // for(a=0; a<24; a++) item[a] = 0; for(a=0; a<11; a++){ c = ftell(txt_file); if(c < filesize_zone) fread(&item[a], 1, 1, txt_file); else{ item[a] = '\0'; a = 32; endoffile = 1; } if(item[a] == ' ' || item[a] == 0x9 || item[a] == 0xA || item[a] == 0xD) { if(a == 0) a--; else if(a == 2 && (item[1] == 'x' || item[1] == 'X')){ printf("ERROR 5: Invalid value\n"); fclose(txt_file); free(z); return 5; } else if(a > 0){ item[a] = '\0'; a = 32; } } else { if(item[a] < '0' || item[a] > '9'){ if(a == 1){ if(item[0] != '0' || (item[1] != 'x' && item[1] != 'X')){ printf("ERROR 6: Invalid value\n"); fclose(txt_file); free(z); return 6; } } else if(a == 0){ printf("ERROR 7: Invalid value\n"); fclose(txt_file); free(z); return 6; } else if(a > 1 && (item[a] < 'A' || (item[a] > 'F' && item[a] < 'a') || item[a] > 'f')){ //else if(item[a] != 'x' && item[a] != 'X'){ printf("ERROR 8: Invalid value\n"); fclose(txt_file); free(z); return 7; } } } } if(item[0] == '0' && (item[1] == 'x' || item[1] == 'X')) d = strtol(&item[2], NULL, 16); else d = strtol(&item[0], NULL, 10); if(endoffile == 1){ endoffile = 0; return 255; } printf("VALUE = %i\n", d); return 0; } int ReadFloatVar(ZONE *z, const char *string, ...) { // READ VARIABLE // for(a=0; a<24; a++) item[a] = 0; for(a=0; a<11; a++){ c = ftell(txt_file); if(c < filesize_zone) fread(&item[a], 1, 1, txt_file); else{ item[a] = '\0'; a = 32; endoffile = 1; } if(item[a] == ' ' || item[a] == 0x9 || item[a] == 0xA || item[a] == 0xD) { if(a == 0) a--; else if(a == 2 && (item[1] == 'x' || item[1] == 'X')){ printf("ERROR 5: Invalid value\n"); fclose(txt_file); free(z); return 5; } else if(a > 0){ item[a] = '\0'; a = 32; } } else { if(item[a] < '0' || item[a] > '9'){ if(a != 1){ printf("ERROR 6: Invalid value\n"); fclose(txt_file); free(z); return 6; } else if(item[a] != '.'){ printf("ERROR 7: Invalid value\n"); fclose(txt_file); free(z); return 7; } } } } f = (float)strtod(&item[0], NULL); if(endoffile == 1){ endoffile = 0; return 255; } printf("VALUE = %f\n", f); return 0; } int CompileZone(ZONE *z, const char *string, ...) { int e; //CreateZone(z); //z = malloc(1); z->Act = 0; z->OSC_SizeTable = 0; z->BATT_SizeTable = 0; z->BDAT_SizeTable = 0; z->BLOCK_SizeTable = 0; z->BMAP_SizeTable = 0; z->BSOL_SizeTable = 0; z->OBJ_SizeTable = 0; z->PAL_SizeTable = 0; z->TMAP_SizeTable = 0; z->WMAP_SizeTable = 0; z->CCYC_SizeTable = 0; z->FILTERDISTORTION_SizeTable = 0; z->FILTERCOMPOSITE_SizeTable = 0; z->OSC_AddressTable = 0; z->BATT_AddressTable = 0; z->BDAT_AddressTable = 0; z->BLOCK_AddressTable = 0; z->BMAP_AddressTable = 0; z->BSOL_AddressTable = 0; z->OBJ_AddressTable = 0; z->PAL_AddressTable = 0; z->TMAP_AddressTable = 0; z->WMAP_AddressTable = 0; z->CCYC_AddressTable = 0; z->FILTERDISTORTION_AddressTable = 0; z->FILTERCOMPOSITE_AddressTable = 0; z->OSC = 0; z->BATT = 0; z->BDAT = 0; z->BLOCK = 0; z->BMAP = 0; z->BSOL = 0; z->OBJ = 0; z->PAL = 0; z->TMAP = 0; z->WMAP = 0; z->CCYC = 0; z->FILTERDISTORTION = 0; z->FILTERCOMPOSITE = 0; txt_file = fopen("ZONE.TXT", "r+b"); fseek(txt_file, 0, SEEK_END); filesize_zone = ftell(txt_file); rewind(txt_file); ////////////// // ZONE.TXT // ////////////// a = 0; b = 0; c = 0; d = 0; while(ReadWord(z, "ZONE.TXT") != 255){ // b = d (b is the item, d is the value) if(b == 1 || b == 2){ // TEXT e = ReadText(z, "ZONE.TXT"); if(e == 255){ printf("DONE!\n"); //free(z); fclose(txt_file); return 0; } else if(b == 1){ for(a=0; a<20; a++) z->LevelName1[a] = item[a]; } else{ for(a=0; a<20; a++) z->LevelName2[a] = item[a]; } } else if(b > 2){ // VARIABLE if(ReadVar(z, "ZONE.TXT") == 255){ printf("DONE!\n"); //free(z); fclose(txt_file); return 0; } else{ if(b == 3){ z->Act_FileCount = d; z->Act = (ACT*)realloc(z->Act, sizeof(ACT) * z->Act_FileCount); } else{ if(b&3 == 0) a = 0xE; else if(b&3 == 1) a = 0xD; else if(b&3 == 2) a = 0xB; else a = 0x7; z->Act[(b>>4)-1].IncludedStages &= a; z->Act[(b>>4)-1].IncludedStages += (d << (b&3)); } } } else{ printf("1: Cannot compile because of an error in \"ZONE.TXT\"\n"); free(z); fclose(txt_file); return 1; } } fclose(txt_file); ///////////////// // STAGExx.TXT // ///////////////// strcpy(&filename[0], ".\\ACTa\\STAGEc.TXT"); for(a01=0; a01 < z->Act_FileCount; a01++){ filename[5] = '1' + a01; for(c01=0; c01<4; c01++){ filename[12] = 'A' + c01; if(fopen(&filename[0], "r+b") != 0 && (z->Act[a01].IncludedStages >> c01) & 1 == 1){ txt_file = fopen(&filename[0], "r+b"); printf("%s\n", &filename[0]); fseek(txt_file, 0, SEEK_END); filesize_zone = ftell(txt_file); rewind(txt_file); while(ReadWord(z, &filename[0]) != 255){ // b = d (b is the item, d is the value) switch(b){ case 0x100: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].Name = d; break; case 0x101: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].ActNumber = d; break; case 0x102: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].MusicRegular = d; break; case 0x103: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].MusicAlternate = d; break; case 0x104: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].OpeningScript = d; break; case 0x105: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].ClosingScript = d; break; case 0x106: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].ActiveScript = d; break; case 0x107: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].WaterEnable = d; break; case 0x108: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].WrapPoint = d; break; case 0x109: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].AboveWaterFilterL = d; break; case 0x10A: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].BelowWaterFilterL = d; break; case 0x10B: ReadFloatVar(z, &filename[0]); z->Act[a01].Stage[c01].AboveWaterFilterSpeed = f; break; case 0x10C: ReadFloatVar(z, &filename[0]); z->Act[a01].Stage[c01].BelowWaterFilterSpeed = f; break; case 0x10D: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].ClearBackground = d; break; // PLACE HOLDER FOR 0x10E case 0x10F: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].Palette = d; break; case 0x110: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].ColorCycle = d; break; case 0x111: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].WaterMap = d; break; case 0x112: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].BlockMap = d; break; case 0x113: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].BlockArt = d; break; case 0x114: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].BlockData = d; break; case 0x115: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].BlockAttributes = d; break; case 0x116: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].BlockSolidity = d; break; case 0x117: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].TileMap = d; break; case 0x118: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].ObjectLayout = d; break; case 0x119: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].WaterHeight = d; break; case 0x11A: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].LevelXL = d; break; case 0x11B: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].LevelXR = d; break; case 0x11C: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].LevelYT = d; break; case 0x11D: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].LevelYB = d; break; case 0x11E: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartX[0] = d; break; case 0x11F: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartY[0] = d; break; case 0x120: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartX[1] = d; break; case 0x121: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartY[1] = d; break; case 0x122: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartX[2] = d; break; case 0x123: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartY[2] = d; break; case 0x124: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartX[3] = d; break; case 0x125: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartY[3] = d; break; case 0x126: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartX[4] = d; break; case 0x127: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartY[4] = d; break; case 0x128: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartX[5] = d; break; case 0x129: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartY[5] = d; break; case 0x12A: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartX[6] = d; break; case 0x12B: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartY[6] = d; break; case 0x12C: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartX[7] = d; break; case 0x12D: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartY[7] = d; break; case 0x12E: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartX[8] = d; break; case 0x12F: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartY[8] = d; break; case 0x130: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartX[9] = d; break; case 0x131: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartY[9] = d; break; case 0x132: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartX[10] = d; break; case 0x133: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartY[10] = d; break; case 0x134: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartX[11] = d; break; case 0x135: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartY[11] = d; break; case 0x136: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartX[12] = d; break; case 0x137: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartY[12] = d; break; case 0x138: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartX[13] = d; break; case 0x139: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartY[13] = d; break; case 0x13A: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartX[14] = d; break; case 0x13B: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartY[14] = d; break; case 0x13C: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartX[15] = d; break; case 0x13D: ReadVar(z, &filename[0]); z->Act[a01].Stage[c01].StartY[15] = d; break; default: printf("1: Cannot compile because of an error in \"STAGExx.TXT\"\n"); free(z); fclose(txt_file); return 1; } } fclose(txt_file); } } } /////////////// // INDEX.TXT // /////////////// c01 = 0; for(a01=0; a01<13; a01++){ switch(a01){ case 0: strcpy(&filename[0], ".\\OSC\\INDEX.TXT"); strcpy(&path[0], ".\\OSC\\"); printf("case %i\n", a01); break; case 1: strcpy(&filename[0], ".\\BATT\\INDEX.TXT"); strcpy(&path[0], ".\\BATT\\"); printf("case %i\n", a01); break; case 2: strcpy(&filename[0], ".\\BDAT\\INDEX.TXT"); strcpy(&path[0], ".\\BDAT\\"); printf("case %i\n", a01); break; case 3: strcpy(&filename[0], ".\\BLOCK\\INDEX.TXT"); strcpy(&path[0], ".\\BLOCK\\"); printf("case %i\n", a01); break; case 4: strcpy(&filename[0], ".\\BMAP\\INDEX.TXT"); strcpy(&path[0], ".\\BMAP\\"); printf("case %i\n", a01); break; case 5: strcpy(&filename[0], ".\\BSOL\\INDEX.TXT"); strcpy(&path[0], ".\\BSOL\\"); printf("case %i\n", a01); break; case 6: strcpy(&filename[0], ".\\OBJ\\INDEX.TXT"); strcpy(&path[0], ".\\OBJ\\"); printf("case %i\n", a01); break; case 7: strcpy(&filename[0], ".\\PAL\\INDEX.TXT"); strcpy(&path[0], ".\\PAL\\"); printf("case %i\n", a01); break; case 8: strcpy(&filename[0], ".\\TMAP\\INDEX.TXT"); strcpy(&path[0], ".\\TMAP\\"); printf("case %i\n", a01); break; case 9: strcpy(&filename[0], ".\\WMAP\\INDEX.TXT"); strcpy(&path[0], ".\\WMAP\\"); printf("case %i\n", a01); break; case 10: strcpy(&filename[0], ".\\CCYC\\INDEX.TXT"); strcpy(&path[0], ".\\CCYC\\"); printf("case %i\n", a01); break; case 11: strcpy(&filename[0], ".\\FILTERDISTORTION\\INDEX.TXT"); strcpy(&path[0], ".\\FILTERDISTORTION\\"); printf("case %i\n", a01); break; default: strcpy(&filename[0], ".\\FILTERCOMPOSITE\\INDEX.TXT"); strcpy(&path[0], ".\\FILTERCOMPOSITE\\"); printf("case %i\n", a01); } txt_file = fopen(&filename[0], "r+b"); fseek(txt_file, 0, SEEK_END); filesize_zone = ftell(txt_file); rewind(txt_file); while(ReadWord(z, "INDEX.TXT") != 255){ // b = d (b is the item, d is the value) if(b > 0x200){ // FILE NAMES printf("text\n"); e = ReadText(z, "INDEX.TXT"); if(e == 255){ printf("DONE!\n"); //free(z); fclose(txt_file); return 0; } else{ for(c=0; c < 24; c++) filename[c] = 0; strcpy(&filename[0], &path[0]); strcat(&filename[0], &item[0]); txt_data = fopen(&filename[0], "r+b"); if(txt_data == NULL) printf("ERROR: CANNOT OPEN DATA FILE!\n"); fseek(txt_data, 0, SEEK_END); c = ftell(txt_data); //filesize_zone = ftell(txt_file); rewind(txt_data); switch(a01){ case 0: printf(" case %i\n", a01); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->OSC = (unsigned char*)realloc(z->OSC, c01 + c); for(a=0; a<c; a++) fread(&z->OSC[c01+a], 1, 1, txt_data); z->OSC_SizeTable[(b-1) & 0xFF] = c; z->OSC_AddressTable[(b-1) & 0xFF] = c01; c01 += c; break; case 1: printf(" case %i\n", a01); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->BATT = (unsigned char*)realloc(z->BATT, c01 + c); for(a=0; a<c; a++) fread(&z->BATT[c01+a], 1, 1, txt_data); z->BATT_SizeTable[(b-1) & 0xFF] = c; z->BATT_AddressTable[(b-1) & 0xFF] = c01; c01 += c; break; case 2: printf(" case %i\n", a01); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->BDAT = (unsigned char*)realloc(z->BDAT, c01 + c); for(a=0; a<c; a++) fread(&z->BDAT[c01+a], 1, 1, txt_data); z->BDAT_SizeTable[(b-1) & 0xFF] = c; z->BDAT_AddressTable[(b-1) & 0xFF] = c01; c01 += c; break; case 3: printf(" case %i\n", a01); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->BLOCK = (unsigned char*)realloc(z->BLOCK, c01 + c); for(a=0; a<c; a++) fread(&z->BLOCK[c01+a], 1, 1, txt_data); z->BLOCK_SizeTable[(b-1) & 0xFF] = c; z->BLOCK_AddressTable[(b-1) & 0xFF] = c01; c01 += c; break; case 4: printf(" case %i\n", a01); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->BMAP = (unsigned char*)realloc(z->BMAP, c01 + c); for(a=0; a<c; a++) fread(&z->BMAP[c01+a], 1, 1, txt_data); z->BMAP_SizeTable[(b-1) & 0xFF] = c; z->BMAP_AddressTable[(b-1) & 0xFF] = c01; c01 += c; break; case 5: printf(" case %i\n", a01); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->BSOL = (unsigned char*)realloc(z->BSOL, c01 + c); for(a=0; a<c; a++) fread(&z->BSOL[c01+a], 1, 1, txt_data); z->BSOL_SizeTable[(b-1) & 0xFF] = c; z->BSOL_AddressTable[(b-1) & 0xFF] = c01; c01 += c; break; case 6: printf(" case %i\n", a01); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->OBJ = (unsigned char*)realloc(z->OBJ, c01 + c); for(a=0; a<c; a++) fread(&z->OBJ[c01+a], 1, 1, txt_data); z->OBJ_SizeTable[(b-1) & 0xFF] = c; z->OBJ_AddressTable[(b-1) & 0xFF] = c01; c01 += c; break; case 7: printf(" case %i\n", a01); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->PAL = (unsigned char*)realloc(z->PAL, c01 + c); for(a=0; a<c; a++) fread(&z->PAL[c01+a], 1, 1, txt_data); z->PAL_SizeTable[(b-1) & 0xFF] = c; z->PAL_AddressTable[(b-1) & 0xFF] = c01; c01 += c; break; case 8: printf(" case %i\n", a01); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->TMAP = (unsigned char*)realloc(z->TMAP, c01 + c); for(a=0; a<c; a++) fread(&z->TMAP[c01+a], 1, 1, txt_data); z->TMAP_SizeTable[(b-1) & 0xFF] = c; z->TMAP_AddressTable[(b-1) & 0xFF] = c01; c01 += c; break; case 9: printf(" case %i\n", a01); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->WMAP = (unsigned char*)realloc(z->WMAP, c01 + c); for(a=0; a<c; a++) fread(&z->WMAP[c01+a], 1, 1, txt_data); z->WMAP_SizeTable[(b-1) & 0xFF] = c; z->WMAP_AddressTable[(b-1) & 0xFF] = c01; c01 += c; break; case 10: printf(" case %i\n", a01); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->CCYC = (unsigned char*)realloc(z->CCYC, c01 + c); for(a=0; a<c; a++) fread(&z->CCYC[c01+a], 1, 1, txt_data); z->CCYC_SizeTable[(b-1) & 0xFF] = c; z->CCYC_AddressTable[(b-1) & 0xFF] = c01; c01 += c; break; case 11: printf(" case %i\n", a01); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->FILTERDISTORTION = (unsigned char*)realloc(z->FILTERDISTORTION, c01 + c); for(a=0; a<c; a++) fread(&z->FILTERDISTORTION[c01+a], 1, 1, txt_data); z->FILTERDISTORTION_SizeTable[(b-1) & 0xFF] = c; z->FILTERDISTORTION_AddressTable[(b-1) & 0xFF] = c01; c01 += c; break; default: printf(" case %i\n", a01); printf(" %s\n", &filename[0]); printf(" %i bytes\n", c); z->FILTERCOMPOSITE = (unsigned char*)realloc(z->FILTERCOMPOSITE, c01 + c); for(a=0; a<c; a++) fread(&z->FILTERCOMPOSITE[c01+a], 1, 1, txt_data); z->FILTERCOMPOSITE_SizeTable[(b-1) & 0xFF] = c; z->FILTERCOMPOSITE_AddressTable[(b-1) & 0xFF] = c01; c01 += c; break; } printf("\n\n========================================\n\n"); fclose(txt_data); } } else if(b == 0x200){ // NUMBER OF FILES printf("var\n"); if(ReadVar(z, "INDEX.TXT") == 255){ printf("DONE!\n"); //free(z); fclose(txt_file); return 0; } else{ switch(a01){ case 0: z->OSC_FileCount = d; z->OSC_SizeTable = (unsigned int*)realloc(z->OSC_SizeTable, d << 2); z->OSC_AddressTable = (unsigned int*)realloc(z->OSC_AddressTable, d << 2); c01 = 0; break; case 1: z->BATT_FileCount = d; z->BATT_SizeTable = (unsigned int*)realloc(z->BATT_SizeTable, d << 2); z->BATT_AddressTable = (unsigned int*)realloc(z->BATT_AddressTable, d << 2); c01 = 0; break; case 2: z->BDAT_FileCount = d; z->BDAT_SizeTable = (unsigned int*)realloc(z->BDAT_SizeTable, d << 2); z->BDAT_AddressTable = (unsigned int*)realloc(z->BDAT_AddressTable, d << 2); c01 = 0; break; case 3: z->BLOCK_FileCount = d; z->BLOCK_SizeTable = (unsigned int*)realloc(z->BLOCK_SizeTable, d << 2); z->BLOCK_AddressTable = (unsigned int*)realloc(z->BLOCK_AddressTable, d << 2); c01 = 0; break; case 4: z->BMAP_FileCount = d; z->BMAP_SizeTable = (unsigned int*)realloc(z->BMAP_SizeTable, d << 2); z->BMAP_AddressTable = (unsigned int*)realloc(z->BMAP_AddressTable, d << 2); c01 = 0; break; case 5: z->BSOL_FileCount = d; z->BSOL_SizeTable = (unsigned int*)realloc(z->BSOL_SizeTable, d << 2); z->BSOL_AddressTable = (unsigned int*)realloc(z->BSOL_AddressTable, d << 2); c01 = 0; break; case 6: z->OBJ_FileCount = d; z->OBJ_SizeTable = (unsigned int*)realloc(z->OBJ_SizeTable, d << 2); z->OBJ_AddressTable = (unsigned int*)realloc(z->OBJ_AddressTable, d << 2); c01 = 0; break; case 7: z->PAL_FileCount = d; z->PAL_SizeTable = (unsigned int*)realloc(z->PAL_SizeTable, d << 2); z->PAL_AddressTable = (unsigned int*)realloc(z->PAL_AddressTable, d << 2); c01 = 0; break; case 8: z->TMAP_FileCount = d; z->TMAP_SizeTable = (unsigned int*)realloc(z->TMAP_SizeTable, d << 2); z->TMAP_AddressTable = (unsigned int*)realloc(z->TMAP_AddressTable, d << 2); c01 = 0; break; case 9: z->WMAP_FileCount = d; z->WMAP_SizeTable = (unsigned int*)realloc(z->WMAP_SizeTable, d << 2); z->WMAP_AddressTable = (unsigned int*)realloc(z->WMAP_AddressTable, d << 2); c01 = 0; break; case 10: z->CCYC_FileCount = d; z->CCYC_SizeTable = (unsigned int*)realloc(z->CCYC_SizeTable, d << 2); z->CCYC_AddressTable = (unsigned int*)realloc(z->CCYC_AddressTable, d << 2); c01 = 0; break; case 11: z->FILTERDISTORTION_FileCount = d; z->FILTERDISTORTION_SizeTable = (unsigned int*)realloc(z->FILTERDISTORTION_SizeTable, d << 2); z->FILTERDISTORTION_AddressTable = (unsigned int*)realloc(z->FILTERDISTORTION_AddressTable, d << 2); c01 = 0; break; default: z->FILTERCOMPOSITE_FileCount = d; z->FILTERCOMPOSITE_SizeTable = (unsigned int*)realloc(z->FILTERCOMPOSITE_SizeTable, d << 2); z->FILTERCOMPOSITE_AddressTable = (unsigned int*)realloc(z->FILTERCOMPOSITE_AddressTable, d << 2); c01 = 0; } } } else{ printf("1: Cannot compile because of an error in \"INDEX.TXT\"\n"); free(z); fclose(txt_file); return 1; } } fclose(txt_file); } return 0; } #endif int CreateZone(ZONE *z) { //z = malloc(1); if(!z) z = malloc(sizeof(ZONE)); z->OSC = 0; z->BATT = 0; z->BDAT = 0; z->BLOCK = 0; z->BMAP = 0; z->BSOL = 0; z->OBJ = 0; z->PAL = 0; z->TMAP = 0; z->WMAP = 0; z->CCYC = 0; z->FILTERDISTORTION = 0; z->FILTERCOMPOSITE = 0; return 0; } int LoadZone(ZONE *z, const char *string, ...) { int a = 0; int b = 0; int c = 0; int d = 0; int x[2]; long filesize; FILE *pzf; pzf = fopen(string, "r+b"); if(!pzf){ allegro_message("Could not open file \"%s\".", string); return 3; // error! } fseek(pzf, 0, SEEK_END); filesize = ftell(pzf); fseek(pzf, 0, SEEK_SET); if(filesize >= 109){ fread(&a, 1, 3, pzf); // "PZF" d = getc(pzf); // version } else return 1; if(a != 0x465A50) // if "PZF" not found in header return 2; if(d != 0) allegro_message("Warning: unrecognized PZF file version!"); // Create an instance of a ZONE //z = malloc(1); ClearZone(z); fread(&z->LevelName1, 1, 20, pzf); //fread(&z->LevelName2, 1, 20, pzf); // unused fseek(pzf, 20, SEEK_CUR); z->Act_FileCount = getc(pzf); z->OSC_FileCount = getc(pzf); z->BATT_FileCount = getc(pzf); z->BDAT_FileCount = getc(pzf); z->BLOCK_FileCount = getc(pzf); z->BMAP_FileCount = getc(pzf); z->BSOL_FileCount = getc(pzf); z->OBJ_FileCount = getc(pzf); z->PAL_FileCount = getc(pzf); z->TMAP_FileCount = getc(pzf); z->WMAP_FileCount = getc(pzf); z->CCYC_FileCount = getc(pzf); z->FILTERDISTORTION_FileCount = getc(pzf); z->FILTERCOMPOSITE_FileCount = getc(pzf); //////////////////// // READ ACT FILES // //////////////////// z->Act = (ACT*)malloc(sizeof(ACT) * z->Act_FileCount); fread(&a, 4, 1, pzf); // Read "Act" table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->Act_FileCount; b++){ x[1] = ftell(pzf); c = getc(pzf); // Read IncludedStages z->Act[b].IncludedStages = c; // Write IncludedStages fread(&a, 4, 1, pzf); // Read stage address fseek(pzf, a, SEEK_SET); // Jump to address for(c=0; c<4; c++){ switch(c){ case 0: a = (z->Act[b].IncludedStages & 1); break; case 1: a = ((z->Act[b].IncludedStages >> 1) & 1); break; case 2: a = ((z->Act[b].IncludedStages >> 2) & 1); break; default: a = ((z->Act[b].IncludedStages >> 3) & 1); } if(a == 1){ z->Act[b].Stage[c].Name = getc(pzf); z->Act[b].Stage[c].ActNumber = getc(pzf); z->Act[b].Stage[c].MusicRegular = getc(pzf); z->Act[b].Stage[c].MusicAlternate = getc(pzf); z->Act[b].Stage[c].OpeningScript = getc(pzf); z->Act[b].Stage[c].ClosingScript = getc(pzf); z->Act[b].Stage[c].ActiveScript = getc(pzf); z->Act[b].Stage[c].WaterEnable = getc(pzf); fread(&z->Act[b].Stage[c].WrapPoint, 2, 1, pzf); z->Act[b].Stage[c].AboveWaterFilterL = getc(pzf); z->Act[b].Stage[c].BelowWaterFilterL = getc(pzf); fread(&z->Act[b].Stage[c].AboveWaterFilterSpeed, 4, 1, pzf); fread(&z->Act[b].Stage[c].BelowWaterFilterSpeed, 4, 1, pzf); z->Act[b].Stage[c].ClearBackground = getc(pzf); // PLACE HOLDER FOR 0x10E z->Act[b].Stage[c].Palette = getc(pzf); z->Act[b].Stage[c].ColorCycle = getc(pzf); z->Act[b].Stage[c].WaterMap = getc(pzf); z->Act[b].Stage[c].BlockMap = getc(pzf); z->Act[b].Stage[c].BlockArt = getc(pzf); z->Act[b].Stage[c].BlockData = getc(pzf); z->Act[b].Stage[c].BlockAttributes = getc(pzf); z->Act[b].Stage[c].BlockSolidity = getc(pzf); z->Act[b].Stage[c].TileMap = getc(pzf); z->Act[b].Stage[c].ObjectLayout = getc(pzf); fread(&z->Act[b].Stage[c].WaterHeight, 2, 1, pzf); fread(&z->Act[b].Stage[c].LevelXL, 2, 1, pzf); fread(&z->Act[b].Stage[c].LevelXR, 2, 1, pzf); fread(&z->Act[b].Stage[c].LevelYT, 2, 1, pzf); fread(&z->Act[b].Stage[c].LevelYB, 2, 1, pzf); fread(&z->Act[b].Stage[c].StartX[0], 2, 16, pzf); fread(&z->Act[b].Stage[c].StartY[0], 2, 16, pzf); } } fseek(pzf, x[1] + 4, SEEK_SET); // Set it up to read the next act } //////////////////// // READ OSC FILES // //////////////////// fseek(pzf, x[0], SEEK_SET); z->OSC_SizeTable = (unsigned int*)malloc(z->OSC_FileCount << 2); z->OSC_AddressTable = (unsigned int*)malloc(z->OSC_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->OSC_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->OSC_AddressTable[b] = filesize_data; z->OSC_SizeTable[b] = d; filesize_data += d; z->OSC = (unsigned char*)realloc(z->OSC, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address fread(&z->OSC[z->OSC_AddressTable[b]], 1, d, pzf); fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////// // READ BATT FILES // ///////////////////// fseek(pzf, x[0], SEEK_SET); z->BATT_SizeTable = (unsigned int*)malloc(z->BATT_FileCount << 2); z->BATT_AddressTable = (unsigned int*)malloc(z->BATT_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->BATT_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->BATT_AddressTable[b] = filesize_data; z->BATT_SizeTable[b] = d; filesize_data += d; z->BATT = (unsigned char*)realloc(z->BATT, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address fread(&z->BATT[z->BATT_AddressTable[b]], 1, d, pzf); fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////// // READ BDAT FILES // ///////////////////// fseek(pzf, x[0], SEEK_SET); z->BDAT_SizeTable = (unsigned int*)malloc(z->BDAT_FileCount << 2); z->BDAT_AddressTable = (unsigned int*)malloc(z->BDAT_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->BDAT_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->BDAT_AddressTable[b] = filesize_data; z->BDAT_SizeTable[b] = d; filesize_data += d; z->BDAT = (unsigned char*)realloc(z->BDAT, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address fread(&z->BDAT[z->BDAT_AddressTable[b]], 1, d, pzf); fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ////////////////////// // READ BLOCK FILES // ////////////////////// fseek(pzf, x[0], SEEK_SET); z->BLOCK_SizeTable = (unsigned int*)malloc(z->BLOCK_FileCount << 2); z->BLOCK_AddressTable = (unsigned int*)malloc(z->BLOCK_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->BLOCK_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->BLOCK_AddressTable[b] = filesize_data; z->BLOCK_SizeTable[b] = d; filesize_data += d; z->BLOCK = (unsigned char*)realloc(z->BLOCK, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address fread(&z->BLOCK[z->BLOCK_AddressTable[b]], 1, d, pzf); fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////// // READ BMAP FILES // ///////////////////// fseek(pzf, x[0], SEEK_SET); z->BMAP_SizeTable = (unsigned int*)malloc(z->BMAP_FileCount << 2); z->BMAP_AddressTable = (unsigned int*)malloc(z->BMAP_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->BMAP_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->BMAP_AddressTable[b] = filesize_data; z->BMAP_SizeTable[b] = d; filesize_data += d; z->BMAP = (unsigned char*)realloc(z->BMAP, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address //fread(&z->BMAP[z->BMAP_AddressTable[b]], 1, d, pzf); z->BMAP[z->BMAP_AddressTable[b]] = getc(pzf); fread(&z->BMAP[z->BMAP_AddressTable[b]+1], 4, (d-1)>>2, pzf); fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////// // READ BSOL FILES // ///////////////////// fseek(pzf, x[0], SEEK_SET); z->BSOL_SizeTable = (unsigned int*)malloc(z->BSOL_FileCount << 2); z->BSOL_AddressTable = (unsigned int*)malloc(z->BSOL_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->BSOL_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->BSOL_AddressTable[b] = filesize_data; z->BSOL_SizeTable[b] = d; filesize_data += d; z->BSOL = (unsigned char*)realloc(z->BSOL, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address fread(&z->BSOL[z->BSOL_AddressTable[b]], 1, d, pzf); fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } //////////////////// // READ OBJ FILES // //////////////////// fseek(pzf, x[0], SEEK_SET); z->OBJ_SizeTable = (unsigned int*)malloc(z->OBJ_FileCount << 2); z->OBJ_AddressTable = (unsigned int*)malloc(z->OBJ_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->OBJ_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->OBJ_AddressTable[b] = filesize_data; z->OBJ_SizeTable[b] = d; filesize_data += d; z->OBJ = (unsigned char*)realloc(z->OBJ, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address fread(&z->OBJ[z->OBJ_AddressTable[b]], 1, d, pzf); fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } //////////////////// // READ PAL FILES // //////////////////// fseek(pzf, x[0], SEEK_SET); z->PAL_SizeTable = (unsigned int*)malloc(z->PAL_FileCount << 2); z->PAL_AddressTable = (unsigned int*)malloc(z->PAL_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->PAL_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->PAL_AddressTable[b] = filesize_data; z->PAL_SizeTable[b] = d; filesize_data += d; z->PAL = (unsigned char*)realloc(z->PAL, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address fread(&z->PAL[z->PAL_AddressTable[b]], 1, d, pzf); fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////// // READ TMAP FILES // ///////////////////// fseek(pzf, x[0], SEEK_SET); z->TMAP_SizeTable = (unsigned int*)malloc(z->TMAP_FileCount << 2); z->TMAP_AddressTable = (unsigned int*)malloc(z->TMAP_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->TMAP_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->TMAP_AddressTable[b] = filesize_data; z->TMAP_SizeTable[b] = d; filesize_data += d; z->TMAP = (unsigned char*)realloc(z->TMAP, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address fread(&z->TMAP[z->TMAP_AddressTable[b]], 2, d>>1, pzf); fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////// // READ WMAP FILES // ///////////////////// fseek(pzf, x[0], SEEK_SET); z->WMAP_SizeTable = (unsigned int*)malloc(z->WMAP_FileCount << 2); z->WMAP_AddressTable = (unsigned int*)malloc(z->WMAP_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->WMAP_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->WMAP_AddressTable[b] = filesize_data; z->WMAP_SizeTable[b] = d; filesize_data += d; z->WMAP = (unsigned char*)realloc(z->WMAP, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address fread(&z->WMAP[z->WMAP_AddressTable[b]], 1, d, pzf); fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////// // READ CCYC FILES // ///////////////////// fseek(pzf, x[0], SEEK_SET); z->CCYC_SizeTable = (unsigned int*)malloc(z->CCYC_FileCount << 2); z->CCYC_AddressTable = (unsigned int*)malloc(z->CCYC_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->CCYC_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->CCYC_AddressTable[b] = filesize_data; z->CCYC_SizeTable[b] = d; filesize_data += d; z->CCYC = (unsigned char*)realloc(z->CCYC, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address fread(&z->CCYC[z->CCYC_AddressTable[b]], 1, d, pzf); fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////////////////// // READ FILTERDISTORTION FILES // ///////////////////////////////// fseek(pzf, x[0], SEEK_SET); z->FILTERDISTORTION_SizeTable = (unsigned int*)malloc(z->FILTERDISTORTION_FileCount << 2); z->FILTERDISTORTION_AddressTable = (unsigned int*)malloc(z->FILTERDISTORTION_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->FILTERDISTORTION_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->FILTERDISTORTION_AddressTable[b] = filesize_data; z->FILTERDISTORTION_SizeTable[b] = d; filesize_data += d; z->FILTERDISTORTION = (unsigned char*)realloc(z->FILTERDISTORTION, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address fread(&z->FILTERDISTORTION[z->FILTERDISTORTION_AddressTable[b]], 1, d, pzf); fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } ///////////////////////////////// // READ FILTERCOMPOSITE FILES // ///////////////////////////////// fseek(pzf, x[0], SEEK_SET); z->FILTERCOMPOSITE_SizeTable = (unsigned int*)malloc(z->FILTERCOMPOSITE_FileCount << 2); z->FILTERCOMPOSITE_AddressTable = (unsigned int*)malloc(z->FILTERCOMPOSITE_FileCount << 2); filesize_data = 0; fread(&a, 4, 1, pzf); // Read table address x[0] = ftell(pzf); // Save current position fseek(pzf, a, SEEK_SET); // Jump to address for(b=0; b < z->FILTERCOMPOSITE_FileCount; b++){ x[1] = ftell(pzf); d = 0; fread(&d, 3, 1, pzf); // Read file size z->FILTERCOMPOSITE_AddressTable[b] = filesize_data; z->FILTERCOMPOSITE_SizeTable[b] = d; filesize_data += d; z->FILTERCOMPOSITE = (unsigned char*)realloc(z->FILTERCOMPOSITE, filesize_data); fread(&a, 4, 1, pzf); // Read file address fseek(pzf, a, SEEK_SET); // Jump to address fread(&z->FILTERCOMPOSITE[z->FILTERCOMPOSITE_AddressTable[b]], 1, d, pzf); fseek(pzf, x[1] + 7, SEEK_SET); // Set it up to read the next file } fclose(pzf); return 0; } int SaveZone(ZONE *z, const char *string, ...) { int x[13]; int y[256]; FILE *pzf; a = 0; b = 0; c = 0; d = 0; //if(pzf == ENOMEM) pzf = fopen(string, "wb"); a = 'P'; b = 'Z'; c = 'F'; d = 0; // version fwrite(&a, 1, 1, pzf); fwrite(&b, 1, 1, pzf); fwrite(&c, 1, 1, pzf); fwrite(&d, 1, 1, pzf); fwrite(&z->LevelName1, 1, 20, pzf); fwrite(&z->LevelName2, 1, 20, pzf); a = 0; fwrite(&z->Act_FileCount, 1, 1, pzf); fwrite(&z->OSC_FileCount, 1, 1, pzf); fwrite(&z->BATT_FileCount, 1, 1, pzf); fwrite(&z->BDAT_FileCount, 1, 1, pzf); fwrite(&z->BLOCK_FileCount, 1, 1, pzf); fwrite(&z->BMAP_FileCount, 1, 1, pzf); fwrite(&z->BSOL_FileCount, 1, 1, pzf); fwrite(&z->OBJ_FileCount, 1, 1, pzf); fwrite(&z->PAL_FileCount, 1, 1, pzf); fwrite(&z->TMAP_FileCount, 1, 1, pzf); fwrite(&z->WMAP_FileCount, 1, 1, pzf); fwrite(&z->CCYC_FileCount, 1, 1, pzf); fwrite(&z->FILTERDISTORTION_FileCount, 1, 1, pzf); fwrite(&z->FILTERCOMPOSITE_FileCount, 1, 1, pzf); x[0] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[1] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[2] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[3] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[4] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[5] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[6] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[7] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[8] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[9] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[10] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[11] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[12] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); x[13] = ftell(pzf); // Save current position fwrite(&a, 4, 1, pzf); ///////////////////// // WRITE ACT FILES // ///////////////////// a = ftell(pzf); // save the table address fseek(pzf, x[0], SEEK_SET); // go back to table pointer fwrite(&a, 4, 1, pzf); // write address value to pointer fseek(pzf, a, SEEK_SET); // go back to the table a = 0; // Setup the act file table for(b=0; b < z->Act_FileCount; b++){ fwrite(&z->Act[b].IncludedStages, 1, 1, pzf); y[b] = ftell(pzf); fwrite(&a, 4, 1, pzf); } // Write the act files for(b=0; b < z->Act_FileCount; b++){ a = ftell(pzf); // save the act file address fseek(pzf, y[b], SEEK_SET); // go back to the act table fwrite(&a, 4, 1, pzf); // write address value to act file fseek(pzf, a, SEEK_SET); // go back to the act file for(c=0; c<4; c++){ switch(c){ case 0: a = (z->Act[b].IncludedStages & 1); break; case 1: a = ((z->Act[b].IncludedStages >> 1) & 1); break; case 2: a = ((z->Act[b].IncludedStages >> 2) & 1); break; default: a = ((z->Act[b].IncludedStages >> 3) & 1); } if(a == 1){ fwrite(&(z->Act[b].Stage[c].Name), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].ActNumber), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].MusicRegular), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].MusicAlternate), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].OpeningScript), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].ClosingScript), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].ActiveScript), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].WaterEnable), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].WrapPoint), 2, 1, pzf); fwrite(&(z->Act[b].Stage[c].AboveWaterFilterL), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].BelowWaterFilterL), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].AboveWaterFilterSpeed), 4, 1, pzf); fwrite(&(z->Act[b].Stage[c].BelowWaterFilterSpeed), 4, 1, pzf); fwrite(&(z->Act[b].Stage[c].ClearBackground), 1, 1, pzf); // PLACE HOLDER FOR 0x10E fwrite(&(z->Act[b].Stage[c].Palette), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].ColorCycle), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].WaterMap), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].BlockMap), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].BlockArt), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].BlockData), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].BlockAttributes), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].BlockSolidity), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].TileMap), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].ObjectLayout), 1, 1, pzf); fwrite(&(z->Act[b].Stage[c].WaterHeight), 2, 1, pzf); fwrite(&(z->Act[b].Stage[c].LevelXL), 2, 1, pzf); fwrite(&(z->Act[b].Stage[c].LevelXR), 2, 1, pzf); fwrite(&(z->Act[b].Stage[c].LevelYT), 2, 1, pzf); fwrite(&(z->Act[b].Stage[c].LevelYB), 2, 1, pzf); fwrite(&(z->Act[b].Stage[c].StartX[0]), 2, 16, pzf); fwrite(&(z->Act[b].Stage[c].StartY[0]), 2, 16, pzf); } } } ///////////////////// // WRITE OSC FILES // ///////////////////// a = ftell(pzf); fseek(pzf, x[1], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->OSC_FileCount; b++){ fwrite(&z->OSC_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->OSC_FileCount; b++){ a = ftell(pzf); // save the OSC file address fseek(pzf, y[b], SEEK_SET); // go back to the OSC table fwrite(&a, 4, 1, pzf); // write address to OSC file fseek(pzf, a, SEEK_SET); // go back to the OSC file a = z->OSC_AddressTable[b]; // Write file for(c=0; c < z->OSC_SizeTable[b]; c++) fwrite(&z->OSC[a+c], 1, 1, pzf); } ////////////////////// // WRITE BATT FILES // ////////////////////// a = ftell(pzf); fseek(pzf, x[2], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->BATT_FileCount; b++){ fwrite(&z->BATT_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->BATT_FileCount; b++){ a = ftell(pzf); // save the BATT file address fseek(pzf, y[b], SEEK_SET); // go back to the BATT table fwrite(&a, 4, 1, pzf); // write address to BATT file fseek(pzf, a, SEEK_SET); // go back to the BATT file a = z->BATT_AddressTable[b]; // Write file for(c=0; c < z->BATT_SizeTable[b]; c++) fwrite(&z->BATT[a+c], 1, 1, pzf); } ////////////////////// // WRITE BDAT FILES // ////////////////////// a = ftell(pzf); fseek(pzf, x[3], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->BDAT_FileCount; b++){ fwrite(&z->BDAT_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->BDAT_FileCount; b++){ a = ftell(pzf); // save the BDAT file address fseek(pzf, y[b], SEEK_SET); // go back to the BDAT table fwrite(&a, 4, 1, pzf); // write address to BDAT file fseek(pzf, a, SEEK_SET); // go back to the BDAT file a = z->BDAT_AddressTable[b]; // Write file for(c=0; c < z->BDAT_SizeTable[b]; c++) fwrite(&z->BDAT[a+c], 1, 1, pzf); } /////////////////////// // WRITE BLOCK FILES // /////////////////////// a = ftell(pzf); fseek(pzf, x[4], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->BLOCK_FileCount; b++){ fwrite(&z->BLOCK_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->BLOCK_FileCount; b++){ a = ftell(pzf); // save the BLOCK file address fseek(pzf, y[b], SEEK_SET); // go back to the BLOCK table fwrite(&a, 4, 1, pzf); // write address to BLOCK file fseek(pzf, a, SEEK_SET); // go back to the BLOCK file a = z->BLOCK_AddressTable[b]; // Write file for(c=0; c < z->BLOCK_SizeTable[b]; c++) fwrite(&z->BLOCK[a+c], 1, 1, pzf); } ////////////////////// // WRITE BMAP FILES // ////////////////////// a = ftell(pzf); fseek(pzf, x[5], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->BMAP_FileCount; b++){ fwrite(&z->BMAP_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->BMAP_FileCount; b++){ a = ftell(pzf); // save the BMAP file address fseek(pzf, y[b], SEEK_SET); // go back to the BMAP table fwrite(&a, 4, 1, pzf); // write address to BMAP file fseek(pzf, a, SEEK_SET); // go back to the BMAP file a = z->BMAP_AddressTable[b]; // Write file for(c=0; c < z->BMAP_SizeTable[b]; c++) fwrite(&z->BMAP[a+c], 1, 1, pzf); } ////////////////////// // WRITE BSOL FILES // ////////////////////// a = ftell(pzf); fseek(pzf, x[6], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->BSOL_FileCount; b++){ fwrite(&z->BSOL_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->BSOL_FileCount; b++){ a = ftell(pzf); // save the BSOL file address fseek(pzf, y[b], SEEK_SET); // go back to the BSOL table fwrite(&a, 4, 1, pzf); // write address to BSOL file fseek(pzf, a, SEEK_SET); // go back to the BSOL file a = z->BSOL_AddressTable[b]; // Write file for(c=0; c < z->BSOL_SizeTable[b]; c++) fwrite(&z->BSOL[a+c], 1, 1, pzf); } ///////////////////// // WRITE OBJ FILES // ///////////////////// a = ftell(pzf); fseek(pzf, x[7], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->OBJ_FileCount; b++){ fwrite(&z->OBJ_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->OBJ_FileCount; b++){ a = ftell(pzf); // save the OBJ file address fseek(pzf, y[b], SEEK_SET); // go back to the OBJ table fwrite(&a, 4, 1, pzf); // write address to OBJ file fseek(pzf, a, SEEK_SET); // go back to the OBJ file a = z->OBJ_AddressTable[b]; // Write file for(c=0; c < z->OBJ_SizeTable[b]; c++) fwrite(&z->OBJ[a+c], 1, 1, pzf); } ///////////////////// // WRITE PAL FILES // ///////////////////// a = ftell(pzf); fseek(pzf, x[8], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->PAL_FileCount; b++){ fwrite(&z->PAL_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->PAL_FileCount; b++){ a = ftell(pzf); // save the PAL file address fseek(pzf, y[b], SEEK_SET); // go back to the PAL table fwrite(&a, 4, 1, pzf); // write address to PAL file fseek(pzf, a, SEEK_SET); // go back to the PAL file a = z->PAL_AddressTable[b]; // Write file for(c=0; c < z->PAL_SizeTable[b]; c++) fwrite(&z->PAL[a+c], 1, 1, pzf); } ////////////////////// // WRITE TMAP FILES // ////////////////////// a = ftell(pzf); fseek(pzf, x[9], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->TMAP_FileCount; b++){ fwrite(&z->TMAP_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->TMAP_FileCount; b++){ a = ftell(pzf); // save the TMAP file address fseek(pzf, y[b], SEEK_SET); // go back to the TMAP table fwrite(&a, 4, 1, pzf); // write address to TMAP file fseek(pzf, a, SEEK_SET); // go back to the TMAP file a = z->TMAP_AddressTable[b]; // Write file for(c=0; c < z->TMAP_SizeTable[b]; c++) fwrite(&z->TMAP[a+c], 1, 1, pzf); } ////////////////////// // WRITE WMAP FILES // ////////////////////// a = ftell(pzf); fseek(pzf, x[10], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->WMAP_FileCount; b++){ fwrite(&z->WMAP_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->WMAP_FileCount; b++){ a = ftell(pzf); // save the WMAP file address fseek(pzf, y[b], SEEK_SET); // go back to the WMAP table fwrite(&a, 4, 1, pzf); // write address to WMAP file fseek(pzf, a, SEEK_SET); // go back to the WMAP file a = z->WMAP_AddressTable[b]; // Write file for(c=0; c < z->WMAP_SizeTable[b]; c++) fwrite(&z->WMAP[a+c], 1, 1, pzf); } ////////////////////// // WRITE CCYC FILES // ////////////////////// a = ftell(pzf); fseek(pzf, x[11], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->CCYC_FileCount; b++){ fwrite(&z->CCYC_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->CCYC_FileCount; b++){ a = ftell(pzf); // save the CCYC file address fseek(pzf, y[b], SEEK_SET); // go back to the CCYC table fwrite(&a, 4, 1, pzf); // write address to CCYC file fseek(pzf, a, SEEK_SET); // go back to the CCYC file a = z->CCYC_AddressTable[b]; // Write file for(c=0; c < z->CCYC_SizeTable[b]; c++) fwrite(&z->CCYC[a+c], 1, 1, pzf); } ////////////////////////////////// // WRITE FILTERDISTORTION FILES // ////////////////////////////////// a = ftell(pzf); fseek(pzf, x[12], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->FILTERDISTORTION_FileCount; b++){ fwrite(&z->FILTERDISTORTION_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->FILTERDISTORTION_FileCount; b++){ a = ftell(pzf); // save the FILTERDISTORTION file address fseek(pzf, y[b], SEEK_SET); // go back to the FILTERDISTORTION table fwrite(&a, 4, 1, pzf); // write address to FILTERDISTORTION file fseek(pzf, a, SEEK_SET); // go back to the FILTERDISTORTION file a = z->FILTERDISTORTION_AddressTable[b]; // Write file for(c=0; c < z->FILTERDISTORTION_SizeTable[b]; c++) fwrite(&z->FILTERDISTORTION[a+c], 1, 1, pzf); } ///////////////////////////////// // WRITE FILTERCOMPOSITE FILES // ///////////////////////////////// a = ftell(pzf); fseek(pzf, x[13], SEEK_SET); fwrite(&a, 4, 1, pzf); fseek(pzf, a, SEEK_SET); a = 0; for(b=0; b < z->FILTERCOMPOSITE_FileCount; b++){ fwrite(&z->FILTERCOMPOSITE_SizeTable[b], 3, 1, pzf); // write 24-bit size y[b] = ftell(pzf); // save address position fwrite(&a, 4, 1, pzf); // address holder } for(b=0; b < z->FILTERCOMPOSITE_FileCount; b++){ a = ftell(pzf); // save the FILTERCOMPOSITE file address fseek(pzf, y[b], SEEK_SET); // go back to the FILTERCOMPOSITE table fwrite(&a, 4, 1, pzf); // write address to FILTERCOMPOSITE file fseek(pzf, a, SEEK_SET); // go back to the FILTERCOMPOSITE file a = z->FILTERCOMPOSITE_AddressTable[b]; // Write file for(c=0; c < z->FILTERCOMPOSITE_SizeTable[b]; c++) fwrite(&z->FILTERCOMPOSITE[a+c], 1, 1, pzf); } fclose(pzf); return 0; }
001tomclark-research-check
Source/Engine/zone.c
C
gpl2
70,507
/***************************************************************************** * ______ * / _ \ _ __ ______ * / /_ / / / //__ / / _ \ * / ____ / / / / / / / * / / / / / /_ / / * /_ / /_ / \ _____ / * ______ * / ____ / ______ _ __ _ ______ * / /___ / _ \ / //_ \ /_ / / _ \ * _\___ \ / / / / / / / / / / / / /_ / * / /_ / / / /_ / / / / / / / / / /____ * \______ / \ _____ / /_ / /_ / /_ / \ ______/ * * * ProSonic Engine * Created by Damian Grove * * Compiled with DJGPP - GCC 2.952 (DOS) / Dev-C++ 4.9.9.2 (Windows) * Libraries used: * - Allegro - 3.9.34 http://www.talula.demon.co.uk/allegro/ * - DUMB - 0.9.3 http://dumb.sourceforge.net/ * - AllegroOgg - 1.0.3 http://nekros.freeshell.org/delirium/ * ****************************************************************************** * * NAME: ProSonic - Structures header * * FILE: structs.h * * DESCRIPTION: * All structures to be used through-out the engine go here. * *****************************************************************************/ #ifndef STRUCTS_H #define STRUCTS_H #ifdef __cplusplus extern "C"{ #endif typedef struct{ short src_x_left; short src_x_right; short src_y_top; short src_y_bottom; short dest_x; short dest_y; short show_if_x_higher; short show_if_x_lower; short show_if_y_higher; short show_if_y_lower; short scroll_wrap_x; short scroll_wrap_y; short scroll_speed_x; short scroll_speed_y; char auto_speed_x; char auto_speed_y; char filter_c; // above water char filter_d; // under water char filter_c_speed; char filter_d_speed; char transparent; char RESERVED_CHAR; } CELL; //////////// // OBJECT // //////////// typedef struct // For any object other than the player { int user[16]; // user defined variables char static_node; char h_tag; char l_tag; unsigned char type; // it's important that we make this unsigned char routine; char status; short x_pos; short y_pos; char render_flags; char width_pixels; char priority; char subtype; char objoff_32; char objoff_34; char anim_frame_duration; short anim_frame; char anim; short x_pos_pre; short y_pos_pre; short x_vel; short y_vel; char x_radius; char y_radius; //unsigned int anim_counter; //unsigned char anim_speed; // Right now, 255 objects are supported by the engine. If needed, there // could be changes to support more than this in the future. Of course, // the Member could be split to have two or more objects stored into a // single object class, but that would be sorta sloppy if the objects // are completely unrelated. char ram[0x1300]; } OBJECT; //////////// // PLAYER // //////////// typedef struct { char player_name[16]; //char network_id; char character; char sidekick; unsigned char CtrlInput; char render_flags; short art_tile; int mappings; short x_pos; unsigned short x_pos_pre; short y_pos; unsigned short y_pos_pre; short x_vel; short y_vel; short inertia; char x_radius; char y_radius; char priority; char anim_frame_duration; short anim_frame; char anim; char next_anim; //char anim_frame_duration; char status; char routine; char routine_secondary; char angle; char flip_angle; char air_left; char flip_turned; char obj_control; char status_secondary; char flips_remaining; char flip_speed; short move_lock; short invulnerable_time; short invincibility_time; short speedshoes_time; char next_tilt; char tilt; char stick_to_convex; char spindash_flag; short spindash_counter; char jumping; char interact; char layer; char layer_plus; short Sonic_top_speed; short Sonic_acceleration; short Sonic_deceleration; char Ctrl_Held; char Ctrl_Press; char Ctrl_Held_Logical; char Ctrl_Press_Logical; char width_pixels; char mapping_frame; short Sonic_Look_delay_counter; short Sonic_Stat_Record_Buf[128]; short Sonic_Pos_Record_Buf[128]; short Camera_X_pos; short Camera_Y_pos; short Camera_Z_pos;///////////////// short Camera_Max_Y_pos; short Camera_Min_X_pos; short Camera_Max_X_pos; short Camera_Min_Y_pos; short Camera_Max_Y_pos_now; short Camera_X_pos_coarse; char Sonic_Pos_Record_Index; short Camera_Y_pos_bias; short Ring_count; unsigned int Score; unsigned char Life_count; char Extra_life_flags; char Last_star_pole_hit; char Saved_Last_star_pole_hit; short Saved_x_pos; short Saved_y_pos; short Saved_Ring_count; int Saved_Timer; short Saved_art_tile; short Saved_layer; short Saved_Camera_X_pos; short Saved_Camera_Y_pos; short Saved_Water_Level; char Saved_Extra_life_flags; char Saved_Extra_life_flags_2P; short Saved_Camera_Max_Y_pos; int Collision_addr; short ram_EEB0; short ram_EEB2; short ram_EEBE; short ram_EED0; short ram_F65C; char ram_F768; char ram_F76A; char ram_F7C7; } PLAYER; typedef struct { unsigned char bind_up; unsigned char bind_down; unsigned char bind_left; unsigned char bind_right; unsigned char bind_b; unsigned char bind_c; unsigned char bind_a; unsigned char bind_start; } BINDING; struct fmtObj{ short x_pos; short y_pos; unsigned char type; unsigned char subtype; unsigned char h_tag; unsigned char l_tag; }; typedef struct fmtObj OBJECT_PLOT; #ifdef __cplusplus } #endif #endif
001tomclark-research-check
Source/Engine/structs.h
C
gpl2
5,887
#ifndef TOOLS_H #define TOOLS_H #include "zone.h" #include "structs.h" #ifdef __cplusplus extern "C"{ #endif void LoadZonePrompt(); void ShowBlockInfo(ZONE *z); BITMAP *tilefile; int coordinate_x; int coordinate_y; int selection_x; int selection_y; char selection_a; int n; int i; int a; int b; short match_count; // 65 blocks instead of 64 -- temporary fix for crash unsigned short imported_blocks[65][0x100]; // 64 blocks, 256 pixels short block_matches[64]; #ifdef __cplusplus } #endif #endif
001tomclark-research-check
Source/Engine/tools.h
C
gpl2
566
#ifndef COMMON_H #define COMMON_H #include "structs.h" #include "zone.h" #ifdef __cplusplus extern "C"{ #endif //#define AUDIO_REC_ENABLED //#define ENABLE_FRAME_CONTROL //#define ENABLE_LOGGING //#define ENABLE_SRAM_LOG_ANALYSIS #define ENABLE_MOUSE // required to use game editor #define EDIT_MODE_TILE_LAYOUT 1 #define EDIT_MODE_BLOCK_MAPPINGS 2 #define EDIT_MODE_SOLIDITY 3 #define EDIT_MODE_OBJECT_LAYOUT 4 #ifdef __GNUC__ #define FUNCINLINE inline #else #define FUNCINLINE #endif char *program_filename; // get from argv[0] char config_section[4][16]; char show_version; char show_watermark; // COMPATIBILITY SETTINGS // 0 = Bug fixed // 1 = Sonic 1 method // 2 = Sonic 2 method // 3 = Sonic 3 method // 4 = Sonic 3K method char compat_super_sonic_countdown; // correct ring countdown timing int mouse_z_previous; char camera_mode; char PlayDemo(signed char d); void RecordDemo(signed char d); //int fade_type; char fade_count; char edit_mode; char edit_selector; int edit_clipboard; char collision_color; char prompt; // when 1, activates LoadZonePrompt() short demo_order[256]; char zone_file_list[257][32]; // last one used for unlisted files char demo_file_list[10][32]; signed char demo_number; int demo_size; unsigned char *demodata; #ifdef ENABLE_SRAM_LOG_ANALYSIS void AnalyzeSRAM(); char sram_file_list[10][32]; int sram_size; unsigned short sram_start; unsigned char *sramdata; char sram_master_key; char sram_segment_key[8]; unsigned char sram_frame[64]; #endif unsigned char titlecard_counter[63]; char titlecard_phase[63]; short titlecard_xpos[63]; short titlecard_ypos[63]; unsigned char *titlecard_data; char titlecard_sequence_end; FILE *titlecard_file; // For YM2612 emulation AUDIOSTREAM *stream; FILE *ym_log_file; char sfxbank[4]; FUNCINLINE void ProcessSound(); void ResetSound(); void PlayPCM(short sound, char buffer, char mix); void PlayFM(short sound, char buffer, char mix); void StreamPCM(char ch, int *pos_left, int *pos_right, unsigned short *poll_left, unsigned short *poll_right, int *buffer_left, int *buffer_right); void StreamFM(char ch, int *pos, int *buffer_left, int *buffer_right); #ifdef AUDIO_REC_ENABLED void RecordPCM(short *sample_data); #endif #define FM_TYPE_NULL -1 #define FM_TYPE_GYM 0 #define FM_TYPE_VGM 1 #define FM_DAC_OFF 0 #define FM_DAC_ON 1 #define FM_REPEAT_OFF 0 #define FM_REPEAT_ON 1 #define PCM_TYPE_MONO 0 #define PCM_TYPE_STEREO 1 #define PCM_REPEAT_OFF 0 #define PCM_REPEAT_ON 1 int digi_card; char bgm_enable; // not used yet char sfx_enable; // not used yet unsigned char *fm_data; int fm_data_address[257]; char fm_data_type[256]; // 0-GYM, 1-VGM, 2-WAV char fm_data_dac[256]; // 0-Off, 1-On char fm_data_repeat[256]; // 0-Off, 1-On char fm_data_ch_type[4]; // 0-GYM, 1-VGM, 2-WAV char fm_data_ch_repeat[4]; // 0-Off, 1-On int fm_data_pos[4]; int fm_data_pos_start[4]; // used for VGM files to quickly find the beginning int fm_data_pos_dac[4]; // used for VGM files that use data banks int fm_data_pos_loop[4]; // used for VGM files that use looping int fm_data_address_dac[4]; // used for VGM files that use data banks unsigned short fm_data_wait[4]; // used for VGM wait counting unsigned short fm_data_sample[4]; // store DAC samples for VGM char fm_reset[4]; // clear some values when FM first starts char fm_track_number[4]; // easy way to track which track is playing unsigned short fm_fader[4]; // amount to subtract from "TL" on FM channels char fm_fade_out[4]; // 0-No, 1-Yes int fm_offset; // used as counter for loading FM files int fm_size; // used as counter for loading FM files unsigned char audio_compression; // measured in 16ths signed char audio_volume; // 31 is full on, -1 is full off //int audio_peak; char bgm_type; // 0 - FM, 1 - PCM FILE *pcm_out; int pcm_record_pos; unsigned char *pcm_data; unsigned short pcm_data_poll[2][4]; int pcm_data_pos[2][4]; int pcm_data_pos_start[2][4]; int pcm_data_address[257]; char pcm_data_format_stereo[256]; char pcm_data_ch_format_stereo[2][4]; char pcm_data_repeat[256]; // 0-Off, 1-On char pcm_data_ch_repeat[2][4]; // 0-Off, 1-On int pcm_offset; // used as counter for loading PCM files int pcm_size; // used as counter for loading PCM files #define FM_VOLUME 0.666667 // -3.5dB #define DAC_VOLUME 0.333333 // -9.5dB float mix_volume; char smart_mix; #ifdef ENABLE_LOGGING char msglog[100000][32]; char msglog_tabs[100000]; int logline; signed char logtab; void TabLog(signed char tab); void WriteLog(const char *string, ...); void VarLog(short var); void RegLog(); void RamLog(unsigned short addr); void DumpLog(const char *string, ...); void ResetLog(); enum VarLogNames{ VAR_ROUTINE, VAR_X_RADIUS, VAR_Y_RADIUS, VAR_X_POS, VAR_X_POS_PRE, VAR_Y_POS, VAR_Y_POS_PRE, VAR_X_VEL, VAR_Y_VEL, VAR_INERTIA, VAR_STATUS, VAR_ANGLE, VAR_ANIM, VAR_LAYER, VAR_VAR_TEMP, REG_A0, REG_A1, REG_A2, REG_A3, REG_A4, REG_A5, REG_A6, REG_A7, REG_D0, REG_D1, REG_D2, REG_D3, REG_D4, REG_D5, REG_D6, REG_D7, REG_SR, REG_PC }; int var_temp; #endif char advance_frame; char Game_paused; FILE *DemoFile; int DemoCount; // 0x668 for Sonic 2, 0x708 for Sonic 1 and Sonic 3 //int DemoSize; int DemoPosition; unsigned char DemoFadeDelay; #ifdef ENABLE_SRAM_LOG_ANALYSIS FILE *SRAMFile; unsigned short SRAMCount; // 0x668 for Sonic 2, 0x708 for Sonic 1 and Sonic 3 unsigned short SRAMPosition; #endif void quit(int e); ZONE z; int ReadBlock(ZONE *z, unsigned short x, unsigned short y); short ReadBackBlock(ZONE *z, unsigned short x, unsigned short y); unsigned char unlisted_zone; // special condition for loading unlisted files unsigned char zone; // 0-255 (8 bits) unsigned char act; // 0-7 (3 bits) unsigned char stage; // 0-4 (2 bits) unsigned char demo; char demo_mode; #define STATE_DIRECTION 0x1 #define STATE_FLOATING 0x2 #define STATE_SPINNING 0x4 #define STATE_STATIC 0x8 #define STATE_AUTO 0x10 #define STATE_PUSHING 0x20 #define STATE_UNDER_WATER 0x40 #define STATE_UNDEFINED 0x80 // uuuuuuup BPtttttt fmbbbbbb bbbbbbbb #define BMAP_BLOCK 0x3FFF #define BMAP_MIRROR 0x4000 #define BMAP_FLIP 0x8000 #define BMAP_TRANSLUCENCY 0x3F0000 #define BMAP_PLATFORM 0x400000 #define BMAP_BARRIER 0x800000 #define BMAP_PLANE 0x1000000 #define BMAP_UNDEFINED 0xFE000000 unsigned char paused; unsigned char frame_skip; // 0 = 60 fps // 1 = 30 fps // 2 = 20 fps // 3 = 15 fps // 4 = 12 fps // 5 = 10 fps char draw_frame; // used to determine when to draw sprites with frame skip char full_screen; unsigned short screen_resolution_x; unsigned short screen_resolution_y; // e.g. 320x224 unsigned short screen_padding_x; unsigned short screen_padding_y; // e.g. 0x16 (320+0=320, 224+16=240) unsigned short screen_offset_x; unsigned short screen_offset_y; // e.g. 0x8 (center 320x224 screen in 320x240 window) unsigned short screen_frame_x; unsigned short screen_frame_y; // e.g. 320x112 unsigned short screen_buffer_x; unsigned short screen_buffer_y; // e.g. 352x112 signed char screen_scale_x; signed char screen_scale_y; signed char screen_double_x; signed char screen_double_y; //char screen_interlace_x; //char screen_interlace_y; char vsync_enable; volatile int close_button_pressed; //unsigned char sound_number; char debug_show_object_nodes; short number_of_objects_in_memory; char key_m_previously_pressed; char key_n_previously_pressed; unsigned int ring_anim_counter; volatile char ticCounter60L; // Logic (reset to 0 when ticCounter60R is 60) volatile unsigned char fps; char show_fps; unsigned int ticCounterL; // Logic volatile unsigned int ticCounterR; // Real-time volatile unsigned char ticCounter60R; // Real-time % 60 volatile char ticUpdated; volatile char waitCounter; //char frames; // 0-3 int water_current_height; // current height of water short water_target; // height for water to move to int water_direction; signed char water_accel; short counter_fe74; int counter_fe74_direction; signed short counter_fe74_accel; enum DrawingMode { NORMAL, MIRROR, FLIP, ROTATE }; CELL background_cell; char num_of_players; char num_of_frames; BINDING key_bind[4]; PLAYER player[16]; PLAYER init_player; BITMAP *LayerB[4]; BITMAP *LayerL[4]; BITMAP *LayerH[4]; BITMAP *LayerSH[4]; BITMAP *LayerM; PLAYER *p; unsigned char frame; int composite; int bmap; int block; int tmap; int wmap; int palette_val; int composite_count; int bmap_count; int block_count; int tmap_count; int wmap_count; int palette_count; unsigned int composite_ptr; unsigned int bmap_ptr; unsigned int block_ptr; unsigned int tmap_ptr; unsigned int wmap_ptr; unsigned int palette_ptr; int tilesize; int tiles_x_short; int tiles_x_long; int tiles_y; unsigned short blocks_x; unsigned short blocks_y; unsigned char num_of_cells; unsigned char num_of_filters; unsigned short cells_ptr; unsigned short filters_ptr; unsigned short bg_rgb_color; unsigned char filter_a; unsigned char filter_b; unsigned char filter_a_speed; unsigned char filter_b_speed; CELL *cell_data; #ifdef __cplusplus } #endif #endif
001tomclark-research-check
Source/Engine/common.h
C
gpl2
9,843
/***************************************************************************** SONIC PZF LIBRARY Copyright(c) Damian Grove, 2006 "zone.h" ------------------------------------------------------------------------ The ProSonic hierarchy works like this: ZONE (e.g. Palmtree Panic Zone) \ \__ ACT (e.g. Act 1) \ \__ STAGE (e.g. Present) MAXIMUM NUMBER OF ZONES 256 MAXIMUM NUMBER OF ACTS 8 MAXIMUM NUMBER OF STAGES 4 ------------------------------------------------------------------------ The PZF format is designed to support 256 zones so game designers will never run out of room to add levels to their games. Although 8 acts seems high, it was picked over a 4 act limit since Knuckles' Chaotix makes use of 5. To ensure better compatibility, the 4 act limit was dropped in favor of the 8 act limit. Stages are different in that the game designer doesn't actually tell ProSonic how many there are. Instead there are a total of 4 stage 'slots' that allow the player to choose which slots to use. The 4 slots are A, B, C, and D. This was done to ensure better compatibility with Sonic CD. Since the third act of every zone in Sonic CD only has 2 future stages (which are C and D), it would only make sense to allow ProSonic to do the same thing. ------------------------------------------------------------------------ FILE DATA FORMAT: All sizes and addresses are stored in little-endian format. z->TYPE_FileCount = 1; z->TYPE [ INT_0 Address to file 0 (from TYPE[0]) INT_1 Size of file 0 (in bytes) FILE_0[INT_1] ] z->TYPE_FileCount = 2; z->TYPE [ INT_0 Address to file 0 (from TYPE[0]) INT_1 Address to file 1 (from TYPE[0]) INT_2 Size of file 0 (in bytes) INT_3 Size of file 1 (in bytes) FILE_0[INT_2] FILE_1[INT_3] ] z->TYPE_FileCount = 3; z->TYPE [ INT_0 Address to file 0 (from TYPE[0]) INT_1 Address to file 1 (from TYPE[0]) INT_2 Address to file 2 (from TYPE[0]) INT_3 Size of file 0 (in bytes) INT_4 Size of file 1 (in bytes) INT_5 Size of file 2 (in bytes) FILE_0[INT_3] FILE_1[INT_4] FILE_2[INT_5] ] ... *****************************************************************************/ #ifndef ZONE_H #define ZONE_H #ifdef __cplusplus extern "C"{ #endif char item[24]; int a; int b; int c; int d; float f; int a01; int c01; int endoffile; long filesize_zone; long filesize_stagea; long filesize_stageb; long filesize_stagec; long filesize_staged; int filesize_data; char filename[256]; char path[256]; FILE *txt_file; FILE *txt_data; /////////// // STAGE // /////////// typedef struct // Previously called a "TIMEZONE" { char Name; char ActNumber; char MusicRegular; char MusicAlternate; char OpeningScript; char ClosingScript; char ActiveScript; char WaterEnable; short WrapPoint; unsigned char AboveWaterFilterL; unsigned char BelowWaterFilterL; float AboveWaterFilterSpeed; float BelowWaterFilterSpeed; char ClearBackground; char ForcePaletteTiles8; char ForcePaletteTiles16; char ForcePaletteSprites8; char ForcePaletteSprites16; //unsigned char BelowWaterFilterB; unsigned char Palette; unsigned char ColorCycle; unsigned char WaterMap; unsigned char BlockMap; unsigned char BlockArt; unsigned char BlockData; unsigned char BlockAttributes; unsigned char BlockSolidity; unsigned char TileMap; unsigned char ObjectLayout; short WaterHeight; short LevelXL; short LevelXR; short LevelYT; short LevelYB; short StartX[16]; short StartY[16]; } STAGE; ///////// // ACT // ///////// typedef struct { char IncludedStages; // (bits: 0000DCBA) STAGE Stage[4]; } ACT; ////////// // ZONE // ////////// typedef struct { char Act_FileCount; ACT *Act; char LevelName1[20]; char LevelName2[20]; unsigned char OSC_FileCount; unsigned char BATT_FileCount; unsigned char BDAT_FileCount; unsigned char BLOCK_FileCount; unsigned char BMAP_FileCount; unsigned char BSOL_FileCount; unsigned char OBJ_FileCount; unsigned char PAL_FileCount; unsigned char TMAP_FileCount; unsigned char WMAP_FileCount; unsigned char CCYC_FileCount; unsigned char FILTERDISTORTION_FileCount; unsigned char FILTERCOMPOSITE_FileCount; unsigned int *OSC_SizeTable; unsigned int *BATT_SizeTable; unsigned int *BDAT_SizeTable; unsigned int *BLOCK_SizeTable; unsigned int *BMAP_SizeTable; unsigned int *BSOL_SizeTable; unsigned int *OBJ_SizeTable; unsigned int *PAL_SizeTable; unsigned int *TMAP_SizeTable; unsigned int *WMAP_SizeTable; unsigned int *CCYC_SizeTable; unsigned int *FILTERDISTORTION_SizeTable; unsigned int *FILTERCOMPOSITE_SizeTable; unsigned int *OSC_AddressTable; unsigned int *BATT_AddressTable; unsigned int *BDAT_AddressTable; unsigned int *BLOCK_AddressTable; unsigned int *BMAP_AddressTable; unsigned int *BSOL_AddressTable; unsigned int *OBJ_AddressTable; unsigned int *PAL_AddressTable; unsigned int *TMAP_AddressTable; unsigned int *WMAP_AddressTable; unsigned int *CCYC_AddressTable; unsigned int *FILTERDISTORTION_AddressTable; unsigned int *FILTERCOMPOSITE_AddressTable; unsigned char *OSC; unsigned char *BATT; unsigned char *BDAT; unsigned char *BLOCK; unsigned char *BMAP; unsigned char *BSOL; unsigned char *OBJ; unsigned char *PAL; unsigned char *TMAP; unsigned char *WMAP; unsigned char *CCYC; unsigned char *FILTERDISTORTION; unsigned char *FILTERCOMPOSITE; } ZONE; unsigned int *COMPILED_MAP; // Main level map field unsigned short *COMPILED_BACKMAP; // Background level map // Compile complete zone map using TMAP and BMAP data. // This should be used in future engine code to optimize for // speed and programming simplicity. // Needed by CompileZone() int ReadWord(ZONE *z, const char *string, ...); int ReadText(ZONE *z, const char *string, ...); int ReadVar(ZONE *z, const char *string, ...); int ReadFloatVar(ZONE *z, const char *string, ...); void ClearZone(ZONE *z); void DeleteZone(ZONE *z); int CreateZone(ZONE *z); int CompileZone(ZONE *z, const char *string, ...); int LoadZone(ZONE *z, const char *string, ...); int SaveZone(ZONE *z, const char *string, ...); #ifdef __cplusplus } #endif #endif
001tomclark-research-check
Source/Engine/zone.h
C
gpl2
6,639
#ifndef TEXT_H #define TEXT_H #include "structs.h" #include "common.h" #ifdef __cplusplus extern "C"{ #endif void DrawCounter10(BITMAP *l, int i, int x, int y, char fillsize, char font); void DrawCounter16(BITMAP *l, int i, int x, int y); void DrawText(int x, int y, unsigned char s, const char *string, ...); void InputText(int x, int y, unsigned char s, const char *string, ...); FUNCINLINE int LoadFont0(); //int LoadFont1(); char Font0[0x800]; //char Font1[0xA00]; char TextBuffer[256]; short keyinput; char ascii; char scancode; short buffer_count; // The following are used for Talk() char typing; // is player currently typing a message? char typing_pos; // cursor position char message_out[64]; // outgoing message buffer char *message; // store messages short *message_time; // store display time of each message char num_of_messages; // how many messages to display short message_time_limit; // how many seconds to display a new message #ifdef __cplusplus } #endif #endif
001tomclark-research-check
Source/Engine/text.h
C
gpl2
1,069
////////////////////////////////////// // Obj01 - Sonic // // Port by Saxman // ////////////////////////////////////// #include <stdio.h> #include <math.h> #include <allegro.h> #include "structs.h" #include "common.h" #include "m68k.h" #include "obj01.h" const short SpindashSpeeds[9] = { 0x800, 0x880, 0x900, 0x980, 0xA00, 0xA80, 0xB00, 0xB80, 0xC00 }; const short SpindashSpeedsSuper[9] = { 0xB00, 0xB80, 0xC00, 0xC80, 0xD00, 0xD80, 0xE00, 0xE80, 0xF00 }; const short Sine_Data[320] = { 0x0000, 0x0006, 0x000C, 0x0012, 0x0019, 0x001F, 0x0025, 0x002B, 0x0031, 0x0038, 0x003E, 0x0044, 0x004A, 0x0050, 0x0056, 0x005C, 0x0061, 0x0067, 0x006D, 0x0073, 0x0078, 0x007E, 0x0083, 0x0088, 0x008E, 0x0093, 0x0098, 0x009D, 0x00A2, 0x00A7, 0x00AB, 0x00B0, 0x00B5, 0x00B9, 0x00BD, 0x00C1, 0x00C5, 0x00C9, 0x00CD, 0x00D1, 0x00D4, 0x00D8, 0x00DB, 0x00DE, 0x00E1, 0x00E4, 0x00E7, 0x00EA, 0x00EC, 0x00EE, 0x00F1, 0x00F3, 0x00F4, 0x00F6, 0x00F8, 0x00F9, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FE, 0x00FF, 0x00FF, 0x00FF, 0x0100, 0x00FF, 0x00FF, 0x00FF, 0x00FE, 0x00FE, 0x00FD, 0x00FC, 0x00FB, 0x00F9, 0x00F8, 0x00F6, 0x00F4, 0x00F3, 0x00F1, 0x00EE, 0x00EC, 0x00EA, 0x00E7, 0x00E4, 0x00E1, 0x00DE, 0x00DB, 0x00D8, 0x00D4, 0x00D1, 0x00CD, 0x00C9, 0x00C5, 0x00C1, 0x00BD, 0x00B9, 0x00B5, 0x00B0, 0x00AB, 0x00A7, 0x00A2, 0x009D, 0x0098, 0x0093, 0x008E, 0x0088, 0x0083, 0x007E, 0x0078, 0x0073, 0x006D, 0x0067, 0x0061, 0x005C, 0x0056, 0x0050, 0x004A, 0x0044, 0x003E, 0x0038, 0x0031, 0x002B, 0x0025, 0x001F, 0x0019, 0x0012, 0x000C, 0x0006, 0x0000, 0xFFFA, 0xFFF4, 0xFFEE, 0xFFE7, 0xFFE1, 0xFFDB, 0xFFD5, 0xFFCF, 0xFFC8, 0xFFC2, 0xFFBC, 0xFFB6, 0xFFB0, 0xFFAA, 0xFFA4, 0xFF9F, 0xFF99, 0xFF93, 0xFF8B, 0xFF88, 0xFF82, 0xFF7D, 0xFF78, 0xFF72, 0xFF6D, 0xFF68, 0xFF63, 0xFF5E, 0xFF59, 0xFF55, 0xFF50, 0xFF4B, 0xFF47, 0xFF43, 0xFF3F, 0xFF3B, 0xFF37, 0xFF33, 0xFF2F, 0xFF2C, 0xFF28, 0xFF25, 0xFF22, 0xFF1F, 0xFF1C, 0xFF19, 0xFF16, 0xFF14, 0xFF12, 0xFF0F, 0xFF0D, 0xFF0C, 0xFF0A, 0xFF08, 0xFF07, 0xFF05, 0xFF04, 0xFF03, 0xFF02, 0xFF02, 0xFF01, 0xFF01, 0xFF01, 0xFF00, 0xFF01, 0xFF01, 0xFF01, 0xFF02, 0xFF02, 0xFF03, 0xFF04, 0xFF05, 0xFF07, 0xFF08, 0xFF0A, 0xFF0C, 0xFF0D, 0xFF0F, 0xFF12, 0xFF14, 0xFF16, 0xFF19, 0xFF1C, 0xFF1F, 0xFF22, 0xFF25, 0xFF28, 0xFF2C, 0xFF2F, 0xFF33, 0xFF37, 0xFF3B, 0xFF3F, 0xFF43, 0xFF47, 0xFF4B, 0xFF50, 0xFF55, 0xFF59, 0xFF5E, 0xFF63, 0xFF68, 0xFF6D, 0xFF72, 0xFF78, 0xFF7D, 0xFF82, 0xFF88, 0xFF8B, 0xFF93, 0xFF99, 0xFF9F, 0xFFA4, 0xFFAA, 0xFFB0, 0xFFB6, 0xFFBC, 0xFFC2, 0xFFC8, 0xFFCF, 0xFFD5, 0xFFDB, 0xFFE1, 0xFFE7, 0xFFEE, 0xFFF4, 0xFFFA, 0x0000, 0x0006, 0x000C, 0x0012, 0x0019, 0x001F, 0x0025, 0x002B, 0x0031, 0x0038, 0x003E, 0x0044, 0x004A, 0x0050, 0x0056, 0x005C, 0x0061, 0x0067, 0x006D, 0x0073, 0x0078, 0x007E, 0x0083, 0x0088, 0x008E, 0x0093, 0x0098, 0x009D, 0x00A2, 0x00A7, 0x00AB, 0x00B0, 0x00B5, 0x00B9, 0x00BD, 0x00C1, 0x00C5, 0x00C9, 0x00CD, 0x00D1, 0x00D4, 0x00D8, 0x00DB, 0x00DE, 0x00E1, 0x00E4, 0x00E7, 0x00EA, 0x00EC, 0x00EE, 0x00F1, 0x00F3, 0x00F4, 0x00F6, 0x00F8, 0x00F9, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FE, 0x00FF, 0x00FF, 0x00FF, }; const char Angle_Data[258] = { 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, }; int CalcSine(){ #ifdef ENABLE_LOGGING WriteLog("CalcSine()"); TabLog(1); RegLog(); #endif //d1 = (cos((90.0/64*0.0174532925)*d0)) * 255; //d0 = (sin((90.0/64*0.0174532925)*d0)) * 255; d0 &= 0xFF; d1 = Sine_Data[d0+0x40]; d0 = Sine_Data[d0]; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int CalcAngle(){ #ifdef ENABLE_LOGGING WriteLog("CalcAngle()"); TabLog(1); RegLog(); #endif //d0 = atan2(d2, d1); i = d3; n = d4; d3 = d1 & 0xFFFF; d4 = d2 & 0xFFFF; d4 |= d3; if(d4 == 0) goto loc_36AA; d4 = d2; if((short)d3 < 0) d3 = -d3; if((short)d4 < 0) d4 = -d4; if((short)d4 < (short)d3){ d4 <<= 8; if((short)d3 == 0){ //allegro_message("DIVIDE BY ZERO! (section 1)"); d4 = 0; } else{ d4 = (unsigned short)d4 / (unsigned short)d3; //if(d4 >= 258) //allegro_message("OUT OF RANGE! A %X", d4); d0 = Angle_Data[d4]; } } else{ d3 <<= 8; if((short)d4 == 0){ //allegro_message("DIVIDE BY ZERO! (section 2)"); d3 = 0; } else{ d3 = (unsigned short)d3 / (unsigned short)d4; //if(d3 >= 258) //allegro_message("OUT OF RANGE! B %X", d3); d0 = 0x40 - Angle_Data[d3]; } } if((short)d1 < 0) d0 = -d0 + 0x80; if((short)d2 < 0) d0 = -d0 + 0x100; d3 = i; d4 = n; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; loc_36AA: #ifdef ENABLE_LOGGING WriteLog("loc_36AA"); #endif d0 = 0x40; d3 = i; d4 = n; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } /*void PalCycle_SuperSonic(){ // this may solve the Super Sonic transformation problem d0 = Super_Sonic_palette; if(d0 == 0) goto return_2186; if(d0 < 0) goto loc_21E6; d0--; if(d0 != 0) goto loc_2188; Palette_frame_count--; if(Palette_frame_count >= 0) return_2186; Palette_frame_count = 3; // lea (Pal_2246).l,a0 // move.w ($FFFFF65C).w,d0 // addq.w #8,($FFFFF65C).w // cmpi.w #$30,($FFFFF65C).w // bcs.s + Super_Sonic_palette = -1; p->obj_control = 0; // + // lea (Normal_palette+4).w,a1 // move.l (a0,d0.w),(a1)+ // move.l 4(a0,d0.w),(a1) return_2186: return; loc_2188: Palette_frame_count--; if(Palette_frame_count >= 0) goto return_2186; Palette_frame_count = 3; // lea (Pal_2246).l,a0 // move.w ($FFFFF65C).w,d0 // subq.w #8,($FFFFF65C).w // bcc.s loc_21B0 // move.b #0,($FFFFF65C).w Super_Sonic_palette = 0; loc_21B0: // lea (Normal_palette+4).w,a1 // move.l (a0,d0.w),(a1)+ // move.l 4(a0,d0.w),(a1) // lea (Pal_22C6).l,a0 // cmpi.b #$D,(Current_Zone).w // beq.s + // cmpi.b #$F,(Current_Zone).w // bne.s return_2186 // lea (Pal_2346).l,a0 //+ lea (Underwater_palette+4).w,a1 // move.l (a0,d0.w),(a1)+ // move.l 4(a0,d0.w),(a1) // rts //; =========================================================================== // loc_21E6: // subq.b #1,(Palette_frame_count).w // bpl.s return_2186 // move.b #7,(Palette_frame_count).w // lea (Pal_2246).l,a0 // move.w ($FFFFF65C).w,d0 // addq.w #8,($FFFFF65C).w // cmpi.w #$78,($FFFFF65C).w // bcs.s + // move.w #$30,($FFFFF65C).w //+ lea (Normal_palette+4).w,a1 // move.l (a0,d0.w),(a1)+ // move.l 4(a0,d0.w),(a1) // lea (Pal_22C6).l,a0 // cmpi.b #$D,(Current_Zone).w // beq.s + // cmpi.b #$F,(Current_Zone).w // bne.w return_2186 // lea (Pal_2346).l,a0 //+ lea (Underwater_palette+4).w,a1 // move.l (a0,d0.w),(a1)+ // move.l 4(a0,d0.w),(a1) // rts //; End of function PalCycle_SuperSonic // //; =========================================================================== //;---------------------------------------------------------------------------- //;Palette for transformation to Super Sonic //;---------------------------------------------------------------------------- //Pal_2246: BINCLUDE "art/palettes/Super Sonic transformation.bin" //;---------------------------------------------------------------------------- //;Palette for transformation to Super Sonic while underwater in CPZ //;---------------------------------------------------------------------------- //Pal_22C6: BINCLUDE "art/palettes/CPZWater SS transformation.bin" //;---------------------------------------------------------------------------- //;Palette for transformation to Super Sonic while underwater in ARZ //;---------------------------------------------------------------------------- //Pal_2346: BINCLUDE "art/palettes/ARZWater SS transformation.bin" }*/ FUNCINLINE int Obj01(){ #ifdef ENABLE_LOGGING WriteLog("Obj01()"); TabLog(1); RegLog(); VarLog(VAR_X_POS); VarLog(VAR_X_POS_PRE); VarLog(VAR_Y_POS); VarLog(VAR_Y_POS_PRE); VarLog(VAR_X_VEL); VarLog(VAR_Y_VEL); VarLog(VAR_INERTIA); VarLog(VAR_STATUS); VarLog(VAR_ANGLE); VarLog(VAR_ANIM); #endif //if(Debug_placement_mode) // goto DebugMode; Obj01_Normal: #ifdef ENABLE_LOGGING WriteLog("Obj01_Normal"); #endif d0 = p->routine; switch(d0){ case 0: goto Obj01_Init; case 2: goto Obj01_Control; case 4: Obj01_Hurt(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; case 6: Obj01_Dead(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; case 8: Obj01_Gone(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; case 10: Obj01_Respawning(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } Obj01_Init: #ifdef ENABLE_LOGGING WriteLog("Obj01_Init"); #endif p->routine += 2; p->y_radius = 0x13; p->x_radius = 9; // mappings = Mapunc_Sonic; p->priority = 2; p->width_pixels = 0x18; p->render_flags = 4; p->Sonic_top_speed = 0x600; p->Sonic_acceleration = 0xC; p->Sonic_deceleration = 0x80; if(p->Last_star_pole_hit != 0) goto Obj01_Init_Continued; p->art_tile = 0x780; //Adjust2PArtPointer(); p->layer = 0x10; #ifdef ENABLE_LOGGING VarLog(VAR_LAYER); #endif p->layer_plus = 0x11; p->Saved_x_pos = p->x_pos; p->Saved_y_pos = p->y_pos; p->Saved_art_tile = p->art_tile; p->Saved_layer = p->layer; Obj01_Init_Continued: #ifdef ENABLE_LOGGING WriteLog("Obj01_Init_Continued"); #endif p->flips_remaining = 0; p->flip_speed = 4; Super_Sonic_flag = 0; p->air_left = 0x1E; p->x_pos -= 0x20; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS); #endif p->y_pos += 0x4; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif p->Sonic_Pos_Record_Index = 0; for(d2=0x3F; d2>=0; d2--) Sonic_RecordPos(); p->x_pos += 0x20; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS); #endif p->y_pos -= 4; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif init_player = *p; Obj01_Control: #ifdef ENABLE_LOGGING WriteLog("Obj01_Control"); #endif if(Debug_mode_flag){ if(p->Ctrl_Press & 0x10){ Debug_placement_mode = 1; Control_Locked = 0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } } if(Control_Locked == 0){ p->Ctrl_Held_Logical = p->Ctrl_Held; p->Ctrl_Press_Logical = p->Ctrl_Press; } if((p->obj_control & 1) == 0){ d0 = p->status & 6; switch(d0){ case 0: Obj01_MdNormal_Checks(); break; case 2: Obj01_MdAir(); break; case 4: Obj01_MdRoll(); break; case 6: Obj01_MdJump(); } } if(p->Camera_Min_Y_pos == -0x100){ p->y_pos &= 0x7FF; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif } Sonic_Display(); Sonic_Super(); Sonic_RecordPos(); Sonic_Water(); p->next_tilt = p->ram_F768; p->tilt = p->ram_F76A; if(p->ram_F7C7){ if(p->anim == 0){ p->anim = p->next_anim; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif } } Sonic_Animate(); if(p->obj_control >= 0) TouchResponse(); LoadSonicDynPLC(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Sonic_Display(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_Display()"); TabLog(1); RegLog(); #endif d0 = p->invulnerable_time; if(d0 == 0) goto Obj01_Display; p->invulnerable_time--; if((d0 & 7) == 0){ d0 >>= 3; goto Obj01_ChkInvin; } d0 >>= 3; Obj01_Display: #ifdef ENABLE_LOGGING WriteLog("Obj01_Display"); #endif DisplaySprite(); Obj01_ChkInvin: #ifdef ENABLE_LOGGING WriteLog("Obj01_ChkInvin"); #endif if((p->status_secondary & 2) == 0) goto Obj01_ChkShoes; if(p->invincibility_time == 0) goto Obj01_ChkShoes; p->invincibility_time--; if(p->invincibility_time != 0) goto Obj01_ChkShoes; if(Current_Boss_ID != 0) goto Obj01_RmvInvin; if((unsigned char)p->air_left < 0xC) goto Obj01_RmvInvin; // move.w (Level_Music).w, d0 // jsr (PlayMusic).l Obj01_RmvInvin: #ifdef ENABLE_LOGGING WriteLog("Obj01_RmvInvin"); #endif p->status_secondary &= 0xFD; Obj01_ChkShoes: #ifdef ENABLE_LOGGING WriteLog("Obj01_ChkShoes"); #endif if((p->status_secondary & 4) == 0) goto Obj01_ExitChk; if(p->speedshoes_time == 0) goto Obj01_ExitChk; p->speedshoes_time--; if(p->speedshoes_time != 0) goto Obj01_ExitChk; p->Sonic_top_speed = 0x600; p->Sonic_acceleration = 0xC; p->Sonic_deceleration = 0x80; if(Super_Sonic_flag == 0) goto Obj01_RmvSpeed; p->Sonic_top_speed = 0xA00; p->Sonic_acceleration = 0x30; p->Sonic_deceleration = 0x100; Obj01_RmvSpeed: #ifdef ENABLE_LOGGING WriteLog("Obj01_RmvSpeed"); #endif p->status_secondary &= 0xFB; // move.w #$7C+$80, d0 // jmp (PlayMusic).l Obj01_ExitChk: #ifdef ENABLE_LOGGING WriteLog("Obj01_ExitChk"); RegLog(); TabLog(-1); #endif return 0; } int Sonic_RecordPos(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_RecordPos()"); TabLog(1); RegLog(); #endif d0 = p->Sonic_Pos_Record_Index; p->Sonic_Pos_Record_Index += 2; p->Sonic_Pos_Record_Index &= 0x7F; if(d0 >= 127) allegro_message("OUT OF RANGE! C %X", d0); p->Sonic_Pos_Record_Buf[d0] = p->x_pos; p->Sonic_Pos_Record_Buf[d0+1] = p->y_pos; p->Sonic_Stat_Record_Buf[d0] = (p->Ctrl_Held << 8) + p->Ctrl_Press; p->Sonic_Stat_Record_Buf[d0+1] = p->status; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Sonic_Water(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_Water()"); TabLog(1); RegLog(); #endif if(Water_flag != 0) goto Obj01_InWater; return_1A18C: #ifdef ENABLE_LOGGING WriteLog("return_1A18C"); RegLog(); TabLog(-1); #endif return 0; Obj01_InWater: #ifdef ENABLE_LOGGING WriteLog("Obj01_InWater"); #endif d0 = Water_Level_1; if(d0 >= p->y_pos) goto Obj01_OutWater; if(p->status & 0x40) goto return_1A18C; p->status |= 0x40; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif // movea.l a0,a1 // bsr.w ResumeMusic // move.b #$A,(Object_RAM+$2080).w // move.b #$81,(Object_RAM+$2080+subtype).w // move.l a0,(Object_RAM+$2080+$3C).w p->Sonic_top_speed = 0x300; p->Sonic_acceleration = 0x6; p->Sonic_deceleration = 0x40; if(Super_Sonic_flag != 0){ p->Sonic_top_speed = 0x500; p->Sonic_acceleration = 0x18; p->Sonic_deceleration = 0x80; } if(p->x_vel < 0){ // p->x_vel /= 2; -- DONE THIS WAY FOR ACCURACY p->x_vel >>= 1; p->x_vel |= 0x8000; } else p->x_vel >>= 1; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif if(p->y_vel < 0){ // p->y_vel /= 4; -- DONE THIS WAY FOR ACCURACY p->y_vel >>= 2; p->y_vel |= 0xC000; } else p->y_vel >>= 2; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif if(p->y_vel == 0) goto return_1A18C; // move.w #$100, (Sonic_Dust+p->anim).w // move.w #$2A+$80, d0 // jmp (PlaySound).l Obj01_OutWater: #ifdef ENABLE_LOGGING WriteLog("Obj01_OutWater"); #endif if((p->status & 0x40) == 0) goto return_1A18C; p->status &= 0xBF; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif // movea.l a0, a1 // bsr.w ResumeMusic p->Sonic_top_speed = 0x600; p->Sonic_acceleration = 0xC; p->Sonic_deceleration = 0x80; if(Super_Sonic_flag != 0){ p->Sonic_top_speed = 0xA00; p->Sonic_acceleration = 0x30; p->Sonic_deceleration = 0x100; } if(p->routine != 4){ p->y_vel *= 2; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif } if(p->y_vel == 0) goto return_1A18C; // move.w #$100, (Sonic_Dust+p->anim).w // movea.l a0, a1 // bsr.w ResumeMusic if(p->y_vel < -0x1000){ p->y_vel = -0x1000; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif } // move.w #$2A+$80, d0 // jmp (PlaySound).l Obj01_MdNormal_Checks(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int Obj01_MdNormal_Checks(){ #ifdef ENABLE_LOGGING WriteLog("Obj01_MdNormal_Checks()"); TabLog(1); RegLog(); #endif d0 = p->Ctrl_Press_Logical & 0x70; if(d0 != 0) goto Obj01_MdNormal; if(p->anim == 0xA) goto return_1A2DE; if(p->anim == 0xB) goto return_1A2DE; if(p->anim != 0x5) goto Obj01_MdNormal; if((unsigned char)p->anim_frame < 0x1E) goto Obj01_MdNormal; d0 = p->Ctrl_Held_Logical & 0x7F; if(d0 == 0) goto return_1A2DE; p->anim = 0xA; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif if((unsigned char)p->anim_frame < 0xAC) goto return_1A2DE; p->anim = 0xB; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif goto return_1A2DE; Obj01_MdNormal: #ifdef ENABLE_LOGGING WriteLog("Obj01_MdNormal"); #endif Sonic_CheckSpindash(); if(double_return){ double_return = 0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } Sonic_Jump(); if(double_return){ double_return = 0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } Sonic_SlopeResist(); Sonic_Move(); Sonic_Roll(); Sonic_LevelBound(); ObjectMove(); AnglePos(); Sonic_SlopeRepel(); return_1A2DE: #ifdef ENABLE_LOGGING WriteLog("return_1A2DE"); RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Obj01_MdAir(){ #ifdef ENABLE_LOGGING WriteLog("Obj01_MdAir()"); TabLog(1); RegLog(); #endif Sonic_JumpHeight(); Sonic_ChgJumpDir(); Sonic_LevelBound(); ObjectMoveAndFall(); if(p->status & 0x40){ p->y_vel -= 0x28; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif } Sonic_JumpAngle(); Sonic_DoLevelCollision(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Obj01_MdRoll(){ #ifdef ENABLE_LOGGING WriteLog("Obj01_MdRoll()"); TabLog(1); RegLog(); #endif if(p->spindash_flag == 0){ Sonic_Jump(); if(double_return){ double_return = 0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } } Sonic_RollRepel(); Sonic_RollSpeed(); Sonic_LevelBound(); ObjectMove(); AnglePos(); Sonic_SlopeRepel(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Obj01_MdJump(){ #ifdef ENABLE_LOGGING WriteLog("Obj01_MdJump()"); TabLog(1); RegLog(); #endif Sonic_JumpHeight(); Sonic_ChgJumpDir(); Sonic_LevelBound(); ObjectMoveAndFall(); if(p->status & 0x40){ p->y_vel -= 0x28; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif } Sonic_JumpAngle(); Sonic_DoLevelCollision(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Sonic_Move(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_Move()"); TabLog(1); RegLog(); #endif d6 = p->Sonic_top_speed; d5 = p->Sonic_acceleration; d4 = p->Sonic_deceleration; if(p->status_secondary < 0) goto Obj01_Traction; if(p->move_lock != 0) goto Obj01_ResetScr; if((p->Ctrl_Held_Logical & 4) == 0) goto Obj01_NotLeft; Sonic_MoveLeft(); Obj01_NotLeft: #ifdef ENABLE_LOGGING WriteLog("Obj01_NotLeft"); #endif if((p->Ctrl_Held_Logical & 8) == 0) goto Obj01_NotRight; Sonic_MoveRight(); Obj01_NotRight: #ifdef ENABLE_LOGGING WriteLog("Obj01_NotRight"); #endif d0 = (p->angle + 0x20) & 0xC0; if(d0 != 0) goto Obj01_ResetScr; if(p->inertia != 0) goto Obj01_ResetScr; p->status &= 0xDF; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->anim = 5; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif if((p->status & 8) == 0) goto Sonic_Balance; d0 = p->interact << 6; // lea (MainCharacter).w,a1 ; a1=character // lea (a1,d0.w),a1 ; a1=object if(a1_status < 0)/////////////////////////////////////// (a1) goto Sonic_Lookup; d2 = (a1_width_pixels << 1) - 2;//////////////////////// (a1) d1 = a1_width_pixels + p->x_pos - a1_x_pos;////////// (a1) if(Super_Sonic_flag != 0) goto SuperSonic_Balance; if((short)d1 < 2) goto Sonic_BalanceOnObjLeft; if((short)d1 >= (short)d2) goto Sonic_BalanceOnObjRight; goto Sonic_Lookup; SuperSonic_Balance: #ifdef ENABLE_LOGGING WriteLog("SuperSonic_Balance"); #endif if((short)d1 < 2) goto SuperSonic_BalanceOnObjLeft; if((short)d1 >= (short)d2) goto SuperSonic_BalanceOnObjRight; goto Sonic_Lookup; Sonic_BalanceOnObjRight: #ifdef ENABLE_LOGGING WriteLog("Sonic_BalanceOnObjRight"); #endif if((p->status & 1) == 0){ p->anim = 6; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif d2 += 6; if((short)d1 < (short)d2) goto Obj01_ResetScr; p->anim = 0xC; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif goto Obj01_ResetScr; } p->anim = 0x1D; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif d2 += 6; if((short)d1 < (short)d2) goto Obj01_ResetScr; p->anim = 0x1E; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->status &= 0xFE; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif goto Obj01_ResetScr; Sonic_BalanceOnObjLeft: #ifdef ENABLE_LOGGING WriteLog("Sonic_BalanceOnObjLeft"); #endif if(p->status & 1){ p->anim = 6; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif if((short)d1 >= -4) goto Obj01_ResetScr; p->anim = 0xC; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif goto Obj01_ResetScr; } p->anim = 0x1D; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif if(d1 >= -4) goto Obj01_ResetScr; p->anim = 0x1E; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->status |= 1; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif goto Obj01_ResetScr; Sonic_Balance: #ifdef ENABLE_LOGGING WriteLog("Sonic_Balance"); #endif ChkFloorEdge(); if((short)d1 < 0xC) goto Sonic_Lookup; if(Super_Sonic_flag != 0) goto SuperSonic_Balance2; if(p->next_tilt != 3) goto Sonic_BalanceLeft; if((p->status & 1) == 0){ p->anim = 6; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif d3 = p->x_pos - 6; ChkFloorEdge_Part2(); if((short)d1 < 0xC) goto Obj01_ResetScr; p->anim = 0xC; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif goto Obj01_ResetScr; } p->anim = 0x1D; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif d3 = p->x_pos - 6; ChkFloorEdge_Part2(); if((short)d1 < 0xC) goto Obj01_ResetScr; p->anim = 0x1E; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->status &= 0xFE; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif goto Obj01_ResetScr; Sonic_BalanceLeft: #ifdef ENABLE_LOGGING WriteLog("Sonic_BalanceLeft"); #endif if(p->tilt != 3) goto Sonic_Lookup; if(p->status & 1){ p->anim = 6; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif d3 = p->x_pos + 6; ChkFloorEdge_Part2(); if((short)d1 < 0xC) goto Obj01_ResetScr; p->anim = 0xC; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif goto Obj01_ResetScr; } p->anim = 0x1D; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif d3 = p->x_pos + 6; ChkFloorEdge_Part2(); if((short)d1 < 0xC) goto Obj01_ResetScr; p->anim = 0x1E; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->status |= 1; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif goto Obj01_ResetScr; SuperSonic_Balance2: #ifdef ENABLE_LOGGING WriteLog("SuperSonic_Balance2"); #endif if(p->next_tilt != 3) goto loc_1A56E; SuperSonic_BalanceOnObjRight: #ifdef ENABLE_LOGGING WriteLog("SuperSonic_BalanceOnObjRight"); #endif p->status &= 0xFE; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif goto loc_1A57C; loc_1A56E: #ifdef ENABLE_LOGGING WriteLog("log_1A56E"); #endif if(p->tilt != 3) goto Sonic_Lookup; SuperSonic_BalanceOnObjLeft: #ifdef ENABLE_LOGGING WriteLog("SuperSonic_BalanceOnObjLeft"); #endif p->status |= 1; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif loc_1A57C: #ifdef ENABLE_LOGGING WriteLog("log_1A57C"); #endif p->anim = 6; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif goto Obj01_ResetScr; Sonic_Lookup: #ifdef ENABLE_LOGGING WriteLog("Sonic_Lookup"); #endif if((p->Ctrl_Held_Logical & 1) == 0) goto Sonic_Duck; p->anim = 7; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->Sonic_Look_delay_counter++; if((unsigned short)p->Sonic_Look_delay_counter < 0x78) goto Obj01_ResetScr_Part2; p->Sonic_Look_delay_counter = 0x78; if(p->Camera_Y_pos_bias == 0xC8) goto Obj01_UpdateSpeedOnGround; p->Camera_Y_pos_bias += 2; goto Obj01_UpdateSpeedOnGround; Sonic_Duck: #ifdef ENABLE_LOGGING WriteLog("Sonic_Duck"); #endif if((p->Ctrl_Held_Logical & 2) == 0) goto Obj01_ResetScr; p->anim = 8; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->Sonic_Look_delay_counter++; if((unsigned short)p->Sonic_Look_delay_counter < 0x78) goto Obj01_ResetScr_Part2; p->Sonic_Look_delay_counter = 0x78; if(p->Camera_Y_pos_bias == 8) goto Obj01_UpdateSpeedOnGround; p->Camera_Y_pos_bias -= 2; goto Obj01_UpdateSpeedOnGround; Obj01_ResetScr: #ifdef ENABLE_LOGGING WriteLog("Obj01_ResetScr"); #endif p->Sonic_Look_delay_counter = 0; Obj01_ResetScr_Part2: #ifdef ENABLE_LOGGING WriteLog("Obj01_ResetScr_Part2"); #endif if(p->Camera_Y_pos_bias == 0x60) goto Obj01_UpdateSpeedOnGround; if((unsigned short)p->Camera_Y_pos_bias < 0x60) p->Camera_Y_pos_bias += 4; p->Camera_Y_pos_bias -= 2; Obj01_UpdateSpeedOnGround: #ifdef ENABLE_LOGGING WriteLog("Obj01_UpdateSpeedOnGround"); #endif if(Super_Sonic_flag != 0) d5 = 0xC; d0 = p->Ctrl_Held_Logical & 0xC; if(d0 != 0) goto Obj01_Traction; d0 = p->inertia; if(d0 == 0) goto Obj01_Traction; if((short)d0 < 0) goto Obj01_SettleLeft; d0 -= d5; if((short)d0 < 0) d0 = 0; p->inertia = d0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif goto Obj01_Traction; Obj01_SettleLeft: #ifdef ENABLE_LOGGING WriteLog("Obj01_SettleLeft"); #endif d0 += d5; if((short)d0 > 0) d0 = 0; p->inertia = d0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif Obj01_Traction: #ifdef ENABLE_LOGGING WriteLog("Obj01_Traction"); #endif d0 = p->angle; CalcSine(); d1 *= p->inertia; if(d1 < 0){ // d1 /= 256; -- DONE THIS WAY FOR ACCURACY d1 >>= 8; d1 |= 0xFF000000; } else d1 >>= 8; p->x_vel = d1; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif d0 *= p->inertia; if(d0 < 0){ // d0 /= 256; -- DONE THIS WAY FOR ACCURACY d0 >>= 8; d0 |= 0xFF000000; } else d0 >>= 8; p->y_vel = d0; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif Obj01_CheckWallsOnGround(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int Obj01_CheckWallsOnGround(){ #ifdef ENABLE_LOGGING WriteLog("Obj01_CheckWallsOnGround()"); TabLog(1); RegLog(); #endif d0 = p->angle + 0x40; if((char)d0 < 0) goto return_1A6BE; d1 = 0x40; if(p->inertia == 0) goto return_1A6BE; if(p->inertia >= 0) d1 = -d1; d0 = p->angle + d1; n = d0; CalcRoomInFront(); d0 = n; if((short)d1 >= 0) goto return_1A6BE; d1 *= 256; d0 += 0x20; d0 &= 0xC0; if(d0 == 0) goto loc_1A6BA; if(d0 == 0x40) goto loc_1A6A8; if(d0 == 0x80) goto loc_1A6A2; p->x_vel += d1; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif p->status |= 0x20; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->inertia = 0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); RegLog(); TabLog(-1); #endif return 0; loc_1A6A2: #ifdef ENABLE_LOGGING WriteLog("loc_1A6A2"); #endif p->y_vel -= d1; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); RegLog(); TabLog(-1); #endif return 0; loc_1A6A8: #ifdef ENABLE_LOGGING WriteLog("loc_1A6A8"); #endif p->x_vel -= d1; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif p->status |= 0x20; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->inertia = 0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); RegLog(); TabLog(-1); #endif return 0; loc_1A6BA: #ifdef ENABLE_LOGGING WriteLog("loc_1A6BA"); #endif p->y_vel += d1; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif return_1A6BE: #ifdef ENABLE_LOGGING WriteLog("return_1A6BE"); RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Sonic_MoveLeft(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_MoveLeft()"); TabLog(1); RegLog(); #endif d0 = p->inertia; if(d0 != 0){ if((short)d0 >= 0) goto Sonic_TurnLeft; } p->status |= 1; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif if(p->status == 0){ p->status &= 0xDF; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->next_anim = 1; } d0 -= d5; d1 = d6; d1 = -d1; if(d0 <= d1){ d0 += d5; if(d0 > d1) d0 = d1; } p->inertia = d0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif p->anim = 0; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); RegLog(); TabLog(-1); #endif return 0; Sonic_TurnLeft: #ifdef ENABLE_LOGGING WriteLog("Sonic_TurnLeft"); #endif d0 -= d4; if((short)d0 <= 0) d0 = -0x80; p->inertia = d0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif d0 = (d0 & 0xFFFFFF00) + ((p->angle + 0x20) & 0xFF); d0 &= 0xFFFFFFC0; if(d0 == 0) goto return_1A744; if((short)d0 < 0x400) goto return_1A744; p->anim = 0xD; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->status &= 0xFE; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif // move.w #$A4, d0 // jsr (PlaySound).l PlayFM(0x24, 3, 0); if((unsigned char)p->air_left < 0xC) goto return_1A744; // move.b #6, (Sonic_Dust+p->routine).w // move.b #$15, (Sonic_Dust+mapping_frame).w return_1A744: #ifdef ENABLE_LOGGING WriteLog("return_1A744"); RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Sonic_MoveRight(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_MoveRight()"); TabLog(1); RegLog(); #endif d0 = p->inertia; if(d0 < 0) goto Sonic_TurnRight; if((p->status & 1) != 0){ p->status &= 0xDE; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->next_anim = 1; } d0 += d5; if(d0 >= d6){ d0 -= d5; if(d0 < d6) d0 = d6; } p->inertia = d0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif p->anim = 0; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); RegLog(); TabLog(-1); #endif return 0; Sonic_TurnRight: #ifdef ENABLE_LOGGING WriteLog("Sonic_TurnRight"); #endif d0 += d4; if((short)d0 >= 0) d0 = 0x80; p->inertia = d0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif d0 = (d0 & 0xFFFFFF00) + ((p->angle + 0x20) & 0xFF); d0 &= 0xFFFFFFC0; if(d0 == 0) goto return_1A7C4; if(d0 > -0x400) goto return_1A7C4; p->anim = 0xD; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->status |= 1; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif // move.w #$24+$80, d0 // jsr (PlaySound).l PlayFM(0x24, 3, 0); if((unsigned char)p->air_left < 0xC) goto return_1A7C4; // move.b #6, (Sonic_Dust+p->routine).w // move.b #$15, (Sonic_Dust+mapping_frame).w return_1A7C4: #ifdef ENABLE_LOGGING WriteLog("return_1A7C4"); RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Sonic_RollSpeed(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_RollSpeed()"); TabLog(1); RegLog(); #endif d6 = p->Sonic_top_speed * 2; d5 = p->Sonic_acceleration; if(d5 < 0){ // d5 /= 2; -- DONE THIS WAY FOR ACCURACY d5 >>= 1; d5 |= 0x80000000; } else d5 >>= 1; d4 = 0x20; if(p->status_secondary < 0) goto Obj01_Roll_ResetScr; if(p->move_lock != 0) goto Sonic_ApplyRollSpeed; if(p->Ctrl_Held_Logical & 4) Sonic_RollLeft(); if((p->Ctrl_Held_Logical & 8) == 0) goto Sonic_ApplyRollSpeed; Sonic_RollRight(); Sonic_ApplyRollSpeed: #ifdef ENABLE_LOGGING WriteLog("Sonic_ApplyRollSpeed"); #endif d0 = p->inertia; if(d0 == 0) goto Sonic_CheckRollStop; if(d0 < 0) goto Sonic_ApplyRollSpeedLeft; d0 -= d5; if(d0 < 0) d0 = 0; p->inertia = d0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif goto Sonic_CheckRollStop; Sonic_ApplyRollSpeedLeft: #ifdef ENABLE_LOGGING WriteLog("Sonic_ApplyRollSpeedLeft"); #endif d0 += d5; if(d0 > 0) d0 = 0; p->inertia = d0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif Sonic_CheckRollStop: #ifdef ENABLE_LOGGING WriteLog("Sonic_CheckRollStop"); #endif if(p->inertia != 0) goto Obj01_Roll_ResetScr; if(p->spindash_flag != 0) goto Sonic_KeepRolling; p->status &= 0xFB; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->y_radius = 0x13; p->x_radius = 9; p->anim = 5; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->y_pos -= 5; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif goto Obj01_Roll_ResetScr; Sonic_KeepRolling: #ifdef ENABLE_LOGGING WriteLog("Sonic_KeepRolling"); #endif p->inertia = 0x400; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif if((p->status & 1) == 0) goto Obj01_Roll_ResetScr; p->inertia = -p->inertia; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif Obj01_Roll_ResetScr://///////////////////////// rest screen during spindash?? #ifdef ENABLE_LOGGING WriteLog("Obj01_Roll_ResetScr"); #endif if(p->Camera_Y_pos_bias == 0x60) goto Sonic_SetRollSpeeds; if((unsigned short)p->Camera_Y_pos_bias < 0x60) p->Camera_Y_pos_bias += 4; p->Camera_Y_pos_bias -= 2; Sonic_SetRollSpeeds: #ifdef ENABLE_LOGGING WriteLog("Sonic_SetRollSpeeds"); #endif d0 = p->angle; CalcSine(); d0 *= p->inertia; if(d0 < 0){ // d0 /= 256; -- DONE THIS WAY FOR ACCURACY d0 >>= 8; d0 |= 0xFF000000; } else d0 >>= 8; p->y_vel = d0; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif d1 *= p->inertia; if(d1 < 0){ // d1 /= 256; -- DONE THIS WAY FOR ACCURACY d1 >>= 8; d1 |= 0xFF000000; } else d1 >>= 8; if(d1 > 0x1000) d1 = 0x1000; if(d1 < -0x1000) d1 = -0x1000; p->x_vel = d1; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif Obj01_CheckWallsOnGround(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Sonic_RollLeft(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_RollLeft()"); TabLog(1); RegLog(); #endif d0 = p->inertia; if(d0 != 0){ if(d0 > 0) goto Sonic_BrakeRollingRight; } p->status |= 1; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->anim = 2; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); RegLog(); TabLog(-1); #endif return 0; Sonic_BrakeRollingRight: #ifdef ENABLE_LOGGING WriteLog("Sonic_BrakeRollingRight"); #endif d0 -= d4; if(d0 < 0) d0 = -0x80; p->inertia = d0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Sonic_RollRight(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_RollRight()"); TabLog(1); RegLog(); #endif d0 = p->inertia; if(d0 < 0) goto Sonic_BrakeRollingLeft; p->status &= 0xFE; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->anim = 2; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); RegLog(); TabLog(-1); #endif return 0; Sonic_BrakeRollingLeft: #ifdef ENABLE_LOGGING WriteLog("Sonic_BrakeRollingLeft"); #endif d0 += d4; if(d0 > 0) d0 = 0x80; p->inertia = d0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); RegLog(); TabLog(-1); #endif return 0; } int Sonic_ChgJumpDir(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_ChgJumpDir()"); TabLog(1); RegLog(); #endif d6 = p->Sonic_top_speed; d5 = p->Sonic_acceleration; d5 *= 2; if(p->status & 0x10) goto Obj01_Jump_ResetScr; d0 = p->x_vel; if(p->Ctrl_Held_Logical & 4){ p->status |= 1; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif d0 -= d5; d1 = d6; d1 = -d1; if(d0 <= d1) d0 = d1; } if(p->Ctrl_Held_Logical & 8){ p->status &= 0xFE; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif d0 += d5; if(d0 >= d6) d0 = d6; } p->x_vel = d0; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif Obj01_Jump_ResetScr: #ifdef ENABLE_LOGGING WriteLog("Obj01_Jump_ResetScr"); #endif if(p->Camera_Y_pos_bias == 0x60) goto Sonic_JumpPeakDecelerate; if((unsigned short)p->Camera_Y_pos_bias < 0x60) p->Camera_Y_pos_bias += 4; p->Camera_Y_pos_bias -= 2; Sonic_JumpPeakDecelerate: #ifdef ENABLE_LOGGING WriteLog("Sonic_JumpPeakDecelerate"); #endif if(p->y_vel < -0x400 || p->y_vel >= 0) goto return_1A972; d0 = p->x_vel; d1 = d0; if(d1 < 0){ // d1 /= 32; -- DONE THIS WAY FOR ACCURACY d1 >>= 5; d1 |= 0xF8000000; } else d1 >>= 5; #ifdef ENABLE_LOGGING VarLog(REG_D0); VarLog(REG_D1); #endif if(d1 == 0) goto return_1A972; if(d1 < 0) goto Sonic_JumpPeakDecelerateLeft; d0 -= d1; if(d0 < 0) d0 = 0; p->x_vel = d0; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); RegLog(); TabLog(-1); #endif return 0; Sonic_JumpPeakDecelerateLeft: #ifdef ENABLE_LOGGING WriteLog("Sonic_JumpPeakDecelerateLeft"); #endif d0 -= d1; if(d0 > 0) d0 = 0; p->x_vel = d0; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif return_1A972: #ifdef ENABLE_LOGGING WriteLog("return_1A972"); RegLog(); TabLog(-1); #endif return 0; } int Sonic_LevelBound(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_LevelBound()"); TabLog(1); RegLog(); #endif d1 = (p->x_pos << 16) + p->x_pos_pre; d0 = p->x_vel; d0 *= 256; d1 += d0; d1 = (d1 >> 16) + (d1 << 16); d0 = p->Camera_Min_X_pos; d0 += 0x10; if((unsigned short)(d0 & 0xFFFF) > (unsigned short)(d1 & 0xFFFF)) goto Sonic_Boundary_Sides; d0 = p->Camera_Max_X_pos; d0 += 0x128; if(Current_Boss_ID == 0) d0 += 0x40; if((unsigned short)(d0 & 0xFFFF) <= (unsigned short)(d1 & 0xFFFF)) goto Sonic_Boundary_Sides; Sonic_Boundary_CheckBottom: #ifdef ENABLE_LOGGING WriteLog("Sonic_Boundary_CheckBottom"); #endif d0 = p->Camera_Max_Y_pos_now; d0 += 0xE0; if(d0 < p->y_pos) goto Sonic_Boundary_Bottom; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; Sonic_Boundary_Bottom: #ifdef ENABLE_LOGGING WriteLog("Sonic_Boundary_Bottom"); #endif KillCharacter(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; Sonic_Boundary_Sides: #ifdef ENABLE_LOGGING WriteLog("Sonic_Boundary_Sides"); #endif p->x_pos = d0 & 0xFFFF; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS); #endif p->x_pos_pre = 0; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS_PRE); #endif p->x_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif p->inertia = 0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif goto Sonic_Boundary_CheckBottom; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0;/////////// exclude } FUNCINLINE int Sonic_Roll(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_Roll()"); TabLog(1); RegLog(); #endif if(p->status_secondary < 0) goto Obj01_NoRoll; d0 = p->inertia; if(d0 < 0) d0 = -d0; if((unsigned short)d0 < 0x80) goto Obj01_NoRoll; d0 = p->Ctrl_Held_Logical & 0xC; if(d0 != 0) goto Obj01_NoRoll; if(p->Ctrl_Held_Logical & 2) goto Obj01_ChkRoll; Obj01_NoRoll: #ifdef ENABLE_LOGGING WriteLog("Obj01_NoRoll"); RegLog(); TabLog(-1); #endif return 0; Obj01_ChkRoll: #ifdef ENABLE_LOGGING WriteLog("Obj01_ChkRoll"); #endif if((p->status & 4) == 0) goto Obj01_DoRoll; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; Obj01_DoRoll: #ifdef ENABLE_LOGGING WriteLog("Obj01_DoRoll"); #endif p->status |= 4; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->y_radius = 0xE; p->x_radius = 7; p->anim = 2; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->y_pos += 5; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif // move.w #$BE, d0 // jsr (PlaySound).l PlayFM(0x3E, 3, 0); if(p->inertia != 0) goto return_1AA36; p->inertia = 0x200; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif return_1AA36: #ifdef ENABLE_LOGGING WriteLog("return_1AA36"); RegLog(); TabLog(-1); #endif return 0; } int Sonic_Jump(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_Jump()"); TabLog(1); RegLog(); #endif d0 = p->Ctrl_Press_Logical & 0x70; if(d0 == 0) goto return_1AAE6; d0 = (p->angle + 0x80) & 0xFF; CalcRoomOverHead(); if(d1 < 6) goto return_1AAE6; d2 = 0x680; if(Super_Sonic_flag != 0) d2 = 0x800; if(p->status & 0x40) d2 = 0x380; d0 = p->angle; d0 -= 0x40; CalcSine(); d1 *= d2; if(d1 < 0){ // d1 /= 256; -- DONE THIS WAY FOR ACCURACY d1 >>= 8; d1 |= 0xFF000000; } else d1 >>= 8; p->x_vel += d1; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif d0 *= d2; if(d0 < 0){ // d0 /= 256; -- DONE THIS WAY FOR ACCURACY d0 >>= 8; d0 |= 0xFF000000; } else d0 >>= 8; p->y_vel += d0; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif p->status |= 2; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->status &= 0xDF; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif double_return = 1; // addq.l #4, sp p->jumping = 1; p->stick_to_convex = 0; // move.w #$A0, d0 // jsr (PlaySound).l PlayFM(0x20, 2, 0); p->y_radius = 19; p->x_radius = 9; if((p->status & 4) != 0) goto Sonic_RollJump; p->y_radius = 0xE; p->x_radius = 0x7; p->anim = 2; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->status |= 4; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->y_pos += 5; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif return_1AAE6: #ifdef ENABLE_LOGGING WriteLog("return_1AAE6"); RegLog(); TabLog(-1); #endif return 0; Sonic_RollJump: #ifdef ENABLE_LOGGING WriteLog("Sonic_RollJump"); #endif p->status |= 0x10; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); RegLog(); TabLog(-1); #endif return 0; } int Sonic_JumpHeight(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_JumpHeight()"); TabLog(1); RegLog(); #endif if(p->jumping == 0) goto Sonic_UpVelCap; d1 = -0x400; if(p->status & 0x40) d1 = -0x200; if(d1 > p->y_vel){ d0 = p->Ctrl_Held_Logical & 0x70; if(d0 == 0){ p->y_vel = d1; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif } } if((p->y_vel >> 8) == 0) goto Sonic_CheckGoSuper; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; Sonic_UpVelCap: #ifdef ENABLE_LOGGING WriteLog("Sonic_UpVelCap"); #endif if(p->spindash_flag != 0) goto return_1AB36; if(p->y_vel >= -0xFC0) goto return_1AB36; p->y_vel = -0xFC0; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif return_1AB36: #ifdef ENABLE_LOGGING WriteLog("return_1AB36"); RegLog(); TabLog(-1); #endif return 0; Sonic_CheckGoSuper: #ifdef ENABLE_LOGGING WriteLog("Sonic_CheckGoSuper"); #endif if(Super_Sonic_flag != 0) goto return_1ABA4; if(Emerald_count != 7) goto return_1ABA4; if((signed short)p->Ring_count < 50) // changed from (unsigned short) goto return_1ABA4; Super_Sonic_palette = 1; Palette_frame_count = 0xF; Super_Sonic_flag = 1; //p->obj_control = 0x81; // commented out only temporarily p->anim = 0x1F; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif // move.b #$7E, (Object_RAM+$2040).w p->Sonic_top_speed = 0xA00; p->Sonic_acceleration = 0x30; p->Sonic_deceleration = 0x100; p->invincibility_time = 0; p->status_secondary |= 2; // move.w #$5F+$80, d0 // jsr (PlaySound).l // move.w #$16+$80, d0 // jmp (PlayMusic).l return_1ABA4: #ifdef ENABLE_LOGGING WriteLog("return_1ABA4"); RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Sonic_Super(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_Super()"); TabLog(1); RegLog(); #endif if(Super_Sonic_flag == 0) goto return_1AC3C; if(Update_HUD_timer == 0) goto Sonic_RevertToNormal; Super_Sonic_frame_count--; if(Super_Sonic_frame_count >= 0) goto return_1AC3C; if(compat_super_sonic_countdown) Super_Sonic_frame_count = 60; else Super_Sonic_frame_count = 59; if(p->Ring_count == 0) goto Sonic_RevertToNormal; Update_HUD_rings |= 1; if(p->Ring_count == 1 || p->Ring_count == 10 || p->Ring_count == 100) Update_HUD_rings |= 0x80; p->Ring_count--; if(p->Ring_count > 0) //if(p->Ring_count != 0) goto return_1AC3C; Sonic_RevertToNormal: #ifdef ENABLE_LOGGING WriteLog("Sonic_RevertToNormal"); #endif Super_Sonic_palette = 2; p->ram_F65C = 0x28; Super_Sonic_flag = 0; p->next_anim = 1; p->invincibility_time = 1; p->Sonic_top_speed = 0x600; p->Sonic_acceleration = 0xC; p->Sonic_deceleration = 0x80; if(p->status & 0x40){ p->Sonic_top_speed = 0x300; p->Sonic_acceleration = 0x6; p->Sonic_deceleration = 0x40; } return_1AC3C: #ifdef ENABLE_LOGGING WriteLog("return_1AC3C"); RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Sonic_CheckSpindash(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_CheckSpindash()"); TabLog(1); RegLog(); #endif a0 = p->spindash_flag; if(p->spindash_flag != 0) goto Sonic_UpdateSpindash; if(p->anim != 8) goto return_1AC8C; d0 = p->Ctrl_Press_Logical & 0x70; if(d0 == 0) goto return_1AC8C; p->anim = 9; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif // move.w #$E0, d0 // jsr (PlaySound).l PlayFM(0x60, 3, 0); double_return = 1; // addq.l #4, sp p->spindash_flag = 1; p->spindash_counter = 0; if((unsigned char)p->air_left >= 0xC) ;// move.b #2, (Sonic_Dust+p->anim).w Sonic_LevelBound(); AnglePos(); return_1AC8C: #ifdef ENABLE_LOGGING WriteLog("return_1AC8C"); RegLog(); TabLog(-1); #endif return 0; Sonic_UpdateSpindash: #ifdef ENABLE_LOGGING WriteLog("Sonic_UpdateSpindash"); #endif d0 = p->Ctrl_Held_Logical; if((d0 & 2) != 0) goto Sonic_ChargingSpindash; p->y_radius = 0xE; p->x_radius = 0x7; p->anim = 2; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->y_pos += 5; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif p->spindash_flag = 0; d0 = (p->spindash_counter >> 8); // add.w d0, d0 //if(d0 >= 9) // allegro_message("OUT OF RANGE! D %X", d0); p->inertia = SpindashSpeeds[d0]; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif if(Super_Sonic_flag != 0){ //if(d0 >= 9) // allegro_message("OUT OF RANGE! E %X", d0); p->inertia = SpindashSpeedsSuper[d0]; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif } d0 = p->inertia; d0 -= 0x800; d0 <<= 1; d0 &= 0x1F00; d0 = -d0; d0 += 0x2000; p->ram_EED0 = d0; if((p->status & 1) != 0){ p->inertia = -p->inertia; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif } p->status |= 4; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif // move.b #0, (Sonic_Dust+p->anim).w // move.w #$3C+$80, d0 // jsr (PlaySound).l PlayFM(0x3C, 3, 0); goto Obj01_Spindash_ResetScr; Sonic_ChargingSpindash: #ifdef ENABLE_LOGGING WriteLog("Sonic_ChargingSpindash"); #endif if(p->spindash_counter != 0){ d0 = p->spindash_counter; d0 >>= 5; p->spindash_counter -= d0; if(p->spindash_counter < 0) p->spindash_counter = 0; } d0 = p->Ctrl_Press_Logical & 0x70; if(d0 == 0) goto Obj01_Spindash_ResetScr; p->anim = 0x9; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->next_anim = 0; // move.w #$E0, d0 // jsr (PlaySound).l PlayFM(0x60, 3, 0); p->spindash_counter += 0x200; if((unsigned short)p->spindash_counter < 0x800) goto Obj01_Spindash_ResetScr; p->spindash_counter = 0x800; Obj01_Spindash_ResetScr: #ifdef ENABLE_LOGGING WriteLog("Obj01_Spindash_ResetScr"); #endif double_return = 1; // addq.l #4, sp if(p->Camera_Y_pos_bias == 0x60) goto loc_1AD8C; if((unsigned short)p->Camera_Y_pos_bias < 0x60) p->Camera_Y_pos_bias += 4; p->Camera_Y_pos_bias -= 2; loc_1AD8C: #ifdef ENABLE_LOGGING WriteLog("loc_1AD8C"); #endif Sonic_LevelBound(); AnglePos(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Sonic_SlopeResist(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_SlopeResist()"); TabLog(1); RegLog(); #endif d0 = p->angle + 0x60; if((unsigned char)d0 >= 0xC0) goto return_1ADCA; d0 = p->angle; CalcSine(); d0 *= 0x20; if(d0 < 0){ // d0 /= 256; -- DONE THIS WAY FOR ACCURACY d0 >>= 8; d0 |= 0xFF000000; } else d0 >>= 8; if(p->inertia == 0) goto return_1ADCA; if(p->inertia < 0) goto loc_1ADC6; if((short)d0 != 0){ p->inertia += d0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif } #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; loc_1ADC6: #ifdef ENABLE_LOGGING WriteLog("loc_1ADC6"); #endif p->inertia += d0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif return_1ADCA: #ifdef ENABLE_LOGGING WriteLog("return_1ADCA"); RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Sonic_RollRepel(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_RollRepel()"); TabLog(1); RegLog(); #endif d0 = p->angle + 0x60; if((unsigned char)d0 >= 0xC0)//if(d0 >= -0x40) goto return_1AE06; d0 = p->angle; CalcSine(); d0 *= 0x50; if(d0 < 0){ // d0 /= 256; -- DONE THIS WAY FOR ACCURACY d0 >>= 8; d0 |= 0xFF000000; } else d0 >>= 8; if(p->inertia < 0) goto loc_1ADFC; if(d0 >= 0) goto loc_1ADF6; if(d0 < 0){ // d0 /= 4; -- DONE THIS WAY FOR ACCURACY d0 >>= 2; d0 |= 0xC0000000; } else d0 >>= 2; loc_1ADF6: #ifdef ENABLE_LOGGING WriteLog("loc_1ADF6"); #endif p->inertia += d0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); RegLog(); TabLog(-1); #endif return 0; loc_1ADFC: #ifdef ENABLE_LOGGING WriteLog("loc_1ADFC"); #endif if(d0 < 0) goto loc_1AE02; if(d0 < 0){ // d0 /= 4; -- DONE THIS WAY FOR ACCURACY d0 >>= 2; d0 |= 0xC0000000; } else d0 >>= 2; loc_1AE02: #ifdef ENABLE_LOGGING WriteLog("loc_1AE02"); #endif p->inertia += d0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif return_1AE06: #ifdef ENABLE_LOGGING WriteLog("return_1AE06"); RegLog(); TabLog(-1); #endif return 0; } int Sonic_SlopeRepel(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_SlopeRepel()"); TabLog(1); RegLog(); #endif // nop if(p->stick_to_convex != 0) goto return_1AE42; if(p->move_lock != 0) goto loc_1AE44; d0 = (p->angle + 0x20) & 0xC0; if(d0 == 0) goto return_1AE42; d0 = p->inertia; if(d0 >= 0) goto loc_1AE2C; d0 = -d0; loc_1AE2C: #ifdef ENABLE_LOGGING WriteLog("loc_1AE2C"); #endif if((unsigned short)d0 >= 0x280) goto return_1AE42; p->inertia = 0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif p->status |= 2; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->move_lock = 0x1E; return_1AE42: #ifdef ENABLE_LOGGING WriteLog("return_1AE42"); RegLog(); TabLog(-1); #endif return 0; loc_1AE44: #ifdef ENABLE_LOGGING WriteLog("loc_1AE44"); #endif p->move_lock--; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int Sonic_JumpAngle(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_JumpAngle()"); TabLog(1); RegLog(); #endif d0 = p->angle; if(d0 == 0) goto Sonic_JumpFlip; if((char)d0 >= 0) goto loc_1AE5A; d0 += 2; if((char)d0 < 0) goto Sonic_JumpAngleSet; d0 = 0; goto Sonic_JumpAngleSet; loc_1AE5A: #ifdef ENABLE_LOGGING WriteLog("loc_1AE5A"); #endif d0 -= 2; if((char)d0 > 0) goto Sonic_JumpAngleSet; d0 = 0; Sonic_JumpAngleSet: #ifdef ENABLE_LOGGING WriteLog("Sonic_JumpAngleSet"); #endif p->angle = d0; #ifdef ENABLE_LOGGING VarLog(VAR_ANGLE); #endif Sonic_JumpFlip: #ifdef ENABLE_LOGGING WriteLog("Sonic_JumpFlip"); #endif d0 = p->flip_angle; if(d0 == 0) goto return_1AEA8; if(p->inertia < 0) goto Sonic_JumpLeftFlip; Sonic_JumpRightFlip: #ifdef ENABLE_LOGGING WriteLog("Sonic_JumpRightFlip"); #endif d1 = p->flip_speed; d0 += d1; if((char)d0 > 0) goto Sonic_JumpFlipSet; p->flips_remaining--; if(p->flips_remaining < 0) goto Sonic_JumpFlipSet; p->flips_remaining = 0; d0 = 0; goto Sonic_JumpFlipSet; Sonic_JumpLeftFlip: #ifdef ENABLE_LOGGING WriteLog("Sonic_JumpLeftFlip"); #endif if(p->flip_turned != 0) goto Sonic_JumpRightFlip; d1 = p->flip_speed; d0 -= d1; if((char)d0 < 0) goto Sonic_JumpFlipSet; p->flips_remaining--; if(p->flips_remaining < 0) goto Sonic_JumpFlipSet; p->flips_remaining = 0; d0 = 0; Sonic_JumpFlipSet: #ifdef ENABLE_LOGGING WriteLog("Sonic_JumpFlipSet"); #endif p->flip_angle = d0; return_1AEA8: #ifdef ENABLE_LOGGING WriteLog("return_1AEA8"); RegLog(); TabLog(-1); #endif return 0; } int Sonic_DoLevelCollision(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_DoLevelCollision()"); TabLog(1); RegLog(); #endif p->Collision_addr = 0; if(p->layer != 0x10) p->Collision_addr = 0x400; d5 = p->layer_plus; d1 = p->x_vel; d2 = p->y_vel; CalcAngle(); d0 -= 0x20; d0 &= 0xC0; if((char)d0 == 0x40) goto Sonic_HitLeftWall; if((unsigned char)d0 == 0x80) goto Sonic_HitCeilingAndWalls; if((char)d0 == -0x40) goto Sonic_HitRightWall; CheckLeftWallDist(); if(d1 < 0){ p->x_pos -= d1; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS); #endif p->x_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif } CheckRightWallDist(); if(d1 < 0){ p->x_pos += d1; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS); #endif p->x_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif } Sonic_CheckFloor(); if(d1 >= 0) goto return_1AF8A; d2 = (p->y_vel >> 8) + 8; d2 = -d2; if(d1 < d2){ if(d0 < d2) goto return_1AF8A; } p->y_pos += d1; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif p->angle = d3; #ifdef ENABLE_LOGGING VarLog(VAR_ANGLE); #endif Sonic_ResetOnFloor(0); d0 = (d3 + 0x20) & 0x40; if((char)d0 != 0) goto loc_1AF68; d0 = (d3 + 0x10) & 0x20; if((char)d0 == 0) goto loc_1AF5A; if(p->y_vel < 0){ // p->y_vel /= 2; -- DONE THIS WAY FOR ACCURACY p->y_vel >>= 1; p->y_vel |= 0x80000000; } else p->y_vel >>= 1; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif goto loc_1AF7C; loc_1AF5A: #ifdef ENABLE_LOGGING WriteLog("loc_1AF5A"); #endif p->y_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif p->inertia = p->x_vel; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); RegLog(); TabLog(-1); #endif return 0; loc_1AF68: #ifdef ENABLE_LOGGING WriteLog("loc_1AF68"); #endif p->x_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif if(p->y_vel <= 0xFC0) goto loc_1AF7C; p->y_vel = 0xFC0; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif loc_1AF7C: #ifdef ENABLE_LOGGING WriteLog("loc_1AF7C"); #endif p->inertia = p->y_vel; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif if((char)d3 >= 0) goto return_1AF8A; p->inertia = -p->inertia; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif return_1AF8A: #ifdef ENABLE_LOGGING WriteLog("return_1AF8A"); RegLog(); TabLog(-1); #endif return 0; Sonic_HitLeftWall: #ifdef ENABLE_LOGGING WriteLog("Sonic_HitLeftWall"); #endif CheckLeftWallDist(); if(d1 >= 0) goto Sonic_HitCeiling; p->x_pos -= d1; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS); #endif p->x_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif p->inertia = p->y_vel; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); RegLog(); TabLog(-1); #endif return 0; Sonic_HitCeiling: #ifdef ENABLE_LOGGING WriteLog("Sonic_HitCeiling"); #endif CheckCeilingDist(); if(d1 >= 0) goto Sonic_HitFloor; p->y_pos -= d1; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif if(p->y_vel >= 0) goto return_1AFBE; p->y_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif return_1AFBE: #ifdef ENABLE_LOGGING WriteLog("return_1AFBE"); RegLog(); TabLog(-1); #endif return 0; Sonic_HitFloor: #ifdef ENABLE_LOGGING WriteLog("Sonic_HitFloor"); #endif if(p->y_vel < 0) goto return_1AFE6; Sonic_CheckFloor(); if(d1 >= 0) goto return_1AFE6; p->y_pos += d1; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif p->angle = d3; #ifdef ENABLE_LOGGING VarLog(VAR_ANGLE); #endif Sonic_ResetOnFloor(0); p->y_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif p->inertia = p->x_vel; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif return_1AFE6: #ifdef ENABLE_LOGGING WriteLog("return_1AFE6"); RegLog(); TabLog(-1); #endif return 0; Sonic_HitCeilingAndWalls: #ifdef ENABLE_LOGGING WriteLog("Sonic_HitCeilingAndWalls"); #endif CheckLeftWallDist(); if(d1 < 0){ p->x_pos -= d1; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS); #endif p->x_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif } CheckRightWallDist(); if(d1 < 0){ p->x_pos += d1; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS); #endif p->x_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif } CheckCeilingDist(); if(d1 >= 0) goto return_1B042; p->y_pos -= d1; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif d0 = (d3 + 0x20) & 0x40; if(d0 != 0) goto loc_1B02C; p->y_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); RegLog(); TabLog(-1); #endif return 0; loc_1B02C: #ifdef ENABLE_LOGGING WriteLog("loc_1B02C"); #endif p->angle = d3; #ifdef ENABLE_LOGGING VarLog(VAR_ANGLE); #endif Sonic_ResetOnFloor(0); p->inertia = p->y_vel; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif if(d3 >= 0) goto return_1B042; p->inertia = -p->inertia; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif return_1B042: #ifdef ENABLE_LOGGING WriteLog("return_1B042"); RegLog(); TabLog(-1); #endif return 0; Sonic_HitRightWall: #ifdef ENABLE_LOGGING WriteLog("Sonic_HitRightWall"); #endif CheckRightWallDist(); if(d1 >= 0) goto Sonic_HitCeiling2; p->x_pos += d1; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS); #endif p->x_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif p->inertia = p->y_vel; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); RegLog(); TabLog(-1); #endif return 0; Sonic_HitCeiling2: #ifdef ENABLE_LOGGING WriteLog("Sonic_HitCeiling2"); #endif CheckCeilingDist(); if(d1 >= 0) goto Sonic_HitFloor2; p->y_pos -= d1; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif if(p->y_vel >= 0) goto return_1B076; p->y_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif return_1B076: #ifdef ENABLE_LOGGING WriteLog("return_1B076"); RegLog(); TabLog(-1); #endif return 0; Sonic_HitFloor2: #ifdef ENABLE_LOGGING WriteLog("Sonic_HitFloor2"); #endif if(p->y_vel < 0) goto return_1B09E; Sonic_CheckFloor(); if((short)d1 >= 0) goto return_1B09E; p->y_pos += d1; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif p->angle = d3; #ifdef ENABLE_LOGGING VarLog(VAR_ANGLE); #endif Sonic_ResetOnFloor(0); p->y_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif p->inertia = p->x_vel; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif return_1B09E: #ifdef ENABLE_LOGGING WriteLog("return_1B09E"); RegLog(); TabLog(-1); #endif return 0; } int Sonic_ResetOnFloor(char label){ #ifdef ENABLE_LOGGING WriteLog("Sonic_ResetOnFloor()"); TabLog(1); RegLog(); #endif switch(label){ case 1: goto Sonic_ResetOnFloor_Part2; case 2: goto Sonic_ResetOnFloor_Part3; } if(p->spindash_flag != 0) goto Sonic_ResetOnFloor_Part3; p->anim = 0; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif Sonic_ResetOnFloor_Part2: #ifdef ENABLE_LOGGING WriteLog("Sonic_ResetOnFloor_Part2"); #endif // _cmpi.b #1, 0(a0) // bne.w Tails_ResetOnFloor_Part2 if((p->status & 4) == 0) goto Sonic_ResetOnFloor_Part3; p->status &= 0xFB; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->y_radius = 0x13; p->x_radius = 0x9; p->anim = 0; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->y_pos -= 5; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif Sonic_ResetOnFloor_Part3: #ifdef ENABLE_LOGGING WriteLog("Sonic_ResetOnFloor_Part3"); #endif p->status &= 0xCD; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->jumping = 0; Chain_Bonus_counter = 0; p->flip_angle = 0; p->flip_turned = 0; p->flips_remaining = 0; p->Sonic_Look_delay_counter = 0; if(p->anim != 0x14) goto return_1B11E; p->anim = 0; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif return_1B11E: #ifdef ENABLE_LOGGING WriteLog("return_1B11E"); RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Obj01_Hurt(){/////////////////////////////////////////// #ifdef ENABLE_LOGGING WriteLog("Obj01_Hurt()"); TabLog(1); RegLog(); #endif if(Debug_mode_flag == 0) goto Obj01_Hurt_Normal; if((p->Ctrl_Press & 0x10) == 0) goto Obj01_Hurt_Normal; Debug_placement_mode = 1; Control_Locked = 0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; Obj01_Hurt_Normal: #ifdef ENABLE_LOGGING WriteLog("Obj01_Hurt_Normal"); #endif if(p->routine_secondary < 0){ Sonic_HurtInstantRecover(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } ObjectMove(); p->y_vel += 0x30; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif if(p->status & 0x40){ p->y_vel -= 0x20; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif } if(p->Camera_Min_Y_pos == -0x100){ p->y_pos &= 0x7FF; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif } Sonic_HurtStop(); Sonic_LevelBound(); Sonic_RecordPos(); Sonic_Animate(); LoadSonicDynPLC(); DisplaySprite(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Sonic_HurtStop(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_HurtStop()"); TabLog(1); RegLog(); #endif d0 = p->Camera_Max_Y_pos_now + 0xE0; if(d0 < p->y_pos){ KillCharacter(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } Sonic_DoLevelCollision(); if(p->status & 2) goto return_1B1C8; d0 = 0; p->y_vel = d0; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif p->x_vel = d0; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif p->inertia = d0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif p->obj_control = d0; p->anim = 0; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->routine -= 2; p->invulnerable_time = 0x78; p->spindash_flag = 0; return_1B1C8: #ifdef ENABLE_LOGGING WriteLog("return_1B1C8"); RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Sonic_HurtInstantRecover(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_HurtInstantRecover()"); TabLog(1); RegLog(); #endif p->routine -= 2; p->routine_secondary = 0; Sonic_RecordPos(); Sonic_Animate(); LoadSonicDynPLC(); DisplaySprite(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Obj01_Dead(){ #ifdef ENABLE_LOGGING WriteLog("Obj01_Dead()"); TabLog(1); RegLog(); #endif if(Debug_mode_flag != 0){ if(p->Ctrl_Press & 0x10){ Debug_placement_mode = 1; Control_Locked = 0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } } CheckGameOver(); ObjectMoveAndFall(); Sonic_RecordPos(); Sonic_Animate(); LoadSonicDynPLC(); DisplaySprite(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int CheckGameOver(){ #ifdef ENABLE_LOGGING WriteLog("CheckGameOver()"); TabLog(1); RegLog(); #endif p->ram_EEBE = 1; p->spindash_flag = 0; d0 = p->Camera_Max_Y_pos_now + 0x100; if(d0 >= p->y_pos) goto return_1B31A; p->routine = 8; p->spindash_counter = 0x3C; Update_HUD_lives += 1; p->Life_count -= 1; if(p->Life_count != 0) goto Obj01_ResetLevel; p->spindash_counter = 0; // move.b #$39, (Object_RAM+$80).w // move.b #$39, (Object_RAM+$C0).w // move.b #1, (Object_RAM+$C0+mapping_frame).w // move.w a0, (Object_RAM+$80+parent).w Time_Over_flag = 0; Obj01_Finished: #ifdef ENABLE_LOGGING WriteLog("Obj01_Finished"); #endif Update_HUD_timer = 0; Update_HUD_timer_2P = 0; p->routine = 8; // move.w #$9B, d0 // jsr (PlayMusic).l // moveq #3, d0 #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; // jmp (LoadPLC).l Obj01_ResetLevel: #ifdef ENABLE_LOGGING WriteLog("Obj01_ResetLevel"); #endif if(Time_Over_flag == 0) goto Obj01_ResetLevel_Part2; p->spindash_counter = 0; // move.b #$39, (Object_RAM+$80).w // move.b #$39, (Object_RAM+$C0).w // move.b #2, (Object_RAM+$80+mapping_frame).w // move.b #3, (Object_RAM+$C0+mapping_frame).w // move.w a0, (Object_RAM+$80+parent).w goto Obj01_Finished; Obj01_ResetLevel_Part2: #ifdef ENABLE_LOGGING WriteLog("Obj01_ResetLevel_Part2"); #endif if(Two_player_mode == 0) goto return_1B31A; p->ram_EEBE = 0; p->routine = 0xA; p->x_pos = p->Saved_x_pos; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS); #endif p->y_pos = p->Saved_y_pos; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif p->art_tile = p->Saved_art_tile; p->layer = p->Saved_layer; #ifdef ENABLE_LOGGING VarLog(VAR_LAYER); #endif p->Ring_count = 0; p->Extra_life_flags = 0; p->obj_control = 0; p->anim = 5; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->x_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif p->y_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif p->inertia = 0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif p->status = 2; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->move_lock = 0; p->spindash_counter = 0; return_1B31A: #ifdef ENABLE_LOGGING WriteLog("return_1B31A"); RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Obj01_Gone(){ #ifdef ENABLE_LOGGING WriteLog("Obj01_Gone()"); TabLog(1); RegLog(); #endif if(p->spindash_counter != 0){ p->spindash_counter -= 1; if(p->spindash_counter == 0) Level_Inactive_flag = 1; } #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int Obj01_Respawning(){ #ifdef ENABLE_LOGGING WriteLog("Obj01_Respawning()"); TabLog(1); RegLog(); #endif if(p->ram_EEB0 == 0){ if(p->ram_EEB2 == 0) p->routine = 2; } Sonic_Animate(); LoadSonicDynPLC(); //DisplaySprite(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int Sonic_Animate(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_Animate()"); TabLog(1); RegLog(); #endif Read_Animation: if(p->next_anim != p->anim){ p->next_anim = p->anim; p->anim_frame = 0; p->anim_frame_duration = 0; p->status &= 0xDF; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif } d0 = GetAnimationSpeed(0, &p->anim); //DrawCounter16(LayerSH[frame-1], p->anim_frame_duration, 80, 80); //DrawCounter16(LayerSH[frame-1], d0, 80, 88); switch(d0){ case 0xFF: goto SAnim_WalkRun; case 0xFE: goto SAnim_Roll; //case 0xFD: // goto SAnim_Push; } p->render_flags = (p->render_flags & 0xFC) | (p->status & 1); ReadAnimation(0x00, &p->anim, &p->anim_frame, &p->anim_frame_duration, &d0); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0;////////////////////////////////////////////// SAnim_WalkRun: d0 = p->inertia; if(d0 < 0) d0 = -d0; p->anim = 1; // running if(d0 < 0x600) p->anim = 0; // walking d0 = 7 - (d0 >> 8); ReadAnimation(0x00, &p->anim, &p->anim_frame, &p->anim_frame_duration, &d0); /*if(p->flip_angle) goto SAnim_Tumble; d1 = 0; d0 = p->angle; if(d0 > 0) d0--; d2 = p->status & 1; if(d2) d0 = ~d0; d0 += 0x10; if(d0 < 0) d1 = 3; p->render_flags &= 0xFC; d2 ^= d1; p->render_flags |= d2; if(p->status & 0xDF) goto SAnim_Push; d0 >>= 4; d0 &= 6; d2 = p->inertia; if(d2 < 0) d2 = -d2; if(p->status_secondary < 0) d2 += d2; p->anim = 1; // running if(d2 < 0x600){ p->anim = 0; // walking d0 += d0; } d0 += d0; d3 = d0; d1 = p->anim_frame;/////////////////////////////////////// //a7 = GetAnimationSpeed(0, &p->anim); a7 = d4; ReadAnimation(0x00, &p->anim, &p->anim_frame, &p->anim_frame_duration, &a7); if(p->anim_frame_duration == a7){ d2 = -d2; d2 += 0x800; if(d2 >= 0) d2 = 0; d2 >>= 8; p->anim_frame_duration = d2; p->anim_frame++; }*/ #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; // LINE NUMBER 34901 /*d0++; if(d0 != 0) goto SAnim_Roll; d0 = p->flip_angle; if(d0 != 0) goto SAnim_Tumble; d0 = p->angle; if(d0 > 0) d0--; d2 = p->status & 1; if(d2 == 0) d0 = ~d0; d0 += 0x10; if(d0 < 0) d1 = 3; p->render_flags &= 0xFC; d2 ^= d1; p->render_flags |= d2; if(p->status & 0x20) goto SAnim_Push; d0 >>= 4; d0 &= 6; d2 = p->inertia; if(d2 < 0) d2 = -d2; if(p->status_secondary < 0) d2 += d2; if(Super_Sonic_flag) goto SAnim_Super; a1 = 1; if(d2 >= 0x600){ a1 = 0; d0 += d0; } d0 += d0; d3 = d0; d1 = p->anim_frame; d0 = DrawAnimation(z, LayerL[frame-1], 0, &p->anim, NORMAL, 0, &p->anim_frame, &p->anim_frame_duration, 160, 112); if(d0 == -1){ p->anim_frame = 0; d0 = DrawAnimation(z, LayerL[frame-1], 0, &p->anim, NORMAL, 0, &p->anim_frame, &p->anim_frame_duration, 160, 112); } //p->mapping_frame = d0 + d3; p->anim_frame_duration--; if(p->anim_frame_duration >= 0) return 0; d2 = -d2; d2 += 0x800; if(d2 < 0) d2 = 0; d2 >>= 8; p->anim_frame_duration = d2; p->anim_frame++; return 0; SAnim_Super: return 0; SAnim_SuperRun: return 0; SAnim_SuperWalk: return 0; SAnim_Tumble: return 0; SAnim_Tumble_Left: return 0; */ SAnim_Roll: d0 = p->inertia; if(d0 < 0) d0 = -d0; d0 = 7 - (d0 >> 8); ReadAnimation(0x00, &p->anim, &p->anim_frame, &p->anim_frame_duration, &d0); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; SAnim_Push: #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int AnglePos(){ #ifdef ENABLE_LOGGING WriteLog("AnglePos()"); TabLog(1); RegLog(); #endif p->Collision_addr = 0; if(p->layer != 0x10) p->Collision_addr = 0x400; d5 = p->layer; if(p->status & 8){ d0 = 0; p->ram_F768 = d0; p->ram_F76A = d0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } d0 = 3; p->ram_F768 = d0; p->ram_F76A = d0; d0 = p->angle + 0x20; if((char)d0 >= 0) goto loc_1E286; d0 = p->angle; if((char)d0 < 0) d0--; d0 += 0x20; goto loc_1E292; loc_1E286: #ifdef ENABLE_LOGGING WriteLog("loc_1E286"); #endif d0 = p->angle; if((char)d0 < 0) d0++; loc_1E28E: #ifdef ENABLE_LOGGING WriteLog("loc_1E28E"); #endif d0 += 0x1F; loc_1E292: #ifdef ENABLE_LOGGING WriteLog("loc_1E292"); #endif d0 &= 0xC0; if(d0 == 0x40) goto loc_1E4E8; if(d0 == 0x80) goto loc_1E43A; if(d0 == 0xC0) goto Sonic_WalkVertR; d2 = p->y_pos; d3 = p->x_pos; d0 = p->y_radius; d2 += d0; d0 = p->x_radius; d3 += d0; a4 = p->ram_F768; a3 = 0x10; d6 = 0; FindFloor(); p->ram_F768 = a4; n = d1; d2 = p->y_pos; d3 = p->x_pos; d0 = p->y_radius; d2 += d0; d0 = p->x_radius; d0 = -d0; d3 += d0; a4 = p->ram_F76A; a3 = 0x10; d6 = 0; FindFloor(); p->ram_F76A = a4; d0 = n; Sonic_Angle(); if((short)d1 == 0) goto return_1E31C; if((short)d1 >= 0) goto loc_1E31E; // FIX ME: Should do this on init frame, but doesn't. if((short)d1 < -0xE) goto return_1E31C; p->y_pos += (short)d1; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif return_1E31C: #ifdef ENABLE_LOGGING WriteLog("return_1E31C"); RegLog(); TabLog(-1); #endif return 0; loc_1E31E: #ifdef ENABLE_LOGGING WriteLog("loc_1E31E"); #endif d0 = (p->x_vel >> 8); if((char)d0 < 0) d0 = -d0; d0 += 4; if((unsigned char)d0 >= 0xE) d0 = 0xE; if((char)d1 > (char)d0) goto loc_1E33C; loc_1E336: #ifdef ENABLE_LOGGING WriteLog("loc_1E336"); #endif p->y_pos += (short)d1; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); RegLog(); TabLog(-1); #endif return 0; loc_1E33C: #ifdef ENABLE_LOGGING WriteLog("loc_1E33C"); #endif if(p->stick_to_convex != 0) goto loc_1E336; p->status |= 2; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->status &= 0xDF; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->next_anim = 1; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; Sonic_WalkVertR: #ifdef ENABLE_LOGGING WriteLog("Sonic_WalkVertR"); #endif d2 = p->y_pos; d3 = p->x_pos; d0 = p->x_radius; d0 = -d0; d2 += d0; d0 = p->y_radius; d3 += d0; a4 = p->ram_F768; a3 = 0x10; d6 = 0; FindWall(); p->ram_F768 = a4; n = d1; d2 = p->y_pos; d3 = p->x_pos; d0 = p->x_radius; d2 += d0; d0 = p->y_radius; d3 += d0; a4 = p->ram_F76A; a3 = 0x10; d6 = 0; FindWall(); p->ram_F76A = a4; d0 = n; Sonic_Angle(); if(d1 == 0) goto return_1E400; if(d1 >= 0) goto loc_1E402; if(d1 < -0xE) goto return_1E400; p->x_pos += d1; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS); #endif return_1E400: #ifdef ENABLE_LOGGING WriteLog("return_1E400"); RegLog(); TabLog(-1); #endif return 0; loc_1E402: #ifdef ENABLE_LOGGING WriteLog("loc_1E402"); #endif d0 = (p->y_vel >> 8); if((char)d0 < 0) d0 = -d0; d0 += 4; if((unsigned char)d0 >= 0xE) d0 = 0xE; if((char)d1 > (char)d0) goto loc_1E420; loc_1E41A: #ifdef ENABLE_LOGGING WriteLog("loc_1E41A"); #endif p->x_pos += d1; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS); RegLog(); TabLog(-1); #endif return 0; loc_1E420: #ifdef ENABLE_LOGGING WriteLog("loc_1E420"); #endif if(p->stick_to_convex != 0) goto loc_1E41A; p->status |= 2; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->status &= 0xDF; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->next_anim = 1; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; loc_1E43A: #ifdef ENABLE_LOGGING WriteLog("loc_1E43A"); #endif d2 = p->y_pos; d3 = p->x_pos; d0 = p->y_radius; d2 -= d0; d2 ^= 0xF; d0 = p->x_radius; d3 += d0; a4 = p->ram_F768; a3 = -0x10; d6 = 0x8000; FindFloor(); p->ram_F768 = a4; n = d1; d2 = p->y_pos; d3 = p->x_pos; d0 = p->y_radius; d2 -= d0; d2 ^= 0xF; d0 = p->x_radius; d3 -= d0; a4 = p->ram_F76A; a3 = -0x10; d6 = 0x8000; FindFloor(); p->ram_F76A = a4; d0 = n; Sonic_Angle(); if(d1 == 0) goto return_1E4AE; if(d1 >= 0) goto loc_1E4B0; if(d1 < -0xE) goto return_1E4AE; p->y_pos -= d1; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif return_1E4AE: #ifdef ENABLE_LOGGING WriteLog("loc_1E4AE"); RegLog(); TabLog(-1); #endif return 0; loc_1E4B0: #ifdef ENABLE_LOGGING WriteLog("loc_1E4B0"); #endif d0 = (p->x_vel >> 8); if((char)d0 < 0) d0 = -d0; d0 += 4; if((unsigned char)d0 >= 0xE) d0 = 0xE; if((char)d1 > (char)d0) goto loc_1E4CE; loc_1E4C8: #ifdef ENABLE_LOGGING WriteLog("loc_1E4C8"); #endif p->y_pos -= d1; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); RegLog(); TabLog(-1); #endif return 0; loc_1E4CE: #ifdef ENABLE_LOGGING WriteLog("loc_1E4CE"); #endif if(p->stick_to_convex != 0) goto loc_1E4C8; p->status |= 2; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->status &= 0xDF; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->next_anim = 1; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; loc_1E4E8: #ifdef ENABLE_LOGGING WriteLog("loc_1E4E8"); #endif d2 = p->y_pos; d3 = p->x_pos; d0 = p->x_radius; d2 -= d0; d0 = p->y_radius; d3 -= d0; d3 ^= 0xF; //WriteLog("*******************************"); //VarLog(VAR_X_POS); //VarLog(VAR_Y_POS); //VarLog(VAR_X_RADIUS); //VarLog(VAR_Y_RADIUS); //VarLog(REG_D3); //VarLog(REG_D2); //WriteLog("*******************************"); a4 = p->ram_F768; a3 = -0x10; d6 = 0x4000; FindWall(); p->ram_F768 = a4; n = d1; d2 = p->y_pos; d3 = p->x_pos; d0 = p->x_radius; d2 += d0; d0 = p->y_radius; d3 -= d0; d3 ^= 0xF; //WriteLog("*******************************"); //VarLog(VAR_X_POS); //VarLog(VAR_Y_POS); //VarLog(VAR_X_RADIUS); //VarLog(VAR_Y_RADIUS); //VarLog(REG_D3); //VarLog(REG_D2); //WriteLog("*******************************"); a4 = p->ram_F76A; a3 = -0x10; d6 = 0x4000; FindWall(); p->ram_F76A = a4; d0 = n; Sonic_Angle(); if(d1 == 0) goto return_1E55C; if(d1 >= 0) goto loc_1E55E; if(d1 < -0xE) goto return_1E55C; p->x_pos -= d1; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS); #endif return_1E55C: #ifdef ENABLE_LOGGING WriteLog("loc_1E55C"); RegLog(); TabLog(-1); #endif return 0; loc_1E55E: #ifdef ENABLE_LOGGING WriteLog("loc_1E55E"); #endif d0 = (p->y_vel >> 8); if((char)d0 < 0) d0 = -d0; d0 += 4; if((unsigned char)d0 >= 0xE) d0 = 0xE; if((char)d1 > (char)d0) goto loc_1E57C; loc_1E576: #ifdef ENABLE_LOGGING WriteLog("loc_1E576"); #endif p->x_pos -= (short)d1; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS); RegLog(); TabLog(-1); #endif return 0; loc_1E57C: #ifdef ENABLE_LOGGING WriteLog("loc_1E57C"); #endif if(p->stick_to_convex != 0) goto loc_1E576; p->status |= 2; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->status &= 0xDF; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->next_anim = 1; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int Sonic_Angle(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_Angle()"); TabLog(1); RegLog(); #endif d2 = p->ram_F76A; if(d1 > d0){ d2 = p->ram_F768; d1 = d0; } if((d2 & 1) != 0) goto loc_1E380; d0 = d2 - p->angle; if((char)d0 < 0) d0 = -d0; if((char)d0 >= 0x20) goto loc_1E380; p->angle = d2; #ifdef ENABLE_LOGGING VarLog(VAR_ANGLE); RegLog(); TabLog(-1); #endif return 0; loc_1E380: #ifdef ENABLE_LOGGING WriteLog("loc_1E380"); #endif d2 = p->angle; d2 += 0x20; d2 &= 0xC0; p->angle = d2; #ifdef ENABLE_LOGGING VarLog(VAR_ANGLE); RegLog(); TabLog(-1); #endif return 0; } int Floor_ChkTile(){ short x, y; #ifdef ENABLE_LOGGING WriteLog("Floor_ChkTile()"); TabLog(1); RegLog(); #endif x = (((short)d3)>>4); y = (((short)d2)>>4); // this function is customized for ProSonic // d3 is a modified 'p->x_pos' // d2 is a modified 'p->y_pos' if(x < 0) x = ((z.TMAP[tmap_ptr-2]+1) * (2<<tilesize)) - x; if(y < 0) y = ((z.TMAP[tmap_ptr-1]+1) * (2<<tilesize)) - y; a1 = COMPILED_MAP[ (x % ((z.TMAP[tmap_ptr-2]+1) * (2<<tilesize))) + ((y % ((z.TMAP[tmap_ptr-1]+1) * (2<<tilesize))) * ((z.TMAP[tmap_ptr-2]+1) * (2<<tilesize)))]; //a1 = ReadBlock(&z, (short)d3, (short)d2); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int FindFloor(){ #ifdef ENABLE_LOGGING WriteLog("FindFloor()"); TabLog(1); RegLog(); #endif Floor_ChkTile(); d0 = a1; d4 = d0; d0 &= 0x3FFF; if(d0 == 0) goto loc_1E7E2; if((d4 & (1 << d5)) != 0) goto loc_1E7F0; loc_1E7E2: #ifdef ENABLE_LOGGING WriteLog("loc_1E7E2"); #endif d2 += a3; FindFloor2(); d2 -= a3; d1 += 0x10; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; loc_1E7F0: #ifdef ENABLE_LOGGING WriteLog("loc_1E7F0"); #endif a2 = p->Collision_addr; i = z.Act[act].Stage[stage].BlockSolidity; i = z.BSOL_AddressTable[i]; a4 = z.BATT[a2 + d0 + i]; // slope d0 <<= 5; // we do this because solidity is 32 bytes per block d1 = d3 & 0xFFFF; #ifdef ENABLE_LOGGING WriteLog(">>>---->"); RegLog(); WriteLog("<----<<<"); #endif if(d4 & 0x4000){ d1 = ~d1; a4 = -a4; } if(d4 & 0x8000){ a4 += 0x40; a4 = -a4; a4 -= 0x40; } d1 &= 0xF; d1 += d0; d0 = z.BSOL[(a2 << 5) + d1 + i]; // ext.w d0 d4 ^= d6; if(d4 & 0x8000) d0 = -d0; if(d0 == 0) goto loc_1E7E2; if((char)d0 < 0) goto loc_1E85E; if(d0 == 0x10) goto loc_1E86A; d1 = d2 & 0xF; d0 += d1; d1 = 0xF - (char)d0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; loc_1E85E: #ifdef ENABLE_LOGGING WriteLog("loc_1E85E"); #endif d1 = d2 & 0xF; d0 += d1; if(d0 >= 0) goto loc_1E7E2; loc_1E86A: #ifdef ENABLE_LOGGING WriteLog("loc_1E86A"); #endif d2 -= a3; FindFloor2(); d2 += a3; d1 -= 0x10; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int FindFloor2(){ #ifdef ENABLE_LOGGING WriteLog("FindFloor2()"); TabLog(1); RegLog(); #endif Floor_ChkTile(); d0 = a1; d4 = d0; d0 &= 0x3FFF; if(d0 == 0) goto loc_1E88A; if((d4 & (1 << d5)) != 0) goto loc_1E898; loc_1E88A: #ifdef ENABLE_LOGGING WriteLog("loc_1E88A"); #endif d1 = 0xF; d0 = d2 & 0xF; d1 -= d0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; loc_1E898: #ifdef ENABLE_LOGGING WriteLog("loc_1E898"); #endif a2 = p->Collision_addr; i = z.Act[act].Stage[stage].BlockSolidity; i = z.BSOL_AddressTable[i]; a4 = z.BATT[a2 + d0 + i]; // slope d0 <<= 5; d1 = d3 & 0xFFFF; #ifdef ENABLE_LOGGING WriteLog(">>>---->"); RegLog(); WriteLog("<----<<<"); #endif if(d4 & 0x4000){ d1 = ~d1; a4 = -a4; } if(d4 & 0x8000){ a4 += 0x40; a4 = -a4; a4 -= 0x40; } d1 &= 0xF; d1 += d0; d0 = z.BSOL[(a2 << 5) + d1 + i]; // ext.w d0 d4 ^= d6; if(d4 & 0x8000) d0 = -d0; if(d0 == 0) goto loc_1E88A; if((char)d0 < 0) goto loc_1E900; d1 = d2 & 0xF; d0 += d1; d1 = 0xF - (char)d0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; loc_1E900: #ifdef ENABLE_LOGGING WriteLog("loc_1E900"); #endif d1 = d2 & 0xF; d0 += d1; if(d0 >= 0) goto loc_1E88A; d1 = (~d1) & 0xFFFF; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int Obj_CheckInFloor(){ #ifdef ENABLE_LOGGING WriteLog("Obj_CheckInFloor()"); TabLog(1); RegLog(); #endif Floor_ChkTile(); d0 = a1; d4 = d0; d0 &= 0x3FFF; if(d0 == 0) goto loc_1E922; if((d4 & (1 << d5)) != 0) goto loc_1E928; loc_1E922: #ifdef ENABLE_LOGGING WriteLog("loc_1E922"); #endif d1 = 0x10; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; loc_1E928: #ifdef ENABLE_LOGGING WriteLog("loc_1E928"); #endif a2 = p->Collision_addr; i = z.Act[act].Stage[stage].BlockSolidity; i = z.BSOL_AddressTable[i]; a4 = z.BATT[a2 + d0 + i]; // slope d0 <<= 5; d1 = d3 & 0xFFFF; if(d4 & 0x4000){ d1 = ~d1; a4 = -a4; } if(d4 & 0x8000){ a4 += 0x40; a4 = -a4; a4 -= 0x40; } d1 &= 0xF; d1 += d0; d0 = z.BSOL[(a2 << 5) + d1 + i]; // ext.w d0 d4 ^= d6; if(d4 & 0x8000) d0 = -d0; if(d0 == 0) goto loc_1E922; if((char)d0 < 0) goto loc_1E996; if(d0 == 0x10) goto loc_1E9A2; d1 = d2 & 0xF; d0 += d1; d1 = 0xF - (char)d0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; loc_1E996: #ifdef ENABLE_LOGGING WriteLog("loc_1E996"); #endif d1 = d2 & 0xF; d0 += d1; if(d0 >= 0) goto loc_1E922; //RegLog(); TabLog(-1); return 0; // ???? ???? ???? ???? loc_1E9A2: #ifdef ENABLE_LOGGING WriteLog("loc_1E9A2"); #endif d2 -= a3; FindFloor2(); d2 += a3; d1 -= 0x10; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int FindWall(){ #ifdef ENABLE_LOGGING WriteLog("FindWall()"); TabLog(1); RegLog(); #endif Floor_ChkTile(); d0 = a1; d4 = d0; d0 &= 0x3FFF; if(d0 == 0) goto loc_1E9C2; if((d4 & (1 << d5)) != 0) goto loc_1E9D0; loc_1E9C2: #ifdef ENABLE_LOGGING WriteLog("loc_1E9C2"); #endif d3 += a3; FindWall2(); d3 -= a3; d1 += 0x10; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; loc_1E9D0: #ifdef ENABLE_LOGGING WriteLog("loc_1E9D0"); #endif a2 = p->Collision_addr; i = z.Act[act].Stage[stage].BlockSolidity; i = z.BSOL_AddressTable[i]; a4 = z.BATT[a2 + d0 + i]; // slope d0 <<= 5; d1 = d2 & 0xFFFF; #ifdef ENABLE_LOGGING WriteLog("// slope"); VarLog(REG_A4); WriteLog("// slope index"); VarLog(REG_D0); WriteLog("// something else"); VarLog(REG_D1); WriteLog("// something else"); VarLog(REG_D2); #endif if(d4 & 0x8000){ d1 = ~d1; a4 += 0x40; a4 = -a4; a4 -= 0x40; } if(d4 & 0x4000) a4 = -a4; d1 &= 0xF; d1 += d0; d0 = z.BSOL[(a2 << 5) + d1 + i + 0x10]; #ifdef ENABLE_LOGGING WriteLog("// solidity"); VarLog(REG_D0); #endif // ext.w d0 d4 ^= d6; if(d4 & 0x4000) d0 = -d0; if(d0 == 0) goto loc_1E9C2; if((char)d0 < 0) goto loc_1EA3E; if(d0 == 0x10) goto loc_1EA4A; d1 = d3 & 0xF; d0 += d1; d1 = 0xF - (char)d0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; loc_1EA3E: #ifdef ENABLE_LOGGING WriteLog("loc_1EA3E"); #endif d1 = d3 & 0xF; d0 += d1; if((short)d0 >= 0) goto loc_1E9C2; loc_1EA4A: #ifdef ENABLE_LOGGING WriteLog("loc_1EA4A"); #endif d3 -= a3; FindWall2(); d3 += a3; d1 -= 0x10; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int FindWall2(){ #ifdef ENABLE_LOGGING WriteLog("FindWall2()"); TabLog(1); RegLog(); #endif Floor_ChkTile(); d0 = a1; d4 = d0; d0 &= 0x3FFF; if(d0 == 0) goto loc_1EA6A; if((d4 & (1 << d5)) != 0) goto loc_1EA78; loc_1EA6A: #ifdef ENABLE_LOGGING WriteLog("loc_1EA6A"); #endif d1 = 0xF; d0 = d3 & 0xF; d1 -= d0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; loc_1EA78: #ifdef ENABLE_LOGGING WriteLog("loc_1EA78"); #endif a2 = p->Collision_addr; i = z.Act[act].Stage[stage].BlockSolidity; i = z.BSOL_AddressTable[i]; a4 = z.BATT[a2 + d0 + i]; // slope d0 <<= 5; d1 = d2 & 0xFFFF; if(d4 & 0x8000){ d1 = ~d1; a4 += 0x40; a4 = -a4; a4 -= 0x40; } if(d4 & 0x4000) a4 = -a4; d1 &= 0xF; d1 += d0; d0 = z.BSOL[(a2 << 5) + d1 + i + 0x10]; // ext.w d0 d4 ^= d6; if(d4 & 0x4000) d0 = -d0; if(d0 == 0) goto loc_1EA6A; if((char)d0 < 0) goto loc_1EAE0; d1 = d3 & 0xF; d0 += d1; d1 = 0xF - (char)d0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; loc_1EAE0: #ifdef ENABLE_LOGGING WriteLog("loc_1EAE0"); #endif d1 = d3 & 0xF; d0 += d1; if(d0 >= 0) goto loc_1EA6A; d1 = (~d1) & 0xFFFF; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int CalcRoomInFront(){ #ifdef ENABLE_LOGGING WriteLog("CalcRoomInFront()"); TabLog(1); RegLog(); #endif p->Collision_addr = 0; if(p->layer != 0x10) p->Collision_addr = 0x400; d5 = p->layer_plus; d3 = (p->x_pos << 16) + p->x_pos_pre; d2 = (p->y_pos << 16) + p->y_pos_pre; d1 = p->x_vel; d1 *= 256; d3 += d1; d1 = p->y_vel; d1 *= 256; d2 += d1; d2 = (d2 >> 16) + (d2 << 16); d3 = (d3 >> 16) + (d3 << 16); p->ram_F768 = d0; p->ram_F76A = d0; d1 &= 0xFFFFFF00; d1 |= d0; d0 += 0x20; if((char)d0 >= 0) goto loc_1EBDC; d0 = (char)d1; if((char)d0 < 0) d0--; d0 += 0x20; goto loc_1EBE6; loc_1EBDC: #ifdef ENABLE_LOGGING WriteLog("loc_1EBDC"); #endif d0 &= 0xFFFFFF00; d0 |= d1; if((char)d0 < 0) d0++; d0 += 0x1F; loc_1EBE6: #ifdef ENABLE_LOGGING WriteLog("loc_1EBE6"); RegLog(); #endif d0 &= 0xC0; if(d0 == 0){ // Copied the code here d2 += 0xA; a4 = p->ram_F768; a3 = 0x10; d6 = 0; FindFloor(); p->ram_F768 = a4; d2 = 0; d3 = p->ram_F768; if((d3 & 1) != 0) d3 = d2; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } if((unsigned char)d0 == 0x80){ CheckSlopeDist(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } d1 &= 0xFFFFFF38; if((char)d1 == 0) d2 += 8; if((char)d0 == 0x40){ CheckLeftWallDist_Part2(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } CheckRightWallDist_Part2(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int CalcRoomOverHead(){ #ifdef ENABLE_LOGGING WriteLog("CalcRoomOverHead()"); TabLog(1); RegLog(); #endif p->Collision_addr = 0; if(p->layer != 0x10) p->Collision_addr = 0x400; d5 = p->layer_plus; p->ram_F768 = d0; p->ram_F76A = d0; d0 += 0x20; d0 &= 0xC0; if(d0 == 0x40){ CheckLeftCeilingDist(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } if(d0 == 0x80){ CheckCeilingDist(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } if(d0 == 0xC0){ CheckRightCeilingDist(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } Sonic_CheckFloor(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int Sonic_CheckFloor(){ #ifdef ENABLE_LOGGING WriteLog("Sonic_CheckFloor()"); TabLog(1); RegLog(); #endif p->Collision_addr = 0; if(p->layer != 0x10) p->Collision_addr = 0x400; d5 = p->layer; d2 = p->y_pos; d3 = p->x_pos; d0 = p->y_radius; d2 += d0; d0 = p->x_radius; d3 += d0; a4 = p->ram_F768; a3 = 0x10; d6 = 0; FindFloor(); p->ram_F768 = a4; n = d1; d2 = p->y_pos; d3 = p->x_pos; d0 = p->y_radius; d2 += d0; d0 = p->x_radius; d3 -= d0; a4 = p->ram_F76A; a3 = 0x10; d6 = 0; FindFloor(); p->ram_F76A = a4; d0 = n; d2 = 0; loc_1ECC6: // COPY THIS CODE WHERE BRANCHED #ifdef ENABLE_LOGGING WriteLog("loc_1ECC6"); #endif d3 = p->ram_F76A; if(d1 > d0){ d3 = p->ram_F768; i = d1; d1 = d0; d0 = i; } loc_1ECD4: // ALONG WITH THIS #ifdef ENABLE_LOGGING WriteLog("loc_1ECD4"); #endif if(d3 & 1) d3 = d2; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int ChkFloorEdge(){ #ifdef ENABLE_LOGGING WriteLog("ChkFloorEdge()"); TabLog(1); RegLog(); #endif d3 = p->x_pos; ChkFloorEdge_Part2(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int ChkFloorEdge_Part2(){ #ifdef ENABLE_LOGGING WriteLog("ChkFloorEdge_Part2()"); TabLog(1); RegLog(); #endif d2 = p->y_pos; d0 = p->y_radius; d2 += d0; p->Collision_addr = 0; if(p->layer != 0x10) p->Collision_addr = 0x400; p->ram_F768 = 0; a4 = p->ram_F768; a3 = 0x10; d6 = 0; d5 = p->layer; FindFloor(); p->ram_F768 = a4; d3 = p->ram_F768; if(d3 & 1) d0 = 0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int CheckRightCeilingDist(){ #ifdef ENABLE_LOGGING WriteLog("CheckRightCeilingDist()"); TabLog(1); RegLog(); #endif d2 = p->y_pos; d3 = p->x_pos; d0 = p->x_radius; d2 -= d0; d0 = p->y_radius; d3 += d0; a4 = p->ram_F768; a3 = 0x10; d6 = 0; FindWall(); p->ram_F768 = a4; n = d1; d2 = p->y_pos; d3 = p->x_pos; d0 = p->x_radius; d2 += d0; d0 = p->y_radius; d3 += d0; a4 = p->ram_F76A; a3 = 0x10; d6 = 0; FindWall(); p->ram_F76A = a4; d0 = n; d2 = -0x40; d3 = p->ram_F76A; if(d1 > d0){ d3 = p->ram_F768; i = d1; d1 = d0; d0 = i; } if(d3 & 1) d3 = d2; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int CheckRightWallDist(){ #ifdef ENABLE_LOGGING WriteLog("CheckRightWallDist()"); TabLog(1); RegLog(); #endif d2 = p->y_pos; d3 = p->x_pos; CheckRightWallDist_Part2(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int CheckRightWallDist_Part2(){ #ifdef ENABLE_LOGGING WriteLog("CheckRightWallDist_Part2()"); TabLog(1); RegLog(); #endif d3 += 0xA; a4 = p->ram_F768; a3 = 0x10; d6 = 0; FindWall(); p->ram_F768 = a4; d2 = -0x40; d3 = p->ram_F768; if(d3 & 1) d3 = d2; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int CheckCeilingDist(){ #ifdef ENABLE_LOGGING WriteLog("CheckCeilingDist()"); TabLog(1); RegLog(); #endif d2 = p->y_pos; d3 = p->x_pos; d0 = p->y_radius; d2 -= d0; d2 ^= 0xF; d0 = p->x_radius; d3 += d0; a4 = p->ram_F768; a3 = -0x10; d6 = 0x800; FindFloor(); p->ram_F768 = a4; n = d1; d2 = p->y_pos; d3 = p->x_pos; d0 = p->y_radius; d2 -= d0; d2 ^= 0xF; d0 = p->x_radius; d3 -= d0; a4 = p->ram_F76A; a3 = -0x10; d6 = 0x800; FindFloor(); p->ram_F76A = a4; d0 = n; d2 = 0x80; d3 = p->ram_F76A; if(d1 > d0){ d3 = p->ram_F768; i = d1; d1 = d0; d0 = i; } if(d3 & 1) d3 = d2; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int CheckSlopeDist(){ #ifdef ENABLE_LOGGING WriteLog("CheckSlopeDist()"); TabLog(1); RegLog(); #endif d2 -= 0xA; d2 ^= 0xF; a4 = p->ram_F768; a3 = -0x10; d6 = 0x800; FindFloor(); p->ram_F768 = a4; d2 = 0x80; d3 = p->ram_F768; if(d3 & 1) d3 = d2; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int CheckLeftCeilingDist(){ #ifdef ENABLE_LOGGING WriteLog("CheckLeftCeilingDist()"); TabLog(1); RegLog(); #endif d2 = p->y_pos; d3 = p->x_pos; d0 = p->x_radius; d2 -= d0; d0 = p->y_radius; d3 -= d0; d3 ^= 0xF; a4 = p->ram_F768; a3 = -0x10; d6 = 0x400; FindWall(); p->ram_F768 = a4; n = d1; d2 = p->y_pos; d3 = p->x_pos; d0 = p->x_radius; d2 += d0; d0 = p->y_radius; d3 -= d0; d3 ^= 0xF; a4 = p->ram_F76A; a3 = -0x10; d6 = 0x400; FindWall(); p->ram_F76A = a4; d0 = n; d2 = 0x40; d3 = p->ram_F76A; if(d1 > d0){ d3 = p->ram_F768; i = d1; d1 = d0; d0 = i; } if(d3 & 1) d3 = d2; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int CheckLeftWallDist(){ #ifdef ENABLE_LOGGING WriteLog("CheckLeftWallDist()"); TabLog(1); RegLog(); #endif d2 = p->y_pos; d3 = p->x_pos; CheckLeftWallDist_Part2(); #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int CheckLeftWallDist_Part2(){ #ifdef ENABLE_LOGGING WriteLog("CheckLeftWallDist_Part2()"); TabLog(1); RegLog(); #endif d3 -= 0xA; d3 ^= 0xF; a4 = p->ram_F768; a3 = -0x10; d6 = 0x4000; // add extra zero for mirror flag//0x400; FindWall(); p->ram_F768 = a4; d2 = 0x40; d3 = p->ram_F768; if(d3 & 1) d3 = d2; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int LoadSonicDynPLC(){ #ifdef ENABLE_LOGGING WriteLog("*** LoadSonicDynPLC()"); TabLog(1); RegLog(); #endif /*p->anim = 1; p->anim_frame = 1; p->anim_frame_duration = 1; d0 = 1;*/ //DrawSprite(&z, LayerH[frame-1], 0, 1, 0, 0, 160, 112); PositionCamera(p->x_pos, p->y_pos); a7 = (unsigned char)p->angle >> 5; if(a7 >= 4) a7 = (((unsigned char)(p->angle-1) >> 5) + 1) & 7; a6 = 0; if(p->status & 1){ if(a7 == 4) a6 = ROTATE; else if(a7 > 4 && p->anim == 0){ p->anim = 0x40 + a7 - 5; a6 = ROTATE; } else if(a7 > 0 && p->anim == 0) p->anim = 0x40 + a7 - 1; else if(a7 > 4 && p->anim == 1){ p->anim = 0x43 + a7 - 5; a6 = ROTATE; } else if(a7 > 0 && p->anim == 1) p->anim = 0x43 + a7 - 1; } else{ if(a7 == 4) a6 = ROTATE; else if(a7 > 4 && p->anim == 0) p->anim = 0x40 + 7 - a7; else if(a7 > 0 && p->anim == 0){ p->anim = 0x40 + 3 - a7; a6 = ROTATE; } else if(a7 > 4 && p->anim == 1) p->anim = 0x40 + 7 - a7; else if(a7 > 0 && p->anim == 1){ p->anim = 0x43 + 3 - a7; a6 = ROTATE; } } if(p->art_tile & 0x8000) DrawAnimation(&z, LayerSH[frame-1], 0, p->anim, p->anim_frame, (p->status & 1) ^ a6, 0, &p->anim_frame_duration, d0, p->x_pos - p->Camera_X_pos, p->y_pos - p->Camera_Y_pos - p->y_radius-1); else DrawAnimation(&z, LayerH[frame-1], 0, p->anim, p->anim_frame, (p->status & 1) ^ a6, 0, &p->anim_frame_duration, d0, p->x_pos - p->Camera_X_pos, p->y_pos - p->Camera_Y_pos - p->y_radius-1); if(p->anim >= 0x43) p->anim = 1; else if(p->anim >= 0x40) p->anim = 0; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int KillCharacter(){ #ifdef ENABLE_LOGGING WriteLog("*** KillCharacter()"); TabLog(1); RegLog(); #endif if(Debug_placement_mode) goto loc_3F972; p->status_secondary = 0; p->routine = 6; Sonic_ResetOnFloor(1); p->status |= 2; #ifdef ENABLE_LOGGING VarLog(VAR_STATUS); #endif p->y_vel = -0x700; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif p->x_vel = 0; #ifdef ENABLE_LOGGING VarLog(VAR_X_VEL); #endif p->inertia = 0; #ifdef ENABLE_LOGGING VarLog(VAR_INERTIA); #endif p->anim = 0x18; #ifdef ENABLE_LOGGING VarLog(VAR_ANIM); #endif p->art_tile |= 0x80; d0 = 0xA3; // A2 is the address of object interacting with player //cmpi.b #$36,(a2) //bne.s loc_3F96C //move.w #$A6,d0 loc_3F96C: #ifdef ENABLE_LOGGING WriteLog("loc_3F96C"); #endif //jsr (PlaySound).l PlayFM(0x23, 3, 0); // --- this will need correction --- loc_3F972: #ifdef ENABLE_LOGGING WriteLog("loc_3F972"); #endif d0 = -1; #ifdef ENABLE_LOGGING RegLog(); TabLog(-1); #endif return 0; } int DisplaySprite(){ #ifdef ENABLE_LOGGING WriteLog("*** DisplaySprite()"); TabLog(1); RegLog(); RegLog(); TabLog(-1); #endif return 0; // IGNORING FOR NOW //////////////// } int ObjectMoveAndFall(){ #ifdef ENABLE_LOGGING WriteLog("ObjectMoveAndFall()"); TabLog(1); RegLog(); #endif d2 = (p->x_pos << 16) + p->x_pos_pre; d3 = (p->y_pos << 16) + p->y_pos_pre; d0 = p->x_vel; d0 *= 256; d2 += d0; d0 = p->y_vel; p->y_vel += 0x38; #ifdef ENABLE_LOGGING VarLog(VAR_Y_VEL); #endif d0 *= 256; d3 += d0; p->x_pos = d2 >> 16; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS); #endif p->x_pos_pre = d2; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS_PRE); #endif p->y_pos = d3 >> 16; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif p->y_pos_pre = d3; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS_PRE); RegLog(); TabLog(-1); #endif return 0; } int ObjectMove(){ #ifdef ENABLE_LOGGING WriteLog("ObjectMove()"); TabLog(1); RegLog(); #endif d2 = (p->x_pos << 16) + p->x_pos_pre; d3 = (p->y_pos << 16) + p->y_pos_pre; d0 = p->x_vel; d0 <<= 8; d2 += d0; d0 = p->y_vel; d0 <<= 8; d3 += d0; p->x_pos = (d2 >> 16); #ifdef ENABLE_LOGGING VarLog(VAR_X_POS); #endif p->x_pos_pre = d2; #ifdef ENABLE_LOGGING VarLog(VAR_X_POS_PRE); #endif p->y_pos = (d3 >> 16); #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS); #endif p->y_pos_pre = d3; #ifdef ENABLE_LOGGING VarLog(VAR_Y_POS_PRE); RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE int TouchResponse(){ #ifdef ENABLE_LOGGING WriteLog("*** TouchResponse()"); TabLog(1); RegLog(); RegLog(); TabLog(-1); #endif return 0; } FUNCINLINE void PositionCamera(short x, short y){ int cam_offset_x = x - p->Camera_X_pos - (screen_resolution_x >> 1); int cam_offset_y = y - p->Camera_Y_pos - (screen_resolution_y >> 1) - (p->Camera_Y_pos_bias - 0x60); // if the screen is fading, return and keep the camera still if(fade_count != 0) return; // does camera need to scroll right? if(cam_offset_x > 0){ // is player more than 16 pixels right of where camera needs to be? if(cam_offset_x > 0x10) p->Camera_X_pos += 0x10; else p->Camera_X_pos += cam_offset_x; } // does camera need to scroll left? if(cam_offset_x < -0x10){ // is player more than 16 pixels left of where camera needs to be? if(cam_offset_x < -0x20) p->Camera_X_pos -= 0x10; else p->Camera_X_pos += (cam_offset_x + 0x10); } // is player rolling? if(p->status & 4) cam_offset_y -= 5; // is player in the air? if(p->status & 2){ // is player facing left? if(p->status & 3){ if(cam_offset_y > 0x15){ if(cam_offset_y > 0x25) p->Camera_Y_pos += 0x10; else p->Camera_Y_pos += (cam_offset_y - 0x15); } if(cam_offset_y < -0x2B){ if(cam_offset_y < -0x3B) p->Camera_Y_pos -= 0x10; else p->Camera_Y_pos += (cam_offset_y + 0x2B); } } // else, player is facing right else{ if(p->y_vel > 0x600 || p->y_vel < -0x600){ if(cam_offset_y > 0x10){ if(cam_offset_y > 0x20) p->Camera_Y_pos += 0x10; else p->Camera_Y_pos += (cam_offset_y - 0x10); } if(cam_offset_y < -0x30){ if(cam_offset_y < -0x40) p->Camera_Y_pos -= 0x10; else p->Camera_Y_pos += cam_offset_y + 0x30; } } else{ if(cam_offset_y > 0x10){ if(cam_offset_y > 0x16) p->Camera_Y_pos += 0x6; else p->Camera_Y_pos += (cam_offset_y - 0x10); } if(cam_offset_y < -0x30){ if(cam_offset_y < -0x36) p->Camera_Y_pos -= 0x6; else p->Camera_Y_pos += cam_offset_y + 0x30; } } } } // else, player isn't in the air else{ if(p->y_vel > 0x600 || p->y_vel < -0x600){ if(cam_offset_y > 0x10){ if(cam_offset_y > 0x20) p->Camera_Y_pos += 0x10; else p->Camera_Y_pos += (cam_offset_y - 0x10); } else if(cam_offset_y < 0x10){ if(cam_offset_y < -0x20) p->Camera_Y_pos -= 0x10; else p->Camera_Y_pos += (cam_offset_y + 0x10); } } else{ if(cam_offset_y > -0x10){ if(cam_offset_y > -0xA) p->Camera_Y_pos += 0x6; else p->Camera_Y_pos += (cam_offset_y + 0x10); } else if(cam_offset_y < -0x10){ if(cam_offset_y < -0x16) p->Camera_Y_pos -= 0x6; else p->Camera_Y_pos += (cam_offset_y + 0x10); } } } //////////////////// // Camera correction //////////////////// // for the X axis if(!camera_mode){ if(p->Camera_Max_X_pos - p->Camera_X_pos <= 0x100) p->Camera_Min_X_pos = p->Camera_Max_X_pos - 0x100; } if(p->Camera_X_pos < p->Camera_Min_X_pos) p->Camera_X_pos = p->Camera_Min_X_pos; else if(p->Camera_X_pos > p->Camera_Max_X_pos - (screen_resolution_x-320)) p->Camera_X_pos = p->Camera_Max_X_pos - (screen_resolution_x-320); // for the Y axis if(p->Camera_Y_pos <= p->Camera_Min_Y_pos){ if(p->Camera_Min_Y_pos < 0){ p->Camera_Y_pos &= z.Act[act].Stage[stage].WrapPoint-1; if(p->Camera_Y_pos >= 0) p->Camera_Y_pos += ((p->Camera_Max_Y_pos - (screen_resolution_y-224)) << 8); else p->Camera_Y_pos &= ((z.Act[act].Stage[stage].WrapPoint-1 << 8) + 0xFF); } else p->Camera_Y_pos = p->Camera_Min_Y_pos; } if(screen_resolution_y-224 >= 0){ if(p->Camera_Y_pos >= p->Camera_Max_Y_pos && p->Camera_Y_pos >= z.Act[act].Stage[stage].WrapPoint && p->Camera_Min_Y_pos < 0){ p->Camera_Y_pos &= z.Act[act].Stage[stage].WrapPoint-1; p->y_pos &= z.Act[act].Stage[stage].WrapPoint-1; } else if(p->Camera_Y_pos > p->Camera_Max_Y_pos + (screen_resolution_y-224)) p->Camera_Y_pos = p->Camera_Max_Y_pos + (screen_resolution_y-224); } else{ if(p->Camera_Y_pos >= p->Camera_Max_Y_pos && p->Camera_Y_pos >= z.Act[act].Stage[stage].WrapPoint && p->Camera_Min_Y_pos < 0){ p->Camera_Y_pos &= z.Act[act].Stage[stage].WrapPoint-1; p->y_pos &= z.Act[act].Stage[stage].WrapPoint-1; } else if(p->Camera_Y_pos > p->Camera_Max_Y_pos - (screen_resolution_y-224)) p->Camera_Y_pos = p->Camera_Max_Y_pos - (screen_resolution_y-224); } // Don't know what it's for, but BRIDGE.BIN depends on this to function. p->Camera_X_pos_coarse = (p->Camera_X_pos - 128) / 256; }
001tomclark-research-check
Source/Engine/obj01.c
C
gpl2
105,873
/***************************************************************************** * ______ * / _ \ _ __ ______ * / /_ / / / //__ / / _ \ * / ____ / / / / / / / * / / / / / /_ / / * /_ / /_ / \ _____ / * ______ * / ____ / ______ _ __ _ ______ * / /___ / _ \ / //_ \ /_ / / _ \ * _\___ \ / / / / / / / / / / / / /_ / * / /_ / / / /_ / / / / / / / / / /____ * \______ / \ _____ / /_ / /_ / /_ / \ ______/ * * * ProSonic Engine * Created by Damian Grove * * Compiled with DJGPP - GCC 2.952 (DOS) / Dev-C++ 4.9.9.2 (Windows) * Libraries used: * - Allegro - 3.9.34 http://www.talula.demon.co.uk/allegro/ * - DUMB - 0.9.3 http://dumb.sourceforge.net/ * - AllegroOgg - 1.0.3 http://nekros.freeshell.org/delirium/ * ****************************************************************************** * * NAME: ProSonic - Object code and management * * FILE: objects.c * * DESCRIPTION: * This file contains code for game objects and their functionality. Also * included is the node manager which gets rid of wasted memory space and * organized the objects that are being used. The object buffer will hold up * to 128 objects, and the total number of objects allowed in a single level * is 1023. * *****************************************************************************/ #include <stdio.h> // Standard input/output #include <allegro.h> // Allegro game library #include "error.h" //#include "draw.h" //#include "text.h" #include "m68k.h" #include "obj01.h" #include "objects.h" #include "sprites.h" #include "script.h" void AllocateObjects(ZONE *z){ short i; short n = z->Act[act].Stage[stage].ObjectLayout; int size = z->OBJ_SizeTable[n]; int address = z->OBJ_AddressTable[n]; if((int)(size_t)Objects != ENOMEM){ free(Objects); Objects = 0; } for(i=0; i < MAX_LEVEL_OBJECTS; i++) ObjectStates[i] = 0; Objects = (OBJECT_PLOT*)malloc(size + (MAX_BUFFER_OBJECTS << 3)); for(i=0; i < (size >> 3); i++){ Objects[i].x_pos = (z->OBJ[address + (i << 3)] << 8) + z->OBJ[address + (i << 3) + 1]; Objects[i].y_pos = (z->OBJ[address + (i << 3) + 2] << 8) + z->OBJ[address + (i << 3) + 3]; Objects[i].type = z->OBJ[address + (i << 3) + 4]; Objects[i].subtype = z->OBJ[address + (i << 3) + 5]; Objects[i].h_tag = z->OBJ[address + (i << 3) + 6]; Objects[i].l_tag = z->OBJ[address + (i << 3) + 7]; } ObjectCount = (size >> 3); for(i = 0; i < MAX_BUFFER_OBJECTS; i++) { // Clear debug object memory ObjectNodes[i] = 0xFFFF; Objects[ObjectCount + i].x_pos = 0xFFFF; Objects[ObjectCount + i].y_pos = 0x0; Objects[ObjectCount + i].type = 0x0; Objects[ObjectCount + i].subtype = 0x0; Objects[ObjectCount + i].h_tag = 0x0; Objects[ObjectCount + i].l_tag = 0x0; // Clear object on-screen buffer memory objObject[i].static_node = 0; objObject[i].routine = 0; objObject[i].status = 0; objObject[i].render_flags = 0; objObject[i].width_pixels = 0; objObject[i].priority = 0; objObject[i].objoff_32 = 0; objObject[i].objoff_34 = 0; objObject[i].anim_frame_duration = 0; objObject[i].anim_frame = 0; objObject[i].anim = 0; objObject[i].x_pos_pre = 0; objObject[i].y_pos_pre = 0; objObject[i].x_vel = 0; objObject[i].y_vel = 0; objObject[i].x_radius = 0; objObject[i].x_radius = 0; for(n=0; n < 16; n++) objObject[i].user[n] = 0; for(n=0; n < 0x1300; n++) objObject[i].ram[n] = 0; } } // This manages object nodes. Object nodes keep track of what objects are in // memory. This function constantly swaps in objects that enter the play area, // and swaps out objects that are outside the play area. This is important // since ProSonic supports 128 objects in the play area at one time. FUNCINLINE void ManageObjectNodes(ZONE *z) { int a; int b; //int c; short LimitL = p->Camera_X_pos - OBJECT_BUFFER_SCOPE; short LimitR = p->Camera_X_pos + OBJECT_BUFFER_SCOPE + screen_resolution_x; unsigned short ObjectNumber; unsigned short NodeNumber = 0; if(frame == 1){ for(a=0; a < MAX_BUFFER_OBJECTS; a++){ if(ObjectScopePoll[a] >= num_of_frames){ objObject[a].user[0] = 0; objObject[a].user[1] = 0; objObject[a].user[2] = 0; objObject[a].user[3] = 0; objObject[a].user[4] = 0; objObject[a].user[5] = 0; objObject[a].user[6] = 0; objObject[a].user[7] = 0; objObject[a].user[8] = 0; objObject[a].user[9] = 0; objObject[a].user[10] = 0; objObject[a].user[11] = 0; objObject[a].user[12] = 0; objObject[a].user[13] = 0; objObject[a].user[14] = 0; objObject[a].user[15] = 0; objObject[a].routine = 0; objObject[a].x_pos = 0; objObject[a].y_pos = 0; objObject[a].render_flags = 0; objObject[a].priority = 0; objObject[a].subtype = 0; objObject[a].objoff_32 = 0; objObject[a].objoff_34 = 0; objObject[a].type = 0; objObject[a].subtype = 0; objObject[a].h_tag = 0; objObject[a].l_tag = 0; objObject[a].x_pos_pre = 0; objObject[a].y_pos_pre = 0; objObject[a].x_vel = 0; objObject[a].y_vel = 0; objObject[a].x_radius = 0; objObject[a].x_radius = 0; objObject[a].static_node = 0; objObject[a].status = 0; for(i=0; i < 0x1300; i++) objObject[a].ram[i] = 0; ObjectNodes[a] = 0xFFFF; } ObjectScopePoll[a] = 0; } } if(LimitL < 0) LimitL = 0; if(LimitR < 0) LimitR = 0; // Find the first object within the object scope for(ObjectNumber = 0; (Objects[ObjectNumber].x_pos < LimitL && ObjectNumber < ObjectCount) || Objects[ObjectNumber].type == 0; ObjectNumber++); // Code for permanent objects for(; Objects[ObjectNumber].x_pos < LimitR && ObjectNumber < ObjectCount; ObjectNumber++) { if(Objects[ObjectNumber].type > 0) { for(a = 0; a < MAX_BUFFER_OBJECTS; a++) { if(ObjectNodes[a] == ObjectNumber) { b = 1; // Object is listed in the nodes table a = MAX_BUFFER_OBJECTS; // Stop checking for exisitng node } else b = 0; // Object is NOT listed at the current node } if(b == 0) // If object is NOT listed in the nodes table { for(a = 0; a < MAX_BUFFER_OBJECTS; a++) { if(ObjectNodes[a] >= MAX_LEVEL_OBJECTS) { ObjectNodes[a] = ObjectNumber; // Put the object at the next available node BufferObjectCount = a + 1; objObject[a].x_pos = Objects[ObjectNumber].x_pos; objObject[a].y_pos = Objects[ObjectNumber].y_pos; objObject[a].type = Objects[ObjectNumber].type; objObject[a].subtype = Objects[ObjectNumber].subtype; objObject[a].h_tag = Objects[ObjectNumber].h_tag; objObject[a].l_tag = Objects[ObjectNumber].l_tag; a = MAX_BUFFER_OBJECTS; b = 1; // Set to 1 to indicate no errors found } } if(b == 0) quit(ERROR_OBJECT_BUFFER); } } } // Code for temporary objects ObjectNumber = ObjectCount; for(; ObjectNumber < ObjectCount + MAX_BUFFER_OBJECTS; ObjectNumber++) { if(Objects[ObjectNumber].x_pos >= LimitL && Objects[ObjectNumber].x_pos < LimitR) { for(a = MAX_BUFFER_OBJECTS - 1; a >= 0; a--) { if(ObjectNodes[a] == ObjectNumber) { b = 1; // Object is listed in the nodes table a = -1; // Stop checking for exisitng node } else b = 0; // Object is NOT listed at the current node } if(b == 0) // If object is NOT listed in the nodes table { for(a = MAX_BUFFER_OBJECTS - 1; a >= 0; a--) // added "- 1" --- 01/01/2006 { if(ObjectNodes[a] >= MAX_LEVEL_OBJECTS) { ObjectNodes[a] = ObjectNumber; // Put the object at the next available node a = -1; objObject[a].x_pos = Objects[ObjectNumber].x_pos; objObject[a].y_pos = Objects[ObjectNumber].y_pos; objObject[a].type = Objects[ObjectNumber].type; objObject[a].subtype = Objects[ObjectNumber].subtype; objObject[a].h_tag = Objects[ObjectNumber].h_tag; objObject[a].l_tag = Objects[ObjectNumber].l_tag; } } } } else { Objects[ObjectNumber].x_pos = 0xFFFF; Objects[ObjectNumber].y_pos = 0x0; Objects[ObjectNumber].type = 0x0; Objects[ObjectNumber].subtype = 0x0; Objects[ObjectNumber].h_tag = 0x0; Objects[ObjectNumber].l_tag = 0x0; } } for(NodeNumber = 0; NodeNumber < MAX_BUFFER_OBJECTS; NodeNumber++) { if(ObjectNodes[NodeNumber] < ObjectCount + MAX_BUFFER_OBJECTS) { // We actually execute objects here if(ObjectNodes[NodeNumber] < MAX_LEVEL_OBJECTS){ if((objObject[NodeNumber].x_pos >= LimitL && objObject[NodeNumber].x_pos < LimitR) || objObject[NodeNumber].static_node){ switch(Objects[ObjectNodes[NodeNumber]].type){ case 0: // NULL break; case 0x03: // Side swapper fncSideSwapper(z, NodeNumber); break; case 0x25: // Ring fncRing(z, NodeNumber); break; default: // *** 68000 emulation *** fncM68K(z, NodeNumber); } } } PollObject(NodeNumber); } } } FUNCINLINE void PollObject(unsigned short NodeNumber){ short LimitL = p->Camera_X_pos - OBJECT_BUFFER_SCOPE; short LimitR = p->Camera_X_pos + OBJECT_BUFFER_SCOPE + screen_resolution_x; if(LimitL < 0) LimitL = 0; if(LimitR < 0) LimitR = 0; if(objObject[NodeNumber].x_pos < LimitL && !objObject[NodeNumber].static_node) PollObjectFrame(NodeNumber); else if(objObject[NodeNumber].x_pos >= LimitR && !objObject[NodeNumber].static_node) PollObjectFrame(NodeNumber); } void PollObjectFrame(unsigned short NodeNumber){ if(ObjectNodes[NodeNumber] >= ObjectCount && ObjectNodes[NodeNumber] != 0xFFFF) // If it's a temporary object, delete it from memory { Objects[ObjectNodes[NodeNumber]].x_pos = 0xFFFF; Objects[ObjectNodes[NodeNumber]].y_pos = 0x0; Objects[ObjectNodes[NodeNumber]].type = 0x0; Objects[ObjectNodes[NodeNumber]].subtype = 0x0; Objects[ObjectNodes[NodeNumber]].h_tag = 0x0; Objects[ObjectNodes[NodeNumber]].l_tag = 0x0; ObjectNodes[NodeNumber] = 0xFFFF; } if(ObjectNodes[NodeNumber] < MAX_LEVEL_OBJECTS){ ObjectScopePoll[NodeNumber]++; } } void CreateObject(char type, char subtype, char h_tag, char l_tag, short x_pos, short y_pos) { int a; short n = z.Act[act].Stage[stage].ObjectLayout; int size = z.OBJ_SizeTable[n]; unsigned short ObjectCount = (size >> 3); for(a = MAX_BUFFER_OBJECTS - 1; a >= 0; a--) { if(ObjectNodes[a] >= MAX_LEVEL_OBJECTS) { ObjectNodes[a] = ObjectCount + a; Objects[ObjectCount + a].x_pos = x_pos; Objects[ObjectCount + a].y_pos = y_pos; Objects[ObjectCount + a].type = type; Objects[ObjectCount + a].subtype = subtype; Objects[ObjectCount + a].h_tag = h_tag; Objects[ObjectCount + a].l_tag = l_tag; objObject[a].x_pos = Objects[ObjectCount + a].x_pos; objObject[a].y_pos = Objects[ObjectCount + a].y_pos; objObject[a].type = Objects[ObjectCount + a].type; objObject[a].subtype = Objects[ObjectCount + a].subtype; objObject[a].h_tag = Objects[ObjectCount + a].h_tag; objObject[a].l_tag = Objects[ObjectCount + a].l_tag; a = 0; } } } // This will permanently write an object out of memory so it will never be // loaded as a node again. void DestroyObject(unsigned short NodeNumber) { Objects[ObjectNodes[NodeNumber]].type = 0; // Set object class to 0 Objects[ObjectNodes[NodeNumber]].subtype = 0; // Set object member to 0 Objects[ObjectNodes[NodeNumber]].h_tag = 0; Objects[ObjectNodes[NodeNumber]].l_tag = 0; ObjectNodes[NodeNumber] = 0xFFFF; // Free the node // Clear object on-screen buffer memory objObject[NodeNumber].x_pos = 0xFFFF; objObject[NodeNumber].y_pos = 0; objObject[NodeNumber].type = 0; objObject[NodeNumber].subtype = 0; objObject[NodeNumber].h_tag = 0; objObject[NodeNumber].l_tag = 0; objObject[NodeNumber].static_node = 0; objObject[NodeNumber].routine = 0; objObject[NodeNumber].status = 0; objObject[NodeNumber].render_flags = 0; objObject[NodeNumber].width_pixels = 0; objObject[NodeNumber].priority = 0; objObject[NodeNumber].objoff_32 = 0; objObject[NodeNumber].objoff_34 = 0; objObject[NodeNumber].anim_frame_duration = 0; objObject[NodeNumber].anim_frame = 0; objObject[NodeNumber].anim = 0; objObject[NodeNumber].x_pos_pre = 0; objObject[NodeNumber].y_pos_pre = 0; objObject[NodeNumber].x_vel = 0; objObject[NodeNumber].y_vel = 0; objObject[NodeNumber].x_radius = 0; objObject[NodeNumber].x_radius = 0; for(n=0; n < 16; n++) objObject[NodeNumber].user[n] = 0; for(n=0; n < 0x1300; n++) objObject[NodeNumber].ram[n] = 0; } // * 0B * // Side swappers! Woohoo FUNCINLINE void fncSideSwapper(ZONE *z, unsigned short NodeNumber){ OBJECT *o = &objObject[NodeNumber]; short range[4] = { 0x20, 0x40, 0x80, 0x100 }; if(o->user[0] == 0) o->user[0] = o->y_pos & 0xF800; //o->y_pos &= 0x7FF; // temporary fix o->subtype = o->subtype; // temporary fix o->anim = 0; //o->anim_counter = ObjectStates[ObjectNodes[NodeNumber]] << 1; //o->anim_speed = 1; // subtype: 76543210 // 10 --- size // 2 ---- direction // 3 ---- layer coming in from left // 4 ---- layer coming in from right // 5 ---- plane coming in from left // 6 ---- plane coming in from right // 7 ---- if on, only works when on ground //DrawCounter16(LayerH[frame-1], o->subtype + (o->type << 8), o->x_pos - p->Camera_X_pos - 16 + 16, o->y_pos - (signed short)(p->Camera_Y_pos) - 16); //DrawCounter16(LayerSH[frame-1], ObjectStates[ObjectNodes[NodeNumber]] + (o->type << 8), o->x_pos - p->Camera_X_pos - 16 + 16, o->y_pos - (signed short)(p->Camera_Y_pos) - 16 + 16); //DrawCounter16(LayerH[frame-1], o->user[0], o->x_pos - p->Camera_X_pos - 16 + 16, o->y_pos - (signed short)(p->Camera_Y_pos) + 8); //int x_pos = Objects[ObjectNodes[NodeNumber]].x_pos; //int y_pos = Objects[ObjectNodes[NodeNumber]].y_pos; //int ObjM = Objects[ObjectNodes[NodeNumber]].Member; switch(o->routine){ case 0: goto Obj03_Init; break; case 2: goto Obj03_MainX; break; case 4: goto Obj03_MainY; } Obj03_Init: o->render_flags |= 4; o->width_pixels = 0x10; o->priority = 5; if((o->subtype & 4) == 0) goto Obj03_Init_CheckX; //Obj03_Init_CheckY: o->routine = 4; if(o->y_pos < p->y_pos) //ObjectStates[ObjectNodes[NodeNumber]] = 1; ObjectStates[ObjectNodes[NodeNumber]] |= (1 << (frame-1)); goto Obj03_MainY; Obj03_Init_CheckX: o->routine = 2; if(o->x_pos < p->x_pos) //ObjectStates[ObjectNodes[NodeNumber]] = 1; ObjectStates[ObjectNodes[NodeNumber]] |= (1 << (frame-1)); Obj03_MainX: if(Debug_placement_mode) return; //if(ObjectStates[ObjectNodes[NodeNumber]] == 0){ if((ObjectStates[ObjectNodes[NodeNumber]] & (1 << (frame-1))) == 0){////////////////////////////// if(o->x_pos > p->x_pos) return; } else if(o->x_pos <= p->x_pos) return; //ObjectStates[ObjectNodes[NodeNumber]] ^= 1; ObjectStates[ObjectNodes[NodeNumber]] ^= (1 << (frame-1)); if(p->y_pos < (o->y_pos - range[o->subtype & 3])) return; if(p->y_pos >= (o->y_pos + range[o->subtype & 3])) return; if(o->subtype < 0 && p->status & 2) return; if((o->render_flags & 1) == 0){ //DrawText((screen_resolution_x >> 1) - 32, screen_resolution_y >> 1, 0x30, "ACTIVE!"); p->layer = 0x10; p->layer_plus = 0x11; //if(ObjectStates[ObjectNodes[NodeNumber]] == 1){ if(ObjectStates[ObjectNodes[NodeNumber]] & (1 << (frame-1))){ if(o->subtype & 8){ p->layer = 0x12; p->layer_plus = 0x13; } } else if(o->subtype & 0x10){ p->layer = 0x12; p->layer_plus = 0x13; } /*WriteLog("MAIN_X"); VarLog(VAR_LAYER); d0 = NodeNumber; d1 = ObjectNodes[NodeNumber]; VarLog(REG_D0); VarLog(REG_D1); WriteLog("OBJECT=========="); d2 = o->x_pos; d3 = o->y_pos; d4 = o->subtype; d7 = ObjectStates[ObjectNodes[NodeNumber]]; VarLog(REG_D2); VarLog(REG_D3); VarLog(REG_D4); VarLog(REG_D7); WriteLog("PLAYER=========="); d5 = p->x_pos; d6 = p->y_pos; VarLog(REG_D5); VarLog(REG_D6);*/ } p->art_tile &= 0x7FFF; if(o->subtype & 0x20) p->art_tile |= 0x8000; return; Obj03_MainY: if(Debug_placement_mode) return; //if(ObjectStates[ObjectNodes[NodeNumber]] != 0) if(ObjectStates[ObjectNodes[NodeNumber]] & (1 << (frame-1))) goto Obj03_MainY_Alt; if(o->y_pos > p->y_pos) return; //ObjectStates[ObjectNodes[NodeNumber]] = 1; ObjectStates[ObjectNodes[NodeNumber]] |= (1 << (frame-1)); if(p->x_pos < (o->x_pos - range[o->subtype & 3])) return; if(p->x_pos >= (o->x_pos + range[o->subtype & 3])) return; if(o->subtype < 0 && p->status & 2) return; if((o->render_flags & 1) == 0){ //DrawText((screen_resolution_x >> 1) - 32, screen_resolution_y >> 1, 0x30, "ACTIVE!"); p->layer = 0x10; p->layer_plus = 0x11; if(o->subtype & 8){ p->layer = 0x12; p->layer_plus = 0x13; } /*WriteLog("MAIN_Y"); VarLog(VAR_LAYER); d0 = NodeNumber; d1 = ObjectNodes[NodeNumber]; VarLog(REG_D0); VarLog(REG_D1); WriteLog("OBJECT=========="); d2 = o->x_pos; d3 = o->y_pos; d4 = o->subtype; d7 = ObjectStates[ObjectNodes[NodeNumber]]; VarLog(REG_D2); VarLog(REG_D3); VarLog(REG_D4); VarLog(REG_D7); WriteLog("PLAYER=========="); d5 = p->x_pos; d6 = p->y_pos; VarLog(REG_D5); VarLog(REG_D6);*/ } p->art_tile &= 0x7FFF; if(o->subtype & 0x20) p->art_tile |= 0x8000; return; Obj03_MainY_Alt: if(o->y_pos <= p->y_pos) return; //ObjectStates[ObjectNodes[NodeNumber]] = 0; if(ObjectStates[ObjectNodes[NodeNumber]] & (1 << (frame-1))) ObjectStates[ObjectNodes[NodeNumber]] ^= (1 << (frame-1)); if(p->x_pos < (o->x_pos - range[o->subtype & 3])) return; if(p->x_pos >= (o->x_pos + range[o->subtype & 3])) return; if(o->subtype < 0 && p->status & 2) return; if((o->render_flags & 1) == 0){ //DrawText((screen_resolution_x >> 1) - 32, screen_resolution_y >> 1, 0x30, "ACTIVE!"); p->layer = 0x10; p->layer_plus = 0x11; if(o->subtype & 0x10){ p->layer = 0x12; p->layer_plus = 0x13; } /*WriteLog("MAIN_ALT"); VarLog(VAR_LAYER); d0 = NodeNumber; d1 = ObjectNodes[NodeNumber]; VarLog(REG_D0); VarLog(REG_D1); WriteLog("OBJECT=========="); d2 = o->x_pos; d3 = o->y_pos; d4 = o->subtype; d7 = ObjectStates[ObjectNodes[NodeNumber]]; VarLog(REG_D2); VarLog(REG_D3); VarLog(REG_D4); VarLog(REG_D7); WriteLog("PLAYER=========="); d5 = p->x_pos; d6 = p->y_pos; VarLog(REG_D5); VarLog(REG_D6);*/ } p->art_tile &= 0x7FFF; if(o->subtype & 0x40) p->art_tile |= 0x8000; } // * 10 * // If you don't know what rings do, you don't know Sonic. FUNCINLINE void fncRing(ZONE *z, unsigned short NodeNumber) { OBJECT *o = &objObject[NodeNumber]; static char RingSfxPan; if(o->static_node == 0 && o->x_pos - p->x_pos <= 14 && o->x_pos - p->x_pos >= -14 && o->y_pos - (p->y_pos & (z->Act[act].Stage[stage].WrapPoint-1)) <= 22 && o->y_pos - (p->y_pos & (z->Act[act].Stage[stage].WrapPoint-1)) >= -22) { o->anim = 1; o->anim_frame_duration = GetAnimationSpeed(0x25, (unsigned char *)&o->anim); o->static_node = 1; // Keep in memory until we manually delete it ++p->Ring_count; if(p->Ring_count > 999) p->Ring_count = 999; else if(p->Ring_count == 100 && (p->Extra_life_flags & 1) == 0){ p->Extra_life_flags |= 1; p->Life_count++; } else if(p->Ring_count == 200 && (p->Extra_life_flags & 2) == 0){ p->Extra_life_flags |= 2; p->Life_count++; } RingSfxPan ^= 1; if(RingSfxPan) PlayPCM(0x35, 1, 1); // LEFT STEREO else PlayPCM(0x35, 1, 2); // RIGHT STEREO } if(o->static_node) { o->anim = 1; d0 = GetAnimationSpeed(0x25, (unsigned char *)&o->anim); ReadAnimation(0x25, (unsigned char *)&o->anim, (unsigned short *)&o->anim_frame, &o->anim_frame_duration, (unsigned char*)&d0); DrawAnimation(z, LayerH[frame-1], 0x25, o->anim, o->anim_frame, NORMAL, 0, &o->anim_frame_duration, d0, o->x_pos - p->Camera_X_pos - 8 + 16, o->y_pos - (signed short)(p->Camera_Y_pos) - 8); ObjectStates[ObjectNodes[NodeNumber]]++; } else{ o->anim = 0; ReadAnimation(0x25, (unsigned char *)&o->anim, (unsigned short *)&o->anim_frame, &o->anim_frame_duration, (unsigned char*)&d0); d0 = GetAnimationSpeed(0x25, (unsigned char *)&o->anim); o->anim_frame = (ticCounterL % (((d0+1) << 2)) >> 3); DrawAnimation(z, LayerH[frame-1], 0x25, o->anim, o->anim_frame, NORMAL, 0, &o->anim_frame_duration, d0, o->x_pos - p->Camera_X_pos - 8 + 16, o->y_pos - (signed short)(p->Camera_Y_pos) - 8); } if(o->static_node && o->anim_frame_duration < 0 && o->anim_frame == 3) DestroyObject(NodeNumber); } void RunFunction(unsigned char function){ int i; if(obj_script) free(obj_script); obj_script = (char *)malloc(game_script_size[function]); for(i=0; i < game_script_size[function]; i++) obj_script[i] = script[game_script_start[function] + i]; //if(obj_script_type[function] == SCRIPT_TYPE_PROCODE){ // Not a 68000 binary file fncProcode(0); return; //} } void fncProcode(unsigned short NodeNumber){ int i; int src; int dest; int op; int type1; int type2; int type3; int type4; int type5; int type6; int type7; int type8; int type9; int type10; int size1; int size2; int size3; int size4; int size5; int size6; int size7; int size8; int size9; int size10; int num1; int num2; int num3; int num4; int num5; int num6; int num7; int num8; int num9; int num10; int ptr; char string[64]; OBJECT *o = &objObject[NodeNumber]; internal_ovar_ptrs[0] = (int *)&o->user[0]; internal_ovar_ptrs[1] = (int *)&o->static_node; internal_ovar_ptrs[2] = (int *)&o->h_tag; internal_ovar_ptrs[3] = (int *)&o->l_tag; internal_ovar_ptrs[4] = (int *)&o->type; internal_ovar_ptrs[5] = (int *)&o->routine; internal_ovar_ptrs[6] = (int *)&o->status; internal_ovar_ptrs[7] = (int *)&o->x_pos; internal_ovar_ptrs[8] = (int *)&o->y_pos; internal_ovar_ptrs[9] = (int *)&o->render_flags; internal_ovar_ptrs[10] = (int *)&o->width_pixels; internal_ovar_ptrs[11] = (int *)&o->priority; internal_ovar_ptrs[12] = (int *)&o->subtype; internal_ovar_ptrs[13] = (int *)&o->objoff_32; internal_ovar_ptrs[14] = (int *)&o->objoff_34; internal_ovar_ptrs[15] = (int *)&o->anim_frame_duration; internal_ovar_ptrs[16] = (int *)&o->anim_frame; internal_ovar_ptrs[17] = (int *)&o->anim; internal_ovar_ptrs[18] = (int *)&o->x_pos_pre; internal_ovar_ptrs[19] = (int *)&o->y_pos_pre; internal_ovar_ptrs[20] = (int *)&o->x_vel; internal_ovar_ptrs[21] = (int *)&o->y_vel; internal_ovar_ptrs[22] = (int *)&o->x_radius; internal_ovar_ptrs[23] = (int *)&o->y_radius; script_pos = 0; if_scope = 0; break_ptr[0] = -1; while(script_pos >= 0){ switch(obj_script[script_pos]){ case 0x0: // assignment script_pos++; type1 = obj_script[script_pos]; script_pos++; // Get destination i = *(short *)(&obj_script[script_pos]); script_pos += 2; if(i >= 0x800){ // GVAR i -= 0x800; dest = (int)internal_gvar_ptrs[i]; size1 = internal_gvar_size[i]; } else if(i >= 0x100){ // OVAR i -= 0x100; dest = (int)internal_ovar_ptrs[i]; size1 = internal_ovar_size[i]; } else{ // PVAR dest = (int)internal_pvar_ptrs[frame-1][i]; size1 = internal_pvar_size[i]; } if(type1 == 2){ type3 = obj_script[script_pos]; script_pos++; // Get destination subscript if(type3 == 0){ // immediate dest += ((*(int *)(&obj_script[script_pos])) * size1); script_pos += 4; } else{ // variable i = *(short *)(&obj_script[script_pos]); script_pos += 2; if(i >= 0x800){ // GVAR i -= 0x800; switch(internal_gvar_size[i]){ case 4: dest += ((*(int *)internal_gvar_ptrs[i]) * size1); break; case 2: dest += ((*(short *)internal_gvar_ptrs[i]) * size1); break; case 1: dest += ((*(char *)internal_gvar_ptrs[i]) * size1); } } else if(i >= 0x100){ // OVAR i -= 0x100; switch(internal_ovar_size[i]){ case 4: dest += ((*(int *)internal_ovar_ptrs[i]) * size1); break; case 2: dest += ((*(short *)internal_ovar_ptrs[i]) * size1); break; case 1: dest += ((*(char *)internal_ovar_ptrs[i]) * size1); } } else{ // PVAR switch(internal_pvar_size[i]){ case 4: dest += ((*(int *)internal_pvar_ptrs[frame-1][i]) * size1); break; case 2: dest += ((*(short *)internal_pvar_ptrs[frame-1][i]) * size1); break; case 1: dest += ((*(char *)internal_pvar_ptrs[frame-1][i]) * size1); } } } } // Get operation op = obj_script[script_pos]; script_pos++; // Get source if(op > 2){ type2 = obj_script[script_pos]; script_pos++; if(type2 == 0){ // immediate src = *(int *)(&obj_script[script_pos]); size2 = 0; script_pos += 4; } else{ // variable i = *(short *)(&obj_script[script_pos]); script_pos += 2; if(i >= 0x800){ // GVAR i -= 0x800; src = (int)internal_gvar_ptrs[i]; size2 = internal_gvar_size[i]; } else if(i >= 0x100){ // OVAR i -= 0x100; src = (int)internal_ovar_ptrs[i]; size2 = internal_ovar_size[i]; } else{ // PVAR src = (int)internal_pvar_ptrs[frame-1][i]; size2 = internal_pvar_size[i]; } } if(type2 == 2){ type4 = obj_script[script_pos]; script_pos++; // Get source subscript if(type4 == 0){ // immediate src += ((*(int *)(&obj_script[script_pos])) * size2); script_pos += 4; } else{ // variable i = *(short *)(&obj_script[script_pos]); script_pos += 2; if(i >= 0x800){ // GVAR i -= 0x800; switch(internal_gvar_size[i]){ case 4: src += ((*(int *)internal_gvar_ptrs[i]) * size2); break; case 2: src += ((*(short *)internal_gvar_ptrs[i]) * size2); break; case 1: src += ((*(char *)internal_gvar_ptrs[i]) * size2); } } else if(i >= 0x100){ // OVAR i -= 0x100; switch(internal_ovar_size[i]){ case 4: src += ((*(int *)internal_ovar_ptrs[i]) * size2); break; case 2: src += ((*(short *)internal_ovar_ptrs[i]) * size2); break; case 1: src += ((*(char *)internal_ovar_ptrs[i]) * size2); } } else{ // PVAR switch(internal_pvar_size[i]){ case 4: src += ((*(int *)internal_pvar_ptrs[frame-1][i]) * size2); break; case 2: src += ((*(short *)internal_pvar_ptrs[frame-1][i]) * size2); break; case 1: src += ((*(char *)internal_pvar_ptrs[frame-1][i]) * size2); } } } } } procode_set(size1, dest, op, size2, src); break; case 0x6: // "if" script_pos++; // Get next branch ptr ptr = *(int *)(&obj_script[script_pos]); script_pos += 4; // Get endif ptr break_ptr[if_scope+1] = *(int *)(&obj_script[script_pos]); script_pos += 4; // Get destination type1 = obj_script[script_pos]; script_pos++; if(type1 == 0){ // immediate dest = *(int *)(&obj_script[script_pos]); size1 = 0; script_pos += 4; } else{ // variable i = *(short *)(&obj_script[script_pos]); script_pos += 2; if(i >= 0x800){ // GVAR i -= 0x800; dest = (int)internal_gvar_ptrs[i]; size1 = internal_gvar_size[i]; } else if(i >= 0x100){ // OVAR i -= 0x100; dest = (int)internal_ovar_ptrs[i]; size1 = internal_ovar_size[i]; } else{ // PVAR dest = (int)internal_pvar_ptrs[frame-1][i]; size1 = internal_pvar_size[i]; } } // Get operation op = obj_script[script_pos]; script_pos++; // Get source type2 = obj_script[script_pos]; script_pos++; if(type2 == 0){ // immediate src = *(int *)(&obj_script[script_pos]); size2 = 0; script_pos += 4; } else{ // variable i = *(short *)(&obj_script[script_pos]); script_pos += 2; if(i >= 0x800){ // GVAR i -= 0x800; src = (int)internal_gvar_ptrs[i]; size2 = internal_gvar_size[i]; } else if(i >= 0x100){ // OVAR i -= 0x100; src = (int)internal_ovar_ptrs[i]; size2 = internal_ovar_size[i]; } else{ // PVAR src = (int)internal_pvar_ptrs[frame-1][i]; size2 = internal_pvar_size[i]; } } i = procode_if(size1, dest, op, size2, src); if(i) if_scope++; else{ // if(ptr) script_pos = ptr; // else // fix for when pointer is zero // script_pos = break_ptr[if_scope+1]; } break; case 0x7: // "elseif" script_pos++; // Get next branch ptr ptr = *(int *)(&obj_script[script_pos]); script_pos += 4; // Get destination type1 = obj_script[script_pos]; script_pos++; if(type1 == 0){ // immediate dest = *(int *)(&obj_script[script_pos]); size1 = 0; script_pos += 4; } else{ // variable i = *(short *)(&obj_script[script_pos]); script_pos += 2; if(i >= 0x800){ // GVAR i -= 0x800; dest = (int)internal_gvar_ptrs[i]; size1 = internal_gvar_size[i]; } else if(i >= 0x100){ // OVAR i -= 0x100; dest = (int)internal_ovar_ptrs[i]; size1 = internal_ovar_size[i]; } else{ // PVAR dest = (int)internal_pvar_ptrs[frame-1][i]; size1 = internal_pvar_size[i]; } } // Get operation op = obj_script[script_pos]; script_pos++; // Get source type2 = obj_script[script_pos]; script_pos++; if(type2 == 0){ // immediate src = *(int *)(&obj_script[script_pos]); size2 = 0; script_pos += 4; } else{ // variable i = *(short *)(&obj_script[script_pos]); script_pos += 2; if(i >= 0x800){ // GVAR i -= 0x800; src = (int)internal_gvar_ptrs[i]; size2 = internal_gvar_size[i]; } else if(i >= 0x100){ // OVAR i -= 0x100; src = (int)internal_ovar_ptrs[i]; size2 = internal_ovar_size[i]; } else{ // PVAR src = (int)internal_pvar_ptrs[frame-1][i]; size2 = internal_pvar_size[i]; } } i = procode_if(size1, dest, op, size2, src); if(i) if_scope++; else{ // if(ptr) script_pos = ptr; // else // fix for when pointer is zero // script_pos = break_ptr[if_scope+1]; } break; case 0xA: // "break" script_pos = break_ptr[if_scope]; if_scope--; break; case 0xD: // "playfm" script_pos++; // FM number procode_process_number(&type1, &src, &size1, 2); // buffer procode_process_number(&type2, &dest, &size2, 1); // mix procode_process_number(&type3, &op, &size3, 1); procode_playfm(size1, src, size2, dest, size3, op); break; case 0xE: // "playpcm" script_pos++; // PCM number procode_process_number(&type1, &src, &size1, 2); // buffer procode_process_number(&type2, &dest, &size2, 1); // mix procode_process_number(&type3, &op, &size3, 1); procode_playpcm(size1, src, size2, dest, size3, op); break; case 0xF: // "resetsound" script_pos++; ResetSound(); break; case 0x10: // "textout" script_pos++; // X position procode_process_number(&type1, &num1, &size1, 2); // Y position procode_process_number(&type2, &num2, &size2, 2); // Color procode_process_number(&type3, &num3, &size3, 1); for(i=0; i < 64; i++){ string[i] = obj_script[script_pos]; script_pos++; if(string[i] == 0) i = 64; } procode_textout(size1, num1, size2, num2, size3, num3, string); break; case 0x11: // "drawsprite" script_pos++; // Layer procode_process_number(&type1, &num1, &size1, 1); /* // Sheet procode_process_number(&type2, &num2, &size2, 1); // Sprite procode_process_number(&type3, &num3, &size3, 1); */ // Drawing flags procode_process_number(&type4, &num4, &size4, 1); // Translucency procode_process_number(&type5, &num5, &size5, 1); // X position procode_process_number(&type6, &num6, &size6, 2); // Y position procode_process_number(&type7, &num7, &size7, 2); procode_drawsprite(NodeNumber, size1, num1, size4, num4, size5, num5, size6, num6, size7, num7); break; case 0x12: // "animate" script_pos++; // Layer procode_process_number(&type1, &num1, &size1, 1); /* // Sheet procode_process_number(&type2, &num2, &size2, 1); // Animation procode_process_number(&type3, &num3, &size3, 1); // Frame procode_process_number(&type4, &num4, &size4, 2); */ // Drawing flags procode_process_number(&type5, &num5, &size5, 1); // Translucency procode_process_number(&type6, &num6, &size6, 1); /* // Frame duration procode_process_number(&type7, &num7, &size7, 1); // Speed procode_process_number(&type8, &num8, &size8, 1); */ // X position procode_process_number(&type9, &num9, &size9, 2); // Y position procode_process_number(&type10, &num10, &size10, 2); procode_animate(NodeNumber, size1, num1, size5, num5, size6, num6, size9, num9, size10, num10); break; case 0x13: // "destroy" DestroyObject(NodeNumber); case 0x14: // "return" return; case 0x15: // "counterout" script_pos++; // Type procode_process_number(&type1, &num1, &size1, 1); // Fill procode_process_number(&type2, &num2, &size2, 1); // Number procode_process_number(&type3, &num3, &size3, 4); // X procode_process_number(&type4, &num4, &size4, 2); // Y procode_process_number(&type5, &num5, &size5, 2); procode_counterout(size1, num1, size2, num2, size3, num3, size4, num4, size5, num5); break; case 0x16: // "fadeoutfm" script_pos++; // buffer procode_process_number(&type1, &num1, &size1, 1); procode_fadeoutfm(size1, num1); break; case 0x17: // "move" script_pos++; procode_move(NodeNumber); break; case 0x18: // "spawn" script_pos++; // type procode_process_number(&type1, &num1, &size1, 1); // subtype procode_process_number(&type2, &num2, &size2, 1); // high tag procode_process_number(&type3, &num3, &size3, 1); // low tag procode_process_number(&type4, &num4, &size4, 1); // x position procode_process_number(&type5, &num5, &size5, 2); // y position procode_process_number(&type6, &num6, &size6, 2); procode_spawn(size1, num1, size2, num2, size3, num3, size4, num4, size5, num5, size6, num6); break; case 0x19: // "rest" script_pos++; // milliseconds procode_process_number(&type1, &num1, &size1, 2); procode_rest(size1, num1); break; case 0x1A: // "setgfxmode" script_pos++; // res_x procode_process_number(&type1, &num1, &size1, 2); // res_y procode_process_number(&type2, &num2, &size2, 2); // pad_x procode_process_number(&type3, &num3, &size3, 2); // pad_y procode_process_number(&type4, &num4, &size4, 2); // dbl_x procode_process_number(&type5, &num5, &size5, 2); // dbl_y procode_process_number(&type6, &num6, &size6, 2); // full procode_process_number(&type7, &num7, &size7, 1); procode_setgfxmode(size1, num1, size2, num2, size3, num3, size4, num4, size5, num5, size6, num6, size7, num7); break; case 0x1B: // "startzone" script_pos++; // zone procode_process_number(&type1, &num1, &size1, 1); // act procode_process_number(&type2, &num2, &size2, 1); // stage procode_process_number(&type3, &num3, &size3, 1); procode_startzone(size1, num1, size2, num2, size3, num3); break; default: // !!! ERROR !!! allegro_message("Error found in script:\n\no->type = 0x%X\nscript_pos = 0x%X\nobj_script[script_pos] = 0x%X", objObject[NodeNumber].type, script_pos, obj_script[script_pos]); return; } } return; } void fncM68K(ZONE *z, unsigned short NodeNumber){ OBJECT *o = &objObject[NodeNumber]; /*if(o->type == 0xD){ DrawCounter16(LayerH[frame-1], obj_script_size[o->type], 0, 0); DrawCounter16(LayerH[frame-1], obj_script_type[o->type], 35, 0); DrawCounter16(LayerH[frame-1], Update_HUD_timer, 70, 0); DrawCounter16(LayerH[frame-1], Two_player_mode, 105, 0); }*/ if(obj_script_size[o->type] == 0) return; if(obj_script) free(obj_script); obj_script = (char *)malloc(obj_script_size[o->type]); for(i=0; i < obj_script_size[o->type]; i++) obj_script[i] = script[obj_script_start[o->type] + i]; if(obj_script_type[o->type] == SCRIPT_TYPE_PROCODE){ // Not a 68000 binary file fncProcode(NodeNumber); return; } //if(p->x_pos < 0x1000){ p->x_pos = 0x1000; p->y_pos = 0x200; p->Camera_X_pos = 0x1000; p->Camera_Y_pos = 0x200; } //o->subtype = 0x82; o->subtype = o->subtype; if(o->status == 0) o->status = (o->y_pos >> 13); o->ram[0x0] = o->type; o->ram[0x8] = o->x_pos >> 8; o->ram[0x9] = o->x_pos; o->ram[0xC] = (o->y_pos >> 8) & 0x1F; o->ram[0xD] = o->y_pos; o->ram[0x22] = o->status; o->ram[0x28] = o->subtype; //DrawCounter16(LayerH[frame-1], o->subtype + (o->type << 8), o->x_pos - p->Camera_X_pos - 16 + 16, (o->y_pos & 0x1FFF) - p->Camera_Y_pos - 16); for(i=0; i < 0x1300; i++) ram_68k[0xFFFF - 0xB100 - i] = o->ram[i]; reg_a[0] = 0xFFFFB100; // last object in object RAM (this object) reg_a[7] = 0xFFFFFFFC; RunScript(NodeNumber); /*reg_a[0] = 0xFFFFB140; // last object in object RAM (this object) reg_a[7] = 0xFFFFFFFC; RunScript(NodeNumber); reg_a[0] = 0xFFFFB180; // last object in object RAM (this object) reg_a[7] = 0xFFFFFFFC; RunScript(NodeNumber);*/ //o->x_pos = (ram_68k[0xFFFF - 0xB108] << 8) + ram_68k[0xFFFF - 0xB109]; //o->y_pos = (ram_68k[0xFFFF - 0xB10C] << 8) + ram_68k[0xFFFF - 0xB10D]; //o->subtype = ram_68k[0xFFFF - 0xB128]; //DrawCounter16(LayerSH[frame-1], ram_68k[0xFFFF - 0xF7B2], 120, 0); /*if(p->x_pos > 0x2200 && p->y_pos > 0x380 && ram_68k[0xFFFF - 0xB124] == 2 && (p->anim == 2 || p->anim == 3)){ DumpLog("Motorola.log"); allegro_message("!"); rest(40); }*/ for(i=0; i < 0x1300; i++) o->ram[i] = ram_68k[0xFFFF - 0xB100 - i]; o->status = o->ram[0x22]; } // These are needed to port "prosonic_lift.asm" /* void MvSonicOnPtfm(){ d0 = o->y_pos; d0 -= d3; // Skip these lines of code since they're unused anyway // bra.s loc_19BA2 // move.w y_pos(a0),d0 // subi.w #9,d0 loc_19BA2: if(p->obj_control < 0) goto return_19BCA; if((unsigned char)p->routine >= 6) goto return_19BCA; if(Debug_placement_mode) goto return_19BCA; d1 = 0; d1 = p->y_radius; d0 -= d1; p->y_pos = d0; d2 -= o->x_pos; p->x_pos -= d2; return_19BCA: return; } void PlatformObject(){ // lea (MainCharacter).w,a1 d6 = 3; stack[1] = d1; stack[2] = d2; stack[3] = d3; stack[4] = d4; PlatformObject_SingleCharacter(); d1 = stack[1]; d2 = stack[2]; d3 = stack[3]; d4 = stack[4]; // lea (Sidekick).w,a1 d6++; PlatformObject_SingleCharacter(); return; } void PlatformObject_SingleCharacter(){ if(o->status & (1 << d6) == 0){ //goto loc_19DBA; loc_19DBA(); return; } d2 = d1; d2 += d2; if(p->status & 2 == 0){ d0 = p->x_pos; d0 -= o->x_pos; d0 += d1; if((short)d0 >= 0){ if((unsigned short)d0 < d2) goto loc_19C80; } } p->status &= 0xF7; p->status |= 2; o->status &= ((1 << d6) ^ 0xFF); d4 = 0; return; loc_19C80: d2 = d4; MvSonicOnPtfm(); d4 = 0; return; } void loc_19DBA(){ if(p->y_vel < 0) goto return_19E8E; d0 = p->x_pos; d0 -= o->x_pos; d0 += d1; if(d0 < 0) goto return_19E8E; if((unsigned short)d0 >= d1) goto return_19E8E; loc_19DD8: d0 = o->y_pos; d0 -= d3; loc_19DDE: d2 = p->y_pos; d1 = p->y_radius; d1 += d2; d1 += 4; d0 -= d1; if((short)d0 > 0) goto return_19E8E; if((short)d0 < -10) goto return_19E8E; if(p->obj_control < 0) goto return_19E8E; if(p->routine >= 6) goto return_19E8E; d2 += d0; d2 += 3; p->y_pos = d2; loc_19E14: if((p->status & 8) == 0) goto loc_19E30; // moveq #0,d0 // move.b interact(a1),d0 // lsl.w #6,d0 // addi.l #Object_RAM,d0 // movea.l d0,a3 ; a3=object // bclr d6,status(a3) loc_19E30: // FINISH ME! FINISH ME! FINISH ME! }*/
001tomclark-research-check
Source/Engine/objects.c
C
gpl2
42,378
#include <stdio.h> // Standard input/output #include <allegro.h> // Allegro game library #include "error.h" //#include "draw.h" //#include "text.h" #include "m68k.h" #include "obj01.h" #include "objects.h" #include "sprites.h" #include "script.h" void procode_process_number(long *store_type, long *store_value, long *store_size, char size){ // purposely excluded "FUNCINLINE" for this function *store_type = obj_script[script_pos]; script_pos++; if(*store_type == 0){ // immediate switch(size){ case 1: *store_value = *(char *)(&obj_script[script_pos]); break; case 2: *store_value = *(short *)(&obj_script[script_pos]); break; case 4: *store_value = *(int *)(&obj_script[script_pos]); break; } *store_size = 0; script_pos += size; } else{ // variable i = *(short *)(&obj_script[script_pos]); script_pos += 2; if(i >= 0x800){ // GVAR i -= 0x800; *store_value = (int)internal_gvar_ptrs[i]; *store_size = internal_gvar_size[i]; } else if(i >= 0x100){ // OVAR i -= 0x100; *store_value = (int)internal_ovar_ptrs[i]; *store_size = internal_ovar_size[i]; } else{ // PVAR *store_value = (int)internal_pvar_ptrs[frame-1][i]; *store_size = internal_pvar_size[i]; } } } FUNCINLINE void procode_set(char size1, long dest, char op, char size2, long src){ switch(op){ case 0: // ~ switch(size1){ case 4: *(int *)dest ^= 0xFFFFFFFF; break; case 2: *(short *)dest ^= 0xFFFF; break; case 1: *(char *)dest ^= 0xFF; } break; case 1: // ++ switch(size1){ case 4: (*(int *)dest)++; break; case 2: (*(short *)dest)++; break; case 1: (*(char *)dest)++; break; } break; case 2: // -- switch(size1){ case 4: (*(int *)dest)--; break; case 2: (*(short *)dest)--; break; case 1: (*(char *)dest)--; break; } break; case 3: // = switch(size1){ case 4: switch(size2){ case 4: *(int *)dest = *(int *)src; break; case 2: *(int *)dest = *(short *)src; break; case 1: *(int *)dest = *(char *)src; break; case 0: *(int *)dest = src; break; } break; case 2: switch(size2){ case 4: case 2: *(short *)dest = *(short *)src; break; case 1: *(short *)dest = *(char *)src; break; case 0: *(short *)dest = src; break; } break; case 1: switch(size2){ case 4: case 2: case 1: *(char *)dest = *(char *)src; break; case 0: *(char *)dest = src; break; } break; } break; case 4: // + switch(size1){ case 4: switch(size2){ case 4: *(int *)dest += *(int *)src; break; case 2: *(int *)dest += *(short *)src; break; case 1: *(int *)dest += *(char *)src; break; case 0: *(int *)dest += src; break; } break; case 2: switch(size2){ case 4: case 2: *(short *)dest += *(short *)src; break; case 1: *(short *)dest += *(char *)src; break; case 0: *(short *)dest += src; break; } break; case 1: switch(size2){ case 4: case 2: case 1: *(char *)dest += *(char *)src; break; case 0: *(char *)dest += src; break; } break; } break; case 5: // - switch(size1){ case 4: switch(size2){ case 4: *(int *)dest -= *(int *)src; break; case 2: *(int *)dest -= *(short *)src; break; case 1: *(int *)dest -= *(char *)src; break; case 0: *(int *)dest -= src; break; } break; case 2: switch(size2){ case 4: case 2: *(short *)dest -= *(short *)src; break; case 1: *(short *)dest -= *(char *)src; break; case 0: *(short *)dest -= src; break; } break; case 1: switch(size2){ case 4: case 2: case 1: *(char *)dest -= *(char *)src; break; case 0: *(char *)dest -= src; break; } break; } break; case 6: // * switch(size1){ case 4: switch(size2){ case 4: *(int *)dest *= *(int *)src; break; case 2: *(int *)dest *= *(short *)src; break; case 1: *(int *)dest *= *(char *)src; break; case 0: *(int *)dest *= src; break; } break; case 2: switch(size2){ case 4: case 2: *(short *)dest *= *(short *)src; break; case 1: *(short *)dest *= *(char *)src; break; case 0: *(short *)dest *= src; break; } break; case 1: switch(size2){ case 4: case 2: case 1: *(char *)dest *= *(char *)src; break; case 0: *(char *)dest *= src; break; } break; } break; case 7: // / switch(size1){ case 4: switch(size2){ case 4: *(int *)dest /= *(int *)src; break; case 2: *(int *)dest /= *(short *)src; break; case 1: *(int *)dest /= *(char *)src; break; case 0: *(int *)dest /= src; break; } break; case 2: switch(size2){ case 4: case 2: *(short *)dest /= *(short *)src; break; case 1: *(short *)dest /= *(char *)src; break; case 0: *(short *)dest /= src; break; } break; case 1: switch(size2){ case 4: case 2: case 1: *(char *)dest /= *(char *)src; break; case 0: *(char *)dest /= src; break; } break; } break; case 8: // % switch(size1){ case 4: switch(size2){ case 4: *(int *)dest %= *(int *)src; break; case 2: *(int *)dest %= *(short *)src; break; case 1: *(int *)dest %= *(char *)src; break; case 0: *(int *)dest %= src; break; } break; case 2: switch(size2){ case 4: case 2: *(short *)dest %= *(short *)src; break; case 1: *(short *)dest %= *(char *)src; break; case 0: *(short *)dest %= src; break; } break; case 1: switch(size2){ case 4: case 2: case 1: *(char *)dest %= *(char *)src; break; case 0: *(char *)dest %= src; break; } break; } break; case 9: // << switch(size1){ case 4: switch(size2){ case 4: *(int *)dest <<= *(int *)src; break; case 2: *(int *)dest <<= *(short *)src; break; case 1: *(int *)dest <<= *(char *)src; break; case 0: *(int *)dest <<= src; break; } break; case 2: switch(size2){ case 4: case 2: *(short *)dest <<= *(short *)src; break; case 1: *(short *)dest <<= *(char *)src; break; case 0: *(short *)dest <<= src; break; } break; case 1: switch(size2){ case 4: case 2: case 1: *(char *)dest <<= *(char *)src; break; case 0: *(char *)dest <<= src; break; } break; } break; case 10: // >> switch(size1){ case 4: switch(size2){ case 4: *(int *)dest >>= *(int *)src; break; case 2: *(int *)dest >>= *(short *)src; break; case 1: *(int *)dest >>= *(char *)src; break; case 0: *(int *)dest >>= src; break; } break; case 2: switch(size2){ case 4: case 2: *(short *)dest >>= *(short *)src; break; case 1: *(short *)dest >>= *(char *)src; break; case 0: *(short *)dest >>= src; break; } break; case 1: switch(size2){ case 4: case 2: case 1: *(char *)dest >>= *(char *)src; break; case 0: *(char *)dest >>= src; break; } break; } break; case 11: // & switch(size1){ case 4: switch(size2){ case 4: *(int *)dest &= *(int *)src; break; case 2: *(int *)dest &= *(short *)src; break; case 1: *(int *)dest &= *(char *)src; break; case 0: *(int *)dest &= src; break; } break; case 2: switch(size2){ case 4: case 2: *(short *)dest &= *(short *)src; break; case 1: *(short *)dest &= *(char *)src; break; case 0: *(short *)dest &= src; break; } break; case 1: switch(size2){ case 4: case 2: case 1: *(char *)dest &= *(char *)src; break; case 0: *(char *)dest &= src; break; } break; } break; case 12: // | switch(size1){ case 4: switch(size2){ case 4: *(int *)dest |= *(int *)src; break; case 2: *(int *)dest |= *(short *)src; break; case 1: *(int *)dest |= *(char *)src; break; case 0: *(int *)dest |= src; break; } break; case 2: switch(size2){ case 4: case 2: *(short *)dest |= *(short *)src; break; case 1: *(short *)dest |= *(char *)src; break; case 0: *(short *)dest |= src; break; } break; case 1: switch(size2){ case 4: case 2: case 1: *(char *)dest |= *(char *)src; break; case 0: *(char *)dest |= src; break; } break; } break; case 13: // ^ switch(size1){ case 4: switch(size2){ case 4: *(int *)dest ^= *(int *)src; break; case 2: *(int *)dest ^= *(short *)src; break; case 1: *(int *)dest ^= *(char *)src; break; case 0: *(int *)dest ^= src; break; } break; case 2: switch(size2){ case 4: case 2: *(short *)dest ^= *(short *)src; break; case 1: *(short *)dest ^= *(char *)src; break; case 0: *(short *)dest ^= src; break; } break; case 1: switch(size2){ case 4: case 2: case 1: *(char *)dest ^= *(char *)src; break; case 0: *(char *)dest ^= src; break; } break; } break; } } char procode_if(char size1, long dest, char op, char size2, long src){ // purposely excluded "FUNCINLINE" for this function char r; switch(op){ case 0: // == switch(size1){ case 4: switch(size2){ case 4: r = (*(int *)dest == *(int *)src); break; case 2: r = (*(int *)dest == *(short *)src); break; case 1: r = (*(int *)dest == *(char *)src); break; case 0: r = (*(int *)dest == src); break; } break; case 2: switch(size2){ case 4: case 2: r = (*(short *)dest == *(short *)src); break; case 1: r = (*(short *)dest == *(char *)src); break; case 0: r = (*(short *)dest == src); break; } break; case 1: switch(size2){ case 4: case 2: case 1: r = (*(char *)dest == *(char *)src); break; case 0: r = (*(char *)dest == src); break; } break; case 0: switch(size2){ case 4: r = (dest == *(int *)src); break; case 2: r = (dest == *(short *)src); break; case 1: r = (dest == *(char *)src); break; case 0: r = (dest == src); break; } break; } break; case 1: // > switch(size1){ case 4: switch(size2){ case 4: r = (*(int *)dest > *(int *)src); break; case 2: r = (*(int *)dest > *(short *)src); break; case 1: r = (*(int *)dest > *(char *)src); break; case 0: r = (*(int *)dest > src); break; } break; case 2: switch(size2){ case 4: case 2: r = (*(short *)dest > *(short *)src); break; case 1: r = (*(short *)dest > *(char *)src); break; case 0: r = (*(short *)dest > src); break; } break; case 1: switch(size2){ case 4: case 2: case 1: r = (*(char *)dest > *(char *)src); break; case 0: r = (*(char *)dest > src); break; } break; case 0: switch(size2){ case 4: r = (dest > *(int *)src); break; case 2: r = (dest > *(short *)src); break; case 1: r = (dest > *(char *)src); break; case 0: r = (dest > src); break; } break; } break; case 2: // < switch(size1){ case 4: switch(size2){ case 4: r = (*(int *)dest < *(int *)src); break; case 2: r = (*(int *)dest < *(short *)src); break; case 1: r = (*(int *)dest < *(char *)src); break; case 0: r = (*(int *)dest < src); break; } break; case 2: switch(size2){ case 4: case 2: r = (*(short *)dest < *(short *)src); break; case 1: r = (*(short *)dest < *(char *)src); break; case 0: r = (*(short *)dest < src); break; } break; case 1: switch(size2){ case 4: case 2: case 1: r = (*(char *)dest < *(char *)src); break; case 0: r = (*(char *)dest < src); break; } break; case 0: switch(size2){ case 4: r = (dest < *(int *)src); break; case 2: r = (dest < *(short *)src); break; case 1: r = (dest < *(char *)src); break; case 0: r = (dest < src); break; } break; } break; case 3: // >= switch(size1){ case 4: switch(size2){ case 4: r = (*(int *)dest >= *(int *)src); break; case 2: r = (*(int *)dest >= *(short *)src); break; case 1: r = (*(int *)dest >= *(char *)src); break; case 0: r = (*(int *)dest >= src); break; } break; case 2: switch(size2){ case 4: case 2: r = (*(short *)dest >= *(short *)src); break; case 1: r = (*(short *)dest >= *(char *)src); break; case 0: r = (*(short *)dest >= src); break; } break; case 1: switch(size2){ case 4: case 2: case 1: r = (*(char *)dest >= *(char *)src); break; case 0: r = (*(char *)dest >= src); break; } break; case 0: switch(size2){ case 4: r = (dest >= *(int *)src); break; case 2: r = (dest >= *(short *)src); break; case 1: r = (dest >= *(char *)src); break; case 0: r = (dest >= src); break; } break; } break; case 4: // <= switch(size1){ case 4: switch(size2){ case 4: r = (*(int *)dest <= *(int *)src); break; case 2: r = (*(int *)dest <= *(short *)src); break; case 1: r = (*(int *)dest <= *(char *)src); break; case 0: r = (*(int *)dest <= src); break; } break; case 2: switch(size2){ case 4: case 2: r = (*(short *)dest <= *(short *)src); break; case 1: r = (*(short *)dest <= *(char *)src); break; case 0: r = (*(short *)dest <= src); break; } break; case 1: switch(size2){ case 4: case 2: case 1: r = (*(char *)dest <= *(char *)src); break; case 0: r = (*(char *)dest <= src); break; } break; case 0: switch(size2){ case 4: r = (dest <= *(int *)src); break; case 2: r = (dest <= *(short *)src); break; case 1: r = (dest <= *(char *)src); break; case 0: r = (dest <= src); break; } break; } break; case 5: // != switch(size1){ case 4: switch(size2){ case 4: r = (*(int *)dest != *(int *)src); break; case 2: r = (*(int *)dest != *(short *)src); break; case 1: r = (*(int *)dest != *(char *)src); break; case 0: r = (*(int *)dest != src); break; } break; case 2: switch(size2){ case 4: case 2: r = (*(short *)dest != *(short *)src); break; case 1: r = (*(short *)dest != *(char *)src); break; case 0: r = (*(short *)dest != src); break; } break; case 1: switch(size2){ case 4: case 2: case 1: r = (*(char *)dest != *(char *)src); break; case 0: r = (*(char *)dest != src); break; } break; case 0: switch(size2){ case 4: r = (dest != *(int *)src); break; case 2: r = (dest != *(short *)src); break; case 1: r = (dest != *(char *)src); break; case 0: r = (dest != src); break; } break; } break; } return r; } FUNCINLINE void procode_playfm(char size1, long src, char size2, long dest, char size3, long op){ short number; char buffer; char mix; switch(size1){ case 4: case 2: number = *(short *)src; break; case 1: number = *(char *)src; break; case 0: number = src; } switch(size2){ case 4: case 2: case 1: buffer = *(char *)dest; break; case 0: buffer = dest; } switch(size3){ case 4: case 2: case 1: mix = *(char *)op; break; case 0: mix = op; } PlayFM(number, buffer, mix); } FUNCINLINE void procode_playpcm(char size1, long src, char size2, long dest, char size3, long op){ short number; char buffer; char mix; switch(size1){ case 4: case 2: number = *(short *)src; break; case 1: number = *(char *)src; break; case 0: number = src; } switch(size2){ case 4: case 2: case 1: buffer = *(char *)dest; break; case 0: buffer = dest; } switch(size3){ case 4: case 2: case 1: mix = *(char *)op; break; case 0: mix = op; } PlayPCM(number, buffer, mix); } FUNCINLINE void procode_textout(char size1, long num1, char size2, long num2, char size3, long num3, const char *string, ...){ short x; short y; char color; switch(size1){ case 4: case 2: x = *(short *)num1; break; case 1: x = *(char *)num1; break; case 0: x = num1; } switch(size2){ case 4: case 2: y = *(short *)num2; break; case 1: y = *(char *)num2; break; case 0: y = num2; } switch(size3){ case 4: case 2: case 1: color = *(char *)num3; break; case 0: color = num3; } DrawText(x, y, color, string); } FUNCINLINE void procode_drawsprite(unsigned short NodeNumber, char size1, long num1, char size2, long num2, char size3, long num3, char size4, long num4, char size5, long num5){ char layer; char flags; char trans; short x; short y; OBJECT *o = &objObject[NodeNumber]; switch(size1){ case 4: case 2: case 1: layer = *(char *)num1; break; case 0: layer = num1; } switch(size2){ case 4: case 2: case 1: flags = *(char *)num2; break; case 0: flags = num2; } switch(size3){ case 4: case 2: case 1: trans = *(char *)num3; break; case 0: trans = num3; } switch(size4){ case 4: case 2: x = *(short *)num4; break; case 1: x = *(char *)num4; break; case 0: x = num4; } switch(size5){ case 4: case 2: y = *(short *)num5; break; case 1: y = *(char *)num5; break; case 0: y = num5; } switch(layer){ case 0: DrawSprite(&z, LayerSH[frame-1], o->type, o->anim_frame, flags, trans, x+16, y); break; case 1: DrawSprite(&z, LayerH[frame-1], o->type, o->anim_frame, flags, trans, x+16, y); break; case 2: DrawSprite(&z, LayerL[frame-1], o->type, o->anim_frame, flags, trans, x+16, y); break; case 3: DrawSprite(&z, LayerB[frame-1], o->type, o->anim_frame, flags, trans, x+16, y); break; } } FUNCINLINE void procode_animate(unsigned short NodeNumber, char size1, long num1, char size2, long num2, char size3, long num3, char size4, long num4, char size5, long num5){ char layer; char flags; char trans; short x; short y; unsigned char speed; OBJECT *o = &objObject[NodeNumber]; switch(size1){ case 4: case 2: case 1: layer = *(char *)num1; break; case 0: layer = num1; } switch(size2){ case 4: case 2: case 1: flags = *(char *)num2; break; case 0: flags = num2; } switch(size3){ case 4: case 2: case 1: trans = *(char *)num3; break; case 0: trans = num3; } switch(size4){ case 4: case 2: x = *(short *)num4; break; case 1: x = *(char *)num4; break; case 0: x = num4; } switch(size5){ case 4: case 2: y = *(short *)num5; break; case 1: y = *(char *)num5; break; case 0: y = num5; } speed = GetAnimationSpeed(o->type, (unsigned char *)&o->anim); ReadAnimation(o->type, (unsigned char *)&o->anim, (unsigned short *)&o->anim_frame, &o->anim_frame_duration, &speed); switch(layer){ case 0: DrawAnimation(&z, LayerSH[frame-1], o->type, o->anim, o->anim_frame, flags, trans, &o->anim_frame_duration, speed, x+16, y); break; case 1: DrawAnimation(&z, LayerH[frame-1], o->type, o->anim, o->anim_frame, flags, trans, &o->anim_frame_duration, speed, x+16, y); break; case 2: DrawAnimation(&z, LayerL[frame-1], o->type, o->anim, o->anim_frame, flags, trans, &o->anim_frame_duration, speed, x+16, y); break; case 3: DrawAnimation(&z, LayerB[frame-1], o->type, o->anim, o->anim_frame, flags, trans, &o->anim_frame_duration, speed, x+16, y); break; } } FUNCINLINE void procode_counterout(char size1, long num1, char size2, long num2, char size3, long num3, char size4, long num4, char size5, long num5){ char type; char fill; int number; short x; short y; switch(size1){ case 4: case 2: case 1: type = *(char *)num1; break; case 0: type = num1; } switch(size2){ case 4: case 2: case 1: fill = *(char *)num2; break; case 0: fill = num2; } switch(size3){ case 4: number = *(int *)num3; break; case 2: number = *(short *)num3; break; case 1: number = *(char *)num3; break; case 0: number = num3; } switch(size4){ case 4: case 2: x = *(short *)num4; break; case 1: x = *(char *)num4; break; case 0: x = num4; } switch(size5){ case 4: case 2: y = *(short *)num5; break; case 1: y = *(char *)num5; break; case 0: y = num5; } switch(type){ case 0: case 1: DrawCounter10(LayerSH[frame-1], number, x, y, fill, type); break; case 2: DrawCounter16(LayerSH[frame-1], number, x, y); break; } } FUNCINLINE void procode_fadeoutfm(char size1, long num1){ char buffer; switch(size1){ case 4: case 2: case 1: buffer = *(char *)num1; break; case 0: buffer = num1; } FadeOutFM(buffer); } FUNCINLINE void procode_move(unsigned short NodeNumber){ OBJECT *o = &objObject[NodeNumber]; int x_pos = (o->x_pos << 16) | (unsigned short)(o->x_pos_pre); int y_pos = (o->y_pos << 16) | (unsigned short)(o->y_pos_pre); x_pos += (o->x_vel << 8); y_pos += (o->y_vel << 8); o->x_pos = x_pos >> 16; o->x_pos_pre = x_pos; o->y_pos = y_pos >> 16; o->y_pos_pre = y_pos; } FUNCINLINE void procode_spawn(char size1, long num1, char size2, long num2, char size3, long num3, char size4, long num4, char size5, long num5, char size6, long num6){ char type; char subtype; char htag; char ltag; short x; short y; switch(size1){ case 4: case 2: case 1: type = *(char *)num1; break; case 0: type = num1; } switch(size2){ case 4: case 2: case 1: subtype = *(char *)num2; break; case 0: subtype = num2; } switch(size3){ case 4: case 2: case 1: htag = *(char *)num3; break; case 0: htag = num3; } switch(size4){ case 4: case 2: case 1: ltag = *(char *)num4; break; case 0: ltag = num4; } switch(size5){ case 4: case 2: x = *(short *)num5; break; case 1: x = *(char *)num5; break; case 0: x = num5; } switch(size6){ case 4: case 2: y = *(short *)num6; break; case 1: y = *(char *)num6; break; case 0: y = num6; } CreateObject(type, subtype, htag, ltag, x, y); } FUNCINLINE void procode_rest(char size1, long num1){ short ms; switch(size1){ case 4: case 2: ms = *(short *)num1; break; case 1: ms = *(char *)num1; break; case 0: ms = num1; } rest(ms); } FUNCINLINE void procode_setgfxmode(char size1, long num1, char size2, long num2, char size3, long num3, char size4, long num4, char size5, long num5, char size6, long num6, char size7, long num7){ unsigned short res_x, res_y; unsigned short pad_x, pad_y; unsigned short dbl_x, dbl_y; unsigned char full; switch(size1){ case 4: case 2: res_x = *(short *)num1; break; case 1: res_x = *(char *)num1; break; case 0: res_x = num1; } switch(size2){ case 4: case 2: res_y = *(short *)num2; break; case 1: res_y = *(char *)num2; break; case 0: res_y = num2; } switch(size3){ case 4: case 2: pad_x = *(short *)num3; break; case 1: pad_x = *(char *)num3; break; case 0: pad_x = num3; } switch(size4){ case 4: case 2: pad_y = *(short *)num4; break; case 1: pad_y = *(char *)num4; break; case 0: pad_y = num4; } switch(size5){ case 4: case 2: dbl_x = *(short *)num5; break; case 1: dbl_x = *(char *)num5; break; case 0: dbl_x = num5; } switch(size6){ case 4: case 2: dbl_y = *(short *)num6; break; case 1: dbl_y = *(char *)num6; break; case 0: dbl_y = num6; } switch(size7){ case 4: case 2: case 1: full = *(char *)num7; break; case 0: full = num7; } SetGfxMode(res_x, res_y, pad_x, pad_y, dbl_x, dbl_y, full); } FUNCINLINE void procode_startzone(char size1, long num1, char size2, long num2, char size3, long num3){ char z; char a; char s; switch(size1){ case 4: case 2: case 1: z = *(char *)num1; break; case 0: z = num1; } switch(size2){ case 4: case 2: case 1: a = *(char *)num2; break; case 0: a = num2; } switch(size3){ case 4: case 2: case 1: s = *(char *)num3; break; case 0: s = num3; } zone = z; act = a; stage = s; Level_Inactive_flag = 1; }
001tomclark-research-check
Source/Engine/script2.c
C
gpl2
29,197
#include <stdio.h> #include <string.h> #include <allegro.h> //#include "zone.h" //#include "structs.h" //#include "common.h" //#include "text.h" #include "obj01.h" #include "menus.h" void InitLevelSelect() { menu_column_size = 7;//13; menu_column_count = 2; menu_timer1 = 0; selection_menu[0].offset_x = 0x10; selection_menu[0].offset_y = 0x48; selection_menu[0].show = 1; selection_menu[0].rows = 1; strcpy(selection_menu[0].string, "ZONE\0"); selection_menu[0].row[0].var_size = 0; // char // this will be done by scripting in the future selection_menu[0].row[0].var_ptr8 = &zone; selection_menu[0].row[0].type = 1; selection_menu[0].row[0].min_value = 0x00; selection_menu[0].row[0].max_value = 0xFF; selection_menu[0].row[0].offset_x = 0x70; selection_menu[0].row[0].offset_y = 0x48; selection_menu[0].row[0].value_digits = 2; selection_menu[0].row[0].columns = 0; //////////////////////////////////////////////////////////// selection_menu[1].offset_x = 0x10; selection_menu[1].offset_y = 0x58; selection_menu[1].show = 1; selection_menu[1].rows = 1; strcpy(selection_menu[1].string, "DEMO\0"); selection_menu[1].row[0].var_size = 0; // char // this will be done by scripting in the future selection_menu[1].row[0].var_ptr8 = &demo_number; selection_menu[1].row[0].type = 1; selection_menu[1].row[0].min_value = 0x0; selection_menu[1].row[0].max_value = 0x9; selection_menu[1].row[0].offset_x = 0x70; selection_menu[1].row[0].offset_y = 0x58; selection_menu[1].row[0].value_digits = 1; selection_menu[1].row[0].columns = 0; //////////////////////////////////////////////////////////// selection_menu[2].offset_x = 0x10; selection_menu[2].offset_y = 0x68; selection_menu[2].show = 1; selection_menu[2].rows = 1; strcpy(selection_menu[2].string, "RINGS\0"); selection_menu[2].row[0].var_size = 1; // short // this will be done by scripting in the future selection_menu[2].row[0].var_ptr16 = &player[0].Ring_count; selection_menu[2].row[0].type = 1; selection_menu[2].row[0].min_value = 0; selection_menu[2].row[0].max_value = 999; selection_menu[2].row[0].offset_x = 0x70; selection_menu[2].row[0].offset_y = 0x68; selection_menu[2].row[0].value_digits = 3; selection_menu[2].row[0].columns = 0; //////////////////////////////////////////////////////////// selection_menu[3].offset_x = 0x10; selection_menu[3].offset_y = 0x78; selection_menu[3].show = 1; selection_menu[3].rows = 1; strcpy(selection_menu[3].string, "LIVES\0"); selection_menu[3].row[0].var_size = 0; // char // this will be done by scripting in the future selection_menu[3].row[0].var_ptr8 = &player[0].Life_count; selection_menu[3].row[0].type = 1; selection_menu[3].row[0].min_value = 0; selection_menu[3].row[0].max_value = 99; selection_menu[3].row[0].offset_x = 0x70; selection_menu[3].row[0].offset_y = 0x78; selection_menu[3].row[0].value_digits = 2; selection_menu[3].row[0].columns = 0; //////////////////////////////////////////////////////////// selection_menu[4].offset_x = 0x10; selection_menu[4].offset_y = 0x88; selection_menu[4].show = 1; selection_menu[4].rows = 1; strcpy(selection_menu[4].string, "EMERALDS\0"); selection_menu[4].row[0].var_size = 0; // char // this will be done by scripting in the future selection_menu[4].row[0].var_ptr8 = &Emerald_count; selection_menu[4].row[0].type = 1; selection_menu[4].row[0].min_value = 0; selection_menu[4].row[0].max_value = 7; selection_menu[4].row[0].offset_x = 0x70; selection_menu[4].row[0].offset_y = 0x88; selection_menu[4].row[0].value_digits = 1; selection_menu[4].row[0].columns = 0; //////////////////////////////////////////////////////////// selection_menu[5].offset_x = 0x10; selection_menu[5].offset_y = 0x98; selection_menu[5].show = 1; selection_menu[5].rows = 1; strcpy(selection_menu[5].string, "FRAME SKIP\0"); selection_menu[5].row[0].var_size = 0; // char // this will be done by scripting in the future selection_menu[5].row[0].var_ptr8 = &frame_skip; selection_menu[5].row[0].type = 1; selection_menu[5].row[0].min_value = 0x0; selection_menu[5].row[0].max_value = 0x5; selection_menu[5].row[0].offset_x = 0x70; selection_menu[5].row[0].offset_y = 0x98; selection_menu[5].row[0].value_digits = 1; selection_menu[5].row[0].columns = 0; //////////////////////////////////////////////////////////// selection_menu[6].offset_x = 0x10; selection_menu[6].offset_y = 0xA8; selection_menu[6].show = 1; selection_menu[6].rows = 1; strcpy(selection_menu[6].string, "EDIT MODE\0"); selection_menu[6].row[0].var_size = 0; // char // this will be done by scripting in the future selection_menu[6].row[0].var_ptr8 = &edit_mode; selection_menu[6].row[0].type = 1; selection_menu[6].row[0].min_value = 0x0; selection_menu[6].row[0].max_value = 0x4; selection_menu[6].row[0].offset_x = 0x70; selection_menu[6].row[0].offset_y = 0xA8; selection_menu[6].row[0].value_digits = 1; selection_menu[6].row[0].columns = 0; //////////////////////////////////////////////////////////// selection_menu[7].offset_x = 0xB0; selection_menu[7].offset_y = 0x48; selection_menu[7].show = 1; selection_menu[7].rows = 1; strcpy(selection_menu[7].string, "VSYNC\0"); selection_menu[7].row[0].var_size = 0; // char // this will be done by scripting in the future selection_menu[7].row[0].var_ptr8 = &vsync_enable; selection_menu[7].row[0].type = 1; selection_menu[7].row[0].min_value = 0x0; selection_menu[7].row[0].max_value = 0x1; selection_menu[7].row[0].offset_x = 0x110; selection_menu[7].row[0].offset_y = 0x48; selection_menu[7].row[0].value_digits = 1; selection_menu[7].row[0].columns = 0; //////////////////////////////////////////////////////////// selection_menu[8].offset_x = 0xB0; selection_menu[8].offset_y = 0x58; selection_menu[8].show = 1; selection_menu[8].rows = 1; strcpy(selection_menu[8].string, "SMART MIX\0"); selection_menu[8].row[0].var_size = 0; // char // this will be done by scripting in the future selection_menu[8].row[0].var_ptr8 = &smart_mix; selection_menu[8].row[0].type = 1; selection_menu[8].row[0].min_value = 0x0; selection_menu[8].row[0].max_value = 0x1; selection_menu[8].row[0].offset_x = 0x110; selection_menu[8].row[0].offset_y = 0x58; selection_menu[8].row[0].value_digits = 1; selection_menu[8].row[0].columns = 0; //////////////////////////////////////////////////////////// selection_menu[9].offset_x = 0xB0; selection_menu[9].offset_y = 0x68; selection_menu[9].show = 1; selection_menu[9].rows = 1; strcpy(selection_menu[9].string, "VOLUME\0"); selection_menu[9].row[0].var_size = 0; // char // this will be done by scripting in the future selection_menu[9].row[0].var_ptr8 = &audio_volume; selection_menu[9].row[0].type = 1; selection_menu[9].row[0].min_value = -1; selection_menu[9].row[0].max_value = 0x1F; selection_menu[9].row[0].offset_x = 0x110; selection_menu[9].row[0].offset_y = 0x68; selection_menu[9].row[0].value_digits = 2; selection_menu[9].row[0].columns = 0; //////////////////////////////////////////////////////////// selection_menu[10].offset_x = 0xB0; selection_menu[10].offset_y = 0x78; selection_menu[10].show = 1; selection_menu[10].rows = 1; strcpy(selection_menu[10].string, "EMPTY 10\0"); selection_menu[10].row[0].type = 0; selection_menu[10].row[0].offset_x = 0x110; selection_menu[10].row[0].offset_y = 0x78; selection_menu[10].row[0].columns = 0; strcpy(selection_menu[10].row[0].string[0], "\0"); //////////////////////////////////////////////////////////// selection_menu[11].offset_x = 0xB0; selection_menu[11].offset_y = 0x88; selection_menu[11].show = 1; selection_menu[11].rows = 1; strcpy(selection_menu[11].string, "EMPTY 11\0"); selection_menu[11].row[0].type = 0; selection_menu[11].row[0].offset_x = 0x110; selection_menu[11].row[0].offset_y = 0x88; selection_menu[11].row[0].columns = 0; strcpy(selection_menu[11].row[0].string[0], "\0"); //////////////////////////////////////////////////////////// selection_menu[12].offset_x = 0xB0; selection_menu[12].offset_y = 0x98; selection_menu[12].show = 1; selection_menu[12].rows = 1; strcpy(selection_menu[12].string, "EMPTY 12\0"); selection_menu[12].row[0].type = 0; selection_menu[12].row[0].offset_x = 0x110; selection_menu[12].row[0].offset_y = 0x98; selection_menu[12].row[0].columns = 0; strcpy(selection_menu[12].row[0].string[0], "\0"); //////////////////////////////////////////////////////////// selection_menu[13].offset_x = 0xB0; selection_menu[13].offset_y = 0xA8; selection_menu[13].show = 1; selection_menu[13].rows = 1; strcpy(selection_menu[13].string, "EMPTY 13\0"); selection_menu[13].row[0].type = 0; selection_menu[13].row[0].offset_x = 0x110; selection_menu[13].row[0].offset_y = 0xA8; selection_menu[13].row[0].columns = 0; strcpy(selection_menu[13].row[0].string[0], "\0"); //////////////////////////////////////////////////////////// //selection_menu[13].show = 0; } void Menu(PLAYER *p){ int a; int b; int value; char digits; if(frame == 1){ if(menu_timer1 > 0) menu_timer1--; if(menu_timer2 > 0) menu_timer2--; if(key[KEY_UP]){ if(menu_timer1 == 0){ menu_timer1 = 12; menu_timer2 = 0; menu_timer3 = 1; menu_timer4 = 1; menu_sub_selection--; if(menu_sub_selection < 0){ if(menu_selection == 0) menu_selection = (menu_column_size * menu_column_count); menu_selection--; } while(selection_menu[menu_selection].show == 0){ if(menu_selection == 0) menu_selection = (menu_column_size * menu_column_count); menu_selection--; } if(menu_sub_selection < 0) menu_sub_selection = selection_menu[menu_selection].rows - 1; } } else if(key[KEY_DOWN]){ if(menu_timer2 == 0){ menu_timer1 = 0; menu_timer2 = 12; menu_timer3 = 1; menu_timer4 = 1; menu_sub_selection++; if(menu_sub_selection >= selection_menu[menu_selection].rows){ menu_sub_selection = 0; menu_selection++; menu_selection %= (menu_column_size * menu_column_count); } while(selection_menu[menu_selection].show == 0){ menu_selection++; menu_selection %= (menu_column_size * menu_column_count); } } } else if(key[KEY_LEFT]){ if(menu_timer3 == 0 && selection_menu[menu_selection].row[menu_sub_selection].type == 0){ menu_timer1 = 0; menu_timer2 = 0; menu_timer3 = 1; menu_timer4 = 0; menu_selection -= menu_column_size; if(menu_selection < 0) menu_selection += (menu_column_size * menu_column_count); while(selection_menu[menu_selection].show == 0){ menu_selection -= menu_column_size; if(menu_selection < 0) menu_selection += (menu_column_size * menu_column_count); } if(menu_sub_selection >= selection_menu[menu_selection].rows) menu_sub_selection = selection_menu[menu_selection].rows - 1; } else if(menu_timer3 == 0 && selection_menu[menu_selection].row[menu_sub_selection].type == 1){ menu_timer1 = 0; menu_timer2 = 0; menu_timer3 = 1; menu_timer4 = 0; if(selection_menu[menu_selection].row[menu_sub_selection].var_size == 0){ (*selection_menu[menu_selection].row[menu_sub_selection].var_ptr8)--; if(*selection_menu[menu_selection].row[menu_sub_selection].var_ptr8 < selection_menu[menu_selection].row[menu_sub_selection].min_value) *selection_menu[menu_selection].row[menu_sub_selection].var_ptr8 = (char)(selection_menu[menu_selection].row[menu_sub_selection].max_value); } else{ (*selection_menu[menu_selection].row[menu_sub_selection].var_ptr16)--; if(*selection_menu[menu_selection].row[menu_sub_selection].var_ptr16 < selection_menu[menu_selection].row[menu_sub_selection].min_value) *selection_menu[menu_selection].row[menu_sub_selection].var_ptr16 = (short int)(selection_menu[menu_selection].row[menu_sub_selection].max_value); } } } else if(key[KEY_RIGHT]){ if(menu_timer4 == 0 && selection_menu[menu_selection].row[menu_sub_selection].type == 0){ menu_timer1 = 0; menu_timer2 = 0; menu_timer3 = 0; menu_timer4 = 1; menu_selection += menu_column_size; menu_selection %= (menu_column_size * menu_column_count); while(selection_menu[menu_selection].show == 0){ menu_selection += menu_column_size; menu_selection %= (menu_column_size * menu_column_count); } if(menu_sub_selection >= selection_menu[menu_selection].rows) menu_sub_selection = selection_menu[menu_selection].rows - 1; } else if(menu_timer4 == 0 && selection_menu[menu_selection].row[menu_sub_selection].type == 1){ menu_timer1 = 0; menu_timer2 = 0; menu_timer3 = 0; menu_timer4 = 1; if(selection_menu[menu_selection].row[menu_sub_selection].var_size == 0){ if(*selection_menu[menu_selection].row[menu_sub_selection].var_ptr8 >= selection_menu[menu_selection].row[menu_sub_selection].max_value) *selection_menu[menu_selection].row[menu_sub_selection].var_ptr8 = (char)(selection_menu[menu_selection].row[menu_sub_selection].min_value); else // we do it this way to prevent bugs with the max value and size (*selection_menu[menu_selection].row[menu_sub_selection].var_ptr8)++; } else{ if(*selection_menu[menu_selection].row[menu_sub_selection].var_ptr16 >= selection_menu[menu_selection].row[menu_sub_selection].max_value) *selection_menu[menu_selection].row[menu_sub_selection].var_ptr16 = (short int)(selection_menu[menu_selection].row[menu_sub_selection].min_value); else // we do it this way to prevent bugs with the max value and size (*selection_menu[menu_selection].row[menu_sub_selection].var_ptr16)++; } } } if(!key[KEY_UP]) menu_timer1 = 0; if(!key[KEY_DOWN]) menu_timer2 = 0; if(!key[KEY_LEFT]) menu_timer3 = 0; if(!key[KEY_RIGHT]) menu_timer4 = 0; } for(a=0; a < (menu_column_size * menu_column_count); a++){ if(a == menu_selection) DrawText( selection_menu[a].offset_x, selection_menu[a].offset_y, 1, selection_menu[a].string); else DrawText( selection_menu[a].offset_x, selection_menu[a].offset_y, 0, selection_menu[a].string); for(b=0; b < selection_menu[a].rows; b++){ if(selection_menu[a].row[b].type == 1){ for(digits = selection_menu[a].row[b].value_digits; digits > 0; digits--){ if(selection_menu[a].row[b].var_size == 0) value = ((*selection_menu[a].row[b].var_ptr8) & (0xF << ((digits * 4) - 4))) >> ((digits * 4) - 4); else value = ((*selection_menu[a].row[b].var_ptr16) & (0xF << ((digits * 4) - 4))) >> ((digits * 4) - 4); if(value > 9) selection_menu[a].row[b].string[0][selection_menu[a].row[b].value_digits - digits] = (value-10)+'A'; else selection_menu[a].row[b].string[0][selection_menu[a].row[b].value_digits - digits] = value+'0'; } selection_menu[a].row[b].string[0][(short)selection_menu[a].row[b].value_digits] = '\0'; } if(b == menu_sub_selection && a == menu_selection) DrawText( selection_menu[a].row[b].offset_x, selection_menu[a].row[b].offset_y, 1, selection_menu[a].row[b].string[0]); else DrawText( selection_menu[a].row[b].offset_x, selection_menu[a].row[b].offset_y, 0, selection_menu[a].row[b].string[0]); } } }
001tomclark-research-check
Source/Engine/menus.c
C
gpl2
15,887
#ifndef OBJ01_H #define OBJ01_H #include "common.h" #ifdef __cplusplus extern "C"{ #endif int CalcSine(); int CalcAngle(); FUNCINLINE int Obj01(); FUNCINLINE int Sonic_Display(); int Sonic_RecordPos(); FUNCINLINE int Sonic_Water(); int Obj01_MdNormal_Checks(); FUNCINLINE int Obj01_MdAir(); FUNCINLINE int Obj01_MdRoll(); FUNCINLINE int Obj01_MdJump(); FUNCINLINE int Sonic_Move(); int Obj01_CheckWallsOnGround(); FUNCINLINE int Sonic_MoveLeft(); FUNCINLINE int Sonic_MoveRight(); FUNCINLINE int Sonic_RollSpeed(); FUNCINLINE int Sonic_RollLeft(); FUNCINLINE int Sonic_RollRight(); int Sonic_ChgJumpDir(); int Sonic_LevelBound(); FUNCINLINE int Sonic_Roll(); int Sonic_Jump(); int Sonic_JumpHeight(); FUNCINLINE int Sonic_Super(); FUNCINLINE int Sonic_CheckSpindash(); FUNCINLINE int Sonic_SlopeResist(); FUNCINLINE int Sonic_RollRepel(); int Sonic_SlopeRepel(); int Sonic_JumpAngle(); int Sonic_DoLevelCollision(); int Sonic_ResetOnFloor(char label); FUNCINLINE int Obj01_Hurt(); FUNCINLINE int Sonic_HurtStop(); FUNCINLINE int Sonic_HurtInstantRecover(); FUNCINLINE int Obj01_Dead(); FUNCINLINE int CheckGameOver(); FUNCINLINE int Obj01_Gone(); FUNCINLINE int Obj01_Respawning(); int Sonic_Animate(); int AnglePos(); int Sonic_Angle(); int Floor_ChkTile(); int FindFloor(); int FindFloor2(); int Obj_CheckInFloor(); int FindWall(); int FindWall2(); FUNCINLINE int CalcRoomInFront(); FUNCINLINE int CalcRoomOverHead(); int Sonic_CheckFloor(); FUNCINLINE int ChkFloorEdge(); int ChkFloorEdge_Part2(); FUNCINLINE int CheckRightCeilingDist(); int CheckRightWallDist(); int CheckRightWallDist_Part2(); int CheckCeilingDist(); FUNCINLINE int CheckSlopeDist(); FUNCINLINE int CheckLeftCeilingDist(); int CheckLeftWallDist(); int CheckLeftWallDist_Part2(); int LoadSonicDynPLC(); int KillCharacter(); int DisplaySprite(); int ObjectMoveAndFall(); int ObjectMove(); FUNCINLINE int TouchResponse(); FUNCINLINE void PositionCamera(short x, short y); // additional temporary storage int i; int n; int stack[16]; // quick and dirty fix to force a function return to exit the object char double_return; // quick and dirty fix for external object variables char a1_status;/////////////////////!!! (a1) char a1_width_pixels;///////////////!!! (a1) short a1_x_pos;//////////////////////!!! (a1) char Update_HUD_lives_2P; char Update_HUD_rings_2P; char Update_HUD_timer_2P; char Update_HUD_score_2P; char Two_player_mode; short Water_Level_1; char Palette_frame_count; char Super_Sonic_palette; short Super_Sonic_frame_count; char Water_flag; char Extra_life_flags_2P; char Control_Locked; short Chain_Bonus_counter; char Current_Boss_ID; short Level_Inactive_flag; short Timer_frames; short Debug_object; short Debug_placement_mode; short Debug_mode_flag; char Emerald_count; char Continue_count; char Super_Sonic_flag; char Time_Over_flag; char Update_HUD_lives; char Update_HUD_rings; char Update_HUD_timer; char Update_HUD_score; char Update_Bonus_score; short Chain_Bonus_counter; short Perfect_rings_left; char Time_Over_flag; char Time_Over_flag_2P; char Last_star_pole_hit; char Last_star_pole_hit_2P; int Timer; short Timer_minute_word; char Timer_minute; char Timer_second; char Timer_millisecond; #ifdef __cplusplus } #endif #endif
001tomclark-research-check
Source/Engine/obj01.h
C
gpl2
3,401
#include <stdio.h> #include <allegro.h> #include "structs.h" #include "common.h" #include "m68k.h" #include "script.h" FUNCINLINE void get_ccr_flags(){ cc_x = (sr >> 4) & 1; cc_n = (sr >> 3) & 1; cc_z = (sr >> 2) & 1; cc_v = (sr >> 1) & 1; cc_c = sr & 1; } FUNCINLINE void store_ccr_flags(){ sr &= 0xFFE0; sr += ((cc_x << 4) + (cc_n << 3) + (cc_z << 2) + (cc_v << 1) + cc_c); } int read_script(char s, char format){ unsigned int value; //allegro_message("read_script"); //allegro_message("s = %i", s); switch(s){ case 1: value = obj_script[pc]; pc++; break; case 2: value = obj_script[pc] + (obj_script[pc+1] << 8); pc += 2; break; case 3: value = obj_script[pc] + (obj_script[pc+1] << 8) + (obj_script[pc+2] << 16); pc += 3; break; case 4: value = obj_script[pc] + (obj_script[pc+1] << 8) + (obj_script[pc+2] << 16) + (obj_script[pc+3] << 24); pc += 4; break; } //allegro_message("value = %X", value); if(format == MOTOROLA) value = swap_endian(s, value); //allegro_message("value = %X", value); return value; } int swap_endian(char s, unsigned int v){ if(s == 2) v = (((v >> 8) & 0xFF) + (v << 8)) & 0xFFFF; else if(s == 4){ v = (v >> 24) + ((v >> 8) & 0x0000FF00) + ((v << 8) & 0x00FF0000) + (v << 24); } return v; } int calc_effective_address(char s, char m, char r){ int i; int index; int xn; //allegro_message("calc_effective_address"); ea_big_endian = 0; switch(m){ case 0: // Dn ea = (int)&reg_d[r]; break; case 1: // An ea = (int)&reg_a[r]; break; case 2: // (An) ea = reg_a[r]; if(!addr_literal){ if(((ea >> 16) & 0xFF) == 0xFF) ea = (int)(&ram_68k) + 0xFFFF - (ea & 0xFFFF) - (s-1); else ea += (int)obj_script; } break; case 3: // (An)+ ea = reg_a[r]; if(r == 7){ if(s == 4) reg_a[r] += 4; else reg_a[r] += 2; } else reg_a[r] += s; if(!addr_literal){ if(((ea >> 16) & 0xFF) == 0xFF) ea = (int)(&ram_68k) + 0xFFFF - (ea & 0xFFFF) - (s-1); else ea += (int)obj_script; } break; case 4: // -(An) if(r == 7){ if(s == 4) reg_a[r] -= 4; else reg_a[r] -= 2; } else reg_a[r] -= s; ea = reg_a[r]; if(!addr_literal){ if(((ea >> 16) & 0xFF) == 0xFF) ea = (int)(&ram_68k) + 0xFFFF - (ea & 0xFFFF) - (s-1); else ea += (int)obj_script; } break; case 5: // (D16, An) ea = reg_a[r] + read_script(2, MOTOROLA); if(!addr_literal){ if(((ea >> 16) & 0xFF) == 0xFF) ea = (int)(&ram_68k) + 0xFFFF - (ea & 0xFFFF) - (s-1); else ea += (int)obj_script; } break; case 6: // (D8, An, Xn) ea = read_script(2, MOTOROLA); index = ea >> 8; if(index & 0x80) xn = reg_a[(index >> 4) & 7]; else xn = reg_d[(index >> 4) & 7]; if(index & 8) ea = (signed char)(ea & 0xFF) + reg_a[r] + xn; else ea = (signed char)(ea & 0xFF) + reg_a[r] + (signed short)xn; if(!addr_literal){ if(((ea >> 16) & 0xFF) == 0xFF) ea = (int)(&ram_68k) + 0xFFFF - (ea & 0xFFFF) - (s-1); else ea += (int)obj_script; } break; case 7: switch(r){ case 0: // (xxx).W ea = read_script(2, MOTOROLA); if(!addr_literal){ if(ea & 0x8000){ ea = ea | 0xFFFF0000; ea = (int)(&ram_68k) + 0xFFFF - (ea & 0xFFFF) - (s-1); } else ea += (int)obj_script; } break; case 1: // (xxx).L ea = read_script(4, MOTOROLA); if(!addr_literal){ if(((ea >> 16) & 0xFF) == 0xFF) ea = (int)(&ram_68k) + 0xFFFF - (ea & 0xFFFF) - (s-1); else ea += (int)obj_script; } break; case 2: // (D16, PC) i = read_script(2, MOTOROLA); ea = pc + (short)i; if(!addr_literal){ //if(((ea >> 16) & 0xFF) == 0xFF) // ea = (int)(&ram_68k) + 0xFFFF - (ea & 0xFFFF) - (s-1); //else ea += (int)obj_script; } break; case 3: // (D8, PC, Xn) ea = read_script(2, MOTOROLA); i = ea & 0xFF; index = ea >> 8; if(index & 0x80) xn = reg_a[(index >> 4) & 7]; else xn = reg_d[(index >> 4) & 7]; if(index & 8) ea = (signed char)(ea & 0xFF) + pc-2 + xn; else ea = (signed char)(ea & 0xFF) + pc-2 + (signed short)xn; if(!addr_literal){ //if(((ea >> 16) & 0xFF) == 0xFF) // ea = (int)(&ram_68k) + 0xFFFF - (ea & 0xFFFF) - (s-1); //else ea += (int)obj_script; ea_big_endian = 1; } break; case 4: // #imm if(s == 4) imm = read_script(4, MOTOROLA); else imm = read_script(2, MOTOROLA); ea = (int)&imm; break; } } addr_literal = 0; return 0; } void op_add(short data){ char reg = (data >> 9) & 7; char opmode = (data >> 6) & 7; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; int Sm; int Dm; int Rm; unsigned int i; if(opmode == 3 || opmode == 7){ #ifdef ENABLE_LOGGING WriteLog("ADDA"); #endif calc_effective_address((opmode >> 1) + 1, ea_mode, ea_reg); } else{ #ifdef ENABLE_LOGGING WriteLog("ADD"); #endif calc_effective_address(1 << (opmode & 3), ea_mode, ea_reg); } if(opmode == 3 || opmode == 7){ // ADDA switch(opmode){ case 3: // word i = reg_a[reg] & 0xFFFF; i += *(short *)ea; reg_a[reg] = (reg_a[reg] & 0xFFFF0000) + (unsigned short)i; break; case 7: // long reg_a[reg] += *(int *)ea; break; } } else if(opmode & 4){ // ADD switch(opmode & 3){ case 0: Sm = reg_d[reg]; Dm = *(char *)ea; i = *(char *)ea; i += reg_d[reg]; *(char *)ea = (char)i; Rm = *(char *)ea; break; case 1: Sm = reg_d[reg]; Dm = *(short *)ea; i = *(short *)ea; i += reg_d[reg]; *(short *)ea = (short)i; Rm = *(short *)ea; break; case 2: Sm = reg_d[reg]; Dm = *(short *)ea; *(int *)ea += reg_d[reg]; Rm = *(int *)ea; break; } } else{ // ADD switch(opmode & 3){ case 0: Sm = *(char *)ea; Dm = (char)reg_d[reg]; i = reg_d[reg] & 0xFF; i += *(char *)ea; reg_d[reg] = (reg_d[reg] & 0xFFFFFF00) + (unsigned char)i; Rm = (char)reg_d[reg]; break; case 1: Sm = *(short *)ea; Dm = (short)reg_d[reg]; i = reg_d[reg] & 0xFFFF; i += *(short *)ea; reg_d[reg] = (reg_d[reg] & 0xFFFF0000) + (unsigned short)i; Rm = (short)reg_d[reg]; break; case 2: Sm = *(int *)ea; Dm = reg_d[reg]; reg_d[reg] += *(int *)ea; Rm = reg_d[reg]; break; } } if(!(opmode == 3 || opmode == 7)){ get_ccr_flags(); cc_n = (Rm < 0); cc_z = (Rm == 0); Sm >>= 31; Dm >>= 31; Rm >>= 31; cc_v = ((Sm && Dm && !Rm) || (!Sm && !Dm && Rm)); cc_c = ((Sm && Dm) || (!Rm && Dm) || (Sm && !Rm)); cc_x = cc_c; store_ccr_flags(); } } void op_addi(short data){ char size = (data >> 6) & 3; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; int Sm; int Dm; int Rm; //unsigned int i; #ifdef ENABLE_LOGGING WriteLog("ADDI"); #endif calc_effective_address(1 << size, ea_mode, ea_reg); switch(size){ case 0: Sm = (char)imm; Dm = *(char *)ea; imm = read_script(2, MOTOROLA); *(char *)ea += imm; Rm = *(char *)ea; break; case 1: Sm = (short)imm; Dm = *(short *)ea; imm = read_script(2, MOTOROLA); *(short *)ea += imm; Rm = *(short *)ea; break; case 2: Sm = imm; Dm = *(int *)ea; imm = read_script(4, MOTOROLA); *(int *)ea += imm; Rm = *(int *)ea; break; } get_ccr_flags(); cc_n = (Rm < 0); cc_z = (Rm == 0); Sm >>= 31; Dm >>= 31; Rm >>= 31; cc_v = ((Sm && Dm && !Rm) || (!Sm && !Dm && Rm)); cc_c = ((Sm && Dm) || (!Rm && Dm) || (Sm && !Rm)); cc_x = cc_c; store_ccr_flags(); } void op_addq(short data){ char size = (data >> 6) & 3; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; int Sm; int Dm; int Rm; //unsigned int i; #ifdef ENABLE_LOGGING WriteLog("ADDQ"); #endif calc_effective_address(1 << size, ea_mode, ea_reg); switch(size){ case 0: Sm = (char)imm; Dm = *(char *)ea; imm = (data >> 9) & 7; if(!imm) imm = 8; *(char *)ea += imm; Rm = *(char *)ea; break; case 1: Sm = (short)imm; Dm = *(short *)ea; imm = (data >> 9) & 7; if(!imm) imm = 8; *(short *)ea += imm; Rm = *(short *)ea; break; case 2: Sm = imm; Dm = *(int *)ea; imm = (data >> 9) & 7; if(!imm) imm = 8; *(int *)ea += imm; Rm = *(int *)ea; break; } get_ccr_flags(); cc_n = (Rm < 0); cc_z = (Rm == 0); Sm >>= 31; Dm >>= 31; Rm >>= 31; cc_v = ((Sm && Dm && !Rm) || (!Sm && !Dm && Rm)); cc_c = ((Sm && Dm) || (!Rm && Dm) || (Sm && !Rm)); cc_x = cc_c; store_ccr_flags(); } void op_and(short data){ char reg = (data >> 9) & 7; char opmode = (data >> 6) & 7; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; unsigned int i; #ifdef ENABLE_LOGGING WriteLog("AND"); #endif get_ccr_flags(); calc_effective_address(1 << (opmode & 3), ea_mode, ea_reg); if(opmode & 4){ switch(opmode & 3){ case 0: i = *(char *)ea; i &= reg_d[reg]; *(char *)ea = (char)i; cc_n = (i >> 7) & 1; break; case 1: i = *(short *)ea; i &= reg_d[reg]; *(short *)ea = (short)i; cc_n = (i >> 15) & 1; break; case 2: *(int *)ea &= reg_d[reg]; cc_n = (i >> 31) & 1; break; } } else{ switch(opmode & 3){ case 0: i = reg_d[reg] & 0xFF; i &= *(char *)ea; reg_d[reg] = (reg_d[reg] & 0xFFFFFF00) + (unsigned char)i; cc_n = (reg_d[reg] >> 7) & 1; break; case 1: i = reg_d[reg] & 0xFFFF; i &= *(short *)ea; reg_d[reg] = (reg_d[reg] & 0xFFFF0000) + (unsigned short)i; cc_n = (reg_d[reg] >> 15) & 1; break; case 2: reg_d[reg] &= *(int *)ea; cc_n = reg_d[reg] >> 31; break; } } cc_z = (i == 0); cc_v = 0; cc_c = 0; store_ccr_flags(); } void op_andi(short data){ char size = (data >> 6) & 3; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; //unsigned int i; #ifdef ENABLE_LOGGING WriteLog("ANDI"); #endif if(data == 0x23C){ imm = read_script(2, MOTOROLA); ea = (int)&sr; *(char *)ea &= imm; return; } if(data == 0x27C){ imm = read_script(2, MOTOROLA); ea = (int)&sr; *(short *)ea &= imm; return; } get_ccr_flags(); calc_effective_address(1 << size, ea_mode, ea_reg); switch(size){ case 0: imm = read_script(2, MOTOROLA); *(char *)ea &= imm; cc_n = ((*(char *)ea & 0x80) != 0); cc_z = (*(char *)ea == 0); break; case 1: imm = read_script(2, MOTOROLA); *(short *)ea &= imm; cc_n = ((*(short *)ea & 0x8000) != 0); cc_z = (*(short *)ea == 0); break; case 2: imm = read_script(4, MOTOROLA); *(int *)ea &= imm; cc_n = ((*(int *)ea & 0x80000000) != 0); cc_z = (*(int *)ea == 0); break; } cc_v = 0; cc_c = 0; store_ccr_flags(); } void op_bcc(short data){ char condition = (data >> 8) & 0xF; int displacement = data & 0xFF; char result; get_ccr_flags(); switch(condition){ case 0: #ifdef ENABLE_LOGGING WriteLog("BRA"); #endif result = 1; break; case 1: #ifdef ENABLE_LOGGING WriteLog("BSR"); #endif result = 1; break; case 2: #ifdef ENABLE_LOGGING WriteLog("BHI"); #endif result = (!cc_c && !cc_z); break; case 3: #ifdef ENABLE_LOGGING WriteLog("BLS"); #endif result = (cc_c || cc_z); break; case 4: #ifdef ENABLE_LOGGING WriteLog("BCC"); #endif result = (!cc_c); break; case 5: #ifdef ENABLE_LOGGING WriteLog("BCS"); #endif result = cc_c; break; case 6: #ifdef ENABLE_LOGGING WriteLog("BNE"); #endif result = (!cc_z); break; case 7: #ifdef ENABLE_LOGGING WriteLog("BEQ"); #endif result = cc_z; break; case 8: #ifdef ENABLE_LOGGING WriteLog("BVC"); #endif result = (!cc_v); break; case 9: #ifdef ENABLE_LOGGING WriteLog("BVS"); #endif result = cc_v; break; case 10: #ifdef ENABLE_LOGGING WriteLog("BPL"); #endif result = (!cc_n); break; case 11: #ifdef ENABLE_LOGGING WriteLog("BMI"); #endif result = cc_n; break; case 12: #ifdef ENABLE_LOGGING WriteLog("BGE"); #endif result = ((cc_n && cc_v) || (!cc_n && !cc_v)); break; case 13: #ifdef ENABLE_LOGGING WriteLog("BLT"); #endif result = ((cc_n && !cc_v) || (!cc_n && cc_v)); break; case 14: #ifdef ENABLE_LOGGING WriteLog("BGT"); #endif result = ((cc_n && cc_v && !cc_z) || (!cc_n && !cc_v && !cc_z)); break; case 15: #ifdef ENABLE_LOGGING WriteLog("BLE"); #endif result = (cc_z || (cc_n && !cc_v) || (!cc_n && cc_v)); break; } /*if(pc >= 0x7E && pc <= 0x82){ allegro_message("%X", cc_z); rest(35); }*/ if(condition == 1){ // BSR reg_a[7] -= 4; *(int *)(&ram_68k[reg_a[7] & 0xFFFF]) = pc; if(displacement == 0) *(int *)(&ram_68k[reg_a[7] & 0xFFFF]) += 2; } if(displacement == 0){ // 16-bit displacement = read_script(2, MOTOROLA) - 2; //pc -= 2; if(displacement & 0x8000) displacement |= 0xFFFF8000; } //else if(displacement == 0xFF) // 32-bit // displacement = read_script(4, MOTOROLA); else if(displacement & 0x80){ // 8-bit displacement |= 0xFFFFFF80; //pc -= 2; } if(result) pc += (displacement/* - 2*/); //else if(displacement == 0) // pc += 2; } void op_bchg(short data){ char size; char reg = (data >> 9) & 7; char opmode = (data >> 6) & 7; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; unsigned int i; #ifdef ENABLE_LOGGING WriteLog("BCHG"); #endif if(ea_mode == 0) size = 4; else size = 1; get_ccr_flags(); if(opmode == 5){ calc_effective_address(size, ea_mode, ea_reg); switch(size){ case 1: i = *(char *)ea; cc_z = ((i & (1 << (reg_d[reg] % 8))) == 0); i ^= (1 << (reg_d[reg] % 8)); *(char *)ea = (char)i; break; case 4: i = *(int *)ea; cc_z = ((i & (1 << (reg_d[reg] % 32))) == 0); i ^= (1 << (reg_d[reg] % 32)); *(int *)ea = (int)i; break; } } else{ switch(size){ case 1: imm = read_script(2, MOTOROLA); calc_effective_address(size, ea_mode, ea_reg); i = *(int *)ea; cc_z = ((i & (1 << (imm % 8))) == 0); i ^= (1 << (imm % 8)); *(char *)ea = (char)i; break; case 4: imm = read_script(2, MOTOROLA); calc_effective_address(size, ea_mode, ea_reg); i = *(int *)ea; cc_z = ((i & (1 << (imm % 32))) == 0); i ^= (1 << (imm % 32)); *(int *)ea = (int)i; break; } } store_ccr_flags(); } void op_bclr(short data){ char size; char reg = (data >> 9) & 7; char opmode = (data >> 6) & 7; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; unsigned int i; #ifdef ENABLE_LOGGING WriteLog("BCLR"); #endif if(ea_mode == 0) size = 4; else size = 1; get_ccr_flags(); if(opmode == 6){ calc_effective_address(size, ea_mode, ea_reg); switch(size){ case 1: i = *(char *)ea; cc_z = ((i & (1 << (reg_d[reg] % 8))) == 0); i = ~((~i) | (1 << (reg_d[reg] % 8))); *(char *)ea = (char)i; break; case 4: i = *(int *)ea; cc_z = ((i & (1 << (reg_d[reg] % 32))) == 0); i = ~((~i) | (1 << (reg_d[reg] % 32))); *(int *)ea = (int)i; break; } } else{ switch(size){ case 1: imm = read_script(2, MOTOROLA); calc_effective_address(size, ea_mode, ea_reg); i = *(char *)ea; cc_z = ((i & (1 << (imm % 8))) == 0); i = ~((~i) | (1 << (imm % 8))); *(char *)ea = (char)i; break; case 4: imm = read_script(2, MOTOROLA); calc_effective_address(size, ea_mode, ea_reg); i = *(int *)ea; cc_z = ((i & (1 << (imm % 32))) == 0); i = ~((~i) | (1 << (imm % 32))); *(int *)ea = (int)i; break; } } store_ccr_flags(); } void op_bset(short data){ char size; char reg = (data >> 9) & 7; char opmode = (data >> 6) & 7; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; unsigned int i; #ifdef ENABLE_LOGGING WriteLog("BSET"); #endif if(ea_mode == 0) size = 4; else size = 1; get_ccr_flags(); if(opmode == 7){ calc_effective_address(size, ea_mode, ea_reg); switch(size){ case 1: i = *(char *)ea; cc_z = ((i & (1 << (reg_d[reg] % 8))) == 0); i |= (1 << (reg_d[reg] % 8)); *(char *)ea = (char)i; break; case 4: i = *(int *)ea; cc_z = ((i & (1 << (reg_d[reg] % 32))) == 0); i |= (1 << (reg_d[reg] % 32)); *(int *)ea = (int)i; break; } } else{ switch(size){ case 1: imm = read_script(2, MOTOROLA); calc_effective_address(size, ea_mode, ea_reg); i = *(int *)ea; cc_z = ((i & (1 << (imm % 8))) == 0); i |= (1 << (imm % 8)); *(char *)ea = (char)i; break; case 4: imm = read_script(2, MOTOROLA); calc_effective_address(size, ea_mode, ea_reg); i = *(int *)ea; cc_z = ((i & (1 << (imm % 32))) == 0); i |= (1 << (imm % 32)); *(int *)ea = (int)i; break; } } store_ccr_flags(); } void op_btst(short data){ char size; // 1 char reg = (data >> 9) & 7; // 4 char opmode = (data >> 6) & 7; // 0 char ea_mode = (data >> 3) & 7; // 5 char ea_reg = data & 7; // 0 unsigned int i; #ifdef ENABLE_LOGGING WriteLog("BTST"); #endif if(ea_mode == 0) size = 4; else size = 1; get_ccr_flags(); if(opmode == 4){ calc_effective_address(size, ea_mode, ea_reg); switch(size){ case 1: i = *(char *)ea; i >>= (reg_d[reg] % 8); cc_z = (i & 1) ^ 1; break; case 4: i = *(int *)ea; i >>= (reg_d[reg] % 32); cc_z = (i & 1) ^ 1; break; } } else{ switch(size){ case 1: imm = read_script(2, MOTOROLA); calc_effective_address(size, ea_mode, ea_reg); i = *(int *)ea; i >>= (imm % 8); cc_z = (i & 1) ^ 1; break; case 4: imm = read_script(2, MOTOROLA); calc_effective_address(size, ea_mode, ea_reg); i = *(int *)ea; i >>= (imm % 32); cc_z = (i & 1) ^ 1; break; } } store_ccr_flags(); } void op_clr(short data){ char size = (data >> 6) & 3; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; //unsigned int i; #ifdef ENABLE_LOGGING WriteLog("CLR"); #endif calc_effective_address(1 << size, ea_mode, ea_reg); switch(size){ case 0: *(char *)ea = 0; break; case 1: *(short *)ea = 0; break; case 2: *(int *)ea = 0; break; } get_ccr_flags(); cc_n = 0; cc_z = 1; cc_v = 0; cc_c = 0; store_ccr_flags(); } void op_cmp(short data){ char reg = (data >> 9) & 7; char opmode = (data >> 6) & 7; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; int Rm; int Dm; int Sm; //unsigned int i; #ifdef ENABLE_LOGGING if(opmode < 3) WriteLog("CMP"); else WriteLog("CMPA"); #endif calc_effective_address(1 << (opmode & 3), ea_mode, ea_reg); switch(opmode & 7){ case 0: Rm = (char)reg_d[reg] - *(char *)ea; Dm = (char)reg_d[reg]; Sm = *(char *)ea; //if(Sm & 0x80) // Sm |= 0xFFFFFF80; break; case 1: Rm = (short)reg_d[reg] - *(short *)ea; Dm = (short)reg_d[reg]; Sm = *(short *)ea; //if(Sm & 0x8000) // Sm |= 0xFFFF8000; break; case 2: Rm = reg_d[reg] - *(int *)ea; Dm = reg_d[reg]; Sm = *(int *)ea; break; case 3: Rm = (short)reg_a[reg] - *(short *)ea; Dm = (short)reg_a[reg]; Sm = *(short *)ea; break; case 7: Rm = reg_a[reg] - *(int *)ea; Dm = reg_a[reg]; Sm = *(int *)ea; break; } get_ccr_flags(); cc_n = (Rm < 0); cc_z = (Rm == 0); Sm >>= 31; Dm >>= 31; Rm >>= 31; cc_v = ((!Sm && Dm && !Rm) || (Sm && !Dm && Rm)); cc_c = ((Sm && !Dm) || (Rm && !Dm) || (Sm && Rm)); store_ccr_flags(); } void op_cmpi(short data){ char size = (data >> 6) & 3; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; int Rm; int Dm; int Sm; //unsigned int i; #ifdef ENABLE_LOGGING WriteLog("CMPI"); #endif switch(size){ case 0: imm = read_script(2, MOTOROLA); calc_effective_address(1 << size, ea_mode, ea_reg); Rm = *(char *)ea - (char)imm; Dm = *(char *)ea; Sm = (char)imm; //if(Sm & 0x80) // Sm |= 0xFFFFFF80; break; case 1: imm = read_script(2, MOTOROLA); calc_effective_address(1 << size, ea_mode, ea_reg); Rm = *(short *)ea - (short)imm; Dm = *(short *)ea; Sm = (short)imm; //if(Sm & 0x8000) // Sm |= 0xFFFF8000; break; case 2: imm = read_script(4, MOTOROLA); calc_effective_address(1 << size, ea_mode, ea_reg); Rm = *(int *)ea - imm; Dm = *(int *)ea; Sm = imm; break; } get_ccr_flags(); cc_n = (Rm < 0); cc_z = (Rm == 0); Sm >>= 31; Dm >>= 31; Rm >>= 31; cc_v = ((!Sm && Dm && !Rm) || (Sm && !Dm && Rm)); cc_c = ((Sm && !Dm) || (Rm && !Dm) || (Sm && Rm)); store_ccr_flags(); } void op_dbcc(short data){ char condition = (data >> 8) & 0xF; int reg = data & 7; short displacement; char result; get_ccr_flags(); displacement = read_script(2, MOTOROLA); switch(condition){ case 0: #ifdef ENABLE_LOGGING WriteLog("DBT"); #endif return; //break; case 1: #ifdef ENABLE_LOGGING WriteLog("DBF"); #endif if((short)reg_d[reg]) result = 0; else result = 1; break; case 2: #ifdef ENABLE_LOGGING WriteLog("DBHI"); #endif result = (!cc_c && !cc_z); break; case 3: #ifdef ENABLE_LOGGING WriteLog("DBLS"); #endif result = (cc_c || cc_z); break; case 4: #ifdef ENABLE_LOGGING WriteLog("DBCC"); #endif result = (!cc_c); break; case 5: #ifdef ENABLE_LOGGING WriteLog("DBCS"); #endif result = cc_c; break; case 6: #ifdef ENABLE_LOGGING WriteLog("DBNE"); #endif result = (!cc_z); break; case 7: #ifdef ENABLE_LOGGING WriteLog("DBEQ"); #endif result = cc_z; break; case 8: #ifdef ENABLE_LOGGING WriteLog("DBVC"); #endif result = (!cc_v); break; case 9: #ifdef ENABLE_LOGGING WriteLog("DBVS"); #endif result = cc_v; break; case 10: #ifdef ENABLE_LOGGING WriteLog("DBPL"); #endif result = (!cc_n); break; case 11: #ifdef ENABLE_LOGGING WriteLog("DBMI"); #endif result = cc_n; break; case 12: #ifdef ENABLE_LOGGING WriteLog("DBGE"); #endif result = ((cc_n && cc_v) || (!cc_n && !cc_v)); break; case 13: #ifdef ENABLE_LOGGING WriteLog("DBLT"); #endif result = ((cc_n && !cc_v) || (!cc_n && cc_v)); break; case 14: #ifdef ENABLE_LOGGING WriteLog("DBGT"); #endif result = ((cc_n && cc_v && !cc_z) || (!cc_n && !cc_v && !cc_z)); break; case 15: #ifdef ENABLE_LOGGING WriteLog("DBLE"); #endif result = (cc_z || (cc_n && !cc_v) || (!cc_n && cc_v)); break; } /*if(pc >= 0x7E && pc <= 0x82){ allegro_message("%X", cc_z); rest(35); }*/ if(!result){ (*(short *)(&reg_d[reg]))--; if((*(short *)(&reg_d[reg])) != -1) pc += (displacement - 2); } } void op_eor(short data){ char reg = (data >> 9) & 7; char opmode = (data >> 6) & 7; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; unsigned int i; #ifdef ENABLE_LOGGING WriteLog("EOR"); #endif get_ccr_flags(); calc_effective_address(1 << (opmode & 3), ea_mode, ea_reg); if(opmode & 4){ switch(opmode & 3){ case 0: i = *(char *)ea; i ^= reg_d[reg]; *(char *)ea = (char)i; cc_n = ((*(char *)ea & 0x80) != 0); cc_z = (*(char *)ea == 0); cc_v = 0; cc_c = 0; break; case 1: i = *(short *)ea; i ^= reg_d[reg]; *(short *)ea = (short)i; cc_n = ((*(short *)ea & 0x8000) != 0); cc_z = (*(short *)ea == 0); cc_v = 0; cc_c = 0; break; case 2: *(int *)ea ^= reg_d[reg]; cc_n = ((*(int *)ea & 0x80000000) != 0); cc_z = (*(int *)ea == 0); cc_v = 0; cc_c = 0; break; } } else{ switch(opmode & 3){ case 0: i = reg_d[reg] & 0xFF; i ^= *(char *)ea; reg_d[reg] = (reg_d[reg] & 0xFFFFFF00) + (unsigned char)i; cc_n = ((reg_d[reg] & 0x80) != 0); cc_z = ((char)reg_d[reg] == 0); cc_v = 0; cc_c = 0; break; case 1: i = reg_d[reg] & 0xFFFF; i ^= *(short *)ea; reg_d[reg] = (reg_d[reg] & 0xFFFF0000) + (unsigned short)i; cc_n = ((reg_d[reg] & 0x8000) != 0); cc_z = ((short)reg_d[reg] == 0); cc_v = 0; cc_c = 0; break; case 2: reg_d[reg] ^= *(int *)ea; cc_n = ((reg_d[reg] & 0x80000000) != 0); cc_z = ((int)reg_d[reg] == 0); cc_v = 0; cc_c = 0; break; } } store_ccr_flags(); } void op_eori(short data){ char size = (data >> 6) & 3; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; unsigned int i; #ifdef ENABLE_LOGGING WriteLog("EORI"); #endif if(data == 0xA3C){ imm = read_script(2, MOTOROLA); ea = (int)&sr; *(char *)ea ^= imm; return; } if(data == 0xA7C){ imm = read_script(2, MOTOROLA); ea = (int)&sr; *(short *)ea ^= imm; return; } get_ccr_flags(); calc_effective_address(1 << size, ea_mode, ea_reg); switch(size){ case 0: imm = read_script(2, MOTOROLA); *(char *)ea ^= imm; cc_n = ((*(char *)ea & 0x80) != 0); cc_z = (*(char *)ea == 0); cc_v = 0; cc_c = 0; break; case 1: imm = read_script(2, MOTOROLA); *(short *)ea ^= imm; cc_n = ((*(short *)ea & 0x8000) != 0); cc_z = (*(short *)ea == 0); cc_v = 0; cc_c = 0; break; case 2: imm = read_script(4, MOTOROLA); *(int *)ea ^= imm; cc_n = ((*(int *)ea & 0x80000000) != 0); cc_z = (*(int *)ea == 0); cc_v = 0; cc_c = 0; break; } store_ccr_flags(); } void op_ext(short data){ char opmode = (data >> 6) & 7; // size char reg = data & 7; char signbit; #ifdef ENABLE_LOGGING WriteLog("EXT"); #endif get_ccr_flags(); switch(opmode){ case 2: // byte -> word signbit = (reg_d[reg] >> 7) & 1; if(signbit) reg_d[reg] |= 0xFF00; else reg_d[reg] &= 0xFFFF00FF; cc_n = ((short)reg_d[reg] < 0); cc_z = ((short)reg_d[reg] == 0); break; case 3: // word -> long signbit = (reg_d[reg] >> 15) & 1; if(signbit) reg_d[reg] |= 0xFFFF0000; else reg_d[reg] &= 0xFFFF; cc_n = (reg_d[reg] < 0); cc_z = (reg_d[reg] == 0); break; } cc_v = 0; cc_c = 0; store_ccr_flags(); } void op_jmp(short data){ char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; calc_effective_address(4, ea_mode, ea_reg); if((data & 0xC0) == 0x80){ #ifdef ENABLE_LOGGING WriteLog("JSR"); #endif //reg_a[7]--; //ram_68k[reg_a[7] & 0xFFFF] = pc; reg_a[7] -= 4; *(int *)(&ram_68k[reg_a[7] & 0xFFFF]) = pc; } #ifdef ENABLE_LOGGING else WriteLog("JMP"); #endif pc = ea; ea = (int)obj_script; pc -= ea; } void op_lea(short data){ char reg = (data >> 9) & 7; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; #ifdef ENABLE_LOGGING WriteLog("LEA"); #endif addr_literal = 1; calc_effective_address(4, ea_mode, ea_reg); if(ea_mode == 7 && ea_reg == 0){ if(ea & 0x8000) ea |= 0xFFFF8000; } reg_a[reg] = ea; //reg_a[reg] = swap_endian(4, reg_a[reg]); } void op_lsd(short data){ char count = (data >> 9) & 7; // 4 char dr = (data >> 8) & 1; // 0 char size = (data >> 6) & 3; // 1 char ir = (data >> 5) & 1; // 0 char mode = (data >> 3) & 7; // 0 char reg = data & 7; // 1 char arithmetic = 0; if(dr){ #ifdef ENABLE_LOGGING if(size == 3){ if(count & 1) WriteLog("LSL"); else WriteLog("ASL"); } else if(mode & 1) WriteLog("LSL"); else WriteLog("ASL"); #endif } else{ if(size == 3){ if(count & 1){ #ifdef ENABLE_LOGGING WriteLog("LSR"); #endif } else{ arithmetic = 1; #ifdef ENABLE_LOGGING WriteLog("ASR"); #endif } } else if(mode & 1){ #ifdef ENABLE_LOGGING WriteLog("LSR"); #endif } else{ arithmetic = 1; #ifdef ENABLE_LOGGING WriteLog("ASR"); #endif } } if(size != 3){ // Destination is a register if(dr){ // LEFT SHIFT switch(size){ case 0: ea = (int)&reg_d[reg]; //ea += 3; if(ir) *(char *)ea <<= (reg_d[count] % 64); else *(char *)ea <<= count; break; case 1: ea = (int)&reg_d[reg]; //ea += 2; if(ir) *(short *)ea <<= (reg_d[count] % 64); else *(short *)ea <<= count; break; case 2: if(ir) reg_d[reg] <<= (reg_d[count] % 64); else reg_d[reg] <<= count; break; } } else{ // RIGHT SHIFT switch(size){ case 0: ea = (int)&reg_d[reg]; //ea += 3; if((*(char *)ea) & 0x80 && arithmetic){ if(ir){ *(char *)ea >>= (reg_d[count] % 64); *(char *)ea |= ((0xFF << (8 - (reg_d[count] % 64))) & 0xFF); } else{ *(char *)ea >>= count; *(char *)ea |= ((0xFF << (8 - count)) & 0xFF); } } else{ if(ir) *(char *)ea >>= (reg_d[count] % 64); else *(char *)ea >>= count; } break; case 1: ea = (int)&reg_d[reg]; //ea += 2; if((*(short *)ea) >> 15 && arithmetic){ if(ir){ *(short *)ea >>= (reg_d[count] % 64); *(short *)ea |= ((0xFFFF << (16 - (reg_d[count] % 64))) & 0xFFFF); } else{ *(short *)ea >>= count; *(short *)ea |= ((0xFF00 << (8 - count)) & 0xFF00); } } else{ if(ir) *(short *)ea >>= (reg_d[count] % 64); else *(short *)ea >>= count; } break; case 2: if(reg_d[reg] & 0x80000000 && arithmetic){ if(ir){ reg_d[reg] >>= (reg_d[count] % 64); reg_d[reg] |= ((0xFFFFFFFF << (32 - (reg_d[count] % 64))) & 0xFFFFFFFF); } else{ reg_d[reg] >>= count; reg_d[reg] |= ((0xFF000000 << (8 - count)) & 0xFF000000); } } else{ if(ir) reg_d[reg] >>= (reg_d[count] % 64); else reg_d[reg] >>= count; } break; } } } else{ // Destination is <EA> if(dr){ // LEFT SHIFT calc_effective_address(2, mode, reg); *(short *)ea <<= count; } else if((*(short *)ea) & 0x8000 && arithmetic){ // RIGHT SHIFT (arithmetic) calc_effective_address(2, mode, reg); *(short *)ea >>= count; *(short *)ea |= ((0xFF00 << (8 - count)) & 0xFF00); } else{ // RIGHT SHIFT (logical) calc_effective_address(2, mode, reg); *(short *)ea >>= count; } } } void op_move(short data){ char size = (data >> 12) & 3; char dest_reg = (data >> 9) & 7; char dest_mode = (data >> 6) & 7; char src_mode = (data >> 3) & 7; char src_reg = data & 7; int Rm; int *dest; int *src; char dest_big_endian; unsigned int i; if(size == 3) size = 2; else if(size == 2) size = 4; #ifdef ENABLE_LOGGING if(dest_mode == 1) WriteLog("MOVEA"); else WriteLog("MOVE"); #endif calc_effective_address(size, src_mode, src_reg); src = (int *)ea; dest_big_endian = ea_big_endian; calc_effective_address(size, dest_mode, dest_reg); dest = (int *)ea; ea_big_endian ^= dest_big_endian; switch(size){ case 1: *(char *)dest = *(char *)src; Rm = *(char *)src; break; case 2: *(short *)dest = *(short *)src; if(ea_big_endian) *(short *)dest = swap_endian(2, *(short *)dest); Rm = *(short *)src; break; case 4: *dest = *src; if(ea_big_endian) *dest = swap_endian(4, *dest); Rm = *src; break; } if(dest_mode != 1){ get_ccr_flags(); cc_n = (Rm < 0); cc_z = (Rm == 0); cc_v = 0; cc_c = 0; store_ccr_flags(); } } void op_movem(short data){ char dr = (data >> 10) & 1; char size = (data >> 6) & 1; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; short mask = read_script(2, MOTOROLA); int i; //allegro_message("%X\n%X\n%X", 2 << size, ea_mode, ea_reg); #ifdef ENABLE_LOGGING WriteLog("MOVEM"); #endif if(dr){ // Memory -> Registers if(ea_mode != 4){ // A7 is bit 15, D0 is bit 0 for(i=0; i < 8; i++){ if((mask >> i) & 1){ calc_effective_address(2 << size, ea_mode, ea_reg); if(size == 0) reg_d[i] = *(short *)ea; else reg_d[i] = *(int *)ea; //allegro_message("A1\n\nea = %X\na7 = %X\nREG = %X", ea, reg_a[7], i); } } for(i=0; i < 8; i++){ if((mask >> (i+8)) & 1){ calc_effective_address(2 << size, ea_mode, ea_reg); if(size == 0) reg_a[i] = *(short *)ea; else reg_a[i] = *(int *)ea; //allegro_message("A2\n\nea = %X\na7 = %X\nREG = %X", ea, reg_a[7], i); } } } else{ // D0 is bit 15, A7 is bit 0 for(i=0; i < 8; i++){ if((mask >> i) & 1){ calc_effective_address(2 << size, ea_mode, ea_reg); if(size == 0) reg_a[7-i] = *(short *)ea; else reg_a[7-i] = *(int *)ea; //allegro_message("A3\n\nea = %X\na7 = %X\nREG = %X", ea, reg_a[7], 7-i); } } for(i=0; i < 8; i++){ if((mask >> (i+8)) & 1){ calc_effective_address(2 << size, ea_mode, ea_reg); if(size == 0) reg_d[7-i] = *(short *)ea; else reg_d[7-i] = *(int *)ea; //allegro_message("A4\n\nea = %X\na7 = %X\nREG = %X", ea, reg_a[7], 7-i); } } } } else{ // Registers -> Memory if(ea_mode != 4){ // A7 is bit 15, D0 is bit 0 for(i=0; i < 8; i++){ if((mask >> i) & 1){ calc_effective_address(2 << size, ea_mode, ea_reg); if(size == 0) *(short *)ea = reg_d[i]; else *(int *)ea = reg_d[i]; //allegro_message("B1\n\nea = %X\na7 = %X\nREG = %X", ea, reg_a[7], i); } } for(i=0; i < 8; i++){ if((mask >> (i+8)) & 1){ calc_effective_address(2 << size, ea_mode, ea_reg); if(size == 0) *(short *)ea = reg_a[i]; else *(int *)ea = reg_a[i]; //allegro_message("B2\n\nea = %X\na7 = %X\nREG = %X", ea, reg_a[7], i); } } } else{ // D0 is bit 15, A7 is bit 0 for(i=0; i < 8; i++){ if((mask >> i) & 1){ calc_effective_address(2 << size, ea_mode, ea_reg); if(size == 0) *(short *)ea = reg_a[7-i]; else *(int *)ea = reg_a[7-i]; //allegro_message("B3\n\nea = %X\na7 = %X\nREG = %X", ea, reg_a[7], 7-i); } } for(i=0; i < 8; i++){ if((mask >> (i+8)) & 1){ calc_effective_address(2 << size, ea_mode, ea_reg); if(size == 0) *(short *)ea = reg_d[7-i]; else *(int *)ea = reg_d[7-i]; //allegro_message("B4\n\nea = %X\na7 = %X\nREG = %X", ea, reg_a[7], 7-i); } } } } } void op_moveq(short data){ char reg = (data >> 9) & 7; unsigned int i; #ifdef ENABLE_LOGGING WriteLog("MOVEQ"); #endif i = data & 0xFF; if(data & 0x80) i |= 0xFFFFFF00; reg_d[reg] = i; get_ccr_flags(); cc_n = (reg_d[reg] < 0); cc_z = (reg_d[reg] == 0); cc_v = 0; cc_c = 0; store_ccr_flags(); } void op_muls(short data){ char reg = (data >> 9) & 7; char opmode = (data >> 6) & 7; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; int Sm; int Dm; int Rm; unsigned int i; if(opmode == 3){ #ifdef ENABLE_LOGGING WriteLog("MULU"); #endif calc_effective_address(2, ea_mode, ea_reg); } else{ #ifdef ENABLE_LOGGING WriteLog("MULS"); #endif calc_effective_address(2, ea_mode, ea_reg); } if(opmode == 3){ // MULU Sm = *(unsigned short *)ea; Dm = reg_d[reg] & 0xFFFF; Rm = Sm * Dm; reg_d[reg] = Rm; } else{ // MULS Sm = *(short *)ea; Dm = (short)reg_d[reg]; Rm = Sm * Dm; reg_d[reg] = Rm; } get_ccr_flags(); cc_n = (Rm < 0); cc_z = (Rm == 0); cc_v = 0; cc_c = 0; store_ccr_flags(); } void op_neg(short data){ char size = (data >> 6) & 3; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; int Dm; int Rm; unsigned int i; #ifdef ENABLE_LOGGING WriteLog("NEG"); #endif get_ccr_flags(); calc_effective_address(1 << size, ea_mode, ea_reg); switch(size){ case 0: Dm = (*(char *)ea)>>7; *(char *)ea = -(*(char *)ea); Rm = (*(char *)ea)>>7; cc_n = (*(char *)ea < 0); cc_z = (*(char *)ea == 0); cc_v = (Dm && Rm); cc_c = (Dm || Rm); cc_x = cc_c; break; case 1: Dm = (*(short *)ea)>>15; *(short *)ea = -(*(short *)ea); Rm = (*(short *)ea)>>15; cc_n = (*(short *)ea < 0); cc_z = (*(short *)ea == 0); cc_v = (Dm && Rm); cc_c = (Dm || Rm); cc_x = cc_c; break; case 2: Dm = (*(int *)ea)>>31; *(int *)ea = -(*(int *)ea); Rm = (*(int *)ea)>>31; cc_n = (*(int *)ea < 0); cc_z = (*(int *)ea == 0); cc_v = (Dm && Rm); cc_c = (Dm || Rm); cc_x = cc_c; break; } store_ccr_flags(); } void op_negx(short data){ char size = (data >> 6) & 3; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; int Dm; int Rm; //unsigned int i; #ifdef ENABLE_LOGGING WriteLog("NEGX"); #endif get_ccr_flags(); calc_effective_address(1 << size, ea_mode, ea_reg); switch(size){ case 0: Dm = *(char *)ea; *(char *)ea = -(*(char *)ea) - cc_x; Rm = *(char *)ea; break; case 1: Dm = *(short *)ea; *(short *)ea = -(*(short *)ea) - cc_x; Rm = *(short *)ea; break; case 2: Dm = *(int *)ea; *(int *)ea = -(*(int *)ea) - cc_x; Rm = *(int *)ea; break; } cc_n = (Rm < 0); if(Rm != 0) cc_z = 0; cc_v = (Dm && Rm); Dm >>= 31; Rm >>= 31; cc_c = (Dm || Rm); cc_x = cc_c; store_ccr_flags(); } void op_not(short data){ char size = (data >> 6) & 3; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; int Rm; //unsigned int i; #ifdef ENABLE_LOGGING WriteLog("NOT"); #endif get_ccr_flags(); calc_effective_address(1 << size, ea_mode, ea_reg); switch(size){ case 0: *(char *)ea = ~(*(char *)ea); Rm = *(char *)ea; break; case 1: *(short *)ea = ~(*(short *)ea); Rm = *(short *)ea; break; case 2: *(int *)ea = ~(*(int *)ea); Rm = *(int *)ea; break; } cc_n = (Rm < 0); cc_z = (Rm == 0); cc_v = 0; cc_c = 0; store_ccr_flags(); } void op_or(short data){ char reg = (data >> 9) & 7; char opmode = (data >> 6) & 7; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; int Sm; int Dm; int Rm; unsigned int i; #ifdef ENABLE_LOGGING WriteLog("OR"); #endif get_ccr_flags(); calc_effective_address(1 << (opmode & 3), ea_mode, ea_reg); if(opmode & 4){ switch(opmode & 3){ case 0: Sm = reg_d[reg]; Dm = *(char *)ea; i = *(char *)ea; i |= reg_d[reg]; *(char *)ea = (char)i; Rm = *(char *)ea; cc_n = ((Rm & 0x80) != 0); break; case 1: Sm = reg_d[reg]; Dm = *(short *)ea; i = *(short *)ea; i |= reg_d[reg]; *(short *)ea = (short)i; Rm = *(short *)ea; cc_n = ((Rm & 0x8000) != 0); break; case 2: Sm = reg_d[reg]; Dm = *(int *)ea; *(int *)ea |= reg_d[reg]; Rm = *(int *)ea; cc_n = ((Rm & 0x80000000) != 0); break; } } else{ switch(opmode & 3){ case 0: Sm = *(char *)ea; Dm = reg_d[reg]; i = reg_d[reg] & 0xFF; i |= *(char *)ea; reg_d[reg] = (reg_d[reg] & 0xFFFFFF00) + (unsigned char)i; Rm = reg_d[reg]; cc_n = ((Rm & 0x80000000) != 0); break; case 1: Sm = *(short *)ea; Dm = reg_d[reg]; i = reg_d[reg] & 0xFFFF; i |= *(short *)ea; reg_d[reg] = (reg_d[reg] & 0xFFFF0000) + (unsigned short)i; Rm = reg_d[reg]; cc_n = ((Rm & 0x80000000) != 0); break; case 2: Sm = *(int *)ea; Dm = reg_d[reg]; reg_d[reg] |= *(int *)ea; Rm = reg_d[reg]; cc_n = ((Rm & 0x80000000) != 0); break; } } cc_z = (Rm == 0); cc_v = 0; cc_c = 0; store_ccr_flags(); } void op_ori(short data){ char size = (data >> 6) & 3; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; int Rm; unsigned int i; #ifdef ENABLE_LOGGING WriteLog("ORI"); #endif if(data == 0x3C){ imm = read_script(2, MOTOROLA); ea = (int)&sr; *(char *)ea |= imm; return; } if(data == 0x7C){ imm = read_script(2, MOTOROLA); ea = (int)&sr; *(short *)ea |= imm; return; } get_ccr_flags(); calc_effective_address(1 << size, ea_mode, ea_reg); switch(size){ case 0: imm = read_script(2, MOTOROLA); *(char *)ea |= imm; Rm = *(char *)ea; break; case 1: imm = read_script(2, MOTOROLA); *(short *)ea |= imm; Rm = *(short *)ea; break; case 2: imm = read_script(4, MOTOROLA); *(int *)ea |= imm; Rm = *(int *)ea; break; } cc_n = (Rm < 0); cc_z = (Rm == 0); cc_v = 0; cc_c = 0; } void op_sub(short data){ char reg = (data >> 9) & 7; char opmode = (data >> 6) & 7; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; int Sm; int Dm; int Rm; unsigned int i; if(opmode == 3 || opmode == 7){ #ifdef ENABLE_LOGGING WriteLog("SUBA"); #endif calc_effective_address((opmode >> 1) + 1, ea_mode, ea_reg); } else{ #ifdef ENABLE_LOGGING WriteLog("SUB"); #endif calc_effective_address(1 << (opmode & 3), ea_mode, ea_reg); } if(opmode == 3 || opmode == 7){ // SUBA switch(opmode){ case 3: // word i = reg_a[reg] & 0xFFFF; i -= *(short *)ea; reg_a[reg] = (reg_a[reg] & 0xFFFF0000) + (unsigned short)i; break; case 7: // long reg_a[reg] -= *(int *)ea; break; } } else if(opmode & 4){ // SUB switch(opmode & 3){ case 0: Sm = (char)reg_d[reg]; Dm = *(char *)ea; i = *(char *)ea; i -= reg_d[reg]; *(char *)ea = (char)i; Rm = *(char *)ea; break; case 1: Sm = (short)reg_d[reg]; Dm = *(short *)ea; i = *(short *)ea; i -= reg_d[reg]; *(short *)ea = (short)i; Rm = *(short *)ea; break; case 2: Sm = reg_d[reg]; Dm = *(int *)ea; *(int *)ea -= reg_d[reg]; Rm = *(int *)ea; break; } } else{ // SUB switch(opmode & 3){ case 0: Sm = *(char *)ea; Dm = (char)reg_d[reg]; i = reg_d[reg] & 0xFF; i -= *(char *)ea; reg_d[reg] = (reg_d[reg] & 0xFFFFFF00) + (unsigned char)i; Rm = (char)reg_d[reg]; break; case 1: Sm = *(short *)ea; Dm = (short)reg_d[reg]; i = reg_d[reg] & 0xFFFF; i -= *(short *)ea; reg_d[reg] = (reg_d[reg] & 0xFFFF0000) + (unsigned short)i; Rm = (short)reg_d[reg]; break; case 2: Sm = *(int *)ea; Dm = reg_d[reg]; reg_d[reg] -= *(int *)ea; Rm = reg_d[reg]; break; } } if(!(opmode == 3 || opmode == 7)){ get_ccr_flags(); cc_n = (Rm < 0); cc_z = (Rm == 0); Sm >>= 31; Dm >>= 31; Rm >>= 31; cc_v = ((!Sm && Dm && !Rm) || (Sm && !Dm && Rm)); cc_c = ((Sm && !Dm) || (Rm && !Dm) || (Sm && Rm)); cc_x = cc_c; store_ccr_flags(); } } void op_subi(short data){ char size = (data >> 6) & 3; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; int Sm; int Dm; int Rm; //unsigned int i; #ifdef ENABLE_LOGGING WriteLog("SUBI"); #endif calc_effective_address(1 << size, ea_mode, ea_reg); switch(size){ case 0: imm = read_script(2, MOTOROLA); Sm = (char)imm; Dm = *(char *)ea; *(char *)ea -= imm; Rm = *(char *)ea; break; case 1: imm = read_script(2, MOTOROLA); Sm = (short)imm; Dm = *(short *)ea; *(short *)ea -= imm; Rm = *(short *)ea; break; case 2: imm = read_script(4, MOTOROLA); Sm = imm; Dm = *(int *)ea; *(int *)ea -= imm; Rm = *(int *)ea; break; } get_ccr_flags(); cc_n = (Rm < 0); cc_z = (Rm == 0); Sm >>= 31; Dm >>= 31; Rm >>= 31; cc_v = ((!Sm && Dm && !Rm) || (Sm && !Dm && Rm)); cc_c = ((Sm && !Dm) || (Rm && !Dm) || (Sm && Rm)); cc_x = cc_c; store_ccr_flags(); } void op_subq(short data){ char size = (data >> 6) & 3; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; int Sm; int Dm; int Rm; //unsigned int i; #ifdef ENABLE_LOGGING WriteLog("SUBQ"); #endif calc_effective_address(1 << size, ea_mode, ea_reg); switch(size){ case 0: imm = (data >> 9) & 7; if(!imm) imm = 8; Sm = (char)imm; Dm = *(char *)ea; *(char *)ea -= imm; Rm = *(char *)ea; break; case 1: imm = (data >> 9) & 7; if(!imm) imm = 8; Sm = (short)imm; Dm = *(short *)ea; *(short *)ea -= imm; Rm = *(short *)ea; break; case 2: imm = (data >> 9) & 7; if(!imm) imm = 8; Sm = (int)imm; Dm = *(int *)ea; *(int *)ea -= imm; Rm = *(int *)ea; break; } get_ccr_flags(); cc_n = (Rm < 0); cc_z = (Rm == 0); Sm >>= 31; Dm >>= 31; Rm >>= 31; cc_v = ((!Sm && Dm && !Rm) || (Sm && !Dm && Rm)); cc_c = ((Sm && !Dm) || (Rm && !Dm) || (Sm && Rm)); cc_x = cc_c; store_ccr_flags(); } void op_swap(short data){ char reg = data & 7; #ifdef ENABLE_LOGGING WriteLog("SWAP"); #endif reg_d[reg] = (reg_d[reg] >> 16) + (reg_d[reg] << 16); get_ccr_flags(); cc_n = (reg_d[reg] >> 31); cc_z = (reg_d[reg] == 0); cc_v = 0; cc_c = 0; store_ccr_flags(); } void op_tst(short data){ char size = (data >> 6) & 3; char ea_mode = (data >> 3) & 7; char ea_reg = data & 7; int Rm; //unsigned int i; #ifdef ENABLE_LOGGING WriteLog("TST"); #endif calc_effective_address(1 << size, ea_mode, ea_reg); switch(size){ case 0: Rm = *(char *)ea; break; case 1: Rm = *(short *)ea; break; case 2: Rm = *(int *)ea; break; } get_ccr_flags(); cc_n = (Rm < 0); cc_z = (Rm == 0); cc_v = 0; cc_c = 0; store_ccr_flags(); //if(pc >= 0x7A && pc <= 0x7E){ // allegro_message("*ea = %X\nram_68k = %X\n\nea = %X\n&ram_68k = %X\n\nRm = %X\ncc_z = %X", *(char *)ea, ram_68k[0xFFFF - 0xC3F2], ea, &ram_68k[0xFFFF - 0xC3F2], Rm, cc_z); // rest(35); //} }
001tomclark-research-check
Source/Engine/m68k.c
C
gpl2
47,563
#include <stdio.h> #include <allegro.h> #include "tools.h" #include "strings.h" #include "common.h" #include "text.h" #include "sprites.h" #include "draw.h" #include "obj01.h" void ShowBlockInfo(ZONE *z){ unsigned short val_tile_offset; int val_bmap_offset; char r, g, b; short val_block_offset; short val_tile; // 14 bits >> 0 & 0x3FFF unsigned int val_bmap; // 32 bits ---- ---- short val_block; // 14 bits >> 0 & 0x3FFF char val_mirror; // 1 bit >> 14 & 0x1 char val_flip; // 1 bit >> 15 & 0x1 char val_platform1; // 1 bit >> 22 & 0x1 char val_barrier1; // 1 bit >> 23 & 0x1 char val_platform2; // 1 bit >> 22 & 0x1 char val_barrier2; // 1 bit >> 23 & 0x1 char val_plane; // 1 bit >> 20 & 0x1 char val_translucency; // 4 bits >> 16 & 0xF //char VAL_RESERVED; // 1 bit >> 21 & 0x1 //short NumberOfTiles; short FullTileSize = (32 << tilesize); short TileBlockRow = (2 << tilesize); short TileMemoryBits = (4 + (tilesize << 1)); // How many bits to shift short OffsetX; short OffsetY; char tileblock_changed = 0; // TEMPORARY SOLUTION TO BAR PEOPLE FROM USING CRASH-PRONE EDITORS if(edit_mode > 1) edit_mode = 0; if(!edit_mode) return; //if(mouse_x < 0 || mouse_y > screen_resolution_x) return; //if(mouse_y < 0 || mouse_y > screen_resolution_y) return; OffsetX = p->Camera_X_pos + (((mouse_pos >> 16) - (screen_offset_x << screen_double_x)) >> screen_double_x); OffsetY = p->Camera_Y_pos + (((mouse_pos & 0xFFFF) - (screen_offset_y << screen_double_y)) >> screen_double_y); // correction for 320x224 with bars at top and bottom of screen if((mouse_pos >> 16) < (screen_offset_x << screen_double_x)) OffsetX = p->Camera_X_pos + (screen_offset_x >> screen_double_x); else if((mouse_pos >> 16) >= ((screen_resolution_x + screen_offset_x) << screen_double_x)) OffsetX = p->Camera_X_pos + ((screen_resolution_x + screen_offset_x) << screen_double_x) - 1; // correction for 320x224 with bars at top and bottom of screen if((mouse_pos & 0xFFFF) < (screen_offset_y << screen_double_y)) OffsetY = p->Camera_Y_pos + (screen_offset_y >> screen_double_y); else if((mouse_pos & 0xFFFF) >= ((screen_resolution_y + screen_offset_y) << screen_double_y)) OffsetY = p->Camera_Y_pos + ((screen_resolution_y + screen_offset_y) << screen_double_y) - 1; val_tile_offset = (OffsetX / FullTileSize) +((OffsetY & z->Act[act].Stage[stage].WrapPoint-1) / FullTileSize * tiles_x_long); val_tile = *(short *)(&z->TMAP[tmap_ptr+((val_tile_offset) << 1)]); if(val_tile > 0){ val_bmap_offset = bmap_ptr +(val_tile << TileMemoryBits) +(((OffsetX >> 4) & (TileBlockRow-1)) << 2) +(((((OffsetY & z->Act[act].Stage[stage].WrapPoint-1) >> 4) & (TileBlockRow-1)) << 2) * TileBlockRow); val_bmap = *(int *)(&z->BMAP[val_bmap_offset]); val_block = val_bmap & 0x3FFF; val_mirror = (val_bmap >> 14) & 1; val_flip = (val_bmap >> 15) & 1; val_platform1 = (val_bmap >> 16) & 1; val_barrier1 = (val_bmap >> 17) & 1; val_platform2 = (val_bmap >> 18) & 1; val_barrier2 = (val_bmap >> 19) & 1; val_plane = (val_bmap >> 20) & 1; val_translucency = (val_bmap >> 26) & 0x3F; OffsetX = ((mouse_pos >> 16) - (screen_offset_x << screen_double_x)) >> screen_double_x; OffsetY = ((mouse_pos & 0xFFFF) - (screen_offset_y << screen_double_y)) >> screen_double_y; // correction for 320x224 with bars at top and bottom of screen if((mouse_pos >> 16) < (screen_offset_x << screen_double_x)) OffsetX = (screen_offset_x >> screen_double_x); else if((mouse_pos >> 16) >= ((screen_resolution_x + screen_offset_x) << screen_double_x)) OffsetX = ((screen_resolution_x + screen_offset_x) << screen_double_x) - 1; // correction for 320x224 with bars at top and bottom of screen if((mouse_pos & 0xFFFF) < (screen_offset_y << screen_double_y)) OffsetY = (screen_offset_y >> screen_double_y); else if((mouse_pos & 0xFFFF) >= ((screen_resolution_y + screen_offset_y) << screen_double_y)) OffsetY = ((screen_resolution_y + screen_offset_y) << screen_double_y) - 1; if(edit_mode < EDIT_MODE_SOLIDITY){ DrawSprite(&(*z), LayerL[frame-1], 0x102, 1, NORMAL, 24, ((OffsetX+16) + (p->Camera_X_pos & 0xF) & 0xFFF0) - (p->Camera_X_pos & 0xF), (OffsetY + (p->Camera_Y_pos & 0xF) & 0xFFF0) - (p->Camera_Y_pos & 0xF)); DrawSprite(&(*z), LayerL[frame-1], 0x102, 0, NORMAL, 40, (OffsetX+16) + 0xC, OffsetY + 0xC); DrawText(OffsetX + 0x10, OffsetY + 0x10, (edit_selector == 0), "TILE"); DrawText(OffsetX + 0x10, OffsetY + 0x18, (edit_selector == 1), "BLOCK"); DrawText(OffsetX + 0x10, OffsetY + 0x20, (edit_selector == 2), "MIRROR"); DrawText(OffsetX + 0x10, OffsetY + 0x28, (edit_selector == 3), "FLIP"); DrawText(OffsetX + 0x10, OffsetY + 0x30, (edit_selector == 4), "PLAT"); DrawText(OffsetX + 0x10, OffsetY + 0x38, (edit_selector == 5), "BARR"); DrawText(OffsetX + 0x10, OffsetY + 0x40, (edit_selector == 6), "PLANE"); DrawText(OffsetX + 0x10, OffsetY + 0x48, (edit_selector == 7), "TRANS"); DrawCounter16(LayerH[frame-1], val_tile, OffsetX + 0x48, OffsetY + 0x10); DrawCounter16(LayerH[frame-1], val_block, OffsetX + 0x48, OffsetY + 0x18); DrawCounter16(LayerH[frame-1], val_mirror, OffsetX + 0x48, OffsetY + 0x20); DrawCounter16(LayerH[frame-1], val_flip, OffsetX + 0x48, OffsetY + 0x28); DrawCounter16(LayerH[frame-1], (val_platform2 << 8) + val_platform1, OffsetX + 0x48, OffsetY + 0x30); DrawCounter16(LayerH[frame-1], (val_barrier2 << 8) + val_barrier1, OffsetX + 0x48, OffsetY + 0x38); DrawCounter16(LayerH[frame-1], val_plane, OffsetX + 0x48, OffsetY + 0x40); DrawCounter16(LayerH[frame-1], val_translucency, OffsetX + 0x48, OffsetY + 0x48); } else{ //n = z->BSOL_AddressTable[z->Act[act].Stage[stage].BlockSolidity]; val_block_offset = z->BLOCK_AddressTable[z->Act[act].Stage[stage].BlockArt]+2; for(i=0; i < 32; i++){ for(n=0; n < 32; n++){ if(i+OffsetY + 0xC + 36 < screen_buffer_y && i+OffsetY + 0xC + 36 >= 0 && n+(OffsetX+16) + 0xC < screen_buffer_x && n+(OffsetX+16) + 0xC >= 0){ r = z->BLOCK[val_block_offset+(val_block<<10) + 1 + ((i>>1)<<6) + ((n>>1)<<2)]; g = z->BLOCK[val_block_offset+(val_block<<10) + 2 + ((i>>1)<<6) + ((n>>1)<<2)]; b = z->BLOCK[val_block_offset+(val_block<<10) + 3 + ((i>>1)<<6) + ((n>>1)<<2)]; if(r < 64 && g < 64 && b < 64){ LayerH[frame-1]->line [i+OffsetY + 0xC + 36] [n+(OffsetX+16) + 0x10] = 1;//////ColorTable[r][g][b]; } } } } for(i=0; i < 32; i++){ for(n=0; n < 32; n++){ if(i+OffsetY + 0xC + 36 < screen_buffer_y && i+OffsetY + 0xC + 36 >= 0 && n+(OffsetX+16) + 0xC + 32 < screen_buffer_x && n+(OffsetX+16) + 0xC + 32 >= 0 && (i>>1)+((OffsetY + (p->Camera_Y_pos & 0xF) & 0xFFF0) - (p->Camera_Y_pos & 0xF)) < screen_buffer_y && (i>>1)+((OffsetY + (p->Camera_Y_pos & 0xF) & 0xFFF0) - (p->Camera_Y_pos & 0xF)) >= 0 && (n>>1)+((OffsetX+16) + (p->Camera_X_pos & 0xF) & 0xFFF0) - (p->Camera_X_pos & 0xF) < screen_buffer_x && (n>>1)+((OffsetX+16) + (p->Camera_X_pos & 0xF) & 0xFFF0) - (p->Camera_X_pos & 0xF) >= 0){ LayerH[frame-1]->line [i+OffsetY + 0xC + 36] [n+(OffsetX+16) + 0x10 + 32] = LayerL[frame-1]->line [(i>>1)+((OffsetY + (p->Camera_Y_pos & 0xF) & 0xFFF0) - (p->Camera_Y_pos & 0xF))] [(n>>1)+((OffsetX+16) + (p->Camera_X_pos & 0xF) & 0xFFF0) - (p->Camera_X_pos & 0xF)]; } } } if(selection_a < 16){ if(OffsetY + 0xC + 36 + 34 < screen_buffer_y && OffsetY + 0xC + 36 + 33 >= 0 && (selection_a << 1) + (OffsetX+16) + 0xC + 33 < screen_buffer_x && (selection_a << 1) + (OffsetX+16) + 0xC + 32 >= 0){ LayerH[frame-1]->line [OffsetY + 0xC + 36 + 34] [(selection_a << 1) + (OffsetX+16) + 0x10 + 32] = 1; LayerH[frame-1]->line [OffsetY + 0xC + 36 + 35] [(selection_a << 1) + (OffsetX+16) + 0x10 + 32] = 1; LayerH[frame-1]->line [OffsetY + 0xC + 36 + 34] [(selection_a << 1) + (OffsetX+16) + 0x10 + 33] = 1; LayerH[frame-1]->line [OffsetY + 0xC + 36 + 35] [(selection_a << 1) + (OffsetX+16) + 0x10 + 33] = 1; } } else{ if(OffsetY + 0xC + 36 + 34 < screen_buffer_y && OffsetY + 0xC + 36 + 33 >= 0 && (selection_a << 1) + (OffsetX+16) + 0xC + 33 < screen_buffer_x && (selection_a << 1) + (OffsetX+16) + 0xC + 32 >= 0){ LayerH[frame-1]->line [((31-selection_a) <<1) + OffsetY + 0xC + 36] [(OffsetX+16) + 0x10 + 32 + 34] = 1; LayerH[frame-1]->line [((31-selection_a) <<1) + OffsetY + 0xC + 37] [(OffsetX+16) + 0x10 + 32 + 34] = 1; LayerH[frame-1]->line [((31-selection_a) <<1) + OffsetY + 0xC + 36] [(OffsetX+16) + 0x10 + 32 + 35] = 1; LayerH[frame-1]->line [((31-selection_a) <<1) + OffsetY + 0xC + 37] [(OffsetX+16) + 0x10 + 32 + 35] = 1; } } DrawSprite(&(*z), LayerL[frame-1], 0x102, 1, NORMAL, 24, (((OffsetX+16) + (p->Camera_X_pos & 0xF) & 0xFFF0) - (p->Camera_X_pos & 0xF)) >> screen_double_x, ((OffsetY + (p->Camera_Y_pos & 0xF) & 0xFFF0) - (p->Camera_Y_pos & 0xF)) >> screen_double_y); DrawSprite(&(*z), LayerL[frame-1], 0x102, 0, NORMAL, 40, ((OffsetX+16) + 0xC) >> screen_double_x, (OffsetY + 0xC) >> screen_double_y); if(edit_selector == 0) DrawText(OffsetX + 0x10, OffsetY + 0x10, 1, "SLOPE1"); else DrawText(OffsetX + 0x10, OffsetY + 0x10, 0, "SLOPE1"); if(edit_selector == 1) DrawText(OffsetX + 0x10, OffsetY + 0x18, 1, "SLOPE2"); else DrawText(OffsetX + 0x10, OffsetY + 0x18, 0, "SLOPE2"); if(edit_selector == 2) DrawText(OffsetX + 0x10, OffsetY + 0x20, 1, "SOLID1"); else DrawText(OffsetX + 0x10, OffsetY + 0x20, 0, "SOLID1"); if(edit_selector == 3) DrawText(OffsetX + 0x10, OffsetY + 0x28, 1, "SOLID2"); else DrawText(OffsetX + 0x10, OffsetY + 0x28, 0, "SOLID2"); n = z->BATT_AddressTable[z->Act[act].Stage[stage].BlockAttributes]; DrawCounter16(LayerH[frame-1], z->BATT[n + val_block], OffsetX + 0x48, OffsetY + 0x10); DrawCounter16(LayerH[frame-1], z->BATT[n + val_block + 0x400], OffsetX + 0x48, OffsetY + 0x18); } } if(waitCounter == 0){ switch(edit_mode){ case EDIT_MODE_TILE_LAYOUT: edit_selector = 0; if(mouse_z != mouse_z_previous){ val_tile += (mouse_z - mouse_z_previous); val_tile &= 0xFF; tileblock_changed = 1; mouse_z_previous = mouse_z; } if(key[KEY_C] && (key[KEY_LCONTROL] || key[KEY_RCONTROL])){ edit_clipboard = val_tile; waitCounter = 12; } else if(key[KEY_V] && (key[KEY_LCONTROL] || key[KEY_RCONTROL])){ val_tile = edit_clipboard; tileblock_changed = 1; waitCounter = 12; } else if(key[KEY_DEL]){ val_tile = 0; tileblock_changed = 1; waitCounter = 12; } else if(key[KEY_EQUALS] || key[KEY_PLUS_PAD]){ val_tile++; tileblock_changed = 1; waitCounter = 12; } else if(key[KEY_MINUS] || key[KEY_MINUS_PAD]){ val_tile--; tileblock_changed = 1; waitCounter = 12; } else if(key[KEY_ASTERISK]){ val_tile += 0x10; tileblock_changed = 1; waitCounter = 12; } else if(key[KEY_SLASH] || key[KEY_SLASH_PAD]){ val_tile -= 0x10; tileblock_changed = 1; waitCounter = 12; } else if(key[KEY_TAB]){ clear(LayerH[frame-1]); InputText((screen_resolution_x >> 1)-156, (screen_resolution_y >> 1)-8, 0, STR_MSG_OPEN_FILE); tilefile = load_bitmap(TextBuffer, NULL); if(tilefile && (tilefile->w < 128 || tilefile->h < 128)) allegro_message("Bitmap image is too small! Must be at least 128x128."); else if(tilefile){ while(!key[KEY_ENTER] && !key[KEY_ESC]){ while(ticUpdated == 0); // wait until 'ticUpdated' is 1 ticUpdated = 0; clear(LayerH[frame-1]); blit(tilefile, LayerH[frame-1], coordinate_x, coordinate_y, 0, 0, tilefile->w, tilefile->h); OffsetX = mouse_pos >> 16; OffsetY = mouse_pos & 0xFFFF; if(OffsetX < 64) OffsetX = 64; if(OffsetY < 64) OffsetY = 64; if(screen_resolution_x - OffsetX < 64) OffsetX = screen_resolution_x - 64; if(screen_resolution_y - OffsetY < 64) OffsetY = screen_resolution_y - 64; if(tilefile->w < screen_resolution_x && OffsetX > tilefile->w - 64) OffsetX = tilefile->w - 64; if(tilefile->h < screen_resolution_y && OffsetY > tilefile->h - 64) OffsetY = tilefile->h - 64; for(n=0; n < 128; n++){ LayerH[frame-1]->line[OffsetY-64][(OffsetX-64+n)<<1] = ~LayerH[frame-1]->line[OffsetY-64][(OffsetX-64+n)<<1]; LayerH[frame-1]->line[OffsetY-64][((OffsetX-64+n)<<1)+1] = ~LayerH[frame-1]->line[OffsetY-64][((OffsetX-64+n)<<1)+1]; LayerH[frame-1]->line[OffsetY+63][(OffsetX-64+n)<<1] = ~LayerH[frame-1]->line[OffsetY+63][(OffsetX-64+n)<<1]; LayerH[frame-1]->line[OffsetY+63][((OffsetX-64+n)<<1)+1] = ~LayerH[frame-1]->line[OffsetY+63][((OffsetX-64+n)<<1)+1]; } for(n=0; n < 128; n++){ LayerH[frame-1]->line[OffsetY-64+n][(OffsetX-64)<<1] = ~LayerH[frame-1]->line[OffsetY-64+n][(OffsetX-64)<<1]; LayerH[frame-1]->line[OffsetY-64+n][((OffsetX-64)<<1)+1] = ~LayerH[frame-1]->line[OffsetY-64+n][((OffsetX-64)<<1)+1]; LayerH[frame-1]->line[OffsetY-64+n][(OffsetX+63)<<1] = ~LayerH[frame-1]->line[OffsetY-64+n][(OffsetX+63)<<1]; LayerH[frame-1]->line[OffsetY-64+n][((OffsetX+63)<<1)+1] = ~LayerH[frame-1]->line[OffsetY-64+n][((OffsetX+63)<<1)+1]; } DrawCounter16(LayerH[frame-1], OffsetX-64 + coordinate_x, OffsetX-52, OffsetY-12); DrawCounter16(LayerH[frame-1], OffsetY-64 + coordinate_y, OffsetX-12, OffsetY-12); blit(LayerH[frame-1], screen, 0, 0, 0, 0, screen_buffer_x, screen_buffer_y); if(key[KEY_UP] && coordinate_y > 0) coordinate_y -= 8; else if(key[KEY_DOWN] && tilefile->h - coordinate_y > screen_resolution_y) coordinate_y += 8; if(key[KEY_LEFT] && coordinate_x > 0) coordinate_x -= 8; else if(key[KEY_RIGHT] && tilefile->w - coordinate_x > screen_resolution_x) coordinate_x += 8; if(tilefile->h - coordinate_y <= screen_resolution_y) coordinate_y = tilefile->h - screen_resolution_y; if(coordinate_y < 0) coordinate_y = 0; if(tilefile->w - coordinate_x <= screen_resolution_x) coordinate_x = tilefile->w - screen_resolution_x; if(coordinate_x < 0) coordinate_x = 0; } clear(LayerH[frame-1]); if(key[KEY_ENTER]){ // store blocks into work memory destroy_bitmap(tilefile); tilefile = 0; set_color_depth(24); tilefile = load_bitmap(TextBuffer, NULL); // FIX ME!!! for(n=0; n < 64; n++){ // 64 blocks for(i=0; i < 256; i++){ // 256 pixels each imported_blocks[n][i] = ((tilefile->line [((n&56)<<1)+coordinate_y+OffsetY-64+(i>>4)] [(((n&7)<<4)+coordinate_x+OffsetX-64+(i&15))*3] >> 3) << 11); imported_blocks[n][i] |= ((tilefile->line [((n&56)<<1)+coordinate_y+OffsetY-64+(i>>4)] [((((n&7)<<4)+coordinate_x+OffsetX-64+(i&15))*3)+1] >> 2) << 5); imported_blocks[n][i] |= (tilefile->line [((n&56)<<1)+coordinate_y+OffsetY-64+(i>>4)] [((((n&7)<<4)+coordinate_x+OffsetX-64+(i&15))*3)+2] >> 3); } } destroy_bitmap(tilefile); tilefile = 0; set_color_depth(16); key[KEY_ENTER] = 0; rest(200); b = -1; while(b < 0){ clear(LayerH[frame-1]); InputText((screen_resolution_x >> 1)-156, (screen_resolution_y >> 1)-8, 0, STR_MSG_REUSE_BLOCKS); if(strcmp(TextBuffer, "Y") != 0 && strcmp(TextBuffer, "y") != 0){ if(strcmp(TextBuffer, "N") != 0 && strcmp(TextBuffer, "n") != 0) allegro_message("Invalid response! Please type 'Y' or 'N'"); else b = 0; } else b = 1; } // clear block_matches[] for(i=0; i < 64; i++) block_matches[i] = 0; for(a=0; a < 64; a++){ match_count = 0; // search for a pre-existing block for(n=0; n < 0x400; n++){ // block for(i=0; i < 0x100; i++){ // index if(*(unsigned short *)&z->BLOCK[block_ptr + (n << 9) + (i<<1)] == imported_blocks[a][i]) match_count++; else{ i = 0x100; match_count=0; } } if(match_count == 0x100){ block_matches[a] = n + 0x4000; // avoid using zero n = 0x400; } } // if after checking all blocks we still don't have a match if(block_matches[a] == 0 || (b == 0 && block_matches[a] != 0x4000)){ // search for empty block match_count=0; for(n=1; n < 0x400; n++){ // block for(i=0; i < 0x100; i++){ // index if(*(unsigned short *)&z->BLOCK[block_ptr + (n << 9) + (i<<1)] == MASK_COLOR_16) match_count++; else{ i = 0x100; match_count=0; } } // if empty block found if(match_count == 0x100){ block_matches[a] = n + 0x4000; // make sure block isn't already in use /*for(i=0; i < 16384; i++){ // check 256 tiles, 64 blocks each if(((z->BMAP[bmap_ptr+(i<<2)+1]&0x3F)<<8) + z->BMAP[bmap_ptr+(i<<2)] == block_matches[a] - 0x4000){ // the block is being used by a tile i = 16384; block_matches[a] = 0x4000; } }*/ // if block isn't being used if(i < 16384){ n = 0x400; // copy block into BLOCK memory for(i=0; i < 0x100; i++) *(unsigned short *)&z->BLOCK[block_ptr + ((block_matches[a]-0x4000) << 9) + (i<<1)] = imported_blocks[a][i]; } } } } } for(n=0; n < 64; n++){ z->BMAP[bmap_ptr + (val_tile << 8) + (n<<2)] = ((block_matches[n]-0x4000)&0xFF); z->BMAP[bmap_ptr + (val_tile << 8) + (n<<2)+1] = ((block_matches[n]-0x4000)>>8); z->BMAP[bmap_ptr + (val_tile << 8) + (n<<2)+2] = 0; z->BMAP[bmap_ptr + (val_tile << 8) + (n<<2)+3] = 0; } } tileblock_changed = 1; key[KEY_ENTER] = 0; key[KEY_ESC] = 0; } else allegro_message("Could not open \"%s\"!", TextBuffer); if(tilefile){ destroy_bitmap(tilefile); tilefile = 0; } } if(val_tile < 0) val_tile = 256 + val_tile; else if(val_tile > 255) val_tile = val_tile - 256; z->TMAP[tmap_ptr+(val_tile_offset << 1)] = (val_tile & 0xFF); z->TMAP[tmap_ptr+(val_tile_offset << 1)+1] = (val_tile >> 8); if(tileblock_changed) UpdateBlockLayout(z); break; case EDIT_MODE_BLOCK_MAPPINGS: if(!edit_selector) edit_selector = 1; if(mouse_z != mouse_z_previous){ val_block += (mouse_z - mouse_z_previous); val_block &= 0x3FF; mouse_z_previous = mouse_z; } if(key[KEY_CLOSEBRACE]){ edit_selector++; edit_selector %= 8; if(!edit_selector) edit_selector = 1; waitCounter = 12; } else if(key[KEY_OPENBRACE]){ edit_selector--; edit_selector %= 8; if(!edit_selector) edit_selector = 7; waitCounter = 12; } if(key[KEY_C] && (key[KEY_LCONTROL] || key[KEY_RCONTROL])){ edit_clipboard = val_bmap; waitCounter = 12; } else if(key[KEY_V] && (key[KEY_LCONTROL] || key[KEY_RCONTROL])){ val_block = edit_clipboard & 0x3FFF; val_mirror = (edit_clipboard >> 14) & 1; val_flip = (edit_clipboard >> 15) & 1; val_platform1 = (edit_clipboard >> 16) & 1; val_barrier1 = (edit_clipboard >> 17) & 1; val_platform2 = (edit_clipboard >> 18) & 1; val_barrier2 = (edit_clipboard >> 19) & 1; val_plane = (edit_clipboard >> 20) & 1; val_translucency = (edit_clipboard >> 26) & 0x3F; waitCounter = 12; } else if(key[KEY_DEL]){ val_block = 0; waitCounter = 12; } else if(key[KEY_EQUALS] || key[KEY_PLUS_PAD]){ switch(edit_selector){ case 1: val_block++; break; case 2: val_mirror^=1; break; case 3: val_flip^=1; break; case 4: val_platform1^=1; break; case 5: val_barrier1^=1; break; case 6: val_plane^=1; break; case 7: val_translucency++; } tileblock_changed = 1; waitCounter = 12; } else if(key[KEY_MINUS] || key[KEY_MINUS_PAD]){ switch(edit_selector){ case 1: val_block--; break; case 2: val_mirror^=1; break; case 3: val_flip^=1; break; case 4: val_platform1^=1; break; case 5: val_barrier1^=1; break; case 6: val_plane^=1; break; case 7: val_translucency--; } tileblock_changed = 1; waitCounter = 12; } else if(key[KEY_ASTERISK]){ switch(edit_selector){ case 1: val_block += 0x10; break; case 2: val_mirror^=1; break; case 3: val_flip^=1; break; case 4: val_platform2^=1; break; case 5: val_barrier2^=1; break; case 6: val_plane^=1; break; case 7: val_translucency += 0x10; } tileblock_changed = 1; waitCounter = 12; } else if(key[KEY_SLASH] || key[KEY_SLASH_PAD]){ switch(edit_selector){ case 1: val_block -= 0x10; break; case 2: val_mirror^=1; break; case 3: val_flip^=1; break; case 4: val_platform2^=1; break; case 5: val_barrier2^=1; break; case 6: val_plane^=1; break; case 7: val_translucency -= 0x10; } tileblock_changed = 1; waitCounter = 12; } if(val_block < 0) val_block = 0x400 + val_block; else if(val_block > 0x3FF) val_block = val_block - 0x400; val_translucency &= 0x3F; val_bmap = val_block + (val_mirror << 14) + (val_flip << 15) + (val_platform1 << 16) + (val_barrier1 << 17) + (val_platform2 << 18) + (val_barrier2 << 19) + (val_plane << 20) + (val_translucency << 26); z->BMAP[val_bmap_offset+3] = val_bmap >> 24; z->BMAP[val_bmap_offset+2] = val_bmap >> 16; z->BMAP[val_bmap_offset+1] = val_bmap >> 8; z->BMAP[val_bmap_offset] = val_bmap; if(tileblock_changed) UpdateBlockLayout(z); break; case EDIT_MODE_SOLIDITY: edit_selector &= 3; if(key[KEY_CLOSEBRACE]){ edit_selector++; edit_selector &= 3; waitCounter = 12; } else if(key[KEY_OPENBRACE]){ edit_selector--; edit_selector &= 3; waitCounter = 12; } if(key[KEY_END]){ selection_a = (selection_a - 1) & 0x1F; waitCounter = 8; } else if(key[KEY_HOME]){ selection_a = (selection_a + 1) & 0x1F; waitCounter = 8; } else if(key[KEY_EQUALS] || key[KEY_PLUS_PAD]){ switch(edit_selector){ case 0: n = z->BATT_AddressTable[z->Act[act].Stage[stage].BlockAttributes]; z->BATT[n + val_block]++; break; case 1: n = z->BATT_AddressTable[z->Act[act].Stage[stage].BlockAttributes]; z->BATT[n + val_block + 0x400]++; break; default: if(selection_a < 16){ n = z->BSOL_AddressTable[z->Act[act].Stage[stage].BlockSolidity]; if(edit_selector == 2){ z->BSOL[n + selection_a + (val_block << 5)]++; z->BSOL[n + selection_a + (val_block << 5)] %= 17; } if(edit_selector == 3){ z->BSOL[n + selection_a + (val_block << 5) + 0x8000]++; z->BSOL[n + selection_a + (val_block << 5) + 0x8000] %= 17; } } else{ n = z->BSOL_AddressTable[z->Act[act].Stage[stage].BlockSolidity]; if(edit_selector == 2){ z->BSOL[n + (31-selection_a) + (val_block << 5)+16]++; z->BSOL[n + (31-selection_a) + (val_block << 5)+16] %= 17; } if(edit_selector == 3){ z->BSOL[n + (31-selection_a) + (val_block << 5)+16 + 0x8000]++; z->BSOL[n + (31-selection_a) + (val_block << 5)+16 + 0x8000] %= 17; } } } waitCounter = 12; } else if(key[KEY_MINUS] || key[KEY_MINUS_PAD]){ switch(edit_selector){ case 0: n = z->BATT_AddressTable[z->Act[act].Stage[stage].BlockAttributes]; z->BATT[n + val_block]--; break; case 1: n = z->BATT_AddressTable[z->Act[act].Stage[stage].BlockAttributes]; z->BATT[n + val_block + 0x400]--; break; default: if(selection_a < 16){ n = z->BSOL_AddressTable[z->Act[act].Stage[stage].BlockSolidity]; if(edit_selector == 2){ z->BSOL[n + selection_a + (val_block << 5)]--; z->BSOL[n + selection_a + (val_block << 5)] %= 17; } if(edit_selector == 3){ z->BSOL[n + selection_a + (val_block << 5) + 0x8000]--; z->BSOL[n + selection_a + (val_block << 5) + 0x8000] %= 17; } } else{ n = z->BSOL_AddressTable[z->Act[act].Stage[stage].BlockSolidity]; if(edit_selector == 2){ z->BSOL[n + (31-selection_a) + (val_block << 5)+16]--; z->BSOL[n + (31-selection_a) + (val_block << 5)+16] %= 17; } if(edit_selector == 3){ z->BSOL[n + (31-selection_a) + (val_block << 5)+16 + 0x8000]--; z->BSOL[n + (31-selection_a) + (val_block << 5)+16 + 0x8000] %= 17; } } } waitCounter = 12; } else if(key[KEY_ASTERISK]){ switch(edit_selector){ case 0: n = z->BATT_AddressTable[z->Act[act].Stage[stage].BlockAttributes]; z->BATT[n + val_block] += 0x10; break; case 1: n = z->BATT_AddressTable[z->Act[act].Stage[stage].BlockAttributes]; z->BATT[n + val_block + 0x400] += 0x10; } waitCounter = 12; } else if(key[KEY_SLASH] || key[KEY_SLASH_PAD]){ switch(edit_selector){ case 0: n = z->BATT_AddressTable[z->Act[act].Stage[stage].BlockAttributes]; z->BATT[n + val_block] -= 0x10; break; case 1: n = z->BATT_AddressTable[z->Act[act].Stage[stage].BlockAttributes]; z->BATT[n + val_block + 0x400] -= 0x10; } waitCounter = 12; } else if(key[KEY_INSERT]){ n = z->BSOL_AddressTable[z->Act[act].Stage[stage].BlockSolidity]; if(edit_selector == 2){ for(i=0; i < 32; i++) z->BSOL[n + selection_a + (val_block << 5) + i] = 0x10; } else if(edit_selector == 3){ for(i=0; i < 32; i++) z->BSOL[n + selection_a + (val_block << 5) + i + 0x8000] = 0x10; } waitCounter = 12; } else if(key[KEY_DEL]){ n = z->BSOL_AddressTable[z->Act[act].Stage[stage].BlockSolidity]; if(edit_selector == 2){ for(i=0; i < 32; i++) z->BSOL[n + selection_a + (val_block << 5) + i] = 0; } else if(edit_selector == 3){ for(i=0; i < 32; i++) z->BSOL[n + selection_a + (val_block << 5) + i + 0x8000] = 0; } waitCounter = 12; } //break; } if(key[KEY_D] && (key[KEY_LCONTROL] || key[KEY_RCONTROL])){ SaveZone(z, "dump.pzf"); allegro_message(STR_MSG_PZF_DUMPED); } if(key[KEY_BACKSLASH]){ p->layer = ((p->layer + 1) & 1) + 0x10; waitCounter = 12; } } } void LoadZonePrompt(){ InputText((screen_resolution_x >> 1)-156, (screen_resolution_y >> 1)-24, 0, STR_MSG_OPEN_FILE); for(i=0; i < 256; i++){ if(TextBuffer[i] >= 'A' && TextBuffer[i] <= 'Z') TextBuffer[i] += 0x20; else if(TextBuffer[i] == '\0') i = 255; } for(i=0; i <= 256; i++){ if(i == 256){ strcpy(zone_file_list[i], TextBuffer); unlisted_zone = 1; } if(strcmp(zone_file_list[i], TextBuffer) == 0){ zone = (i & 0xFF); i = 256; InputText((screen_resolution_x >> 1)-156, (screen_resolution_y >> 1), 0, "ENTER ACT VALUE 1 TO 8:"); act = TextBuffer[0] - '1'; if(act >= z.Act_FileCount) act = 0; InputText((screen_resolution_x >> 1)-156, (screen_resolution_y >> 1)+24, 0, "ENTER STAGE VALUE A TO D:"); if(TextBuffer[0] >= 'a') TextBuffer[0] -= 0x20; stage = TextBuffer[0] - 'A'; if(((z.Act[act].IncludedStages >> stage) & 1) == 0) stage = 0; Level_Inactive_flag = 1; } } }
001tomclark-research-check
Source/Engine/tools.c
C
gpl2
29,664
#include <stdio.h> #include <allegro.h> #include "structs.h" #include "text.h" #include "common.h" #include "obj01.h" char PlayDemo(signed char d){ char demo_players; char demo_flags; //int demo_size; int i; if(frame != 1){ return 1; // temporary } if(!titlecard_sequence_end){ return 1; } if(demo_mode == 1){ if(DemoPosition == 0 && DemoFile == NULL){ DemoFile = fopen(demo_file_list[d], "rb"); #ifdef ENABLE_SRAM_LOG_ANALYSIS SRAMFile = fopen(sram_file_list[d], "rb"); #endif if(DemoFile != NULL){ fseek(DemoFile, 0, SEEK_END); demo_size = ftell(DemoFile); #ifdef ENABLE_SRAM_LOG_ANALYSIS fseek(SRAMFile, 0, SEEK_END); sram_size = ftell(SRAMFile); #endif if(demo_size >= 6){ if(demodata) free(demodata); demodata = (char *)malloc(demo_size); fseek(DemoFile, 0, SEEK_SET); fread(demodata, 1, demo_size, DemoFile); fclose(DemoFile); DemoFile = 0; DemoPosition = 6; #ifdef ENABLE_SRAM_LOG_ANALYSIS if(sramdata) free(sramdata); sramdata = (char *)malloc(sram_size); fseek(SRAMFile, 0, SEEK_SET); fread(sramdata, 1, sram_size, SRAMFile); fclose(SRAMFile); SRAMFile = 0; SRAMPosition = 4; #endif } else{ allegro_message("\"%s\" not found!", demo_file_list[d]); demo_mode = 0; fclose(DemoFile); DemoFile = 0; demo_size = 0; #ifdef ENABLE_SRAM_LOG_ANALYSIS if(SRAMFile) fclose(SRAMFile); SRAMFile = 0; sram_size = 0; #endif return -1; } } else{ //allegro_message("No demo data for \"%s\"!", demo_file_list[d]); //demo_mode = 0; demo_number++; demo_number %= 10; #ifdef ENABLE_SRAM_LOG_ANALYSIS if(SRAMFile) fclose(SRAMFile); #endif return -1; } } if(DemoPosition==6){ demo_players = (demodata[0] & 3) + 1; demo_flags = demodata[0] >> 4; DemoCount = *(unsigned short *)(&demodata[2]); zone = demodata[4]; act = demodata[5] & 7; stage = (demodata[5] >> 4) & 3; #ifdef ENABLE_SRAM_LOG_ANALYSIS SRAMCount = *(unsigned short *)(&sramdata[0]); SRAMCount = (SRAMCount >> 8) | (SRAMCount << 8); sram_start = *(unsigned short *)(&sramdata[2]); sram_start = (sram_start >> 8) | (sram_start << 8); SRAMPosition = 4; #endif if(demo_flags & 1){ for(i=0; i < demo_players; i++){ // demodata[6+(i*5)] is the character p->x_pos = (demodata[7+(i*5)] << 8) + demodata[8+(i*5)]; p->y_pos = (demodata[9+(i*5)] << 8) + demodata[10+(i*5)]; } DemoPosition += (i*5); } else{ for(i=0; i < demo_players; i++){ // demodata[6+i] is the character ; } DemoPosition += i; } ResetSound(); LoadZone(&z, zone_file_list[zone]); InitDraw(&z); AllocateObjects(&z); CreateBlockLayout(&z); // SET UP THE CELL DATA num_of_cells = z.FILTERCOMPOSITE[0]; num_of_filters = z.FILTERCOMPOSITE[1]; cells_ptr = *(short *)&z.FILTERCOMPOSITE[2]; filters_ptr = *(short *)&z.FILTERCOMPOSITE[4]; bg_rgb_color = *(short *)&z.FILTERCOMPOSITE[6]; filter_a = z.FILTERCOMPOSITE[8]; filter_b = z.FILTERCOMPOSITE[9]; filter_a_speed = z.FILTERCOMPOSITE[10]; filter_b_speed = z.FILTERCOMPOSITE[11]; cell_data = (CELL*)(&z.FILTERCOMPOSITE[cells_ptr]); for(i=0; i < 4; i++){ player[i] = init_player; player[i].x_pos = z.Act[act].Stage[stage].StartX[0]; player[i].y_pos = z.Act[act].Stage[stage].StartY[0]; player[i].Camera_X_pos = p->x_pos - (screen_resolution_x >> 1); player[i].Camera_Y_pos = p->y_pos - (screen_resolution_y >> 1) + 0x10; player[i].Camera_Min_X_pos = z.Act[act].Stage[stage].LevelXL; player[i].Camera_Max_X_pos = z.Act[act].Stage[stage].LevelXR; player[i].Camera_Min_Y_pos = z.Act[act].Stage[stage].LevelYT; player[i].Camera_Max_Y_pos = z.Act[act].Stage[stage].LevelYB; player[i].Camera_Max_Y_pos_now = z.Act[act].Stage[stage].LevelYB; player[i].Camera_Y_pos_bias = 0x60; player[i].render_flags |= 0x80; player[i].Ring_count = 0; } Timer_minute = 0; Timer_second = 0; Timer_millisecond = 0; titlecard_sequence_end = 0; strcpy(TextBuffer, "ProSonic - "); strcat(TextBuffer, z.LevelName1); strcat(TextBuffer, " ZONE"); set_window_title(TextBuffer); RunFunction(4); } else if(DemoPosition > 6){ if(DemoCount <= DemoFadeDelay*24 && DemoCount % DemoFadeDelay == 0){ fade_count -= 4; } if(DemoCount > 1){ // Do not make this 0 p->CtrlInput = demodata[DemoPosition]; DemoPosition++; DemoCount--; #ifdef ENABLE_SRAM_LOG_ANALYSIS //if(ticCounterL >= sram_start){ sram_master_key = sramdata[SRAMPosition]; SRAMPosition++; SRAMCount--; for(i=0; i < 8; i++){ sram_segment_key[i] = 0; if(sram_master_key & (0x80 >> i)){ sram_segment_key[i] = sramdata[SRAMPosition]; SRAMPosition++; SRAMCount--; } } for(i=0; i < 8; i++){ for(n=0; n < 8; n++){ if(sram_segment_key[i] & (0x80 >> n)){ sram_frame[(i << 3) + n] = sramdata[SRAMPosition]; SRAMPosition++; SRAMCount--; } } } //} #endif } if(DemoCount == 1){ // Do not make this 0 DemoPosition = 0; demo_mode = 0; free(demodata); demodata = 0; demo_size = 0; demo_number++; DemoFile = 0; if(demo_number >= 3) demo_number = 0; #ifdef ENABLE_SRAM_LOG_ANALYSIS SRAMPosition = 0; if(sramdata) free(sramdata); sram_size = 0; SRAMFile = 0; #endif } } } return 0; } void RecordDemo(signed char d){ char demo_players; char demo_flags; int i; if(frame != 1) return; // temporary if(!titlecard_sequence_end) return; d &= 0xF; if(demo_mode == 2){ if(DemoPosition == 0 && DemoFile == NULL){ DemoFile = fopen(demo_file_list[d], "w+b"); if(DemoFile != NULL){ demo_size = 6; if(demodata) free(demodata); demodata = (char *)malloc(demo_size); DemoPosition = 6; DemoCount = 0; } else{ allegro_message("No demo data!"); demo_mode = 0; } } if(DemoPosition==6){ demodata[0] = 0; // 000000pp (players) demodata[1] = 0; // 00000000 (unused!) demodata[4] = zone; // zzzzzzzz (zone) demodata[5] = (stage << 4) + act; // 00ss0aaa (stage/act) DemoPosition++; demodata = (char *)realloc(demodata, DemoPosition); demodata[6] = 0; LoadZone(&z, zone_file_list[zone]); InitDraw(&z); AllocateObjects(&z); CreateBlockLayout(&z); // SET UP THE CELL DATA num_of_cells = z.FILTERCOMPOSITE[0]; num_of_filters = z.FILTERCOMPOSITE[1]; cells_ptr = *(short *)&z.FILTERCOMPOSITE[2]; filters_ptr = *(short *)&z.FILTERCOMPOSITE[4]; bg_rgb_color = *(short *)&z.FILTERCOMPOSITE[6]; filter_a = z.FILTERCOMPOSITE[8]; filter_b = z.FILTERCOMPOSITE[9]; filter_a_speed = z.FILTERCOMPOSITE[10]; filter_b_speed = z.FILTERCOMPOSITE[11]; cell_data = (CELL*)(&z.FILTERCOMPOSITE[cells_ptr]); for(i=0; i < 4; i++){ player[i] = init_player; player[i].x_pos = z.Act[act].Stage[stage].StartX[0]; player[i].y_pos = z.Act[act].Stage[stage].StartY[0]; player[i].Camera_X_pos = p->x_pos - (screen_resolution_x >> 1); player[i].Camera_Y_pos = p->y_pos - (screen_resolution_y >> 1) + 0x10; player[i].Camera_Min_X_pos = z.Act[act].Stage[stage].LevelXL; player[i].Camera_Max_X_pos = z.Act[act].Stage[stage].LevelXR; player[i].Camera_Min_Y_pos = z.Act[act].Stage[stage].LevelYT; player[i].Camera_Max_Y_pos = z.Act[act].Stage[stage].LevelYB; player[i].Camera_Max_Y_pos_now = z.Act[act].Stage[stage].LevelYB; player[i].Camera_Y_pos_bias = 0x60; player[i].Ring_count = 0; } Timer_minute = 0; Timer_second = 0; Timer_millisecond = 0; titlecard_sequence_end = 0; RunFunction(4); } else if(DemoPosition > 6){ DemoPosition++; DemoCount++; demodata = (char *)realloc(demodata, DemoPosition); demodata[DemoPosition-1] = p->CtrlInput; } } else if(demo_mode == 3){ *(short *)(&demodata[2]) = DemoCount; //for(DemoPosition=0; DemoPosition < DemoCount + 6; DemoPosition++) // fwrite(&demodata[DemoPosition], 1, 1, DemoFile); fwrite(demodata, 1, DemoCount + 6, DemoFile); DemoPosition = 0; demo_mode = 0; free(demodata); demodata = 0; demo_size = 0; fclose(DemoFile); DemoFile = 0; } }
001tomclark-research-check
Source/Engine/demo.c
C
gpl2
8,896
#ifndef MOUSE_H #define MOUSE_H #ifdef __cplusplus extern "C"{ #endif #define ENABLE_MOUSE #ifdef __cplusplus } #endif #endif
001tomclark-research-check
Source/Engine/mouse.h
C
gpl2
159
#include <stdio.h> #include <math.h> #include <allegro.h> #include "error.h" #include "sprites.h" //#include "common.h" // needed for screen resolution size #include "draw.h" // needed for 'pal' unsigned char GetAnimationSpeed(unsigned short s, unsigned char *a){ int SheetSize; unsigned short NumberOfSprites; unsigned short NumberOfAnimations; signed short SpriteSheetSizeX; signed short SpriteSheetSizeY; NumberOfSprites = SpriteTable[SpriteAddressTable[s]]; NumberOfAnimations = SpriteTable[SpriteAddressTable[s]+1]; SpriteSheetSizeX = SpriteTable[SpriteAddressTable[s]+2]; SpriteSheetSizeY = SpriteTable[SpriteAddressTable[s]+3]; SheetSize = SpriteSheetSizeX * SpriteSheetSizeY; if(*a >= NumberOfAnimations) return 1; // prevent engine from crashing return SpriteTable[SpriteAddressTable[s] + (NumberOfSprites << 2) + (SheetSize << 2) + 4 + (*a << 8)]; } unsigned char ReadAnimation(unsigned short s, unsigned char *a, unsigned short *frame, char *ti, unsigned char *AnimationSpeed){ int n; int SheetSize; unsigned short NumberOfSprites; unsigned short NumberOfAnimations; signed short SpriteSheetSizeX; signed short SpriteSheetSizeY; /*signed short SpriteSizeXL; signed short SpriteSizeXR; signed short SpriteSizeYT; signed short SpriteSizeYB;*/ //unsigned char NumberOfFrames; //unsigned short AnimationSpeed; NumberOfSprites = SpriteTable[SpriteAddressTable[s]]; NumberOfAnimations = SpriteTable[SpriteAddressTable[s]+1]; SpriteSheetSizeX = SpriteTable[SpriteAddressTable[s]+2]; SpriteSheetSizeY = SpriteTable[SpriteAddressTable[s]+3]; SheetSize = SpriteSheetSizeX * SpriteSheetSizeY; if(*a >= NumberOfAnimations) return 1; // prevent engine from crashing if(*AnimationSpeed == 0) *AnimationSpeed = 1; if(*ti < 0){ *ti = *AnimationSpeed; *frame += 1; } // Read_Sprite n = SpriteTable[SpriteAddressTable[s] + (NumberOfSprites << 2) + (SheetSize << 2) + 4 + (*a << 8) + 1 + *frame]; if(n == 0xFFFF) // SPECIAL: Restart *frame = 0; else if(n == 0xFFFE) // SPECIAL: Loop from position *frame -= SpriteTable[SpriteAddressTable[s] + (NumberOfSprites << 2) + (SheetSize << 2) + 4 + (*a << 8) + 2 + *frame]; else if(n == 0xFFFD){ // SPECIAL: Start new animation *a = SpriteTable[SpriteAddressTable[s] + (NumberOfSprites << 2) + (SheetSize << 2) + 4 + (*a << 8) + 2 + *frame]; *frame = 0; *AnimationSpeed = GetAnimationSpeed(s, a); } return n; } unsigned char DrawAnimation(ZONE *z, BITMAP *l, unsigned short s, unsigned char a, unsigned short frame, char m, unsigned char tr, char *ti, unsigned char AnimationSpeed, short x, short y){ int n; int SheetSize; unsigned short NumberOfSprites; unsigned short NumberOfAnimations; signed short SpriteSheetSizeX; signed short SpriteSheetSizeY; NumberOfSprites = SpriteTable[SpriteAddressTable[s]]; NumberOfAnimations = SpriteTable[SpriteAddressTable[s]+1]; SpriteSheetSizeX = SpriteTable[SpriteAddressTable[s]+2]; SpriteSheetSizeY = SpriteTable[SpriteAddressTable[s]+3]; SheetSize = SpriteSheetSizeX * SpriteSheetSizeY; if(a >= NumberOfAnimations) return 1; // prevent engine from crashing n = SpriteTable[SpriteAddressTable[s] + (NumberOfSprites << 2) + (SheetSize << 2) + 4 + (a << 8) + 1 + frame]; if(draw_frame && n < NumberOfSprites){ DrawSprite(z, l, s, n, m, tr, x, y); DrawSprite(z, l, s, n, m, tr, x, y - (z->Act[act].Stage[stage].WrapPoint)); DrawSprite(z, l, s, n, m, tr, x, y + (z->Act[act].Stage[stage].WrapPoint)); } //*ti += 1; // Cannot use increment operator *ti -= 1; return 0; } void DrawSprite(ZONE *z, BITMAP *l, unsigned short s, unsigned char ss, char m, unsigned char tr, short x, short y){ // s = sprite // ss = sub-sprite int a; int b; int c; int d; unsigned short val_pixel; // Index unsigned short color_i; // Sprite unsigned char color_rs; unsigned char color_gs; unsigned char color_bs; // Background unsigned char color_rb; unsigned char color_gb; unsigned char color_bb; char mirror; char flip; unsigned short NumberOfSprites; unsigned short NumberOfAnimations; signed short SpriteSheetSizeX; signed short SpriteSheetSizeY; signed short SpriteSizeXL; signed short SpriteSizeXR; signed short SpriteSizeYT; signed short SpriteSizeYB; //unsigned char NumberOfFrames; //unsigned char AnimationSpeed; if(!draw_frame) return; NumberOfSprites = SpriteTable[SpriteAddressTable[s]]; NumberOfAnimations = SpriteTable[SpriteAddressTable[s]+1]; SpriteSheetSizeX = SpriteTable[SpriteAddressTable[s]+2]; SpriteSheetSizeY = SpriteTable[SpriteAddressTable[s]+3]; SpriteSizeXL = SpriteTable[SpriteAddressTable[s] + (SpriteSheetSizeX * SpriteSheetSizeY << 2) + 4 + (ss << 2)]; SpriteSizeXR = SpriteTable[SpriteAddressTable[s] + (SpriteSheetSizeX * SpriteSheetSizeY << 2) + 4 + (ss << 2)+1]; SpriteSizeYT = SpriteTable[SpriteAddressTable[s] + (SpriteSheetSizeX * SpriteSheetSizeY << 2) + 4 + (ss << 2)+2]; SpriteSizeYB = SpriteTable[SpriteAddressTable[s] + (SpriteSheetSizeX * SpriteSheetSizeY << 2) + 4 + (ss << 2)+3]; mirror = (SpriteSizeXL >> 15) & 1; flip = (SpriteSizeYT >> 15) & 1; SpriteSizeXL &= 0x7FFF; SpriteSizeYT &= 0x7FFF; if(ss >= NumberOfSprites) return; // prevent engine from crashing switch(m){ case NORMAL: break; case MIRROR: mirror ^= 1; break; case FLIP: flip ^= 1; break; case ROTATE: mirror ^= 1; flip ^= 1; } if(screen_scale_x && !screen_double_x) x -= 16; //allegro_message("%i, %i", x, y); /*if(y + (SpriteSizeYB - SpriteSizeYT) >= screen_resolution_y){ SpriteSizeYB -= (y + (SpriteSizeYB - SpriteSizeYT)) - screen_resolution_y - 1; } if(x + (SpriteSizeXR - SpriteSizeXL) >= screen_resolution_x){ SpriteSizeXR -= (x + (SpriteSizeXR - SpriteSizeXL)) - screen_resolution_x - 1; } if(y < 0){ abs(y); SpriteSizeYT += y; } if(x < 16){ x = abs(x - 16); SpriteSizeXL += x; } //allegro_message("%i, %i", x, y); if(ticCounter60R == 0) allegro_message("%i, %i, %i, %i", SpriteSizeXL, SpriteSizeXR, SpriteSizeYT, SpriteSizeYB); if(SpriteSizeYT <= SpriteSizeYB && SpriteSizeXL <= SpriteSizeXR) {*/ if(tr > 0){ for(a = SpriteSizeYT; a <= SpriteSizeYB; a += (1<<(screen_scale_y >> screen_double_y))){ for(b = SpriteSizeXL; b <= SpriteSizeXR; b += (1<<(screen_scale_x >> screen_double_x))){ //allegro_message("%i, %i", x + (b - SpriteSizeXL), y + (a - SpriteSizeYT)); if(y + (a - SpriteSizeYT) >= 0 && y + (a - SpriteSizeYT) < screen_buffer_y){ if(x + (b - SpriteSizeXL) >= (16>>screen_scale_x) && x + (b - SpriteSizeXL) < screen_buffer_x-16){ //if(SpriteTable[SpriteAddressTable[s] + 4 + (a*SpriteSheetSizeX << 2) + b+1] != 0xFF){ if(flip == 0) c = a * SpriteSheetSizeX; else c = (SpriteSizeYB + (SpriteSizeYT - a)) * SpriteSheetSizeX; if(mirror == 0) d = b; else d = SpriteSizeXR + (SpriteSizeXL - b); if(z->Act[act].Stage[stage].WaterEnable && y + (a - SpriteSizeYT) + p->Camera_Y_pos >= (water_current_height >> 8)){ val_pixel = SpriteTable[SpriteAddressTable[s] + 4 + (c + d)]; if(val_pixel != MASK_COLOR_16){ color_rs = val_pixel >> 11; color_gs = (val_pixel >> 5) & 0x3F; color_bs = val_pixel & 0x1F; color_i = *(short *)(&l->line[y + (a - SpriteSizeYT)][(x + (b - SpriteSizeXL))<<1]); if(color_i == MASK_COLOR_16 && l == LayerH[frame-1]){ color_i = *(short *)(&LayerL[frame-1]->line[y + (a - SpriteSizeYT)][(x + (b - SpriteSizeXL))<<1]); } if(color_i == MASK_COLOR_16 && l == LayerL[frame-1]){ color_i = *(short *)(&LayerB[frame-1]->line[y + (a - SpriteSizeYT)][(x + (b - SpriteSizeXL))<<1]); } color_rb = color_i >> 11; color_gb = (color_i >> 5) & 0x3F; color_bb = color_i & 0x1F; color_rs = (short)(color_rs + (color_rb - color_rs) * (float)(tr * 0.015625)); color_gs = (short)(color_gs + (color_gb - color_gs) * (float)(tr * 0.015625)); color_bs = (short)(color_bs + (color_bb - color_bs) * (float)(tr * 0.015625)); val_pixel = bestfit_color(_current_palette, color_rs, color_gs, color_bs);//makecol(color_rs << 2, color_gs << 2, color_bs << 2); *(short *)&l->line[(y + (a - SpriteSizeYT))>>(screen_scale_y >> screen_double_y)][((x + (b - SpriteSizeXL))>>(screen_scale_x >> screen_double_x))<<1] = 0; //val_pixel; } } else{ val_pixel = SpriteTable[SpriteAddressTable[s] + 4 + (c + d)]; if(val_pixel != MASK_COLOR_16){ color_rs = val_pixel >> 11; color_gs = (val_pixel >> 5) & 0x3F; color_bs = val_pixel & 0x1F; color_i = *(short *)(&l->line[(y + (a - SpriteSizeYT))>>(screen_scale_y >> screen_double_y)][((x + (b - SpriteSizeXL))>>(screen_scale_x >> screen_double_x))<<1]); if(color_i == MASK_COLOR_16 && l == LayerH[frame-1]){ color_i = *(short *)(&LayerL[frame-1]->line[(y + (a - SpriteSizeYT))>>(screen_scale_y >> screen_double_y)][((x + (b - SpriteSizeXL))>>(screen_scale_x >> screen_double_x))<<1]); } if(color_i == MASK_COLOR_16 && l == LayerL[frame-1]){ color_i = *(short *)(&LayerB[frame-1]->line[(y + (a - SpriteSizeYT))>>(screen_scale_y >> screen_double_y)][((x + (b - SpriteSizeXL))>>(screen_scale_x >> screen_double_x))<<1]); } color_rb = color_i >> 11; color_gb = (color_i >> 5) & 0x3F; color_bb = color_i & 0x1F; color_rs = (short)(color_rs + (color_rb - color_rs) * (float)(tr * 0.015625)); color_gs = (short)(color_gs + (color_gb - color_gs) * (float)(tr * 0.015625)); color_bs = (short)(color_bs + (color_bb - color_bs) * (float)(tr * 0.015625)); val_pixel = (color_rs << 11) | (color_gs << 5) | color_bs; *(short *)&l->line[(y + (a - SpriteSizeYT))>>(screen_scale_y >> screen_double_y)][((x + (b - SpriteSizeXL))>>(screen_scale_x >> screen_double_x))<<1] = val_pixel; } } //} } } } } } else{ for(a = SpriteSizeYT; a <= SpriteSizeYB; a += (1<<(screen_scale_y >> screen_double_y))){ for(b = SpriteSizeXL; b <= SpriteSizeXR; b += (1<<(screen_scale_x >> screen_double_x))){ if(y + (a - SpriteSizeYT) >= 0 && y + (a - SpriteSizeYT) < screen_buffer_y){ if(x + (b - SpriteSizeXL) >= (16>>screen_scale_x) && x + (b - SpriteSizeXL) < screen_buffer_x-16){ // if(SpriteTable[SpriteAddressTable[s] + 4 + (a*SpriteSheetSizeX) + b] != 0xFF){ if(flip == 0) c = a * SpriteSheetSizeX; else c = (SpriteSizeYB + (SpriteSizeYT - a)) * SpriteSheetSizeX; if(mirror == 0) d = b; else d = SpriteSizeXR + (SpriteSizeXL - b); if(z->Act[act].Stage[stage].WaterEnable && y + (a - SpriteSizeYT) + p->Camera_Y_pos >= (water_current_height >> 8)){ val_pixel = SpriteTable[SpriteAddressTable[s] + 4 + (c + d)]; if(val_pixel != MASK_COLOR_16) *(short *)&l->line[(y + (a - SpriteSizeYT))>>(screen_scale_y >> screen_double_y)][((x + (b - SpriteSizeXL))>>(screen_scale_x >> screen_double_x)<<1)-(32 >> (screen_scale_x >> screen_double_x))+32] = 0; //val_pixel; } else{ val_pixel = SpriteTable[SpriteAddressTable[s] + 4 + (c + d)]; if(val_pixel != MASK_COLOR_16) *(short *)&l->line[(y + (a - SpriteSizeYT))>>(screen_scale_y >> screen_double_y)][((x + (b - SpriteSizeXL))>>(screen_scale_x >> screen_double_x)<<1)-(32 >> (screen_scale_x >> screen_double_x))+32] = val_pixel; } //} } } } } } //} } void ClearSprites(){ int i; for(i=0; i < MAX_SPRITE_FILES_ALLOWED; i++) SpriteAddressTable[i] = 0; SpriteTableSize = 0; if((int)(size_t)SpriteTable != ENOMEM){ free(SpriteTable); SpriteTable = 0; } } void LoadSprite(unsigned short s, const char *file, ...){ long pos; int a; int b; int i; int n; int SheetSize; unsigned short NumberOfSprites; unsigned short NumberOfAnimations; signed short SpriteSheetSizeX; signed short SpriteSheetSizeY; signed short SpriteSizeXL; signed short SpriteSizeXR; signed short SpriteSizeYT; signed short SpriteSizeYB; unsigned char NumberOfFrames; unsigned char AnimationSpeed; FILE *psf; PALETTE pal; #ifdef ALLEGRO_DOS allegro_message("Loading sprite file \"%s\"...\n", file); #endif psf = fopen(file, "r+b"); if(psf == NULL){ allegro_message("Could not open file \"%s\". Program closing...\n", file); return; } fread(&NumberOfSprites, 2, 1, psf); fread(&NumberOfAnimations, 2, 1, psf); fread(&SpriteSheetSizeX, 2, 1, psf); fread(&SpriteSheetSizeY, 2, 1, psf); SheetSize = SpriteSheetSizeX * SpriteSheetSizeY; //size = SpriteSizeTable[s-1]; //SpriteAddressTable[s] = size; SpriteAddressTable[s] = SpriteTableSize; SpriteTableSize += (4 + (SheetSize << 2) + (NumberOfSprites << 2) + (NumberOfAnimations << 8)); if(SpriteTable) SpriteTable = (short *)realloc(SpriteTable, SpriteTableSize << 1); else SpriteTable = (short *)malloc(SpriteTableSize << 1); pos = ftell(psf); // save our place so we can go back fseek(psf, NumberOfSprites << 3, SEEK_CUR); for(n=0; n < NumberOfAnimations; n++){ NumberOfFrames = getc(psf); AnimationSpeed = getc(psf); for(i=0; i < NumberOfFrames; i++) fread(&a, 2, 1, psf); } SpriteTable[SpriteAddressTable[s]] = NumberOfSprites; SpriteTable[SpriteAddressTable[s]+1] = NumberOfAnimations; SpriteTable[SpriteAddressTable[s]+2] = SpriteSheetSizeX; SpriteTable[SpriteAddressTable[s]+3] = SpriteSheetSizeY; get_palette(pal); for(n=0; n < SheetSize; n++){ a = getc(psf); b = getc(psf); SpriteTable[SpriteAddressTable[s] + n + 4] = ((b << 8) | a); } fseek(psf, pos, SEEK_SET); for(n=0; n < NumberOfSprites; n++){ fread(&SpriteSizeXL, 2, 1, psf); fread(&SpriteSizeXR, 2, 1, psf); fread(&SpriteSizeYT, 2, 1, psf); fread(&SpriteSizeYB, 2, 1, psf); SpriteTable[SpriteAddressTable[s] + (SheetSize << 2) + 4 + (n << 2)] = SpriteSizeXL; SpriteTable[SpriteAddressTable[s] + (SheetSize << 2) + 4 + (n << 2)+1] = SpriteSizeXR; SpriteTable[SpriteAddressTable[s] + (SheetSize << 2) + 4 + (n << 2)+2] = SpriteSizeYT; SpriteTable[SpriteAddressTable[s] + (SheetSize << 2) + 4 + (n << 2)+3] = SpriteSizeYB; } for(n=0; n < NumberOfAnimations; n++){ NumberOfFrames = getc(psf); AnimationSpeed = getc(psf); //SpriteTable[SpriteAddressTable[s] + (SheetSize << 1) + 4 + (NumberOfSprites << 2) + (n << 8)] = NumberOfFrames; SpriteTable[SpriteAddressTable[s] + (SheetSize << 2) + 4 + (NumberOfSprites << 2) + (n << 8)] = AnimationSpeed; for(i=0; i < NumberOfFrames; i++){ fread(&a, 2, 1, psf); SpriteTable[SpriteAddressTable[s] + (SheetSize << 2) + 4 + (NumberOfSprites << 2) + (n << 8)+1 + i] = a; } for(i = NumberOfFrames; i < 255; i++) SpriteTable[SpriteAddressTable[s] + (SheetSize << 2) + 4 + (NumberOfSprites << 2) + (n << 8)+1 + i] = 0xFF; } fclose(psf); }
001tomclark-research-check
Source/Engine/sprites.c
C
gpl2
15,648
#ifndef SPRITES_H #define SPRITES_H #include "structs.h" #include "zone.h" #ifdef __cplusplus extern "C"{ #endif unsigned char GetAnimationSpeed(unsigned short s, unsigned char *a); unsigned char DrawAnimation(ZONE *z, BITMAP *l, unsigned short s, unsigned char a, unsigned short frame, char m, unsigned char tr, char *ti, unsigned char AnimationSpeed, short x, short y); unsigned char ReadAnimation(unsigned short s, unsigned char *a, unsigned short *frame, char *ti, unsigned char *AnimationSpeed); void DrawSprite(ZONE *z, BITMAP *l, unsigned short s, unsigned char ss, char m, unsigned char tr, short x, short y); void LoadSprite(unsigned short s, const char *f, ...); #define MAX_SPRITE_FILES_ALLOWED 320 int SpriteAddressTable[MAX_SPRITE_FILES_ALLOWED]; int SpriteTableSize; unsigned short *SpriteTable; //int AnimationAddressTable[256]; //int AnimationSizeTable[256]; //char *AnimationTable; #ifdef __cplusplus } #endif #endif
001tomclark-research-check
Source/Engine/sprites.h
C
gpl2
999
/*#include <stdio.h> #include <allegro.h> #include "zone.h" #include "structs.h" #include "common.h" #include "draw.h" #include "text.h" */ #include <stdio.h> #include <math.h> #include <allegro.h> #include "draw.h" #include "text.h" #include "error.h" int InitDraw(ZONE *z) { int i; screen_scale_x = (num_of_frames > 2); screen_scale_y = (num_of_frames > 1); screen_buffer_x = (screen_resolution_x + 32); screen_buffer_y = screen_resolution_y; composite = z->Act[act].Stage[stage].AboveWaterFilterL; bmap = z->Act[act].Stage[stage].BlockMap; block = z->Act[act].Stage[stage].BlockArt; tmap = z->Act[act].Stage[stage].TileMap; wmap = z->Act[act].Stage[stage].WaterMap; palette_val = z->Act[act].Stage[stage].Palette; composite_ptr = z->FILTERCOMPOSITE_AddressTable[composite]; bmap_ptr = z->BMAP_AddressTable[bmap] + 1; block_ptr = z->BLOCK_AddressTable[block] + 2; tmap_ptr = z->TMAP_AddressTable[tmap] + 2; wmap_ptr = z->WMAP_AddressTable[wmap]; palette_ptr = z->PAL_AddressTable[palette_val]; tilesize = z->BMAP[bmap_ptr-1]; tiles_x_short = z->TMAP[tmap_ptr-2] + 1; // e.g. 128 per row tiles_x_long = (z->TMAP[tmap_ptr-2] << 1) + 2; // e.g. 256 per row blocks_x = (z->TMAP[tmap_ptr-2]+1) * (2<<tilesize); blocks_y = (z->TMAP[tmap_ptr-1]+1) * (2<<tilesize); for(i=0; i<4; i++){ if(LayerB[i]){ destroy_bitmap(LayerB[i]); LayerB[i] = 0; } if(LayerL[i]){ destroy_bitmap(LayerL[i]); LayerL[i] = 0; } if(LayerH[i]){ destroy_bitmap(LayerH[i]); LayerH[i] = 0; } if(LayerSH[i]){ destroy_bitmap(LayerSH[i]); LayerSH[i] = 0; } } if(LayerM){ destroy_bitmap(LayerM); LayerM = 0; } if(num_of_frames == 2){ for(i=0; i<2; i++){ LayerB[i] = create_bitmap(screen_buffer_x, screen_buffer_y >> 1 << screen_double_y); LayerL[i] = create_bitmap(screen_buffer_x, screen_buffer_y >> 1 << screen_double_y); LayerH[i] = create_bitmap(screen_buffer_x, screen_buffer_y >> 1 << screen_double_y); LayerSH[i] = create_bitmap(screen_buffer_x, screen_buffer_y >> 1 << screen_double_y); } LayerM = create_bitmap((screen_resolution_x+32)+screen_padding_x, (screen_resolution_y+screen_padding_y) << screen_double_y); } else if(num_of_frames > 2){ for(i=0; i<3; i++){ LayerB[i] = create_bitmap(screen_buffer_x >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); LayerL[i] = create_bitmap(screen_buffer_x >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); LayerH[i] = create_bitmap(screen_buffer_x >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); LayerSH[i] = create_bitmap(screen_buffer_x >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); } if(num_of_frames > 3){ LayerB[3] = create_bitmap(screen_buffer_x >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); LayerL[3] = create_bitmap(screen_buffer_x >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); LayerH[3] = create_bitmap(screen_buffer_x >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); LayerSH[3] = create_bitmap(screen_buffer_x >> 1 << screen_double_x, screen_buffer_y >> 1 << screen_double_y); } LayerM = create_bitmap(((screen_resolution_x+32)+screen_padding_x) << screen_double_x, (screen_resolution_y+screen_padding_y) << screen_double_y); } else{ LayerB[0] = create_bitmap(screen_buffer_x, screen_buffer_y); LayerL[0] = create_bitmap(screen_buffer_x, screen_buffer_y); LayerH[0] = create_bitmap(screen_buffer_x, screen_buffer_y); LayerSH[0] = create_bitmap(screen_buffer_x, screen_buffer_y); } clear(LayerB[0]); clear(LayerL[0]); clear(LayerH[0]); clear(LayerSH[0]); #ifdef ENABLE_MOUSE position_mouse(screen_resolution_x >> 1 << screen_double_x, screen_resolution_y >> 1 << screen_double_y); show_mouse(screen); // the line below 'appears' to prevent a crash while in solidity editing mode position_mouse(screen_resolution_x >> 1 << screen_double_x, screen_resolution_y >> 1 << screen_double_y); #endif return 0; } void SetGfxMode(short res_x, short res_y, short pad_x, short pad_y, short dbl_x, short dbl_y, char full){ screen_resolution_x = res_x; screen_resolution_y = res_y; screen_padding_x = pad_x; screen_padding_y = pad_y; screen_double_x = dbl_x; screen_double_y = dbl_y; screen_offset_x = screen_padding_x >> 1; screen_offset_y = screen_padding_y >> 1; full_screen = full; if(full_screen) SetGfxModeFull(); else SetGfxModeWindow(); InitDraw(&z); } FUNCINLINE void SetGfxModeWindow(){ int i = 1; #ifdef ALLEGRO_DOS request_refresh_rate(60); i = set_gfx_mode(GFX_AUTODETECT, (screen_resolution_x + screen_padding_x) << screen_double_x, (screen_resolution_y + screen_padding_y) << screen_double_y, 0, 0); if(i != 0) quit(ERROR_INIT_SCREEN); #endif #ifdef ALLEGRO_WINDOWS if(desktop_color_depth() == 16) i = set_gfx_mode(GFX_DIRECTX_OVL, (screen_resolution_x + screen_padding_x) << screen_double_x, (screen_resolution_y + screen_padding_y) << screen_double_y, 0, 0); if(i != 0){ i = set_gfx_mode(GFX_DIRECTX_WIN, (screen_resolution_x + screen_padding_x) << screen_double_x, (screen_resolution_y + screen_padding_y) << screen_double_y, 0, 0); if(i != 0){ i = set_gfx_mode(GFX_GDI, (screen_resolution_x + screen_padding_x) << screen_double_x, (screen_resolution_y + screen_padding_y) << screen_double_y, 0, 0); if(i != 0){ quit(ERROR_INIT_SCREEN); } } } #endif #ifdef ALLEGRO_LINUX i = set_gfx_mode(GFX_AUTODETECT_WINDOWED, (screen_resolution_x + screen_padding_x) << screen_double_x, (screen_resolution_y + screen_padding_y) << screen_double_y, 0, 0); if(i != 0) quit(ERROR_INIT_SCREEN); #endif #ifdef ALLEGRO_MACOSX i = set_gfx_mode(GFX_QUARTZ_WINDOW, (screen_resolution_x + screen_padding_x) << screen_double_x, (screen_resolution_y + screen_padding_y) << screen_double_y, 0, 0); if(i != 0) quit(ERROR_INIT_SCREEN); #endif full_screen = 0; // The following line is used to run the engine in the background... #ifndef ALLEGRO_DOS set_display_switch_mode(SWITCH_BACKGROUND); #endif } FUNCINLINE void SetGfxModeFull(){ int i = 1; #ifdef ALLEGRO_DOS request_refresh_rate(60); i = set_gfx_mode(GFX_AUTODETECT, (screen_resolution_x + screen_padding_x) << screen_double_x, (screen_resolution_y + screen_padding_y) << screen_double_y, 0, 0); if(i != 0) quit(ERROR_INIT_SCREEN); #endif #ifdef ALLEGRO_WINDOWS i = set_gfx_mode(GFX_DIRECTX_ACCEL, (screen_resolution_x + screen_padding_x) << screen_double_x, (screen_resolution_y + screen_padding_y) << screen_double_y, 0, 0); if(i != 0){ i = set_gfx_mode(GFX_DIRECTX_SOFT, (screen_resolution_x + screen_padding_x) << screen_double_x, (screen_resolution_y + screen_padding_y) << screen_double_y, 0, 0); if(i != 0){ i = set_gfx_mode(GFX_DIRECTX_SAFE, (screen_resolution_x + screen_padding_x) << screen_double_x, (screen_resolution_y + screen_padding_y) << screen_double_y, 0, 0); if(i != 0){ SetGfxModeWindow(); } } } #endif #ifdef ALLEGRO_LINUX i = set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, (screen_resolution_x + screen_padding_x) << screen_double_x, (screen_resolution_y + screen_padding_y) << screen_double_y, 0, 0); if(i != 0) quit(ERROR_INIT_SCREEN); #endif #ifdef ALLEGRO_MACOSX i = set_gfx_mode(GFX_QUARTZ_FULLSCREEN, (screen_resolution_x + screen_padding_x) << screen_double_x, (screen_resolution_y + screen_padding_y) << screen_double_y, 0, 0); if(i != 0) SetGfxModeWindow(); #endif full_screen = 1; } FUNCINLINE void DrawPlayArea(BITMAP *l, BITMAP *h){ // I make all the variables integers for a slight performance boost unsigned short *block_art; unsigned int block_data; unsigned int blk_x; // short unsigned int blk_y; // short signed int screen_x; // short signed int screen_y; // short int x; int y; unsigned int draw_x; // must be unsigned! unsigned int draw_y; // must be unsigned! unsigned int color; // short unsigned int start_x; // char short screen_scale_x_saved = screen_scale_x; short screen_scale_y_saved = screen_scale_y; const signed short blocks_x_count = blocks_x; // redundant, but improves performance const signed short blocks_y_count = blocks_y; // redundant, but improves performance if(screen_double_x) screen_scale_x = 0; if(screen_double_y) screen_scale_y = 0; if(screen_scale_x){ start_x = p->Camera_X_pos & 1; if(screen_scale_y){ for(y = 0; y < screen_buffer_y+16; y += 16){ screen_y = p->Camera_Y_pos + y; if(y==1) screen_y &= 0xFFF0; for(x = 0; x < screen_buffer_x+16; x += 16){ screen_x = p->Camera_X_pos-16 + x; if(x==1) screen_x &= 0xFFF0; if(screen_x < 0 || screen_y < 0) block_data = 0; else block_data = COMPILED_MAP[ ((screen_x>>4) % blocks_x_count) + (((screen_y>>4) % blocks_y_count) * blocks_x_count)]; block_art = (unsigned short *)&z.BLOCK[((block_data & 0x3FFF) << 9) + block_ptr]; if(block_data & 0x100000){ for(blk_y=0; blk_y < 16; blk_y += 2){ if(y==0 && blk_y < (p->Camera_Y_pos & 0xF)) blk_y = (p->Camera_Y_pos & 0xF); for(blk_x=0; blk_x < 16; blk_x += 2){ if(x==0 && blk_x < (p->Camera_X_pos & 0xF)) blk_x = (p->Camera_X_pos & 0xF); switch((block_data >> 14) & 3){ case 0: color = block_art[blk_x + (blk_y<<4)]; break; case 1: color = block_art[(0xF-blk_x) + (blk_y<<4)]; break; case 2: color = block_art[blk_x + ((0xF-blk_y)<<4)]; break; case 3: color = block_art[(0xF-blk_x) + ((0xF-blk_y)<<4)]; //break; } draw_x = (((screen_x+16 - p->Camera_X_pos + blk_x - (p->Camera_X_pos & 0xF))<<1)>> 1)-start_x; draw_y = (screen_y - p->Camera_Y_pos + blk_y - (p->Camera_Y_pos & 0xF))>> 1; if(draw_y < (screen_buffer_y >> 1) && draw_x < ((screen_buffer_x<<1) >> 1)){ if(color != MASK_COLOR_16){ *(short *)(&h->line[draw_y][draw_x]) = color; } *(short *)(&l->line[draw_y][draw_x]) = MASK_COLOR_16; } } } } else{ for(blk_y=0; blk_y < 16; blk_y += 2){ if(y==0 && blk_y < (p->Camera_Y_pos & 0xF)) blk_y = (p->Camera_Y_pos & 0xF); for(blk_x=0; blk_x < 16; blk_x += 2){ if(x==0 && blk_x < (p->Camera_X_pos & 0xF)) blk_x = (p->Camera_X_pos & 0xF); switch((block_data >> 14) & 3){ case 0: color = block_art[blk_x + (blk_y<<4)]; break; case 1: color = block_art[(0xF-blk_x) + (blk_y<<4)]; break; case 2: color = block_art[blk_x + ((0xF-blk_y)<<4)]; break; case 3: color = block_art[(0xF-blk_x) + ((0xF-blk_y)<<4)]; //break; } draw_x = (((screen_x+16 - p->Camera_X_pos + blk_x - (p->Camera_X_pos & 0xF))<<1)>> 1)-start_x; draw_y = (screen_y - p->Camera_Y_pos + blk_y - (p->Camera_Y_pos & 0xF))>> 1; if(draw_y < (screen_buffer_y >> 1) && draw_x < ((screen_buffer_x<<1) >> 1)){ //*(short *)(&h->line[(screen_y - p->Camera_Y_pos + blk_y - (p->Camera_Y_pos & 0xF))>> 1][(((screen_x+16 - p->Camera_X_pos + blk_x - (p->Camera_X_pos & 0xF))<<1)>> 1)-start_x]) = MASK_COLOR_16; *(short *)(&l->line[draw_y][draw_x]) = color; } } } } } } } else{ for(y = 0; y < screen_buffer_y+16; y += 16){ screen_y = p->Camera_Y_pos + y; if(y==1) screen_y &= 0xFFF0; for(x = 0; x < screen_buffer_x+16; x += 16){ screen_x = p->Camera_X_pos-16 + x; if(x==1) screen_x &= 0xFFF0; if(screen_x < 0 || screen_y < 0) block_data = 0; else block_data = COMPILED_MAP[ ((screen_x>>4) % blocks_x_count) + (((screen_y>>4) % blocks_y_count) * blocks_x_count)]; block_art = (unsigned short *)&z.BLOCK[((block_data & 0x3FFF) << 9) + block_ptr]; if(block_data & 0x100000){ for(blk_y=0; blk_y < 16; blk_y++){ if(y==0 && blk_y < (p->Camera_Y_pos & 0xF)) blk_y = (p->Camera_Y_pos & 0xF); for(blk_x=0; blk_x < 16; blk_x += 2){ if(x==0 && blk_x < (p->Camera_X_pos & 0xF)) blk_x = (p->Camera_X_pos & 0xF); switch((block_data >> 14) & 3){ case 0: color = block_art[blk_x + (blk_y<<4)]; break; case 1: color = block_art[(0xF-blk_x) + (blk_y<<4)]; break; case 2: color = block_art[blk_x + ((0xF-blk_y)<<4)]; break; case 3: color = block_art[(0xF-blk_x) + ((0xF-blk_y)<<4)]; //break; } draw_x = (((screen_x+16 - p->Camera_X_pos + blk_x - (p->Camera_X_pos & 0xF))<<1)>> 1)-start_x; draw_y = screen_y - p->Camera_Y_pos + blk_y - (p->Camera_Y_pos & 0xF); if(draw_y < screen_buffer_y && draw_x < ((screen_buffer_x<<1) >> 1)){ if(color != MASK_COLOR_16){ *(short *)(&h->line[draw_y][draw_x]) = color; } *(short *)(&l->line[draw_y][draw_x]) = MASK_COLOR_16; } } } } else{ for(blk_y=0; blk_y < 16; blk_y++){ if(y==0 && blk_y < (p->Camera_Y_pos & 0xF)) blk_y = (p->Camera_Y_pos & 0xF); for(blk_x=0; blk_x < 16; blk_x += 2){ if(x==0 && blk_x < (p->Camera_X_pos & 0xF)) blk_x = (p->Camera_X_pos & 0xF); switch((block_data >> 14) & 3){ case 0: color = block_art[blk_x + (blk_y<<4)]; break; case 1: color = block_art[(0xF-blk_x) + (blk_y<<4)]; break; case 2: color = block_art[blk_x + ((0xF-blk_y)<<4)]; break; case 3: color = block_art[(0xF-blk_x) + ((0xF-blk_y)<<4)]; //break; } draw_x = (((screen_x+16 - p->Camera_X_pos + blk_x - (p->Camera_X_pos & 0xF))<<1)>> 1)-start_x; draw_y = screen_y - p->Camera_Y_pos + blk_y - (p->Camera_Y_pos & 0xF); if(draw_y < screen_buffer_y && draw_x < ((screen_buffer_x<<1) >> 1)){ //*(short *)(&h->line[screen_y - p->Camera_Y_pos + blk_y - (p->Camera_Y_pos & 0xF)][(((screen_x+16 - p->Camera_X_pos + blk_x - (p->Camera_X_pos & 0xF))<<1)>> 1)-start_x]) = MASK_COLOR_16; *(short *)(&l->line[draw_y][draw_x]) = color; } } } } } } } } else{ start_x = 0; if(screen_scale_y){ for(y = 0; y < screen_buffer_y+16; y += 16){ screen_y = p->Camera_Y_pos + y; if(y==1) screen_y &= 0xFFF0; for(x = 0; x < screen_buffer_x+16; x += 16){ screen_x = p->Camera_X_pos-16 + x; if(x==1) screen_x &= 0xFFF0; if(screen_x < 0 || screen_y < 0) block_data = 0; else block_data = COMPILED_MAP[ ((screen_x>>4) % blocks_x_count) + (((screen_y>>4) % blocks_y_count) * blocks_x_count)]; block_art = (unsigned short *)&z.BLOCK[((block_data & 0x3FFF) << 9) + block_ptr]; if(block_data & 0x100000){ for(blk_y=0; blk_y < 16; blk_y += 2){ if(y==0 && blk_y < (p->Camera_Y_pos & 0xF)) blk_y = (p->Camera_Y_pos & 0xF); for(blk_x=0; blk_x < 16; blk_x++){ if(x==0 && blk_x < (p->Camera_X_pos & 0xF)) blk_x = (p->Camera_X_pos & 0xF); switch((block_data >> 14) & 3){ case 0: color = block_art[blk_x + (blk_y<<4)]; break; case 1: color = block_art[(0xF-blk_x) + (blk_y<<4)]; break; case 2: color = block_art[blk_x + ((0xF-blk_y)<<4)]; break; case 3: color = block_art[(0xF-blk_x) + ((0xF-blk_y)<<4)]; //break; } draw_x = ((screen_x+16 - p->Camera_X_pos + blk_x - (p->Camera_X_pos & 0xF))<<1)-start_x; draw_y = (screen_y - p->Camera_Y_pos + blk_y - (p->Camera_Y_pos & 0xF))>> 1; if(draw_y < (screen_buffer_y >> 1) && draw_x < (screen_buffer_x<<1)){ if(color != MASK_COLOR_16){ *(short *)(&h->line[draw_y][draw_x]) = color; } *(short *)(&l->line[draw_y][draw_x]) = MASK_COLOR_16; } } } } else{ for(blk_y=0; blk_y < 16; blk_y += 2){ if(y==0 && blk_y < (p->Camera_Y_pos & 0xF)) blk_y = (p->Camera_Y_pos & 0xF); for(blk_x=0; blk_x < 16; blk_x++){ if(x==0 && blk_x < (p->Camera_X_pos & 0xF)) blk_x = (p->Camera_X_pos & 0xF); switch((block_data >> 14) & 3){ case 0: color = block_art[blk_x + (blk_y<<4)]; break; case 1: color = block_art[(0xF-blk_x) + (blk_y<<4)]; break; case 2: color = block_art[blk_x + ((0xF-blk_y)<<4)]; break; case 3: color = block_art[(0xF-blk_x) + ((0xF-blk_y)<<4)]; //break; } draw_x = ((screen_x+16 - p->Camera_X_pos + blk_x - (p->Camera_X_pos & 0xF))<<1)-start_x; draw_y = (screen_y - p->Camera_Y_pos + blk_y - (p->Camera_Y_pos & 0xF))>> 1; if(draw_y < (screen_buffer_y >> 1) && draw_x < (screen_buffer_x<<1)){ //*(short *)(&h->line[(screen_y - p->Camera_Y_pos + blk_y - (p->Camera_Y_pos & 0xF))>> 1][((screen_x+16 - p->Camera_X_pos + blk_x - (p->Camera_X_pos & 0xF))<<1)-start_x]) = MASK_COLOR_16; *(short *)(&l->line[draw_y][draw_x]) = color; } } } } } } } else{ for(y = 0; y < screen_buffer_y+16; y += 16){ screen_y = p->Camera_Y_pos + y; if(y==1) screen_y &= 0xFFF0; for(x = 0; x < screen_buffer_x+16; x += 16){ screen_x = p->Camera_X_pos-16 + x; if(x==1) screen_x &= 0xFFF0; if(screen_x < 0 || screen_y < 0) block_data = 0; else block_data = COMPILED_MAP[ ((screen_x>>4) % blocks_x_count) + (((screen_y>>4) % blocks_y_count) * blocks_x_count)]; block_art = (unsigned short *)&z.BLOCK[((block_data & 0x3FFF) << 9) + block_ptr]; if(block_data & 0x100000){ for(blk_y=0; blk_y < 16; blk_y++){ if(y==0 && blk_y < (p->Camera_Y_pos & 0xF)) blk_y = (p->Camera_Y_pos & 0xF); for(blk_x=0; blk_x < 16; blk_x++){ if(x==0 && blk_x < (p->Camera_X_pos & 0xF)) blk_x = (p->Camera_X_pos & 0xF); switch((block_data >> 14) & 3){ case 0: color = block_art[blk_x + (blk_y<<4)]; break; case 1: color = block_art[(0xF-blk_x) + (blk_y<<4)]; break; case 2: color = block_art[blk_x + ((0xF-blk_y)<<4)]; break; case 3: color = block_art[(0xF-blk_x) + ((0xF-blk_y)<<4)]; //break; } draw_x = ((screen_x+16 - p->Camera_X_pos + blk_x - (p->Camera_X_pos & 0xF))<<1)-start_x; draw_y = screen_y - p->Camera_Y_pos + blk_y - (p->Camera_Y_pos & 0xF); if(draw_y < screen_buffer_y && draw_x < (screen_buffer_x<<1)){ if(color != MASK_COLOR_16){ *(short *)(&h->line[draw_y][draw_x]) = color; } *(short *)(&l->line[draw_y][draw_x]) = MASK_COLOR_16; } } } } else{ for(blk_y=0; blk_y < 16; blk_y++){ if(y==0 && blk_y < (p->Camera_Y_pos & 0xF)) blk_y = (p->Camera_Y_pos & 0xF); for(blk_x=0; blk_x < 16; blk_x++){ if(x==0 && blk_x < (p->Camera_X_pos & 0xF)) blk_x = (p->Camera_X_pos & 0xF); switch((block_data >> 14) & 3){ case 0: color = block_art[blk_x + (blk_y<<4)]; break; case 1: color = block_art[(0xF-blk_x) + (blk_y<<4)]; break; case 2: color = block_art[blk_x + ((0xF-blk_y)<<4)]; break; case 3: color = block_art[(0xF-blk_x) + ((0xF-blk_y)<<4)]; //break; } draw_x = ((screen_x+16 - p->Camera_X_pos + blk_x - (p->Camera_X_pos & 0xF))<<1)-start_x; draw_y = screen_y - p->Camera_Y_pos + blk_y - (p->Camera_Y_pos & 0xF); if(draw_y < screen_buffer_y && draw_x < (screen_buffer_x<<1)){ //*(short *)(&h->line[screen_y - p->Camera_Y_pos + blk_y - (p->Camera_Y_pos & 0xF)][((screen_x+16 - p->Camera_X_pos + blk_x - (p->Camera_X_pos & 0xF))<<1)-start_x]) = MASK_COLOR_16; *(short *)(&l->line[draw_y][draw_x]) = color; } } } } } } } } screen_scale_x = screen_scale_x_saved; screen_scale_y = screen_scale_y_saved; } FUNCINLINE void DrawBackArea(BITMAP *b){ // I make all the variables integers for a slight performance boost unsigned short *block_art; unsigned int block_data; unsigned int blk_x; // short unsigned int blk_y; // short signed int screen_x; // short signed int screen_y; // short int x; int y; unsigned int draw_x; // must be unsigned! unsigned int draw_y; // must be unsigned! int cell; unsigned int color; // short unsigned int start_x; // char short screen_scale_x_saved = screen_scale_x; short screen_scale_y_saved = screen_scale_y; short Camera_X_pos_saved = p->Camera_X_pos; short Camera_Y_pos_saved = p->Camera_Y_pos; // The following were commented out due to a performance "loss" //const signed short blocks_x_count = blocks_x; // redundant, but improves performance //const signed short blocks_y_count = blocks_y; // redundant, but improves performance if(screen_double_x) screen_scale_x = 0; if(screen_double_y) screen_scale_y = 0; if(screen_scale_x){ if(screen_scale_y){ for(cell=0; cell < num_of_cells; cell++){ if(p->Camera_X_pos >= cell_data[cell].show_if_x_higher && p->Camera_X_pos <= cell_data[cell].show_if_x_lower && p->Camera_Y_pos >= cell_data[cell].show_if_y_higher && p->Camera_Y_pos <= cell_data[cell].show_if_y_lower){ // Scroll speed p->Camera_X_pos *= ((float)cell_data[cell].scroll_speed_x / 4096); p->Camera_Y_pos *= ((float)cell_data[cell].scroll_speed_y / 4096); // Autoscroll speed if(cell_data[cell].auto_speed_x) p->Camera_X_pos += ticCounterL * (1 / (float)cell_data[cell].auto_speed_x); if(cell_data[cell].auto_speed_y) p->Camera_Y_pos += ticCounterL * (1 / (float)cell_data[cell].auto_speed_y); // Scroll wrap p->Camera_X_pos %= cell_data[cell].scroll_wrap_x; p->Camera_Y_pos %= cell_data[cell].scroll_wrap_y; // Source (top/left) p->Camera_X_pos += cell_data[cell].src_x_left; p->Camera_Y_pos += cell_data[cell].src_y_top; // Destination //x_offset = cell_data[cell].dest_x; //y_offset = cell_data[cell].dest_y; start_x = p->Camera_X_pos & 1; for(y = 0; y < screen_buffer_y+16; y += 16){ screen_y = p->Camera_Y_pos + y; if(y==1) screen_y &= 0xFFF0; for(x = 0; x < screen_buffer_x+16; x += 16){ screen_x = p->Camera_X_pos-16 + x; if(x==1) screen_x &= 0xFFF0; if(screen_x < 0 || screen_y < 0) block_data = 0; else block_data = COMPILED_BACKMAP[ ((screen_x>>4) % blocks_x) + (((screen_y>>4) % blocks_y) * blocks_x)]; block_art = (unsigned short *)&z.BLOCK[((block_data & 0x3FFF) << 9) + block_ptr]; if(block_data & 0x3FFF || !cell_data[cell].transparent){ for(blk_y=0; blk_y < 16; blk_y += 2){ if(y==0 && blk_y < (p->Camera_Y_pos & 0xF)) blk_y = (p->Camera_Y_pos & 0xF); for(blk_x=0; blk_x < 16; blk_x += 2){ if(x==0 && blk_x < (p->Camera_X_pos & 0xF)) blk_x = (p->Camera_X_pos & 0xF); switch((block_data >> 14) & 3){ case 0: color = block_art[blk_x + (blk_y<<4)]; break; case 1: color = block_art[(0xF-blk_x) + (blk_y<<4)]; break; case 2: color = block_art[blk_x + ((0xF-blk_y)<<4)]; break; case 3: color = block_art[(0xF-blk_x) + ((0xF-blk_y)<<4)]; //break; } draw_x = (((screen_x+16 - p->Camera_X_pos + blk_x - (p->Camera_X_pos & 0xF))<<1)>> 1)-start_x; draw_y = (screen_y - p->Camera_Y_pos + blk_y - (p->Camera_Y_pos & 0xF))>> 1; if(draw_y < (screen_buffer_y >> 1) && draw_x < ((screen_buffer_x<<1) >> 1)){ *(short *)(&b->line[draw_y][draw_x]) = color; } } } } } } p->Camera_X_pos = Camera_X_pos_saved; p->Camera_Y_pos = Camera_Y_pos_saved; } } } else{ for(cell=0; cell < num_of_cells; cell++){ if(p->Camera_X_pos >= cell_data[cell].show_if_x_higher && p->Camera_X_pos <= cell_data[cell].show_if_x_lower && p->Camera_Y_pos >= cell_data[cell].show_if_y_higher && p->Camera_Y_pos <= cell_data[cell].show_if_y_lower){ // Scroll speed p->Camera_X_pos *= ((float)cell_data[cell].scroll_speed_x / 4096); p->Camera_Y_pos *= ((float)cell_data[cell].scroll_speed_y / 4096); // Autoscroll speed if(cell_data[cell].auto_speed_x) p->Camera_X_pos += ticCounterL * (1 / (float)cell_data[cell].auto_speed_x); if(cell_data[cell].auto_speed_y) p->Camera_Y_pos += ticCounterL * (1 / (float)cell_data[cell].auto_speed_y); // Scroll wrap p->Camera_X_pos %= cell_data[cell].scroll_wrap_x; p->Camera_Y_pos %= cell_data[cell].scroll_wrap_y; // Source (top/left) p->Camera_X_pos += cell_data[cell].src_x_left; p->Camera_Y_pos += cell_data[cell].src_y_top; // Destination //x_offset = cell_data[cell].dest_x; //y_offset = cell_data[cell].dest_y; start_x = p->Camera_X_pos & 1; for(y = 0; y < screen_buffer_y+16; y += 16){ screen_y = p->Camera_Y_pos + y; if(y==1) screen_y &= 0xFFF0; for(x = 0; x < screen_buffer_x+16; x += 16){ screen_x = p->Camera_X_pos-16 + x; if(x==1) screen_x &= 0xFFF0; if(screen_x < 0 || screen_y < 0) block_data = 0; else block_data = COMPILED_BACKMAP[ ((screen_x>>4) % blocks_x) + (((screen_y>>4) % blocks_y) * blocks_x)]; block_art = (unsigned short *)&z.BLOCK[((block_data & 0x3FFF) << 9) + block_ptr]; if(block_data & 0x3FFF || !cell_data[cell].transparent){ for(blk_y=0; blk_y < 16; blk_y++){ if(y==0 && blk_y < (p->Camera_Y_pos & 0xF)) blk_y = (p->Camera_Y_pos & 0xF); for(blk_x=0; blk_x < 16; blk_x += 2){ if(x==0 && blk_x < (p->Camera_X_pos & 0xF)) blk_x = (p->Camera_X_pos & 0xF); switch((block_data >> 14) & 3){ case 0: color = block_art[blk_x + (blk_y<<4)]; break; case 1: color = block_art[(0xF-blk_x) + (blk_y<<4)]; break; case 2: color = block_art[blk_x + ((0xF-blk_y)<<4)]; break; case 3: color = block_art[(0xF-blk_x) + ((0xF-blk_y)<<4)]; //break; } draw_x = (((screen_x+16 - p->Camera_X_pos + blk_x - (p->Camera_X_pos & 0xF))<<1)>> 1)-start_x; draw_y = screen_y - p->Camera_Y_pos + blk_y - (p->Camera_Y_pos & 0xF); if(draw_y < screen_buffer_y && draw_x < ((screen_buffer_x<<1) >> 1)){ *(short *)(&b->line[draw_y][draw_x]) = color; } } } } } } p->Camera_X_pos = Camera_X_pos_saved; p->Camera_Y_pos = Camera_Y_pos_saved; } } } } else{ if(screen_scale_y){ for(cell=0; cell < num_of_cells; cell++){ if(p->Camera_X_pos >= cell_data[cell].show_if_x_higher && p->Camera_X_pos <= cell_data[cell].show_if_x_lower && p->Camera_Y_pos >= cell_data[cell].show_if_y_higher && p->Camera_Y_pos <= cell_data[cell].show_if_y_lower){ // Scroll speed p->Camera_X_pos *= ((float)cell_data[cell].scroll_speed_x / 4096); p->Camera_Y_pos *= ((float)cell_data[cell].scroll_speed_y / 4096); // Autoscroll speed if(cell_data[cell].auto_speed_x) p->Camera_X_pos += ticCounterL * (1 / (float)cell_data[cell].auto_speed_x); if(cell_data[cell].auto_speed_y) p->Camera_Y_pos += ticCounterL * (1 / (float)cell_data[cell].auto_speed_y); // Scroll wrap p->Camera_X_pos %= cell_data[cell].scroll_wrap_x; p->Camera_Y_pos %= cell_data[cell].scroll_wrap_y; // Source (top/left) p->Camera_X_pos += cell_data[cell].src_x_left; p->Camera_Y_pos += cell_data[cell].src_y_top; // Destination //x_offset = cell_data[cell].dest_x; //y_offset = cell_data[cell].dest_y; start_x = 0; for(y = 0; y < screen_buffer_y+16; y += 16){ screen_y = p->Camera_Y_pos + y; if(y==1) screen_y &= 0xFFF0; for(x = 0; x < screen_buffer_x+16; x += 16){ screen_x = p->Camera_X_pos-16 + x; if(x==1) screen_x &= 0xFFF0; if(screen_x < 0 || screen_y < 0) block_data = 0; else block_data = COMPILED_BACKMAP[ ((screen_x>>4) % blocks_x) + (((screen_y>>4) % blocks_y) * blocks_x)]; block_art =(unsigned short *) &z.BLOCK[((block_data & 0x3FFF) << 9) + block_ptr]; if(block_data & 0x3FFF || !cell_data[cell].transparent){ for(blk_y=0; blk_y < 16; blk_y += 2){ if(y==0 && blk_y < (p->Camera_Y_pos & 0xF)) blk_y = (p->Camera_Y_pos & 0xF); for(blk_x=0; blk_x < 16; blk_x++){ if(x==0 && blk_x < (p->Camera_X_pos & 0xF)) blk_x = (p->Camera_X_pos & 0xF); switch((block_data >> 14) & 3){ case 0: color = block_art[blk_x + (blk_y<<4)]; break; case 1: color = block_art[(0xF-blk_x) + (blk_y<<4)]; break; case 2: color = block_art[blk_x + ((0xF-blk_y)<<4)]; break; case 3: color = block_art[(0xF-blk_x) + ((0xF-blk_y)<<4)]; //break; } draw_x = ((screen_x+16 - p->Camera_X_pos + blk_x - (p->Camera_X_pos & 0xF))<<1)-start_x; draw_y = (screen_y - p->Camera_Y_pos + blk_y - (p->Camera_Y_pos & 0xF))>> 1; if(draw_y < (screen_buffer_y >> 1) && draw_x < (screen_buffer_x<<1)){ *(short *)(&b->line[draw_y][draw_x]) = color; } } } } } } p->Camera_X_pos = Camera_X_pos_saved; p->Camera_Y_pos = Camera_Y_pos_saved; } } } else{ for(cell=0; cell < num_of_cells; cell++){ if(p->Camera_X_pos >= cell_data[cell].show_if_x_higher && p->Camera_X_pos <= cell_data[cell].show_if_x_lower && p->Camera_Y_pos >= cell_data[cell].show_if_y_higher && p->Camera_Y_pos <= cell_data[cell].show_if_y_lower){ // Scroll speed p->Camera_X_pos *= ((float)cell_data[cell].scroll_speed_x / 4096); p->Camera_Y_pos *= ((float)cell_data[cell].scroll_speed_y / 4096); // Autoscroll speed if(cell_data[cell].auto_speed_x) p->Camera_X_pos += ticCounterL * (1 / (float)cell_data[cell].auto_speed_x); if(cell_data[cell].auto_speed_y) p->Camera_Y_pos += ticCounterL * (1 / (float)cell_data[cell].auto_speed_y); // Scroll wrap p->Camera_X_pos %= cell_data[cell].scroll_wrap_x; p->Camera_Y_pos %= cell_data[cell].scroll_wrap_y; // Source (top/left) p->Camera_X_pos += cell_data[cell].src_x_left; p->Camera_Y_pos += cell_data[cell].src_y_top; // Destination //x_offset = cell_data[cell].dest_x; //y_offset = cell_data[cell].dest_y; start_x = 0; for(y = 0; y < screen_buffer_y+16; y += 16){ screen_y = p->Camera_Y_pos + y; if(y==1) screen_y &= 0xFFF0; for(x = 0; x < screen_buffer_x+16; x += 16){ screen_x = p->Camera_X_pos-16 + x; if(x==1) screen_x &= 0xFFF0; if(screen_x < 0 || screen_y < 0) block_data = 0; else block_data = COMPILED_BACKMAP[ ((screen_x>>4) % blocks_x) + (((screen_y>>4) % blocks_y) * blocks_x)]; block_art = (unsigned short *)&z.BLOCK[((block_data & 0x3FFF) << 9) + block_ptr]; if(block_data & 0x3FFF || !cell_data[cell].transparent){ for(blk_y=0; blk_y < 16; blk_y++){ if(y==0 && blk_y < (p->Camera_Y_pos & 0xF)) blk_y = (p->Camera_Y_pos & 0xF); for(blk_x=0; blk_x < 16; blk_x++){ if(x==0 && blk_x < (p->Camera_X_pos & 0xF)) blk_x = (p->Camera_X_pos & 0xF); switch((block_data >> 14) & 3){ case 0: color = block_art[blk_x + (blk_y<<4)]; break; case 1: color = block_art[(0xF-blk_x) + (blk_y<<4)]; break; case 2: color = block_art[blk_x + ((0xF-blk_y)<<4)]; break; case 3: color = block_art[(0xF-blk_x) + ((0xF-blk_y)<<4)]; //break; } draw_x = ((screen_x+16 - p->Camera_X_pos + blk_x - (p->Camera_X_pos & 0xF))<<1)-start_x; draw_y = screen_y - p->Camera_Y_pos + blk_y - (p->Camera_Y_pos & 0xF); if(draw_y < screen_buffer_y && draw_x < (screen_buffer_x<<1)){ *(short *)(&b->line[draw_y][draw_x]) = color; } } } } } } p->Camera_X_pos = Camera_X_pos_saved; p->Camera_Y_pos = Camera_Y_pos_saved; } } } } screen_scale_x = screen_scale_x_saved; screen_scale_y = screen_scale_y_saved; }
001tomclark-research-check
Source/Engine/draw.c
C
gpl2
34,152
/***************************************************************************** * ______ * / _ \ _ __ ______ * / /_ / / / //__ / / _ \ * / ____ / / / / / / / * / / / / / /_ / / * /_ / /_ / \ _____ / * ______ * / ____ / ______ _ __ _ ______ * / /___ / _ \ / //_ \ /_ / / _ \ * _\___ \ / / / / / / / / / / / / /_ / * / /_ / / / /_ / / / / / / / / / /____ * \______ / \ _____ / /_ / /_ / /_ / \ ______/ * * * ProSonic Engine * Created by Damian Grove * * Compiled with DJGPP - GCC 2.952 (DOS) / Dev-C++ 4.9.9.2 (Windows) * Libraries used: * - Allegro - 3.9.34 http://www.talula.demon.co.uk/allegro/ * - DUMB - 0.9.3 http://dumb.sourceforge.net/ * - AllegroOgg - 1.0.3 http://nekros.freeshell.org/delirium/ * ****************************************************************************** * * NAME: ProSonic - Objects functionality header * * FILE: objects.h * * DESCRIPTION: * This file is for anything related specifically to objects and how they * are handled. * *****************************************************************************/ #ifndef OBJECTS_H #define OBJECTS_H //#include "zone.h" #include "structs.h" #include "common.h" #ifdef __cplusplus extern "C"{ #endif #define MAX_LEVEL_OBJECTS 2048 // More than you'll ever need (MUST BE A POWER OF 2!) #define MAX_BUFFER_OBJECTS 128 // If you exceed this, you need to work on your levels #define OBJECT_BUFFER_SCOPE 0x60 // Limit buffer to 0x60 X distance outside screen void fncProcode(unsigned short); void fncM68K(ZONE *z, unsigned short); FUNCINLINE void fncRing(ZONE *z, unsigned short); FUNCINLINE void fncSideSwapper(ZONE *z, unsigned short); FUNCINLINE void ManageObjectNodes(ZONE *z); FUNCINLINE void PollObject(unsigned short); void PollObjectFrame(unsigned short); void CreateObject(char, char, char, char, short, short); void DestroyObject(unsigned short); void AllocateObjects(ZONE *z); unsigned short ObjectCount; // Important for managing object nodes (1024) unsigned short BufferObjectCount; // For statistical analysis (128) unsigned short ObjectNodes[MAX_BUFFER_OBJECTS]; // Each node is 16-bits, and 128 objects allowed unsigned char ObjectStates[MAX_LEVEL_OBJECTS]; // Save certain data from objects, regardless of scope unsigned char ObjectScopePoll[MAX_BUFFER_OBJECTS]; // Polls to see how many players are within range OBJECT_PLOT *Objects; // ZxxOBJ.DAT - Object layout (1023 supported) OBJECT objObject[MAX_BUFFER_OBJECTS]; #ifdef __cplusplus } #endif #endif
001tomclark-research-check
Source/Engine/objects.h
C
gpl2
2,816
#include <stdio.h> #include <allegro.h> #include "structs.h" #include "common.h" #include "m68k.h" #include "objects.h" #include "script.h" #include "obj01.h" void LoadBinary(unsigned char o, const char *filename){ FILE *file_68000; int count; #ifdef ALLEGRO_DOS allegro_message("Loading 68000 binary file \"%s\"...\n", filename); #endif file_68000 = fopen(filename, "rb"); if(file_68000 == NULL){ allegro_message("Could not open file \"%s\"...\n", filename); return; } obj_script_type[o] = SCRIPT_TYPE_MOTOROLA; obj_script_start[o] = script_size; obj_script_size[o] = script_size; fseek(file_68000, 0, SEEK_END); count = ftell(file_68000); script_size += count; obj_script_size[o] = script_size - obj_script_size[o]; fseek(file_68000, 0, SEEK_SET); script = (char*)realloc(script, script_size); fread(&script[obj_script_start[o]], 1, count, file_68000); fclose(file_68000); } void RunScript(unsigned short NodeNumber){ FILE *ramdump; int n; int i; /* The following instructions are implemented - FULLY IMPLEMENTED AND TESTED @ PARTIALLY IMPLEMENTED ? UNTESTED - ADD - ADDA - ADDI - ADDQ - AND - ANDI - ANDI CCR - ANDI SR @ ASL @ ASR - Bcc - BRA - BSR - BCHG - BCLR - BSET - BTST - CLR - CMP - CMPA - CMPI - DBcc - EOR - EORI - EORI CCR - EORI SR - EXT - JMP - JSR - LEA @ LSL @ LSR - MOVE - MOVEA - MOVEM - MOVEQ - MULS - MULU - NEG - NEGX - NOP - NOT - OR - ORI - ORI CCR - ORI SR - RTS - SUB - SUBA - SUBI - SUBQ - SWAP - TST */ DataIn(); #ifdef ENABLE_LOGGING WriteLog("*******************************"); WriteLog("START OF LOG"); #endif for(pc=0; pc < obj_script_size[objObject[NodeNumber].type]; 0){ #ifdef ENABLE_LOGGING WriteLog("*******************************"); VarLog(REG_PC); #endif i = (obj_script[pc] << 8) + obj_script[pc+1]; #ifdef ENABLE_LOGGING var_temp = i; VarLog(VAR_VAR_TEMP); WriteLog("\n"); #endif pc += 2; switch(i >> 12){ case 0: switch(i & 0xF00){ case 0: op_ori(i); break; case 0x200: op_andi(i); break; case 0x400: op_subi(i); break; case 0x600: op_addi(i); break; case 0x800: switch(i & 0xC0){ case 0: op_btst(i); break; case 0x40: op_bchg(i); break; case 0x80: op_bclr(i); break; case 0xC0: op_bset(i); break; } break; case 0xA00: op_eori(i); break; case 0xC00: op_cmpi(i); break; default: if((i & 0x1C0) == 0x100){ op_btst(i); break; } else if((i & 0x1C0) == 0x140){ op_bchg(i); break; } else if((i & 0x1C0) == 0x180){ op_bclr(i); break; } else if((i & 0x1C0) == 0x1C0){ op_bset(i); break; } op_add(i); } break; case 1: op_move(i); break; case 2: op_move(i); break; case 3: op_move(i); break; case 4: if((i & 0xFB8) == 0x880){ op_ext(i); break; } if((i & 0xB80) == 0x880){ op_movem(i); break; } if((i & 0x1C0) == 0x1C0){ op_lea(i); break; } switch(i & 0xF00){ case 0: op_negx(i); break; case 0x200: op_clr(i); break; case 0x400: op_neg(i); break; case 0x600: op_not(i); break; case 0x800: if((i & 0xF8) == 0x40){ op_swap(i); break; } break; case 0xA00: op_tst(i); break; case 0xE00: if(i & 0x80){ op_jmp(i); break; } else if(i == 0x4E71){ #ifdef ENABLE_LOGGING WriteLog("NOP"); #endif break; } else if(i == 0x4E75){ #ifdef ENABLE_LOGGING WriteLog("RTS"); #endif if(reg_a[7] == 0xFFFFFFFC) pc = script_size; else{ //allegro_message("RTS\n\npc = %X", pc); //allegro_message("ram_68k[0xFFF8] = %X", (int)ram_68k[0xFFF8]); pc = *(int *)(&ram_68k[reg_a[7] & 0xFFFF]); reg_a[7] += 4; //allegro_message("RTS\n\npc = %X", pc); } break; } } break; case 5: if((i & 0xF8) == 0xC8){ op_dbcc(i); break; } if(i & 0x100){ op_subq(i); break; } op_addq(i); break; case 6: op_bcc(i); break; case 7: op_moveq(i); break; case 8: op_or(i); break; case 9: op_sub(i); break; case 0xB: if(i & 0x100){ op_eor(i); break; } op_cmp(i); break; case 0xC: if(((i >> 6) & 3) == 3){ op_muls(i); break; } op_and(i); break; case 0xD: op_add(i); break; case 0xE: op_lsd(i); break; case 0xF: DataOut(); switch(i & 0xF00){ case 0x0: pro_jump(i, NodeNumber); break; case 0x100: pro_call(i, NodeNumber); break; } DataIn(); break; default: #ifdef ENABLE_LOGGING WriteLog("INVALID OPCODE!"); #endif //DumpLog("Motorola.log"); allegro_message("INVALID OPCODE!\n\n i = 0x%04X\npc = 0x%04X", i, pc); break; } #ifdef ENABLE_LOGGING d0 = reg_d[0]; d1 = reg_d[1]; d2 = reg_d[2]; d3 = reg_d[3]; d4 = reg_d[4]; d5 = reg_d[5]; d6 = reg_d[6]; d7 = reg_d[7]; a0 = reg_a[0]; a1 = reg_a[1]; a2 = reg_a[2]; a3 = reg_a[3]; a4 = reg_a[4]; a5 = reg_a[5]; a6 = reg_a[6]; a7 = reg_a[7]; VarLog(REG_SR); VarLog(REG_D0); VarLog(REG_D1); VarLog(REG_D2); VarLog(REG_D3); VarLog(REG_D4); VarLog(REG_D5); VarLog(REG_D6); VarLog(REG_D7); VarLog(REG_A0); VarLog(REG_A1); VarLog(REG_A2); VarLog(REG_A3); VarLog(REG_A4); VarLog(REG_A5); VarLog(REG_A6); VarLog(REG_A7); WriteLog("\t~~~ SONIC VALUES ~~~~~~~~~~~~~"); var_temp = (ram_68k[0xFFFF - 0xB002] << 8) + ram_68k[0xFFFF - 0xB003]; WriteLog("\t_art_tile"); VarLog(VAR_VAR_TEMP); var_temp = (ram_68k[0xFFFF - 0xB014] << 8) + ram_68k[0xFFFF - 0xB015]; WriteLog("\t_inertia"); VarLog(VAR_VAR_TEMP); var_temp = (ram_68k[0xFFFF - 0xB02E] << 8) + ram_68k[0xFFFF - 0xB02F]; WriteLog("\t_move_lock"); VarLog(VAR_VAR_TEMP); var_temp = ram_68k[0xFFFF - 0xB018]; WriteLog("\t_priority"); VarLog(VAR_VAR_TEMP); var_temp = ram_68k[0xFFFF - 0xB001]; WriteLog("\t_render_flags"); VarLog(VAR_VAR_TEMP); var_temp = ram_68k[0xFFFF - 0xB024]; WriteLog("\t_routine"); VarLog(VAR_VAR_TEMP); var_temp = ram_68k[0xFFFF - 0xB022]; WriteLog("\t_status"); VarLog(VAR_VAR_TEMP); var_temp = ram_68k[0xFFFF - 0xB028]; WriteLog("\t_subtype"); VarLog(VAR_VAR_TEMP); var_temp = (ram_68k[0xFFFF - 0xB008] << 8) + ram_68k[0xFFFF - 0xB009]; WriteLog("\t_x_pos"); VarLog(VAR_VAR_TEMP); var_temp = (ram_68k[0xFFFF - 0xB010] << 8) + ram_68k[0xFFFF - 0xB011]; WriteLog("\t_x_vel"); VarLog(VAR_VAR_TEMP); var_temp = (ram_68k[0xFFFF - 0xB00C] << 8) + ram_68k[0xFFFF - 0xB00D]; WriteLog("\t_y_pos"); VarLog(VAR_VAR_TEMP); WriteLog("RAM:"); RamLog(0xB000); WriteLog("\t~~~ OBJECT VALUES ~~~~~~~~~~~~"); var_temp = (ram_68k[0xFFFF - 0xB102] << 8) + ram_68k[0xFFFF - 0xB103]; WriteLog("\t_art_tile"); VarLog(VAR_VAR_TEMP); var_temp = (ram_68k[0xFFFF - 0xB114] << 8) + ram_68k[0xFFFF - 0xB115]; WriteLog("\t_inertia"); VarLog(VAR_VAR_TEMP); var_temp = (ram_68k[0xFFFF - 0xB12E] << 8) + ram_68k[0xFFFF - 0xB12F]; WriteLog("\t_move_lock"); VarLog(VAR_VAR_TEMP); var_temp = ram_68k[0xFFFF - 0xB118]; WriteLog("\t_priority"); VarLog(VAR_VAR_TEMP); var_temp = ram_68k[0xFFFF - 0xB101]; WriteLog("\t_render_flags"); VarLog(VAR_VAR_TEMP); var_temp = ram_68k[0xFFFF - 0xB124]; WriteLog("\t_routine"); VarLog(VAR_VAR_TEMP); var_temp = ram_68k[0xFFFF - 0xB122]; WriteLog("\t_status"); VarLog(VAR_VAR_TEMP); var_temp = ram_68k[0xFFFF - 0xB128]; WriteLog("\t_subtype"); VarLog(VAR_VAR_TEMP); var_temp = (ram_68k[0xFFFF - 0xB108] << 8) + ram_68k[0xFFFF - 0xB109]; WriteLog("\t_x_pos"); VarLog(VAR_VAR_TEMP); var_temp = (ram_68k[0xFFFF - 0xB110] << 8) + ram_68k[0xFFFF - 0xB111]; WriteLog("\t_x_vel"); VarLog(VAR_VAR_TEMP); var_temp = (ram_68k[0xFFFF - 0xB10C] << 8) + ram_68k[0xFFFF - 0xB10D]; WriteLog("\t_y_pos"); VarLog(VAR_VAR_TEMP); WriteLog("RAM:"); RamLog(0xB100); #endif //DumpLog("Motorola.log"); //if(i == 0x4441) // allegro_message("HOLY"); //fseek(ramdump, 0, SEEK_SET); //for(n=0; n < 0x10000; n++) // fwrite(&ram_68k[n], 1, 1, ramdump); //allegro_message("%X\n%X", p->x_pos, *(short *)(&ram_68k[0xB008])); } #ifdef ENABLE_LOGGING WriteLog("END OF LOG"); DumpLog("Motorola.log"); #endif //if(obj_script[0x13] != 0xC){ // allegro_message("CRAP"); // rest(40); //} /*ramdump = fopen("ramdump", "w+b"); for(i=0xFFFF; i >=0; i--) fwrite(&ram_68k[i], 1, 1, ramdump); fclose(ramdump);*/ DataOut(); //fclose(ramdump); //allegro_message("PASS"); } void pro_jump(short data, unsigned short NodeNumber){ // F0xx OBJECT *o = &objObject[NodeNumber]; switch(data & 0xFF){ case 0x0: CalcSine(); break; case 0x20: //DestroyObject(o, NodeNumber); PollObjectFrame(NodeNumber); break; case 0x60: PlayFM(d0 & 0x7F, 2, 0); break; case 0x61: PlayPCM(d0 & 0x7F, 2, 0); break; case 0x62: PlayFM(d0 & 0x7F, 0, 0); break; case 0x63: PlayPCM(d0 & 0x7F, 0, 0); break; case 0x81: Sonic_ResetOnFloor(1); break; case 0x83: FindFloor(); break; } #ifdef ENABLE_LOGGING WriteLog("RTS"); #endif if(reg_a[7] == 0xFFFFFFFC) pc = script_size; else{ //allegro_message("RTS\n\npc = %X", pc); //allegro_message("ram_68k[0xFFF8] = %X", (int)ram_68k[0xFFF8]); pc = *(int *)(&ram_68k[reg_a[7] & 0xFFFF]); reg_a[7] += 4; a7 = reg_a[7]; //allegro_message("RTS\n\npc = %X", pc); } } void pro_call(short data, unsigned short NodeNumber){ // F1xx reg_a[7] -= 4; a7 = reg_a[7]; *(int *)(&ram_68k[reg_a[7] & 0xFFFF]) = pc; pro_jump(data, NodeNumber); } /*void pro_call(int target){ if(target >= 0x19C8A && target < 0x19F50) SlopeObject(target); } void SlopeObject(int target){ reg_a[1] = 0xB000; reg_d[6] = 3; reg_a[7] -= 4; ea = &ram_68k[reg_a[7]]; *(int *)ea = reg_d[1]; reg_a[7] -= 4; ea = &ram_68k[reg_a[7]]; *(int *)ea = reg_d[2]; reg_a[7] -= 4; ea = &ram_68k[reg_a[7]]; *(int *)ea = reg_d[3]; reg_a[7] -= 4; ea = &ram_68k[reg_a[7]]; *(int *)ea = reg_d[4]; pro_call(0x19CA0); ea = &ram_68k[reg_a[7]]; reg_d[4] = *(int *)ea; reg_a[7] += 4; ea = &ram_68k[reg_a[7]]; reg_d[3] = *(int *)ea; reg_a[7] += 4; ea = &ram_68k[reg_a[7]]; reg_d[2] = *(int *)ea; reg_a[7] += 4; ea = &ram_68k[reg_a[7]]; reg_d[1] = *(int *)ea; reg_a[7] += 4; reg_a[1] = 0xB040; (*(char *)(&reg_d[6])) += 1; SlopeObject_SingleCharacter: ea = &ram_68k[0xFFFF - (reg_a[0] + 0x22)]; if(((*(char *)ea) >> reg_d[6]) & 1){ pro_call(0x19CA0); return; } (*(short *)(&reg_d[2])) = (*(short *)(&reg_d[1])); (*(short *)(&reg_d[2])) += (*(short *)(&reg_d[2])); //btst #1,status(a1) // solid.asm : line 661 }*/ void DataIn(){ ram_68k[0xFFFF - 0xB001 - ((frame-1) << 6)] = p->render_flags; ram_68k[0xFFFF - 0xB002 - ((frame-1) << 6)] = p->art_tile >> 8; ram_68k[0xFFFF - 0xB003 - ((frame-1) << 6)] = p->art_tile; ram_68k[0xFFFF - 0xB004 - ((frame-1) << 6)] = p->mappings >> 24; ram_68k[0xFFFF - 0xB005 - ((frame-1) << 6)] = p->mappings >> 16; ram_68k[0xFFFF - 0xB006 - ((frame-1) << 6)] = p->mappings >> 8; ram_68k[0xFFFF - 0xB007 - ((frame-1) << 6)] = p->mappings; ram_68k[0xFFFF - 0xB008 - ((frame-1) << 6)] = p->x_pos >> 8; ram_68k[0xFFFF - 0xB009 - ((frame-1) << 6)] = p->x_pos; ram_68k[0xFFFF - 0xB00A - ((frame-1) << 6)] = p->x_pos_pre >> 8; ram_68k[0xFFFF - 0xB00B - ((frame-1) << 6)] = p->x_pos_pre; ram_68k[0xFFFF - 0xB00C - ((frame-1) << 6)] = p->y_pos >> 8; ram_68k[0xFFFF - 0xB00D - ((frame-1) << 6)] = p->y_pos; ram_68k[0xFFFF - 0xB00E - ((frame-1) << 6)] = p->y_pos_pre >> 8; ram_68k[0xFFFF - 0xB00F - ((frame-1) << 6)] = p->y_pos_pre; ram_68k[0xFFFF - 0xB010 - ((frame-1) << 6)] = p->x_vel >> 8; ram_68k[0xFFFF - 0xB011 - ((frame-1) << 6)] = p->x_vel; ram_68k[0xFFFF - 0xB012 - ((frame-1) << 6)] = p->y_vel >> 8; ram_68k[0xFFFF - 0xB013 - ((frame-1) << 6)] = p->y_vel; ram_68k[0xFFFF - 0xB014 - ((frame-1) << 6)] = p->inertia >> 8; ram_68k[0xFFFF - 0xB015 - ((frame-1) << 6)] = p->inertia; ram_68k[0xFFFF - 0xB016 - ((frame-1) << 6)] = p->y_radius; ram_68k[0xFFFF - 0xB017 - ((frame-1) << 6)] = p->x_radius; ram_68k[0xFFFF - 0xB018 - ((frame-1) << 6)] = p->priority; ram_68k[0xFFFF - 0xB019 - ((frame-1) << 6)] = p->width_pixels; ram_68k[0xFFFF - 0xB01A - ((frame-1) << 6)] = p->mapping_frame; ram_68k[0xFFFF - 0xB01B - ((frame-1) << 6)] = p->anim_frame; ram_68k[0xFFFF - 0xB01C - ((frame-1) << 6)] = p->anim; ram_68k[0xFFFF - 0xB01D - ((frame-1) << 6)] = p->next_anim; ram_68k[0xFFFF - 0xB01E - ((frame-1) << 6)] = p->anim_frame_duration;///////////// ram_68k[0xFFFF - 0xB022 - ((frame-1) << 6)] = p->status; ram_68k[0xFFFF - 0xB024 - ((frame-1) << 6)] = p->routine; ram_68k[0xFFFF - 0xB025 - ((frame-1) << 6)] = p->routine_secondary; ram_68k[0xFFFF - 0xB026 - ((frame-1) << 6)] = p->angle; ram_68k[0xFFFF - 0xB027 - ((frame-1) << 6)] = p->flip_angle; ram_68k[0xFFFF - 0xB028 - ((frame-1) << 6)] = p->air_left; ram_68k[0xFFFF - 0xB029 - ((frame-1) << 6)] = p->flip_turned; ram_68k[0xFFFF - 0xB02A - ((frame-1) << 6)] = p->obj_control; ram_68k[0xFFFF - 0xB02B - ((frame-1) << 6)] = p->status_secondary; ram_68k[0xFFFF - 0xB02C - ((frame-1) << 6)] = p->flips_remaining; ram_68k[0xFFFF - 0xB02D - ((frame-1) << 6)] = p->flip_speed; ram_68k[0xFFFF - 0xB02E - ((frame-1) << 6)] = p->move_lock >> 8; ram_68k[0xFFFF - 0xB02F - ((frame-1) << 6)] = p->move_lock; ram_68k[0xFFFF - 0xB030 - ((frame-1) << 6)] = p->invulnerable_time >> 8; ram_68k[0xFFFF - 0xB031 - ((frame-1) << 6)] = p->invulnerable_time; ram_68k[0xFFFF - 0xB032 - ((frame-1) << 6)] = p->invincibility_time >> 8; ram_68k[0xFFFF - 0xB033 - ((frame-1) << 6)] = p->invincibility_time; ram_68k[0xFFFF - 0xB034 - ((frame-1) << 6)] = p->speedshoes_time >> 8; ram_68k[0xFFFF - 0xB035 - ((frame-1) << 6)] = p->speedshoes_time; ram_68k[0xFFFF - 0xB036 - ((frame-1) << 6)] = p->next_tilt; ram_68k[0xFFFF - 0xB037 - ((frame-1) << 6)] = p->tilt; ram_68k[0xFFFF - 0xB038 - ((frame-1) << 6)] = p->stick_to_convex; ram_68k[0xFFFF - 0xB039 - ((frame-1) << 6)] = p->spindash_flag; ram_68k[0xFFFF - 0xB03A - ((frame-1) << 6)] = p->spindash_counter >> 8; ram_68k[0xFFFF - 0xB03B - ((frame-1) << 6)] = p->spindash_counter; ram_68k[0xFFFF - 0xB03C - ((frame-1) << 6)] = p->jumping; ram_68k[0xFFFF - 0xB03D - ((frame-1) << 6)] = p->interact; ram_68k[0xFFFF - 0xB03E - ((frame-1) << 6)] = p->layer - 4; // subtract 4 ram_68k[0xFFFF - 0xB03F - ((frame-1) << 6)] = p->layer_plus - 4; // subtract 4 ram_68k[0xFFFF - 0xEE00 - ((frame-1) << 5)] = p->Camera_X_pos >> 8; ram_68k[0xFFFF - 0xEE01 - ((frame-1) << 5)] = p->Camera_X_pos; ram_68k[0xFFFF - 0xEE04 - ((frame-1) << 5)] = p->Camera_Y_pos >> 8; ram_68k[0xFFFF - 0xEE05 - ((frame-1) << 5)] = p->Camera_Y_pos; ram_68k[0xFFFF - 0xEEC6] = p->Camera_Max_Y_pos >> 8; ram_68k[0xFFFF - 0xEEC7] = p->Camera_Max_Y_pos; ram_68k[0xFFFF - 0xEEC8] = p->Camera_Min_X_pos >> 8; ram_68k[0xFFFF - 0xEEC9] = p->Camera_Min_X_pos; ram_68k[0xFFFF - 0xEECA] = p->Camera_Max_X_pos >> 8; ram_68k[0xFFFF - 0xEECB] = p->Camera_Max_X_pos; ram_68k[0xFFFF - 0xEECC] = p->Camera_Min_Y_pos >> 8; ram_68k[0xFFFF - 0xEECD] = p->Camera_Min_Y_pos; ram_68k[0xFFFF - 0xEECE] = p->Camera_Max_Y_pos_now >> 8; ram_68k[0xFFFF - 0xEECF] = p->Camera_Max_Y_pos_now; ram_68k[0xFFFF - 0xF7D0] = Chain_Bonus_counter >> 8; ram_68k[0xFFFF - 0xF7D1] = Chain_Bonus_counter; ram_68k[0xFFFF - 0xF7D6] = Update_Bonus_score; ram_68k[0xFFFF - 0xF7DA] = p->Camera_X_pos_coarse; ram_68k[0xFFFF - 0xFE10] = zone; ram_68k[0xFFFF - 0xFE11] = act; ram_68k[0xFFFF - 0xFE12] = p->Life_count; ram_68k[0xFFFF - 0xFE1A] = Time_Over_flag; ram_68k[0xFFFF - 0xFE1B] = p->Extra_life_flags; ram_68k[0xFFFF - 0xFE1C] = Update_HUD_lives; ram_68k[0xFFFF - 0xFE1D] = Update_HUD_rings; ram_68k[0xFFFF - 0xFE1E] = Update_HUD_timer; ram_68k[0xFFFF - 0xFE1F] = Update_HUD_score; ram_68k[0xFFFF - 0xFE20] = p->Ring_count >> 8; ram_68k[0xFFFF - 0xFE21] = p->Ring_count; ram_68k[0xFFFF - 0xFE22] = 0; ram_68k[0xFFFF - 0xFE23] = Timer_minute; ram_68k[0xFFFF - 0xFE24] = Timer_second; ram_68k[0xFFFF - 0xFE25] = Timer_millisecond; ram_68k[0xFFFF - 0xFE30] = Last_star_pole_hit; ram_68k[0xFFFF - 0xFE74] = counter_fe74 >> 8; ram_68k[0xFFFF - 0xFE75] = counter_fe74; ram_68k[0xFFFF - 0xFEC8] = Update_HUD_lives_2P; ram_68k[0xFFFF - 0xFEC9] = Update_HUD_rings_2P; ram_68k[0xFFFF - 0xFECA] = Update_HUD_timer_2P; ram_68k[0xFFFF - 0xFECB] = Update_HUD_score_2P; ram_68k[0xFFFF - 0xFECC] = Time_Over_flag_2P; ram_68k[0xFFFF - 0xFEE0] = Last_star_pole_hit_2P; ram_68k[0xFFFF - 0xFF40] = Perfect_rings_left >> 8; ram_68k[0xFFFF - 0xFF41] = Perfect_rings_left; ram_68k[0xFFFF - 0xFFD8] = Two_player_mode; /*reg_a[0] = a0; reg_a[1] = a1; reg_a[2] = a2; reg_a[3] = a3; reg_a[4] = a4; reg_a[5] = a5; reg_a[6] = a6; reg_a[7] = a7;*/ reg_d[0] = d0; reg_d[1] = d1; reg_d[2] = d2; reg_d[3] = d3; reg_d[4] = d4; reg_d[5] = d5; reg_d[6] = d6; reg_d[7] = d7; } void DataOut(){ p->render_flags = ram_68k[0xFFFF - 0xB001 - ((frame-1) << 6)]; p->art_tile = (ram_68k[0xFFFF - 0xB002 - ((frame-1) << 6)] << 8) + ram_68k[0xFFFF - 0xB003 - ((frame-1) << 6)]; p->mappings = (ram_68k[0xFFFF - 0xB004 - ((frame-1) << 6)] << 24) + (ram_68k[0xFFFF - 0xB005 - ((frame-1) << 6)] << 16); + (ram_68k[0xFFFF - 0xB006 - ((frame-1) << 6)] << 8) + ram_68k[0xFFFF - 0xB007 - ((frame-1) << 6)]; p->x_pos = (ram_68k[0xFFFF - 0xB008 - ((frame-1) << 6)] << 8) + ram_68k[0xFFFF - 0xB009 - ((frame-1) << 6)]; p->x_pos_pre = (ram_68k[0xFFFF - 0xB00A - ((frame-1) << 6)] << 8) + ram_68k[0xFFFF - 0xB00B - ((frame-1) << 6)]; p->y_pos = (ram_68k[0xFFFF - 0xB00C - ((frame-1) << 6)] << 8) + ram_68k[0xFFFF - 0xB00D - ((frame-1) << 6)]; p->y_pos_pre = (ram_68k[0xFFFF - 0xB00E - ((frame-1) << 6)] << 8) + ram_68k[0xFFFF - 0xB00F - ((frame-1) << 6)]; p->x_vel = (ram_68k[0xFFFF - 0xB010 - ((frame-1) << 6)] << 8) + ram_68k[0xFFFF - 0xB011 - ((frame-1) << 6)]; p->y_vel = (ram_68k[0xFFFF - 0xB012 - ((frame-1) << 6)] << 8) + ram_68k[0xFFFF - 0xB013 - ((frame-1) << 6)]; p->inertia = (ram_68k[0xFFFF - 0xB014 - ((frame-1) << 6)] << 8) + ram_68k[0xFFFF - 0xB015 - ((frame-1) << 6)]; p->y_radius = ram_68k[0xFFFF - 0xB016 - ((frame-1) << 6)]; p->x_radius = ram_68k[0xFFFF - 0xB017 - ((frame-1) << 6)]; p->priority = ram_68k[0xFFFF - 0xB018 - ((frame-1) << 6)]; p->width_pixels = ram_68k[0xFFFF - 0xB019 - ((frame-1) << 6)]; p->mapping_frame = ram_68k[0xFFFF - 0xB01A - ((frame-1) << 6)]; p->anim_frame = ram_68k[0xFFFF - 0xB01B - ((frame-1) << 6)]; p->anim = ram_68k[0xFFFF - 0xB01C - ((frame-1) << 6)]; p->next_anim = ram_68k[0xFFFF - 0xB01D - ((frame-1) << 6)]; p->anim_frame_duration = ram_68k[0xFFFF - 0xB01E - ((frame-1) << 6)];//////////// p->status = ram_68k[0xFFFF - 0xB022 - ((frame-1) << 6)]; p->routine = ram_68k[0xFFFF - 0xB024 - ((frame-1) << 6)]; p->routine_secondary = ram_68k[0xFFFF - 0xB025 - ((frame-1) << 6)]; p->angle = ram_68k[0xFFFF - 0xB026 - ((frame-1) << 6)]; p->flip_angle = ram_68k[0xFFFF - 0xB027 - ((frame-1) << 6)]; p->air_left = ram_68k[0xFFFF - 0xB028 - ((frame-1) << 6)]; p->flip_turned = ram_68k[0xFFFF - 0xB029 - ((frame-1) << 6)]; p->obj_control = ram_68k[0xFFFF - 0xB02A - ((frame-1) << 6)]; p->status_secondary = ram_68k[0xFFFF - 0xB02B - ((frame-1) << 6)]; p->flips_remaining = ram_68k[0xFFFF - 0xB02C - ((frame-1) << 6)]; p->flip_speed = ram_68k[0xFFFF - 0xB02D - ((frame-1) << 6)]; p->move_lock = (ram_68k[0xFFFF - 0xB02E - ((frame-1) << 6)] << 8) + ram_68k[0xFFFF - 0xB02F - ((frame-1) << 6)]; p->invulnerable_time = (ram_68k[0xFFFF - 0xB030 - ((frame-1) << 6)] << 8) + ram_68k[0xFFFF - 0xB031 - ((frame-1) << 6)]; p->invincibility_time = (ram_68k[0xFFFF - 0xB032 - ((frame-1) << 6)] << 8) + ram_68k[0xFFFF - 0xB033 - ((frame-1) << 6)]; p->speedshoes_time = (ram_68k[0xFFFF - 0xB034 - ((frame-1) << 6)] << 8) + ram_68k[0xFFFF - 0xB035 - ((frame-1) << 6)]; p->next_tilt = ram_68k[0xFFFF - 0xB036 - ((frame-1) << 6)]; p->tilt = ram_68k[0xFFFF - 0xB037 - ((frame-1) << 6)]; p->stick_to_convex = ram_68k[0xFFFF - 0xB038 - ((frame-1) << 6)]; p->spindash_flag = ram_68k[0xFFFF - 0xB039 - ((frame-1) << 6)]; p->spindash_counter = (ram_68k[0xFFFF - 0xB03A - ((frame-1) << 6)] << 8) + ram_68k[0xFFFF - 0xB03B - ((frame-1) << 6)]; p->jumping = ram_68k[0xFFFF - 0xB03C - ((frame-1) << 6)]; p->interact = ram_68k[0xFFFF - 0xB03D - ((frame-1) << 6)]; p->layer = ram_68k[0xFFFF - 0xB03E - ((frame-1) << 6)] + 4; // add four p->layer_plus = ram_68k[0xFFFF - 0xB03F - ((frame-1) << 6)] + 4; // add four p->Camera_X_pos = (ram_68k[0xFFFF - 0xEE00 - ((frame-1) << 5)] << 8) + ram_68k[0xFFFF - 0xEE01 - ((frame-1) << 5)]; p->Camera_Y_pos = (ram_68k[0xFFFF - 0xEE04 - ((frame-1) << 5)] << 8) + ram_68k[0xFFFF - 0xEE05 - ((frame-1) << 5)]; p->Camera_Max_Y_pos = (ram_68k[0xFFFF - 0xEEC6] << 8) + ram_68k[0xFFFF - 0xEEC7]; p->Camera_Min_X_pos = (ram_68k[0xFFFF - 0xEEC8] << 8) + ram_68k[0xFFFF - 0xEEC9]; p->Camera_Max_X_pos = (ram_68k[0xFFFF - 0xEECA] << 8) + ram_68k[0xFFFF - 0xEECB]; p->Camera_Min_Y_pos = (ram_68k[0xFFFF - 0xEECC] << 8) + ram_68k[0xFFFF - 0xEECD]; p->Camera_Max_Y_pos_now = (ram_68k[0xFFFF - 0xEECE] << 8) + ram_68k[0xFFFF - 0xEECF]; Chain_Bonus_counter = (ram_68k[0xFFFF - 0xF7D0] << 8) + ram_68k[0xFFFF - 0xF7D1]; Update_Bonus_score = ram_68k[0xFFFF - 0xF7D6]; p->Camera_X_pos_coarse = ram_68k[0xFFFF - 0xF7DA]; zone = ram_68k[0xFFFF - 0xFE10]; act = ram_68k[0xFFFF - 0xFE11]; p->Life_count = ram_68k[0xFFFF - 0xFE12]; Time_Over_flag = ram_68k[0xFFFF - 0xFE1A]; p->Extra_life_flags = ram_68k[0xFFFF - 0xFE1B]; Update_HUD_lives = ram_68k[0xFFFF - 0xFE1C]; Update_HUD_rings = ram_68k[0xFFFF - 0xFE1D]; Update_HUD_timer = ram_68k[0xFFFF - 0xFE1E]; Update_HUD_score = ram_68k[0xFFFF - 0xFE1F]; p->Ring_count = (ram_68k[0xFFFF - 0xFE20] << 8) + ram_68k[0xFFFF - 0xFE21]; Timer_minute = ram_68k[0xFFFF - 0xFE23]; Timer_second = ram_68k[0xFFFF - 0xFE24]; Timer_millisecond = ram_68k[0xFFFF - 0xFE25]; Last_star_pole_hit = ram_68k[0xFFFF - 0xFE30]; counter_fe74 = (ram_68k[0xFFFF - 0xFE74] << 8) + ram_68k[0xFFFF - 0xFE75]; Update_HUD_lives_2P = ram_68k[0xFFFF - 0xFEC8]; Update_HUD_rings_2P = ram_68k[0xFFFF - 0xFEC9]; Update_HUD_timer_2P = ram_68k[0xFFFF - 0xFECA]; Update_HUD_score_2P = ram_68k[0xFFFF - 0xFECB]; Time_Over_flag_2P = ram_68k[0xFFFF - 0xFECC]; Last_star_pole_hit_2P = ram_68k[0xFFFF - 0xFEE0]; Perfect_rings_left = (ram_68k[0xFFFF - 0xFF40] << 8) + ram_68k[0xFFFF - 0xFF41]; Two_player_mode = ram_68k[0xFFFF - 0xFFD8]; /*a0 = reg_a[0]; a1 = reg_a[1]; a2 = reg_a[2]; a3 = reg_a[3]; a4 = reg_a[4]; a5 = reg_a[5]; a6 = reg_a[6]; a7 = reg_a[7];*/ d0 = reg_d[0]; d1 = reg_d[1]; d2 = reg_d[2]; d3 = reg_d[3]; d4 = reg_d[4]; d5 = reg_d[5]; d6 = reg_d[6]; d7 = reg_d[7]; }
001tomclark-research-check
Source/Engine/script.c
C
gpl2
24,063
#include <stdio.h> #include <allegro.h> #ifndef ALLEGRO_DOS #include <nl.h> #endif //#include "zone.h" //#include "structs.h" //#include "common.h" #include "strings.h" #include "text.h" #include "network.h" #include "common.h" FUNCINLINE int LoadFont0() { FILE *f; f = fopen("font0.dat", "rb"); fread(Font0, 4, 0x200, f); fclose(f); return 0; } void DrawCounter10(BITMAP *l, int i, int x, int y, char fillsize, char font){ unsigned char char1 = i % 10; unsigned char char2 = (i / 10) % 10; unsigned char char3 = (i / 100) % 10; unsigned char char4 = (i / 1000) % 10; unsigned char char5 = (i / 10000) % 10; unsigned char char6 = (i / 100000) % 10; unsigned char char7 = (i / 1000000) % 10; unsigned char char8 = (i / 10000000) % 10; if(char8 == 0 && fillsize < 8) char8 = 0x80; if(char7 == 0 && fillsize < 7 && char8 == 0x80) char7 = 0x80; if(char6 == 0 && fillsize < 6 && char7 == 0x80) char6 = 0x80; if(char5 == 0 && fillsize < 5 && char6 == 0x80) char5 = 0x80; if(char4 == 0 && fillsize < 4 && char5 == 0x80) char4 = 0x80; if(char3 == 0 && fillsize < 3 && char4 == 0x80) char3 = 0x80; if(char2 == 0 && fillsize < 2 && char3 == 0x80) char2 = 0x80; if(char1 == 0 && fillsize < 1 && char2 == 0x80) char1 = 0x80; if(font == 0){ char1 += 8; char2 += 8; char3 += 8; char4 += 8; char5 += 8; char6 += 8; char7 += 8; char8 += 8; } else{ char1 += 0x12; char2 += 0x12; char3 += 0x12; char4 += 0x12; char5 += 0x12; char6 += 0x12; char7 += 0x12; char8 += 0x12; } if(char1 >= 0x80) char1 = 0; if(char2 >= 0x80) char2 = 0; if(char3 >= 0x80) char3 = 0; if(char4 >= 0x80) char4 = 0; if(char5 >= 0x80) char5 = 0; if(char6 >= 0x80) char6 = 0; if(char7 >= 0x80) char7 = 0; if(char8 >= 0x80) char8 = 0; DrawSprite(&z, LayerSH[frame-1], 0x105, char1, NORMAL, 0, x+16, y); DrawSprite(&z, LayerSH[frame-1], 0x105, char2, NORMAL, 0, x+16-0x08, y); DrawSprite(&z, LayerSH[frame-1], 0x105, char3, NORMAL, 0, x+16-0x10, y); DrawSprite(&z, LayerSH[frame-1], 0x105, char4, NORMAL, 0, x+16-0x18, y); DrawSprite(&z, LayerSH[frame-1], 0x105, char5, NORMAL, 0, x+16-0x20, y); DrawSprite(&z, LayerSH[frame-1], 0x105, char6, NORMAL, 0, x+16-0x28, y); DrawSprite(&z, LayerSH[frame-1], 0x105, char7, NORMAL, 0, x+16-0x30, y); DrawSprite(&z, LayerSH[frame-1], 0x105, char8, NORMAL, 0, x+16-0x38, y); } // This is a 16-bit counter void DrawCounter16(BITMAP *l, int i, int x, int y){ int char1 = (i & 0xF000) >> 12; int char2 = (i & 0xF00) >> 8; int char3 = (i & 0xF0) >> 4; int char4 = i & 0xF; int a; if(!draw_frame) return; x += 16; x <<= 1; if(screen_scale_x >> screen_double_x) x = (x >> 1) + 8; if(screen_scale_y >> screen_double_y) y >>= 1; if(y + (8 >> (screen_scale_y >> screen_double_y)) <= screen_buffer_y >> (screen_scale_y >> screen_double_y) && x + (64 >> (screen_scale_x >> screen_double_x)) <= (screen_buffer_x << 1) >> (screen_scale_x >> screen_double_x) && y >= 0 && x >= 0) { for(a = 0; a < 8; a++) { l->line[y + (a >> (screen_scale_y >> screen_double_y))][x] = Font0[(char1 << 7) + (a << 4)]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(1 >> (screen_scale_x >> screen_double_x))] = Font0[(char1 << 7) + (a << 4) + 1]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(2 >> (screen_scale_x >> screen_double_x))] = Font0[(char1 << 7) + (a << 4) + 2]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(3 >> (screen_scale_x >> screen_double_x))] = Font0[(char1 << 7) + (a << 4) + 3]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(4 >> (screen_scale_x >> screen_double_x))] = Font0[(char1 << 7) + (a << 4) + 4]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(5 >> (screen_scale_x >> screen_double_x))] = Font0[(char1 << 7) + (a << 4) + 5]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(6 >> (screen_scale_x >> screen_double_x))] = Font0[(char1 << 7) + (a << 4) + 6]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(7 >> (screen_scale_x >> screen_double_x))] = Font0[(char1 << 7) + (a << 4) + 7]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(8 >> (screen_scale_x >> screen_double_x))] = Font0[(char1 << 7) + (a << 4) + 8]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(9 >> (screen_scale_x >> screen_double_x))] = Font0[(char1 << 7) + (a << 4) + 9]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(10 >> (screen_scale_x >> screen_double_x))] = Font0[(char1 << 7) + (a << 4) + 10]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(11 >> (screen_scale_x >> screen_double_x))] = Font0[(char1 << 7) + (a << 4) + 11]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(12 >> (screen_scale_x >> screen_double_x))] = Font0[(char1 << 7) + (a << 4) + 12]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(13 >> (screen_scale_x >> screen_double_x))] = Font0[(char1 << 7) + (a << 4) + 13]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(14 >> (screen_scale_x >> screen_double_x))] = Font0[(char1 << 7) + (a << 4) + 14]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(15 >> (screen_scale_x >> screen_double_x))] = Font0[(char1 << 7) + (a << 4) + 15]; } for(a = 0; a < 8; a++) { l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(16 >> (screen_scale_x >> screen_double_x))] = Font0[(char2 << 7) + (a << 4)]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(17 >> (screen_scale_x >> screen_double_x))] = Font0[(char2 << 7) + (a << 4) + 1]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(18 >> (screen_scale_x >> screen_double_x))] = Font0[(char2 << 7) + (a << 4) + 2]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(19 >> (screen_scale_x >> screen_double_x))] = Font0[(char2 << 7) + (a << 4) + 3]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(20 >> (screen_scale_x >> screen_double_x))] = Font0[(char2 << 7) + (a << 4) + 4]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(21 >> (screen_scale_x >> screen_double_x))] = Font0[(char2 << 7) + (a << 4) + 5]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(22 >> (screen_scale_x >> screen_double_x))] = Font0[(char2 << 7) + (a << 4) + 6]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(23 >> (screen_scale_x >> screen_double_x))] = Font0[(char2 << 7) + (a << 4) + 7]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(24 >> (screen_scale_x >> screen_double_x))] = Font0[(char2 << 7) + (a << 4) + 8]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(25 >> (screen_scale_x >> screen_double_x))] = Font0[(char2 << 7) + (a << 4) + 9]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(26 >> (screen_scale_x >> screen_double_x))] = Font0[(char2 << 7) + (a << 4) + 10]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(27 >> (screen_scale_x >> screen_double_x))] = Font0[(char2 << 7) + (a << 4) + 11]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(28 >> (screen_scale_x >> screen_double_x))] = Font0[(char2 << 7) + (a << 4) + 12]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(29 >> (screen_scale_x >> screen_double_x))] = Font0[(char2 << 7) + (a << 4) + 13]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(30 >> (screen_scale_x >> screen_double_x))] = Font0[(char2 << 7) + (a << 4) + 14]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(31 >> (screen_scale_x >> screen_double_x))] = Font0[(char2 << 7) + (a << 4) + 15]; } for(a = 0; a < 8; a++) { l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(32 >> (screen_scale_x >> screen_double_x))] = Font0[(char3 << 7) + (a << 4)]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(33 >> (screen_scale_x >> screen_double_x))] = Font0[(char3 << 7) + (a << 4) + 1]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(34 >> (screen_scale_x >> screen_double_x))] = Font0[(char3 << 7) + (a << 4) + 2]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(35 >> (screen_scale_x >> screen_double_x))] = Font0[(char3 << 7) + (a << 4) + 3]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(36 >> (screen_scale_x >> screen_double_x))] = Font0[(char3 << 7) + (a << 4) + 4]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(37 >> (screen_scale_x >> screen_double_x))] = Font0[(char3 << 7) + (a << 4) + 5]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(38 >> (screen_scale_x >> screen_double_x))] = Font0[(char3 << 7) + (a << 4) + 6]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(39 >> (screen_scale_x >> screen_double_x))] = Font0[(char3 << 7) + (a << 4) + 7]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(40 >> (screen_scale_x >> screen_double_x))] = Font0[(char3 << 7) + (a << 4) + 8]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(41 >> (screen_scale_x >> screen_double_x))] = Font0[(char3 << 7) + (a << 4) + 9]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(42 >> (screen_scale_x >> screen_double_x))] = Font0[(char3 << 7) + (a << 4) + 10]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(43 >> (screen_scale_x >> screen_double_x))] = Font0[(char3 << 7) + (a << 4) + 11]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(44 >> (screen_scale_x >> screen_double_x))] = Font0[(char3 << 7) + (a << 4) + 12]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(45 >> (screen_scale_x >> screen_double_x))] = Font0[(char3 << 7) + (a << 4) + 13]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(46 >> (screen_scale_x >> screen_double_x))] = Font0[(char3 << 7) + (a << 4) + 14]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(47 >> (screen_scale_x >> screen_double_x))] = Font0[(char3 << 7) + (a << 4) + 15]; } for(a = 0; a < 8; a++) { l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(48 >> (screen_scale_x >> screen_double_x))] = Font0[(char4 << 7) + (a << 4)]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(49 >> (screen_scale_x >> screen_double_x))] = Font0[(char4 << 7) + (a << 4) + 1]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(50 >> (screen_scale_x >> screen_double_x))] = Font0[(char4 << 7) + (a << 4) + 2]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(51 >> (screen_scale_x >> screen_double_x))] = Font0[(char4 << 7) + (a << 4) + 3]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(52 >> (screen_scale_x >> screen_double_x))] = Font0[(char4 << 7) + (a << 4) + 4]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(53 >> (screen_scale_x >> screen_double_x))] = Font0[(char4 << 7) + (a << 4) + 5]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(54 >> (screen_scale_x >> screen_double_x))] = Font0[(char4 << 7) + (a << 4) + 6]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(55 >> (screen_scale_x >> screen_double_x))] = Font0[(char4 << 7) + (a << 4) + 7]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(56 >> (screen_scale_x >> screen_double_x))] = Font0[(char4 << 7) + (a << 4) + 8]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(57 >> (screen_scale_x >> screen_double_x))] = Font0[(char4 << 7) + (a << 4) + 9]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(58 >> (screen_scale_x >> screen_double_x))] = Font0[(char4 << 7) + (a << 4) + 10]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(59 >> (screen_scale_x >> screen_double_x))] = Font0[(char4 << 7) + (a << 4) + 11]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(60 >> (screen_scale_x >> screen_double_x))] = Font0[(char4 << 7) + (a << 4) + 12]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(61 >> (screen_scale_x >> screen_double_x))] = Font0[(char4 << 7) + (a << 4) + 13]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(62 >> (screen_scale_x >> screen_double_x))] = Font0[(char4 << 7) + (a << 4) + 14]; l->line[y + (a >> (screen_scale_y >> screen_double_y))][x+(63 >> (screen_scale_x >> screen_double_x))] = Font0[(char4 << 7) + (a << 4) + 15]; } } } #ifndef ALLEGRO_DOS void Talk(){ int i; int n; if(typing){ if(keypressed()) keyinput = readkey(); clear_keybuf(); ascii = keyinput; scancode = keyinput >> 8; if(scancode == KEY_ENTER){ typing = 0; if(typing_pos > 0){ message_out[typing_pos] = '\0'; if(net_type){ // if connected to the network i = 1; nlWrite(prosonicnet, &i, 1); // 0x01 = "message" nlWrite(prosonicnet, &net_id[0], 1); // who sent it nlWrite(prosonicnet, message_out, 64); // send message } for(i=0; i <= num_of_messages; i++){ if(message_time[i] == 0){ strcpy(&message[i * 64], message_out); message_out[0] = '\0'; message_time[i] = message_time_limit; if(i == num_of_messages) message_time[0] = 0; // make room for new message i = num_of_messages; } } } Game_paused ^= 1; // this prevents the game from pausing/unpausing } else if(scancode == KEY_BACKSPACE){ if(typing_pos > 0){ typing_pos--; message_out[typing_pos] = '\0'; } } else if(keyinput != 0 && typing_pos < 63){ if(ascii != 0){ message_out[typing_pos] = ascii; typing_pos++; } } keyinput = 0; } else if(key[KEY_T]){ typing = 1; for(typing_pos=0; typing_pos < 64; typing_pos++) message_out[typing_pos] = '\0'; typing_pos = 0; clear_keybuf(); } for(i=0; i <= num_of_messages; i++){ if(message_time[i]) message_time[i]--; } for(i=0; i <= num_of_messages; i++){ if(message_time[0] == 0){ for(n=0; n < num_of_messages; n++){ strcpy(&message[n*64], &message[(n+1)*64]); message_time[n] = message_time[n+1]; } for(n=0; n < 64; n++) message[(num_of_messages * 64) + n] = '\0'; message_time[num_of_messages] = 0; } } for(i=0; i < num_of_messages; i++) DrawText(0, 180-(i<<3), 0, &message[i*64]); DrawText(0, 192, 1, message_out); } #endif void InputText(int x, int y, unsigned char s, const char *string, ...){ for(buffer_count=0; buffer_count < 256; buffer_count++) TextBuffer[buffer_count] = '\0'; buffer_count=0; keyinput = 0; clear_keybuf(); while(!key[KEY_ENTER]){ while(ticUpdated == 0); // wait until 'ticUpdated' is 1 ticUpdated = 0; clear(LayerH[frame-1]); DrawText(x, y, s, string); DrawText(x, y+8, s, &TextBuffer[0]); blit(LayerH[frame-1], screen, 16, 0, 0, 0, screen_buffer_x, screen_buffer_y); if(keypressed()) keyinput = readkey(); clear_keybuf(); ascii = keyinput; scancode = keyinput >> 8; if(scancode == KEY_ENTER) TextBuffer[buffer_count] = '\0'; else if(scancode == KEY_BACKSPACE){ if(buffer_count > 0){ buffer_count--; TextBuffer[buffer_count] = '\0'; } } else if(buffer_count < 255 && keyinput != 0){ #ifdef ALLEGRO_WINDOWS if(ascii != 0 && ascii != '/' && ascii != '*' && ascii != '?' && ascii != '<' && ascii != '>' && ascii != '!'){ TextBuffer[buffer_count] = ascii; buffer_count++; } #else if(ascii != 0 && ascii != '\\' && ascii != '*' && ascii != '?' && ascii != '<' && ascii != '>' && ascii != '!'){ TextBuffer[buffer_count] = ascii; buffer_count++; } #endif } keyinput = 0; } key[KEY_ENTER] = 0; buffer_count=0; Game_paused = 0; } void DrawText(int x, int y, unsigned char s, const char *string, ...){ unsigned char tpos; if(!draw_frame) return; s <<= 7; for(tpos = 0; string[tpos] != '\0'; tpos++) DrawSprite(&z, LayerH[frame-1], 0x104, (string[tpos]-0x2A)+s, NORMAL, 0, x + (tpos << 3) + 16, y); }
001tomclark-research-check
Source/Engine/text.c
C
gpl2
16,190
#ifndef ERROR_H #define ERROR_H #ifdef __cplusplus extern "C"{ #endif #define ERROR_UNKNOWN -1 #define ERROR_NULL 0 #define ERROR_OBJECT_BUFFER 1 #define ERROR_DIVIDE_ZERO 2 #define ERROR_INIT_SCREEN 3 #define ERROR_NO_DEMO_FILES 4 #ifdef __cplusplus } #endif #endif
001tomclark-research-check
Source/Engine/error.h
C
gpl2
334
#ifndef _PSG_H #define _PSG_H #ifdef __cplusplus extern "C" { #endif extern unsigned int PSG_Save[8]; struct _psg { int Current_Channel; int Current_Register; int Register[8]; unsigned int Counter[4]; unsigned int CntStep[4]; int Volume[4]; unsigned int Noise_Type; unsigned int Noise; /* ADDED FOR PROSONIC */ int Volume_b[4]; // Backup of "Volume[n]" }; extern struct _psg PSG; /* Gens */ extern int PSG_Enable; extern int PSG_Improv; extern int *PSG_Buf[2]; extern int PSG_Len; /* end */ void PSG_Write(int data); void PSG_Update_SIN(int **buffer, int length); void PSG_Update(int **buffer, int length); void PSG_Init(int clock, int rate); void PSG_Save_State(void); void PSG_Restore_State(void); /* Gens */ void PSG_Special_Update(void); /* ADDED FOR PROSONIC */ void RestorePSG(char ch); void BackupPSG(char ch); void BackupVolume(); void FadeVolumePSG(unsigned char amount); #ifdef __cplusplus }; #endif #endif
001tomclark-research-check
Source/Engine/psg.h
C
gpl2
1,030
#include "Errors.h" void mem_error() { fprintf(stderr, "Error al pedir memoria.\n"); exit(ERROR_MEMORIA); } void file_error(const char* mensaje) { fprintf(stderr, "%s", mensaje); exit(ERROR_ARCHIVO); } void write_error(const char * mensaje) { fprintf(stderr, "%s", mensaje); exit(ERROR_ESCRITURA); } void read_error(const char * mensaje) { fprintf(stderr, "%s", mensaje); exit(ERROR_LECTURA); } void invalidbase64_error() { fprintf(stderr, "Imposible decodificar archivo, no es un archivo base64 valido.\n"); exit(ERROR_CONVERSION); } void printInvalidArgument() { fprintf(stderr, "Parametro invalido\n"); exit(ERROR_ARGUMENTO); } void printOnlyOneMode() { fprintf(stderr, "Por favor elegir solo un modo de conversion, -e o -d \n"); exit(ERROR_CONVERSION); } void printOneModeIsNeeded() { fprintf(stderr, "Por favor elegir un modo de conversion, -e o -d \n"); exit(ERROR_CONVERSION); }
12014orgcomp
trunk/orgaTP0/src/Errors.c
C
epl
913
#ifndef HELP_H_ #define HELP_H_ #include <stdio.h> void printHelp(char*); void printVersion(); void printNeedOption(char*); #endif
12014orgcomp
trunk/orgaTP0/src/Help.h
C
epl
134
#include "Validation.h" void checkValidBase64(uint8_t position) { if (position == 100) { invalidbase64_error(); } } void checkReadError(FILE* input) { if (ferror(input)) { read_error("Error al leer el archivo de entrada"); } } void checkWriteError(FILE* output) { if (ferror(output)) { write_error(); } }
12014orgcomp
trunk/orgaTP0/src/Validation.c
C
epl
320
#include "BinaryToBase64.h" /* Toma de 1 a 3 bytes binarios y los transforma en 4 en base 64 */ void toBase64(const unsigned char* bytes, int length, char* result) { uint32_t number; /* Numero de 24 bits creado a partir de los bytes de entrada */ uint32_t n[4]; /* Para separar el numero de 24 bits en 4 numeros de 6 bits */ /* Convertir los 3,2 o 1 bytes en un numero de 24 bits */ /* Si tengo 1, 2 o 3 bytes */ number = bytes[0] << 16; if (length >= 2) { /*Si tengo 2 o 3 bytes */ number += bytes[1] << 8; } if (length == 3) { /* Si tengo 3 bytes */ number += bytes[2]; } n[0] = (uint8_t) (number >> 18) & 63; n[1] = (uint8_t) (number >> 12) & 63; n[2] = (uint8_t) (number >> 6) & 63; n[3] = (uint8_t) number & 63; /* Si tengo 1 byte, me salen 2 convertidos y 2 de pad*/ if (length == 1) { result[0] = ALPHABET[n[0]]; result[1] = ALPHABET[n[1]]; } /* Si tengo 2 bytes, me salen 3 convertidos y 1 de pad*/ if (length == 2) { result[0] = ALPHABET[n[0]]; result[1] = ALPHABET[n[1]]; result[2] = ALPHABET[n[2]]; } /* Si tengo 3 bytes, me salen 4 convertidos*/ if (length == 3) { result[0] = ALPHABET[n[0]]; result[1] = ALPHABET[n[1]]; result[2] = ALPHABET[n[2]]; result[3] = ALPHABET[n[3]]; } } int binaryToBase64(FILE* input, FILE* output) { fflush(output); int counter = 0; /* Cuenta cada byte que lee */ int c = fgetc(input); checkReadError(input); unsigned char buffer[3]; /* En este buffer acumulamos 3 bytes. El 4to es para fin de string */ char tmpResult[5]; while (1) { /* Se limpia el resultado temporal */ memset(tmpResult, '=', 4); tmpResult[4] = 0; counter++; if (c == EOF) { /* Cuando llego al EOF convierto los bytes que acumule (si es que tengo alguno) */ counter--; /* Resto uno para que no me cuente el EOF como caracter */ if (counter > 0) { toBase64(buffer, counter,tmpResult); fputs(tmpResult, output); checkWriteError(output); } break; } else { buffer[counter - 1] = c; /* Acumulo el byte en el array */ if (counter == 3) { /* Ya tengo 3 bytes, lo convierto */ toBase64(buffer, counter, tmpResult); fputs(tmpResult, output); checkWriteError(output); counter = 0; } } c = fgetc(input); checkReadError(input); } //Devuelve un 0 si no hubo errores return EXIT_SUCCESS; }
12014orgcomp
trunk/orgaTP0/src/BinaryToBase64.c
C
epl
2,322
#include "Help.h" #include <getopt.h> #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include "BinaryToBase64.h" #include "Base64ToBinary.h" #include "Validation.h" #include "Constants.h" #include "Errors.h" int main(int argc, char** argv) { int next_option; int encoderMode = 0; /* 1 si esta activo */ int decoderMode = 0; /* 1 si esta activo */ int state = 0; char* inputFilename = NULL; char* outputFilename = NULL; int paramCounter = 1; /* Puntero de argumentos que recibe el programa */ FILE *input = NULL, *output = NULL; int cierreDeArchivo = 0; const char* const short_options = "hediov"; const struct option long_options[] = { { "help", 0, NULL, 'h' }, { "encode", 0, NULL, 'e' }, { "decode", 0, NULL, 'd' }, { "input", 0, NULL, 'i' }, { "output", 0, NULL, 'o' }, { "version", 0, NULL, 'v' }, { NULL, 0, NULL, 0 } }; do { next_option = getopt_long(argc, argv, short_options, long_options, NULL); switch (next_option) { case 'h': printHelp(argv[0]); exit(0); case 'e': encoderMode = 1; paramCounter++; break; case 'd': decoderMode = 1; paramCounter++; break; case 'i': inputFilename = argv[paramCounter + 1]; paramCounter += 2; break; case 'o': outputFilename = argv[paramCounter + 1]; paramCounter += 2; break; case 'v': printVersion(); exit(0); case '?': exit(1); default: break; } } while (next_option != -1); if (encoderMode == 1 && decoderMode == 1) { printOnlyOneMode(); } if (encoderMode == 0 && decoderMode == 0) { printOneModeIsNeeded(); } if (inputFilename == NULL || *inputFilename == '-') { input = stdin; } else { input = fopen(inputFilename, "rb"); if (input == NULL) file_error("Error al intentar abrir el archivo de entrada.\n"); } if (outputFilename == NULL || *outputFilename == '-') { output = stdout; } else { output = fopen(outputFilename, "wb"); if (output == NULL) file_error("Error al intentar abrir el archivo de salida.\n"); } if (encoderMode == 1) { binaryToBase64(input, output); } else if (decoderMode == 1) { base64ToBinary(input, output); } if (inputFilename != NULL) cierreDeArchivo = fclose(input); if (cierreDeArchivo != 0) file_error("Error al cerrar el archivo de entrada.\n"); if (outputFilename != NULL) cierreDeArchivo = fclose(output); if (cierreDeArchivo != 0) file_error("Error al cerrar el archivo de salida.\n"); return state; }
12014orgcomp
trunk/orgaTP0/src/main.c
C
epl
2,467
#ifndef BINARYTOBASE64_H_ #define BINARYTOBASE64_H_ #include <stdio.h> #include <stdlib.h> #include "Constants.h" #include "Validation.h" #include "Errors.h" #include <inttypes.h> void toBase64(const unsigned char* bytes, int length, char* result); int binaryToBase64(FILE* input, FILE* output); #endif
12014orgcomp
trunk/orgaTP0/src/BinaryToBase64.h
C
epl
306
#ifndef ERRORS_H_ #define ERRORS_H_ #include <stdlib.h> #include <stdio.h> enum codigoDeError { ERROR_MEMORIA = 2, ERROR_ARCHIVO = 3, ERROR_ESCRITURA = 4, ERROR_LECTURA = 5, ERROR_ARGUMENTO = 6, ERROR_CONVERSION = 7 }; void mem_error(); void file_error(const char* mensaje); void write_error(); void read_error(const char* mensaje); void printInvalidArgument(); void printOnlyOneMode(); void printOneModeIsNeeded(); void invalidbase64_error(); #endif /* ERRORS_H_ */
12014orgcomp
trunk/orgaTP0/src/Errors.h
C
epl
477
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include <inttypes.h> #include "Errors.h" #ifndef VALIDATION_H_ #define VALIDATION_H_ void checkReadError(FILE* input); void checkWriteError(FILE* output); void checkValidBase64(uint8_t position); #endif /* VALIDATION_H_ */
12014orgcomp
trunk/orgaTP0/src/Validation.h
C
epl
306
all: gcc -Wall -lm Base64ToBinary.c BinaryToBase64.c Errors.c Help.c Validation.c main.c -o tp0
12014orgcomp
trunk/orgaTP0/src/makefile
Makefile
epl
97
#ifndef BASE64TOBINARY_H_ #define BASE64TOBINARY_H_ #include <stdio.h> #include <string.h> #include <stdlib.h> #include "Constants.h" #include "Errors.h" #include "Validation.h" #include "Help.h" #include <inttypes.h> int findPositionInAlphabet(char symbol); int toBinary(const unsigned char* buffer, int length, unsigned char* result); int base64ToBinary(FILE* input, FILE* output); #endif /* BASE64TOBINARY_H_ */
12014orgcomp
trunk/orgaTP0/src/Base64ToBinary.h
C
epl
417
#ifndef CONSTANTS_H_ #define CONSTANTS_H_ #define ALPHABET "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" #define PAD_CHAR '=' #endif /* CONSTANTS_H_ */
12014orgcomp
trunk/orgaTP0/src/Constants.h
C
epl
175
#include "Base64ToBinary.h" /* Devuelve el numero asociado al char del Alfabeto64 */ int findPositionInAlphabet(char symbol) { int position = 100; /* Posicion invalida */ int j; for (j = 0; j < 64; j++) { if (ALPHABET[j] == symbol) { position = j; break; } } return position; } int toBinary(const unsigned char* buffer, int length, unsigned char* resultBuff) { uint8_t n[4]; /* 4 bytes de 6 bits cada uno*/ int noPadBytes = 0; /* Analizo cada byte de los 4 que tengo */ int i; for (i = 0; i < 4; i++) { if (buffer[i] != '=') { uint8_t byte = findPositionInAlphabet(buffer[i]); checkValidBase64(byte); n[i] = byte; noPadBytes++; // Cuento cuantos caracteres distintos de = tengo } else { n[i] = 0; } } resultBuff[0] = (n[0] << 2) + (n[1] >> 4); resultBuff[1] = (n[1] << 4) + (n[2] >> 2); resultBuff[2] = (n[2] << 6) + n[3]; return noPadBytes; } int base64ToBinary(FILE* input, FILE* output) { fflush(output); int counter = 0; // Cuenta cada byte que lee int c = fgetc(input); checkReadError(input); unsigned char buffer[4]; // Leo de a 4 caracteres siempre unsigned char tmpResult[3]; int length = 0; while (1) { counter++; if (c == EOF) { break; } else { buffer[counter - 1] = c; /* Acumulo el byte en el array */ if (counter == 4) { /* Ya tengo 4 bytes, lo convierto */ length = toBinary(buffer, counter, tmpResult); fwrite((void*) tmpResult, 1, length-1, output); checkWriteError(output); counter = 0; } } c = fgetc(input); checkReadError(input); } //Devuelve un 0 si no hubo errores return EXIT_SUCCESS; }
12014orgcomp
trunk/orgaTP0/src/Base64ToBinary.c
C
epl
1,611
#include "Help.h" void printHelp( char* executableName ) { printf (" Modo de uso: \n"); printf (" %s [ OPCION ] \n", executableName); printf (" %s [ FICHERO ] \n", executableName); printf (" Pasa el fichero de entrada en base64 a binario y de binario a base64 \n"); printf ("\n Opciones: \n"); printf (" -v, --version Informa de la version y finaliza\n"); printf (" -h, --help Muestra esta ayuda y finaliza\n"); printf (" -e, --encode Codifica el archivo de entrada (binario) en formato base64\n"); printf (" -d, --decode Decodifica el archivo de entrada (base64) a binario\n"); printf (" -i, --input Especifica el archivo de entrada a utilizar (default stdin) \n"); printf (" -o, --output Especifica el archivo de salida a utilizar (default stdout) \n"); printf ("\n Ejemplo de uso: \n"); printf (" %s -e -i archEntrada -o archSalida :Modo codificacion\n", executableName); } void printVersion() { printf (" Version 1.0 \n"); } void printNeedOption ( char* executableName ) { printf (" Se requiere alguna opcion para correr el programa. \n Ejecute %s -h para ver las opciones validas. \n", executableName); }
12014orgcomp
trunk/orgaTP0/src/Help.c
C
epl
1,174
#!/bin/bash cd ../src make > /dev/null cp -a ./tp0 ../tests cd ../tests/ ARCHIVOENTRADA="archivoBase64.txt" SALIDATP0="salidaTp0" SALIDABASE64="salidaBase64" #Mostrar archivos de prueba echo "Archivo de prueba:" cat $ARCHIVOENTRADA if [ "$?" = "0" ]; then #Se ingresa por stdin el archivo y se utiliza tp0 para guardar la decodificacion en un archivo cat $ARCHIVOENTRADA| ./tp0 -d -o $SALIDATP0 echo -e "\nSalida obtenida con base64 de tp0" cat $SALIDATP0 #Se ingresa por stdin el archivo, se lo decodifica con base64 de unix y se dirige stdout a un archivo cat $ARCHIVOENTRADA | base64 -d > $SALIDABASE64 echo -e "\nSalida obtenida con base64 de unix" cat $SALIDABASE64 echo -e "\nComparando ambos archivos... " #Comparacion de ambas salidas diff $SALIDATP0 $SALIDABASE64 if [ "$?" = "0" ]; then echo -e " Los archivos son iguales\n" #END else echo -e " Los archivos son distintos\n" #END #Borrar archivos temporales fi rm $SALIDATP0 rm $SALIDABASE64 rm ./tp0 else exit 1 fi exit 0
12014orgcomp
trunk/orgaTP0/tests/pruebaStdinYSalidaArchivoDecod.sh
Shell
epl
1,038
#!/bin/bash cd ../src make > /dev/null cp -a ./tp0 ../tests cd ../tests/ SALIDATP0="pruebaRandomTp0" SALIDABASE64="pruebaRandomBase64" RANDOMDUMP="randomBin.txt" RANDOMSIZE="100" if [ "$?" = "0" ]; then head -c $RANDOMSIZE /dev/urandom > $RANDOMDUMP ./tp0 -e -i $RANDOMDUMP -o $SALIDATP0 #Codifica en base 64 sin ningun salto de linea base64 -w 0 $RANDOMDUMP > $SALIDABASE64 diff $SALIDATP0 $SALIDABASE64 if [ "$?" = "0" ]; then echo "Los archivos son iguales" else echo "Los archivos son distintos" fi rm $SALIDATP0 rm $SALIDABASE64 rm $RANDOMDUMP rm ./tp0 else exit 1 fi exit 0
12014orgcomp
trunk/orgaTP0/tests/pruebaRandom.sh
Shell
epl
728
#!/bin/bash cd ../src make > /dev/null cp -a ./tp0 ../tests cd ../tests/ SALIDATP0="pruebaRandomTp0" SALIDABASE64="pruebaRandomBase64" RANDOMDUMP="randomBin" RANDOMSIZE="98" if [ "$?" = "0" ]; then head -c $RANDOMSIZE /dev/urandom > $RANDOMDUMP #Codifica en base 64 sin ningun salto de linea base64 -w 0 $RANDOMDUMP > $SALIDABASE64 #Decodifica el archivo codificado usando tp0 ./tp0 -d -i $SALIDABASE64 > $SALIDATP0 #Compara con el binario original diff $SALIDATP0 $RANDOMDUMP if [ "$?" = "0" ]; then echo "Los archivos son iguales" else echo "Los archivos son distintos" fi rm $SALIDATP0 rm $SALIDABASE64 rm $RANDOMDUMP rm ./tp0 else exit 1 fi exit 0
12014orgcomp
trunk/orgaTP0/tests/pruebaRandomDecod.sh
Shell
epl
805
#!/bin/bash cd ../src make > /dev/null cp -a ./tp0 ../tests cd ../tests/ ARCHIVOENTRADA="archivoBase64.txt" SALIDATP0="salidaTp0" SALIDABASE64="salidaBase64" #Mostrar archivos de prueba echo "Archivo de prueba:" cat $ARCHIVOENTRADA if [ "$?" = "0" ]; then #Se ingresa el archivo a tp0, se decodifica y se dirige stdout a un archivo ./tp0 -d -i $ARCHIVOENTRADA > $SALIDATP0 echo -e "\nSalida obtenida con base64 de tp0" cat $SALIDATP0 #Se ingresa el archivo a base64, se decodifica y se dirige stdout a un archivo base64 -d $ARCHIVOENTRADA > $SALIDABASE64 echo -e "\nSalida obtenida con base64 de unix" cat $SALIDABASE64 echo -e "\nComparando ambos archivos... " #Comparacion de ambas salidas diff $SALIDATP0 $SALIDABASE64 if [ "$?" = "0" ]; then echo -e " Los archivos son iguales\n" #END else echo -e " Los archivos son distintos\n" #END #Borrar archivos temporales fi rm $SALIDATP0 rm $SALIDABASE64 rm ./tp0 else exit 1 fi exit 0
12014orgcomp
trunk/orgaTP0/tests/pruebaStdoutYEntradaArchivoDecod.sh
Shell
epl
986
#!/bin/bash directorio_default="../src/" nombre_ejecutable="tp0" #Se puede especificar un subdirectorio opcionalmente gcc -Wall -lm -o $nombre_ejecutable ${1:-$directorio_default}*.c
12014orgcomp
trunk/orgaTP0/tests/compilar.sh
Shell
epl
184
#!/bin/bash cd ../src make > /dev/null cp -a ./tp0 ../tests cd ../tests/ ./tp0 -e -i "archivoInexistente"
12014orgcomp
trunk/orgaTP0/tests/pruebaArchivoInexistente.sh
Shell
epl
106
#!/bin/bash bash pruebaStdinYSalidaArchivo.sh bash pruebaStdinYStdout.sh bash pruebaStdoutYEntradaArchivo.sh bash pruebaArchivoInexistente.sh bash pruebaArchivoSoloLectura.sh bash pruebaRandom.sh #bash pruebaBase64Incorrecto.sh #bash pruebaIdaYvuelta.sh #bash pruebaInfinita.sh
12014orgcomp
trunk/orgaTP0/tests/ejecutarTodasLasPruebas.sh
Shell
epl
279
#!/bin/bash cd ../src make > /dev/null cp -a ./tp0 ../tests cd ../tests/ ARCHIVOENTRADA="archivoBase64.txt" SALIDATP0="salidaTp0" SALIDABASE64="salidaBase64" #Mostrar archivos de prueba echo "Archivo de prueba:" cat $ARCHIVOENTRADA if [ "$?" = "0" ]; then #Se ingresa por stdin el archivo y se utiliza tp0 para guardar la decodificacion en un archivo cat $ARCHIVOENTRADA| ./tp0 -d -o $SALIDATP0 echo -e "\nSalida obtenida con base64 de tp0" cat $SALIDATP0 #Se ingresa por stdin el archivo, se lo decodifica con base64 de unix y se dirige stdout a un archivo cat $ARCHIVOENTRADA | base64 -d > $SALIDABASE64 echo -e "\nSalida obtenida con base64 de unix" cat $SALIDABASE64 echo -e "\nComparando ambos archivos... " #Comparacion de ambas salidas diff $SALIDATP0 $SALIDABASE64 if [ "$?" = "0" ]; then echo -e " Los archivos son iguales\n" #END else echo -e " Los archivos son distintos\n" #END #Borrar archivos temporales fi rm $SALIDATP0 rm $SALIDABASE64 rm ./tp0 else exit 1 fi exit 0
12014orgcomp
trunk/orgaTP0/tests/.svn/text-base/pruebaStdinYSalidaArchivoDecod.sh.svn-base
Shell
epl
1,038
#!/bin/bash directorio="../src/" nombre_ejecutable="tp0" nombre_entrada1="prueba.txt" cd ../src make > /dev/null cp -a ./tp0 ../tests cd ../tests/ valgrind --leak-check=full -v ./$nombre_ejecutable -d -i $archivoBase64.txt
12014orgcomp
trunk/orgaTP0/tests/.svn/text-base/valgrind.sh.svn-base
Shell
epl
225
#!/bin/bash #Pararlo con Ctrl+C cd ../src make > /dev/null cp -a ./tp0 ../tests cd ../tests/ cat -v /dev/urandom | base64 -w0 | ./tp0 -d
12014orgcomp
trunk/orgaTP0/tests/.svn/text-base/pruebaInfinitaDecod.sh.svn-base
Shell
epl
138
#!/bin/bash cd ../src make > /dev/null cp -a ./tp0 ../tests cd ../tests/ ARCHIVOENTRADA="prueba.txt" SALIDATP0="pruebaStdoutConTp0" SALIDABASE64="pruebaStdoutConBase64" #Mostrar archivos de prueba echo "Archivo de prueba:" cat $ARCHIVOENTRADA if [ "$?" = "0" ]; then #Se ingresa el archivo a tp0 y se dirige stdout a un archivo ./tp0 -e -i $ARCHIVOENTRADA > $SALIDATP0 echo -e "\nSalida obtenida con base64 de tp0" cat $SALIDATP0 #Se ingresa el archivo a base64 y se dirige stdout a un archivo base64 -w 0 $ARCHIVOENTRADA > $SALIDABASE64 echo -e "\n\nSalida obtenida con base64 de unix" cat $SALIDABASE64 echo -e "\n\nComparando ambos archivos... " #Comparacion de ambas salidas diff $SALIDATP0 $SALIDABASE64 if [ "$?" = "0" ]; then echo -e " Los archivos son iguales\n" #END else echo -e " Los archivos son distintos\n" #END #Borrar archivos temporales fi rm $SALIDATP0 rm $SALIDABASE64 rm ./tp0 else exit 1 fi exit 0
12014orgcomp
trunk/orgaTP0/tests/.svn/text-base/pruebaStdoutYEntradaArchivo.sh.svn-base
Shell
epl
975
#!/bin/bash cd ../src make > /dev/null cp -a ./tp0 ../tests cd ../tests/ SALIDATP0="pruebaRandomTp0" SALIDABASE64="pruebaRandomBase64" RANDOMDUMP="randomBin" RANDOMSIZE="98" if [ "$?" = "0" ]; then head -c $RANDOMSIZE /dev/urandom > $RANDOMDUMP #Codifica en base 64 sin ningun salto de linea base64 -w 0 $RANDOMDUMP > $SALIDABASE64 #Decodifica el archivo codificado usando tp0 ./tp0 -d -i $SALIDABASE64 > $SALIDATP0 #Compara con el binario original diff $SALIDATP0 $RANDOMDUMP if [ "$?" = "0" ]; then echo "Los archivos son iguales" else echo "Los archivos son distintos" fi rm $SALIDATP0 rm $SALIDABASE64 rm $RANDOMDUMP rm ./tp0 else exit 1 fi exit 0
12014orgcomp
trunk/orgaTP0/tests/.svn/text-base/pruebaRandomDecod.sh.svn-base
Shell
epl
805
#!/bin/bash cd ../src make > /dev/null cp -a ./tp0 ../tests cd ../tests/ SALIDATP0="BinTp0" SALIDABASE64="BinBase64" ENTRADA="archivoBase64.txt" echo "Archivo de prueba:" cat $ENTRADA if [ "$?" = "0" ]; then #Decodifica el archivo codificado usando tp0 cat $ENTRADA | ./tp0 -d > $SALIDATP0 echo -e "\nSalida obtenida con base64 de tp0" cat $SALIDATP0 #Decodifica el archivo codificado usando base64 cat $ENTRADA | base64 -d > $SALIDABASE64 echo -e "\nSalida obtenida con base64 de unix" cat $SALIDABASE64 echo -e "\nComparando ambos archivos... " #Compara ambas conversiones diff $SALIDATP0 $SALIDABASE64 if [ "$?" = "0" ]; then echo "Los archivos son iguales" else echo "Los archivos son distintos" fi rm $SALIDATP0 rm $SALIDABASE64 rm ./tp0 else exit 1 fi exit 0
12014orgcomp
trunk/orgaTP0/tests/.svn/text-base/pruebaStdinStdoutDecod.sh.svn-base
Shell
epl
894
#!/bin/bash cd ../src make > /dev/null cp -a ./tp0 ../tests cd ../tests/ echo -n 'foo' | ./tp0 -e echo ""
12014orgcomp
trunk/orgaTP0/tests/.svn/text-base/pruebaStdinEncode.sh.svn-base
Shell
epl
106
#!/bin/bash cd ../src make > /dev/null cp -a ./tp0 ../tests cd ../tests/ #El archivo tiene caracteres que no son parte del alfabeto cat base64Incorrecto.txt ./tp0 -d -i base64Incorrecto.txt -o archivoBasura rm archivoBasura
12014orgcomp
trunk/orgaTP0/tests/.svn/text-base/pruebaBase64Incorrecto.sh.svn-base
Shell
epl
224
#!/bin/bash directorio_default="../src/" nombre_ejecutable="tp0" #Se puede especificar un subdirectorio opcionalmente gcc -Wall -lm -o $nombre_ejecutable ${1:-$directorio_default}*.c
12014orgcomp
trunk/orgaTP0/tests/.svn/text-base/compilar.sh.svn-base
Shell
epl
184
#!/bin/bash bash pruebaStdinYSalidaArchivo.sh bash pruebaStdinYStdout.sh bash pruebaStdoutYEntradaArchivo.sh bash pruebaArchivoInexistente.sh bash pruebaArchivoSoloLectura.sh bash pruebaRandom.sh #bash pruebaBase64Incorrecto.sh #bash pruebaIdaYvuelta.sh #bash pruebaInfinita.sh
12014orgcomp
trunk/orgaTP0/tests/.svn/text-base/ejecutarTodasLasPruebas.sh.svn-base
Shell
epl
279
#!/bin/bash cd ../src make > /dev/null cp -a ./tp0 ../tests cd ../tests/ SALIDATP0="pruebaRandomTp0" SALIDABASE64="pruebaRandomBase64" RANDOMDUMP="randomBin.txt" RANDOMSIZE="100" if [ "$?" = "0" ]; then head -c $RANDOMSIZE /dev/urandom > $RANDOMDUMP ./tp0 -e -i $RANDOMDUMP -o $SALIDATP0 #Codifica en base 64 sin ningun salto de linea base64 -w 0 $RANDOMDUMP > $SALIDABASE64 diff $SALIDATP0 $SALIDABASE64 if [ "$?" = "0" ]; then echo "Los archivos son iguales" else echo "Los archivos son distintos" fi rm $SALIDATP0 rm $SALIDABASE64 rm $RANDOMDUMP rm ./tp0 else exit 1 fi exit 0
12014orgcomp
trunk/orgaTP0/tests/.svn/text-base/pruebaRandom.sh.svn-base
Shell
epl
728