Log In  

Cart #palman-2 | 2024-03-21 | Embed ▽ | License: CC4-BY-NC-SA
6

So, this is some really simple code to use in your carts to easily load .hex palette
files on the cart. Check out palman.lua on the cart to see how it works.

v1.01 Changed a value to allow reading from .hex files created in Picotron.

v1.1 Added a notify message that the file was not found if the file was not found,
without crashing the cart.

P#144005 2024-03-21 01:14 ( Edited 2024-03-21 13:14)

1

I added the ability to import and export hex files to my paint app to be compatible with this and noticed a potential issue.
For some reason the issue only happens with the hex file exported from my paint app and not the whale.hex file you provided, even though they share some of the same colors.

The issue happens with any color with only numbers on it, causing the split function to turn it into a number instead of a string.

The reason this happens with my hex file and not yours seems to be because of line endings. When you strip out the \n characters, it leaves behind some \r characters that prevent them from being converted into numbers. Editing the function to remove the \r characters confirms this, and will cause the issue to happen with whale.hex as well.

function get_pal(name)
    local naming = "pal/" .. name
    local palette = split(fetch(naming):gsub("\r",""),"\n",true)
    for i = 1, #palette do
        local hexstr = "0x00"..palette[i]
        local nmbr = tonum(hexstr)
        poke4(0x5000 + 4 * (i-1),nmbr)
    end
end

Changing the third parameter of split to false to prevent number conversions will completely fix the issue on both files.
(the gsub is optional since the extra \r characters don't seem to be causing any issues)

function get_pal(name)
    local naming = "pal/" .. name
    local palette = split(fetch(naming),"\n",false)
    for i = 1, #palette do
        local hexstr = "0x00"..palette[i]
        local nmbr = tonum(hexstr)
        poke4(0x5000 + 4 * (i-1),nmbr)
    end
end
P#144014 2024-03-21 04:38 ( Edited 2024-03-21 04:39)
2

Great catch! I definitely wanted it to be integrated with gfx apps on Picotron, so this is great to catch now.

I've updated it with the change you made.

P#144033 2024-03-21 12:25

[Please log in to post a comment]