Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Beginners question [C and SMSDevKit]

Reply to topic Goto page Previous  1, 2, 3
Author Message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12883
  • Location: London
Reply with quote
Post Posted: Thu Jul 25, 2019 8:46 am
The VDP memory has to be accessed by sending data one byte at a time, mostly. Technically, this is because it is mapped to the Z80 as an IO device, not memory mapped, so you can't just "memcpy" the data to where you want it, and random access is much slower than sequential access.

To write two bytes to memory at location 0x1234 you have to write two bytes to set the write address and mode (using the upper bits of the two bytes to set the mode), followed by those 32 bytes. If the screen is on then you also have to do this slower than the Z80 is capable of because the screen rendering is competing for access to the RAM.

Doing this "raw" from C is probably possible but you don't have good control of the timing (although maybe the optimiser is never good enough to make it too fast...).

The answer is perhaps to make some custom assembly to deal with specific cases - for example, setting the tilemap in a 25 bytes column or a 32 bytes row, from a contiguous source buffer. You pay the cost to fill that buffer in C during the screen time and then do the fast "unsafe" load during the VBlank. Maybe this already exists?
  View user's profile Send private message Visit poster's website
  • Joined: 24 Jun 2019
  • Posts: 45
Reply with quote
Post Posted: Thu Jul 25, 2019 12:43 pm
I see and understand :o

So using SMS_setTile for setting multiple values is acceptable?
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12883
  • Location: London
Reply with quote
Post Posted: Thu Jul 25, 2019 1:35 pm
I suspect it's not much slower than the assembly routine.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 2496
Reply with quote
Post Posted: Tue Aug 06, 2019 5:23 pm
I think you should first of all see how quick (slow) it is to update a column of tile using this:

- calculate address of first tile to set (XYtoADDR macro)
- while (column not complete)
--- SMS_setNextTileatAddr (address)
--- setTile (tile)
--- add 64 to your address and loop

(I would say approx 24*100 cycles)
  View user's profile Send private message Visit poster's website
  • Joined: 24 Jun 2019
  • Posts: 45
Reply with quote
Post Posted: Thu Aug 22, 2019 6:41 pm
Thanks guys x3
I made some progress with the game and was actually able to create that flashlight effect ^o^
Wheeee! Thanks x3

I just wonder... how do I know, that I have enough RAM for my variables? :O And what will happend if I exceed the RAM limit? Will I overwrite old values?
  View user's profile Send private message
  • Joined: 08 Sep 2018
  • Posts: 178
Reply with quote
Post Posted: Thu Aug 22, 2019 8:05 pm
Jaberwocky wrote
Thanks guys x3
I made some progress with the game and was actually able to create that flashlight effect ^o^
Wheeee! Thanks x3

I just wonder... how do I know, that I have enough RAM for my variables? :O And what will happend if I exceed the RAM limit? Will I overwrite old values?


You'll know when you exceed the ram limit, It'll cause the program to crash or corrupt. Eventually you're going to hit the stack and corrupt it if you use too much ram. Luckily 8k is a lot for the type of computer the SMS is so odds are you will not break it even with a large amount variables.

Be mindful of your branching logic, number of consecutive conditional jumps, and any other recursive operations. Those can increase the stack and may cause the stack to grow to a point where it overwrites your variables.
  View user's profile Send private message
Reply to topic Goto page Previous  1, 2, 3



Back to the top of this page

Back to SMS Power!