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 - New to SMS programming, issues with copying tile data to VRAM

Reply to topic
Author Message
  • Joined: 08 Apr 2014
  • Posts: 34
Reply with quote
New to SMS programming, issues with copying tile data to VRAM
Post Posted: Tue Apr 08, 2014 7:48 pm
Since this is my first post, here's a little bit about myself: I'm a 17 year old from England currently studying A-level computing, physics and maths at school. Naturally I do a lot of maths and programming inside and outside of school. I have three older brothers, and I grew up playing their Sega Megadrive games. The Master System came before my time, but I plan to buy one sometime and I thought a little bit of Z80 assembly would be a fun programming project to do in my spare time.

To start with, I'm trying to modify Maxim's Hello World tutorial program so that, instead of producing text, it generates a background of checkered tiles in two shades of brown. Later on, I want to add a green square that can be moved by the player, but that's for another time.

Currently I'm using the palette:
PaletteData:
.db $0C $06 $0B $3F
PaletteDataEnd:

According the palette viewer in MEKA, the program successfully loads the palette. (See attachments)

Next, I'm trying to copy my tiles into the VRAM, which consist of a square in each of the colours shown in the palette image attached:
TileData:
; Tile index $000 - Green square
.db $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
; Tile index $001 - Dark brown square
.db $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00
; Tile index $002 - Light brown square
.db $00 $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00
; Tile index $003 - White square square
.db $FF $FF $00 $00 $FF $FF $00 $00 $FF $FF $00 $00 $FF $FF $00 $00 $FF $FF $00 $00 $FF $FF $00 $00 $FF $FF $00 $00 $FF $FF $00 $00
TileDataEnd:


Here's the (slightly) modified version of the code from the Hello World tutorial (extended version) that I've used to load tile data into the VRAM:

    ; 1. Set VRAM write address to tile index 0
    ld hl,$0000 | VRAMWrite
    call SetVDPAddress
    ; 2. Output tile data
    ld hl,TileData          ; Location of tile data
    ld bc,TileDataEnd-TileData          ; Counter for number of bytes to write
    call CopyToVDP


The "SetVDPAddress" and "CopyToVDP" functions are completely unmodified. My problem is that for some reason, this code fails to actually load the tiles. According to MEKA, these are my resultant tiles:

(See the other attached file)

As you can see, this is not what I want at all. I have a feeling that I made a stupid mistake somehow and am missing something incredibly important that will solve everything, but I've been trying to figure this one out for hours now and I'm stumped. Any help would be great.
817J1[1].png (760 B)
The colour palette
817J1[1].png
818f7[1].png (1.38 KB)
My messed up tiles.
818f7[1].png

  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14745
  • Location: London
Reply with quote
Post Posted: Tue Apr 08, 2014 9:30 pm
Have a look at the VRAM in the memory editor to see how it seems to relate to what you are writing. Also, find the VRAM address in the technical info window to check it is what you expect while stepping through the writing code in the debugger.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 08 Jul 2001
  • Posts: 8653
  • Location: Paris, France
Reply with quote
Post Posted: Tue Apr 08, 2014 10:04 pm
Hello and welcome :)
It's rather cool that you are willing to dig into hardware that predate your own birth date.

The debugger is your friend (I'd recommend using MEKA 0.80) then you can step through each instruction and watch the registers and memory change and see if things behave as you expected.

The code that you have posted appears to make sense but that's assuming a lot of other things about the rest of the code. I suggest you play with the debugger first else you can attach your ROM here and we can have a look.
  View user's profile Send private message Visit poster's website
  • Joined: 08 Apr 2014
  • Posts: 34
Reply with quote
Post Posted: Wed Apr 09, 2014 8:11 am
I just found out that the problem was under my nose all along! I used the debugger from MEKA and found that it manages to load the tiles successfully, but then replaces it with garbled stuff when it attempts to load the name table. For some reason the code used in the enhanced version of hello world for the name table doesn't work in my program, so I replaced it with the one from the original version in the tutorial, and now it works! Thanks for the help!
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3828
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Apr 09, 2014 12:16 pm
I don't get how this
; Tile index $001 - Dark brown square
.db $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00 $FF $00 $00 $00

can be a dark brown square. It should be 32 times the same nibble, so 16 bytes all to the same $11 value...

oh, wait, did you exported that using 'Planar' mode?
  View user's profile Send private message Visit poster's website
  • Joined: 08 Apr 2014
  • Posts: 34
Reply with quote
Post Posted: Wed Apr 09, 2014 1:36 pm
Yes, this was using planar output. Is there any functional difference between the two types of output?
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3828
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Apr 09, 2014 2:11 pm
on SMS 'planar' is the correct one, it was me mixing things :p
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!