{"id":9493,"date":"2025-03-18T11:04:44","date_gmt":"2025-03-18T10:04:44","guid":{"rendered":"https:\/\/retrofixer.it\/?page_id=9493"},"modified":"2025-03-19T22:10:02","modified_gmt":"2025-03-19T21:10:02","slug":"magic-bin","status":"publish","type":"page","link":"https:\/\/retrofixer.it\/en\/magic-bin\/","title":{"rendered":"Magic BIN"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-page\" data-elementor-id=\"9493\" class=\"elementor elementor-9493\" data-elementor-post-type=\"page\">\n\t\t\t\t<div class=\"elementor-element elementor-element-2df3093 e-con-full e-flex e-con e-parent\" data-id=\"2df3093\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-5c6ff6a elementor-widget elementor-widget-html\" data-id=\"5c6ff6a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"mycheck\">\r\n<label for=\"projectName\" style=\"padding-top:5px;\">Nome Progetto:<\/label>\r\n    <input type=\"text\" id=\"projectName\" oninput=\"updateUsage()\" style=\"height:30px;margin-left:10px;width:150px;\">\r\n    <br><br>\t\r\n    <label for=\"epromSelect\" style=\" padding:9px 0 0 10px;\">Seleziona EPROM:<\/label>\r\n    <select id=\"epromSelect\" onchange=\"updateUsage()\" style=\"width:120px;margin-left:10px;\">\r\n        <option value=\"27c16\">27c16<\/option>\r\n        <option value=\"27c32\">27c32<\/option>\r\n        <option value=\"27c64\">27c64<\/option>\r\n        <option value=\"27c128\">27c128<\/option>\r\n        <option value=\"27c256\" selected>27c256<\/option>\r\n        <option value=\"27c512\">27c512<\/option>\r\n        <option value=\"27c010\">27c010<\/option>\r\n        <option value=\"27c020\">27c020<\/option>\r\n    <\/select>\r\n    <br><br>\r\n    <label for=\"fillSelect\" style=\" padding:9px 0 0 20px;\">Riempimento:<\/label>\r\n    <select id=\"fillSelect\" onchange=\"updateUsage()\" style=\"width:80px;margin-left:10px;\">\r\n        <option value=\"0\">00<\/option>\r\n        <option value=\"255\" selected>FF<\/option>\r\n    <\/select>\r\n     <button onclick=\"document.getElementById('loadProject').click()\">Carica Progetto<\/button>\r\n     \r\n     <input type=\"file\" id=\"loadProject\" multiple accept=\".json\" onchange=\"loadProject(event)\" style=\"display:none\">\r\n\r\n    <p id=\"fileName\"><\/p>\r\n    \r\n    <button onclick=\"saveProject()\">Salva Progetto<\/button>\r\n   \r\n    <button onclick=\"resetProject()\">Nuovo Progetto<\/button>\r\n    <\/div>\r\n    \r\n    <script>\r\n        let voceSelezionata = null;\r\n        let projectData = {\r\n\t\t\tprojectName: \"\",\t\t\t\r\n            epromType: \"27c256\",\r\n            files: [],\r\n            fillByte: 0xFF,\r\n            selectedFileIndex: null\r\n        };\r\n\r\n        const epromSizes = {\r\n            \"27c16\": 2048,\r\n            \"27c32\": 4096,\r\n            \"27c64\": 8192,\r\n            \"27c128\": 16384,\r\n            \"27c256\": 32768,\r\n            \"27c512\": 65536,\r\n            \"27c010\": 131072,\r\n            \"27c020\": 262144,\r\n        };\r\n\r\n        function addEmptySpace() {\r\n            let spaceSize = parseInt(document.getElementById(\"spaceSize\").value) * 1024;\r\n            projectData.files.push({ name: `Dummy (${spaceSize}B)`, size: spaceSize, data: null });\r\n            updateUsage();\r\n        }\r\n        \r\n        function updateUsage() {\r\n            let selectedEPROM = document.getElementById(\"epromSelect\").value;\r\n            projectData.epromType = selectedEPROM;\r\n            projectData.fillByte = parseInt(document.getElementById(\"fillSelect\").value);\r\n\t\t\tprojectData.projectName = document.getElementById(\"projectName\").value;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   \r\n            let totalSize = projectData.files.reduce((acc, file) => acc + file.size, 0);\r\n            let epromSize = epromSizes[selectedEPROM];\r\n            let usagePercentage = (totalSize \/ epromSize) * 100;\r\n\r\n            document.getElementById(\"usage\").textContent = `${totalSize} \/ ${epromSize} bytes utilizzati (${usagePercentage.toFixed(2)}%)`;\r\n            \r\n            if (usagePercentage>100) {\r\n                document.getElementById(\"usage\").style.color=\"#F00\";\r\n            } else {\r\n                              document.getElementById(\"usage\").style.color=\"#FFF\";\r\n            }\r\n            document.getElementById(\"progress\").value = usagePercentage;\r\n            updateFileList();\r\n        }\r\n\r\n        function addFiles(event) {\r\n            let files = event.target.files;\r\n            for (let i = 0; i < files.length; i++) {\r\n\t\t\t\tif (files[i].name.endsWith(\".bin\") || files[i].name.endsWith(\".rom\")) {\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   \r\n\t\t\t\t\tprojectData.files.push({ name: files[i].name, size: files[i].size, data: files[i] });\r\n\t\t\t\t}\r\n            }\r\n            updateUsage();\r\n        }\r\n\r\n        function saveProject() {\r\n            const projectJson = JSON.stringify(projectData);\r\n            const blob = new Blob([projectJson], { type: \"application\/json\" });\r\n            const link = document.createElement(\"a\");\r\n            link.href = URL.createObjectURL(blob);\r\n            link.download = projectData.projectName || \"eprom_project.json\";\r\n            link.click();\r\n        }\r\n\r\n        function loadProject(event) {\r\n            const file = event.target.files[0];\r\n            if (!file) return;\r\n\r\n            const reader = new FileReader();\r\n            reader.onload = function(e) {\r\n                if (file.name.endsWith(\".json\")) {\r\n                    projectData = JSON.parse(e.target.result);\r\n                    document.getElementById(\"epromSelect\").value = projectData.epromType;\r\n                    document.getElementById(\"fillSelect\").value = projectData.fillByte;\r\n\t\t\t\t\tdocument.getElementById(\"projectName\").value = projectData.projectName;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   \r\n                    updateUsage();\r\n                } else if (file.name.endsWith(\".bin\")) {\r\n                    projectData.files.push({ name: file.name, size: file.size, data: file });\r\n                    updateUsage();\r\n                }\r\n            };\r\n            reader.readAsText(file);\r\n        }\r\n\r\nfunction showHexView() {\r\n    let hexView = document.getElementById(\"hexView\");\r\n    hexView.innerHTML = \"\";\r\n\r\n    if (projectData.selectedFileIndex === null || \r\n        projectData.selectedFileIndex >= projectData.files.length || \r\n        projectData.selectedFileIndex < 0) {\r\n        return;\r\n    }\r\n\r\n    let file = projectData.files[projectData.selectedFileIndex];\r\n    if (!file || !file.data) return;\r\n\r\n    let hexString = \"\";\r\n    for (let i = 0; i < file.data.length; i += 16) {\r\n        let row = file.data.slice(i, i + 16);\r\n        let hex = Array.from(row).map(byte => byte.toString(16).padStart(2, '0')).join(\" \");\r\n        let ascii = Array.from(row).map(byte => (byte >= 32 && byte <= 126) ? String.fromCharCode(byte) : \".\").join(\"\");\r\n        hexString += `<div>${i.toString(16).padStart(6, '0')}: ${hex.padEnd(48)} | ${ascii}<\/div>`;\r\n    }\r\n    hexView.innerHTML = hexString;\r\n}\r\n\r\n        function showHexView2() {\r\n            let hexView = document.getElementById(\"hexView\");\r\n            hexView.innerHTML = \"\";\r\n            alert(projectData.selectedFileIndex);\r\n            \/\/if (projectData.selectedFileIndex === null) return;\r\n            \/\/let file = projectData.files[projectData.selectedFileIndex];\r\n            let file = projectData.files[0];\r\n            hexView.innerHTML = \"check data\";\r\n            if (!file.data) return;\r\n            hexView.innerHTML = \"data ok\";\r\n            let hexString = \"\";\r\n            for (let i = 0; i < file.data.length; i += 16) {\r\n                let row = file.data.slice(i, i + 16);\r\n                let hex = Array.from(row).map(byte => byte.toString(16).padStart(2, '0')).join(\" \");\r\n                let ascii = Array.from(row).map(byte => (byte >= 32 && byte <= 126) ? String.fromCharCode(byte) : \".\").join(\"\");\r\n                hexString += `<div>${i.toString(16).padStart(6, '0')}: ${hex.padEnd(48)} | ${ascii}<\/div>`;\r\n            }\r\n            hexView.innerHTML = hexString;\r\n        }\r\n        \r\n         function updateFileList() {\r\n            let fileList = document.getElementById(\"fileList\");\r\n            fileList.innerHTML = \"\";\r\n            let offset = 0;\r\n            projectData.files.forEach((file, index) => {\r\n                let listItem = document.createElement(\"li\");\r\n                let startAddress = offset.toString(16).toUpperCase().padStart(4, '0');\r\n                let endAddress = (offset + file.size - 1).toString(16).toUpperCase().padStart(4, '0');\r\n                listItem.textContent = `${file.name} - ${file.size} bytes (${startAddress} - ${endAddress})`;\r\n                listItem.onclick = function() {\r\n                    projectData.selectedFileIndex = index;\r\n                    highlightSelectedFile();\r\n                    showHexView();\r\n                };\r\n                listItem.oncontextmenu = function(e) {\r\n                    e.preventDefault();\r\n                    projectData.selectedFileIndex = index;\r\n                    removeSelectedFile();\r\n                };\r\n                \r\n                 listItem.draggable = true;\r\n                listItem.ondragstart = (event) => {\r\n                    event.dataTransfer.setData(\"index\", index);\r\n                };\r\n                listItem.ondragover = (event) => {\r\n                    event.preventDefault();\r\n                };\r\n                listItem.ondrop = (event) => {\r\n                    event.preventDefault();\r\n                    let draggedIndex = event.dataTransfer.getData(\"index\");\r\n                    let droppedIndex = index;\r\n                    let temp = projectData.files[draggedIndex];\r\n                    projectData.files[draggedIndex] = projectData.files[droppedIndex];\r\n                    projectData.files[droppedIndex] = temp;\r\n                    updateFileList();\r\n                };\r\n                fileList.appendChild(listItem);\r\n                offset += file.size;\r\n            });\r\n        }\r\n        \r\n                function highlightSelectedFile() {\r\n            let fileListItems = document.getElementById(\"fileList\").children;\r\n            for (let i = 0; i < fileListItems.length; i++) {\r\n                fileListItems[i].style.color = (i === projectData.selectedFileIndex) ? \"yellow\" : \"white\";\r\n            }\r\n        }\r\n\r\n        function saveROM() {\r\n            let epromSize = epromSizes[projectData.epromType];\r\n            let fullSize = projectData.files.reduce((acc, file) => acc + file.size, 0);\r\n            if (fullSize>epromSize){\r\n                let numParts = Math.ceil(fullSize \/ epromSize);\r\n            let binaryData = new Uint8Array(fullSize);\r\n            let offset = 0;\r\n\r\n            projectData.files.forEach(file => {\r\n                let reader = new FileReader();\r\n                reader.onload = function(e) {\r\n                    let fileBytes = new Uint8Array(e.target.result);\r\n                    binaryData.set(fileBytes, offset);\r\n                    offset += fileBytes.length;\r\n\r\n                    if (offset >= fullSize) {\r\n                        for (let i = 0; i < numParts; i++) {\r\n                            let part = binaryData.slice(i * epromSize, (i + 1) * epromSize);\r\n                            saveBinaryFile(part, `eprom_part_${i + 1}.bin`);\r\n                        }\r\n                    }\r\n                };\r\n                reader.readAsArrayBuffer(file.data);\r\n            });\r\n            } else {\r\n            \r\n            let binaryData = new Uint8Array(epromSize).fill(projectData.fillByte);\r\n            let offset = 0;\r\n\r\n            projectData.files.forEach(file => {\r\n                let reader = new FileReader();\r\n                reader.onload = function(e) {\r\n                    let fileBytes = new Uint8Array(e.target.result);\r\n                    binaryData.set(fileBytes, offset);\r\n                    offset += fileBytes.length;\r\n\r\n                    if (offset >= binaryData.length || projectData.files.indexOf(file) === projectData.files.length - 1) {\r\n                        saveBinaryFile(binaryData, projectData.projectName + \"_eprom_output.bin\");\r\n                    }\r\n                };\r\n                reader.readAsArrayBuffer(file.data);\r\n            });\r\n            }\r\n        }\r\n\r\n        function resetProject() {\r\n            projectData = { epromType: \"27c256\", files: [], fillByte: 0xFF };\r\n\t\t\tdocument.getElementById(\"projectName\").value = \"\";\r\n            document.getElementById(\"romInput\").value = \"\";\r\n            document.getElementById(\"loadProject\").value = \"\";\r\n            updateUsage();\r\n        }\r\n\r\n        function saveBinaryFile(data, filename) {\r\n            const blob = new Blob([data], { type: \"application\/octet-stream\" });\r\n            const link = document.createElement(\"a\");\r\n            link.href = URL.createObjectURL(blob);\r\n            link.download = filename;\r\n            link.click();\r\n        }\r\n        \r\n                function removeSelectedFile() {\r\n            if (projectData.selectedFileIndex !== null) {\r\n                projectData.files.splice(projectData.selectedFileIndex, 1);\r\n                projectData.selectedFileIndex = null;\r\n                updateUsage();\r\n            }\r\n        }\r\n        \r\n\r\n    <\/script>\r\n    \t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-24d02e7 e-con-full e-flex e-con e-child\" data-id=\"24d02e7\" data-element_type=\"container\" data-e-type=\"container\" data-settings=\"{&quot;background_background&quot;:&quot;classic&quot;}\">\n\t\t\t\t<div class=\"elementor-element elementor-element-e1a107b elementor-widget__width-initial elementor-widget elementor-widget-html\" data-id=\"e1a107b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"mycheck\">\n         <button onclick=\"document.getElementById('romInput').click()\">Carica BIN<\/button>\n\n    <select id=\"spaceSize\" style=\"width:100px\">\n        <option value=\"1\">1 KB<\/option>\n        <option value=\"2\">2 KB<\/option>\n        <option value=\"4\">4 KB<\/option>\n        <option value=\"8\">8 KB<\/option>\n        <option value=\"16\">16 KB<\/option>\n        <option value=\"32\">32 KB<\/option>\n        <option value=\"64\">64 KB<\/option>\n        <option value=\"128\">128 KB<\/option>\n    <\/select>\n    <button onclick=\"addEmptySpace()\">Aggiungi Spazio<\/button>\n    <button onclick=\"saveROM()\">Salva ROM<\/button>\n    <button onclick=\"removeSelectedFile()\">Rimuovi ROM<\/button><!--button id=\"cancella\" onclick=\"cancsel()\">Cancella Selezionata<\/button-->\n         <\/div><div class=\"mycheck\">\n    <input type=\"file\" id=\"romInput\" multiple accept=\".bin,.rom\" onchange=\"addFiles(event)\" style=\"display:none;\"><br>\n    <progress id=\"progress\" value=\"0\" max=\"100\" style=\"margin-right:10px\"><\/progress>\n    <p id=\"usage\">0 \/ 32768 bytes utilizzati (0%)<\/p>\n    <\/div><div class=\"mycheck\">\n    <h3>File Caricati<\/h3><\/div>\n    <ul id=\"fileList\"><\/ul>\n\n\n\n\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9e2765c elementor-widget__width-initial elementor-widget elementor-widget-html\" data-id=\"9e2765c\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h4>Hex View<\/h4>\n    <div id=\"hexView\" style=\"font-family: monospace; white-space: pre-wrap;\">--<\/div>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Nome Progetto: Seleziona EPROM: 27c1627c3227c6427c12827c25627c51227c01027c020 Riempimento: 00FF Carica Progetto Salva Progetto Nuovo Progetto Carica BIN 1 KB2 KB4 KB8 KB16 KB32 KB64 KB128 KB Aggiungi Spazio<span class=\"excerpt-hellip\"> [\u2026]<\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-9493","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/pages\/9493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/comments?post=9493"}],"version-history":[{"count":220,"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/pages\/9493\/revisions"}],"predecessor-version":[{"id":9725,"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/pages\/9493\/revisions\/9725"}],"wp:attachment":[{"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/media?parent=9493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/categories?post=9493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/retrofixer.it\/en\/wp-json\/wp\/v2\/tags?post=9493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}