Log In  

This is a basic example i wrote to give a friend some help learning basic use of memory

--basic himem use for small games.
--credit, 𝘭uenardi 𝘭uigi 𝘥e 𝘱olo aka 𝘭egion𝘬𝘪𝘯
--𝘮𝘢𝘬𝘦 𝘴𝘶𝘳𝘦 you are currently in the working folder for these carts.
--this cart 'mem_1.p8' runs the code, 
--create a cart called mem_2.p8 contains 1 sprite we will load and put into himem.
--this copies a entire sprite sheet
--then we will draw the sprites both from this cart and mem2.p8 from himem. 

--dest = destination-
--src = source-
--len = length-

--0x0000 is the start of the graphics memory
--0x1000 is the end of the graphics memory
--0x8000 is the start of himem (high memory)
-- all of these are memory addresses

-- backup current gfx sheet in mem_1.p8 from memory address 0 to 0x1000 and put it down in himem at 0x8000  
This will fill himem from 0x8000 to 0x9000 with data from the sprite sheet already in the cart mem_1.p8
memcpy(0x8000, 0x0000, 0x1000)

-- here we copied to x8000 and we copied from x0000 to x1000 meaning the length is 0x1000  
-- meaning length + destination address = next open space = x9000
--         x1000  + x8000 = x9000

-- meaning here we copy or reload to the next available space = 0x9000

-- load data from a cart from the source address 0x000 to 0x1000 from mem_2.p8
-- just like mem cpy reload will copy to the specified addresse 0x9000
reload(0x9000, 0x0000, 0x1000,'mem_2.p8')

-- now we have both sheets in memory

-- sheet 1 is at 0x8000
-- and
-- sheet 2 is at 0x9000

function _draw()
cls(0) 

--load sprite sheet1 
--copies memory from 0x8000 to 0x0000 and dont forget the lenght 0x1000
memcpy(0x0000, 0x8000, 0x1000) 
--this replaces everything from 0x000 to 0x1000 from 0x8000

-- now we draw everything we want from that sheet
spr(1,32,64) in this case

--load sprite sheet2 
--copies memory from 0x9000 to 0x0000 and dont forget the lenght 0x1000
memcpy(0x0000, 0x9000, 0x1000) 
--this replaces everything from 0x000 to 0x1000 from 0x9000

-- now we draw everything we want from that sheet!
spr(1,96,64)
--done
end

--note that i used sprite index one on both sheets
-- this does impact performance a bit but works for small games that just need a few more sprites handy

see the discord link bellow for the zipped example
https://cdn.discordapp.com/attachments/938158730246254643/997921832227328131/himem_-_basic_example_how_to_use.zip

P#114416 2022-07-16 17:31 ( Edited 2022-07-17 04:16)

1

nice! quick tip: on bbs, use ``` for

code blocks

it just makes everything look nice!
this also works on discord :)

P#114418 2022-07-16 18:54
:: dw817
2

Yep, also you can use
[ code ]
1 2 3 4 5
a b c d e
[ /code ]

Removing the spaces from the brackets yields the following:

1 2 3 4 5
a b c d e

This is how normal multi-line code is recorded for others to view.

When you start a new message, click PREVIEW then click FORMATTING HELP to see all the options available for entering a message.

Now you just need to post a quick cart, could be a demo could be anything really. Show us what you can do. :)

Hope This Helps !

P#114421 2022-07-16 20:50 ( Edited 2022-07-17 01:09)
:: Xeonic
1

ok

P#114432 2022-07-17 04:16

not sure what "small games" refers to, be aware that reload()
doesn't work with BBS.
There is a way to use himen in a BBS-compatible way, as this region is not cleared when calling load(), gist is:

  • run cart1
  • store spritesheet in himem
  • load cart2 (from cart1)
  • store spritesheet in himem
  • load game cart (from cart2)
P#114509 2022-07-18 13:51

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2022-09-28 12:17:22 | 0.009s | Q:15