User Tools

Site Tools


notes:comporg

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:comporg [2022/02/16 19:13] – [Working with Memory in TIC80] mpronti2notes:comporg [2022/04/18 11:33] (current) – [Mouse] mpronti2
Line 14: Line 14:
 =====Working with Memory in TIC80===== =====Working with Memory in TIC80=====
  
-===Persistent Memory===+====Persistent Memory====
  
 In order to change part of persistent memory, the process begins as normal for any other piece of memory - `poke(addr, data, size)`. However, making persistent changes to the cart is a special case - since the cart is loaded into RAM (virtually and in reality) when it is run, changes made to its memory will only apply as long as it is being run, meaning something else needs to happen in order to, say, make a visual change to the editor. After making a change to the cart, the `sync()` function must be called, specifically `sync(0, 0, true)`, which breaks down into: sync(sector bitmask, bank, tocart) - in our case, sync all (0) sectors to bank zero (0), and apply the changes to the cart (true). In order to change part of persistent memory, the process begins as normal for any other piece of memory - `poke(addr, data, size)`. However, making persistent changes to the cart is a special case - since the cart is loaded into RAM (virtually and in reality) when it is run, changes made to its memory will only apply as long as it is being run, meaning something else needs to happen in order to, say, make a visual change to the editor. After making a change to the cart, the `sync()` function must be called, specifically `sync(0, 0, true)`, which breaks down into: sync(sector bitmask, bank, tocart) - in our case, sync all (0) sectors to bank zero (0), and apply the changes to the cart (true).
 +
 +In addition, one can utilize the pmem() function to retrieve or save values to persistent memory without needing the pro version of TIC-80. This is how you use it: pmem(address (0-255), 32-bit value), where the value can be omitted if one only wants to read from the address. This will save value(s) across sessions on that cart, and can be used for high scores, palettes, etc. You may want to have a "reset" function for this if you plan on adjusting and saving the palette, just in case things go sideways and you want to start over.
  
 For specific, upper-level questions (such as how to use peek() and/or poke()), it can be hard to find online resources. However, the "Code examples and snippets" section of the TIC-80 wiki has many examples that can be studied for a greater understanding of the subject matter. For specific, upper-level questions (such as how to use peek() and/or poke()), it can be hard to find online resources. However, the "Code examples and snippets" section of the TIC-80 wiki has many examples that can be studied for a greater understanding of the subject matter.
  
 +It is currently understood that there is 1 kilobyte of persistent memory stored at offset 0x14004 (remember '0x' means it is hexadecimal) in memory. This persistent memory can be manipulated to one's liking as described above, and any usage of `poke()` here will have that data remain in the game cart.
 +
 +====Scanlines====
 +
 +TIC-80 renders the pixels on its screen using scanlines. The concept is straightforward, from the top of the screen to the bottom a scanline is rendered per each row of pixels (up to the Y position maximum).
 +
 +Using the 'SCN()' function, one can manipulate the memory in TIC-80 between each scanline render as such:
 +<code lua>
 +function SCN(scanline)
 +    -- insert code here to manipulate pallete or other things 
 +end
 +</code>
 +One simply has to put this function somewhere in their script, it is similar to the main function 'TIC()' so it requires no additional setup. If one is familiar with modifying the palette, they can modify the palette between scanline rendering allowing for more than 16 colors (maximum colors in a palette) to render at a time.
 +
 +=====TIC-80 Functions=====
 +
 +====Map====
 +
 +If you choose to go the TIC-80 route from week 8 onwards, you may find it beneficial to play with the map. mset(), mget(), and map() are important tools for such an endeavor. You can use combinations of these functions to, for example, manage player collisions with environment(s). You can also use map() in addition to SCN() to display a colorful, fulfilling background without the need to manually display a bunch of sprites.
 +
 +====Audio====
 +
 +The sfx() function within TIC-80 can be used to play audio from the SFX Editor. It can adjust the note, duration, volume, etc.
 +
 +====Mouse====
 +
 +mouse() returns, among others, 3 important things: the x-coordinate of the pointer, the y-coordinate of the pointer, and whether or not the mouse is being clicked. Thus,
 +<code>
 +x,y,z = mouse()
 +</code>
 +will allow you to check where you are currently clicking. This allows for the implementation of buttons for the player.
 =====TIC80 System Variables===== =====TIC80 System Variables=====
  
Line 36: Line 69:
 =====Useful Links===== =====Useful Links=====
  
 +====NES====
 +
 +[[https://en.wikibooks.org/wiki/6502_Assembly#Instructions|6502 Assembly Documentation]]
 +
 +[[https://taywee.github.io/NerdyNights|Nerdy Nights NES Programming Tutorial]]
 +
 +[[https://en.wikibooks.org/wiki/NES_Programming#NES_2A03_CPU_memory_map|NES General Memory Map]]
 +
 +[[https://nesdev-wiki.nes.science/wikipages/PPU_programmer_reference.xhtml#PPU_Registers|Detailed NES PPU Register Map]]
 +
 +[[https://philpem.me.uk/leeedavison/6502/prng/index.html|8-bit Pseudorandom Number Generator Example in 6502 Assembly]]
 +
 +[[https://www.nesdev.org/wiki/PPU_OAM|NES Sprite Bytes]]
 ====TIC-80==== ====TIC-80====
  
Line 42: Line 88:
 [[https://hub.xpub.nl/sandbot/PrototypingTimes/tic80-manual.html|TIC-80 Missing Manual]] [[https://hub.xpub.nl/sandbot/PrototypingTimes/tic80-manual.html|TIC-80 Missing Manual]]
  
 +[[https://github.com/nesbox/TIC-80/wiki/ram|TIC-80 RAM & VRAM Layout]]
 +
 +[[https://github.com/nesbox/TIC-80/wiki/code-examples-and-snippets|TIC-80 Code Examples and Snippets]]
 +
 +[[https://childishgiant.github.io/tic-80-palette-editor|Online TIC-80 Palette Tool]] 
 +
 +[[https://github.com/nesbox/TIC-80/wiki/SCN|SCN (Scanline Function)]]
 +
 +====Lua====
 +[[https://www.lua.org/pil/contents.html|Programming in Lua]]
 ====Projects/Games==== ====Projects/Games====
  
notes/comporg.1645056799.txt.gz · Last modified: 2022/02/16 19:13 by mpronti2