Author Topic: Lesson 01 - fail :(  (Read 8031 times)

0 Members and 1 Guest are viewing this topic.

Offline spinal

  • Coder of DSision
  • Neo MOD
  • Hero Member
  • *
  • Posts: 796
    • spinalcode
Lesson 01 - fail :(
« on: March 02, 2010, 04:00:02 AM »
OK, I tried following the tutorial here, and finished with this.

the problem is, even though the code is short and as far as I can tell I followed the instructions, but the stupid thing doesn't work.
According the site, when I run the rom, I should get a nice dark green screen, however, I get nothing. :(.

Can someone tell me what I did wrong?

-Thanks-

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: Lesson 01 - fail :(
« Reply #1 on: March 02, 2010, 04:06:40 AM »
Change it from HIROM to LOROM.

Offline spinal

  • Coder of DSision
  • Neo MOD
  • Hero Member
  • *
  • Posts: 796
    • spinalcode
Re: Lesson 01 - fail :(
« Reply #2 on: March 02, 2010, 04:28:20 AM »
In  the neo menu? tried that, didn't help. It doesn't work in emu either.

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: Lesson 01 - fail :(
« Reply #3 on: March 02, 2010, 04:34:56 AM »
No, in your header code.

Offline spinal

  • Coder of DSision
  • Neo MOD
  • Hero Member
  • *
  • Posts: 796
    • spinalcode
Re: Lesson 01 - fail :(
« Reply #4 on: March 02, 2010, 04:41:55 AM »
That worked, although I get a bunch of **** on the screen when running on hardware.

Also, when attempting to swap some gfx in an example program for my own, i'm not seeing anything on the screen, I assume im doing something wrong....

link to pastebin to save space in the thread.

...like not knowing what im doing i guess.
« Last Edit: March 02, 2010, 06:09:20 AM by spinal »

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: Lesson 01 - fail :(
« Reply #5 on: March 02, 2010, 03:05:51 PM »
Running the ROM in the BSNES debugger is very useful to find out what's wrong.

The Snes_Init routine sets all registers to 8-bit, but in LoadPalette and LoadVRAM you assume that X and Y are 16-bit. So you need to make them 16-bit by inserting a REP #$10 after you've called Snes_Init.

Offline spinal

  • Coder of DSision
  • Neo MOD
  • Hero Member
  • *
  • Posts: 796
    • spinalcode
Re: Lesson 01 - fail :(
« Reply #6 on: March 04, 2010, 03:49:38 AM »
OK, I got the tiles loaded, but...
1. How to a load a map? where do I copy it to?
2. In the below copy, I am trying to scroll the screen by 8 pixels then jump back. However, it doesn't seem to be doing anything at all. Have I missed something stupid again?

3. This would be far easier in BASIC :P

Code: [Select]
;============================================================================
; Includes
;============================================================================

;== Include MemoryMap, Vector Table, and HeaderInfo ==
.INCLUDE "header.inc"

;=== Include Library Routines & Macros ===
.INCLUDE "InitSNES.asm"



;============================================================================
; Macros
;============================================================================
;============================================================================
;LoadPalette - Macro that loads palette information into CGRAM
;----------------------------------------------------------------------------
; In: SRC_ADDR -- 24 bit address of source data,
;     START -- Color # to start on,
;     SIZE -- # of COLORS to copy
;----------------------------------------------------------------------------
; Out: None
;----------------------------------------------------------------------------
; Modifies: A,X
; Requires: mem/A = 8 bit, X/Y = 16 bit
;----------------------------------------------------------------------------
.MACRO LoadPalette
    lda #\2
    sta $2121       ; Start at START color
    lda #:\1        ; Using : before the parameter gets its bank.
    ldx #\1         ; Not using : gets the offset address.
    ldy #(\3 * 2)   ; 2 bytes for every color
    jsr DMAPalette
.ENDM

;============================================================================
; LoadBlockToVRAM -- Macro that simplifies calling LoadVRAM to copy data to VRAM
;----------------------------------------------------------------------------
; In: SRC_ADDR -- 24 bit address of source data
;     DEST -- VRAM address to write to (WORD address!!)
;     SIZE -- number of BYTEs to copy
;----------------------------------------------------------------------------
; Out: None
;----------------------------------------------------------------------------
; Modifies: A, X, Y
;----------------------------------------------------------------------------

;LoadBlockToVRAM SRC_ADDRESS, DEST, SIZE
;   requires:  mem/A = 8 bit, X/Y = 16 bit
.MACRO LoadBlockToVRAM
    ldx #\2         ; DEST
    stx $2116       ; $2116: Word address for accessing VRAM.
    lda #:\1        ; SRCBANK
    ldx #\1         ; SRCOFFSET
    ldy #\3         ; SIZE
    jsr LoadVRAM
.ENDM



;============================================================================
; Main Code
;============================================================================

.BANK 0 SLOT 0
.ORG 0
.SECTION "MainCode"

Start:
    InitSNES    ; Clear registers, etc.

    ; Load Palette for our tiles
    LoadPalette BG_Palette, 0,15

    ; Load Tile data to VRAM
    LoadBlockToVRAM Tiles, $0000, $0800 ; 64 tiles, 4bpp, = 2048 bytes = $0800


    lda #$80
    sta $2115
    ldx #$0400
    stx $2116
    lda #$01
    sta $2118

   
    ; Setup Video modes and other stuff, then turn on the screen
    jsr SetupVideo




Infinity:

; Attempt to scroll screen by 8 pixels then jump back
lda $210D ; load screen Y location into a
inc a ; a = a + 1
sta $210D ; screen Y = a

jmp Infinity    ; loop forever








;============================================================================
; SetupVideo -- Sets up the video mode and tile-related registers
;----------------------------------------------------------------------------
; In: None
;----------------------------------------------------------------------------
; Out: None
;----------------------------------------------------------------------------
SetupVideo:
    lda #%00000000
    sta $2105           ; Set Video mode 0, 8x8 tiles, 4 color BG1/BG2/BG3/BG4

    lda #$04            ; Set BG1's Tile Map offset to $0400 (Word address)
    sta $2107           ; And the Tile Map size to 32x32

    stz $210B           ; Set BG1's Character VRAM offset to $0000 (word address)

    lda #$01            ; Enable BG1
    sta $212C



    lda #$0F
    sta $2100           ; Turn on screen, full Brightness

    rts
;============================================================================

;============================================================================
; LoadVRAM -- Load data into VRAM
;----------------------------------------------------------------------------
; In: A:X  -- points to the data
;     Y     -- Number of bytes to copy (0 to 65535)  (assumes 16-bit index)
;----------------------------------------------------------------------------
; Out: None
;----------------------------------------------------------------------------
; Modifies: none
;----------------------------------------------------------------------------
; Notes:  Assumes VRAM address has been previously set!!
;----------------------------------------------------------------------------
LoadVRAM:
    stx $4302   ; Store Data offset into DMA source offset
    sta $4304   ; Store data Bank into DMA source bank
    sty $4305   ; Store size of data block

    lda #$01
    sta $4300   ; Set DMA mode (word, normal increment)
    lda #$18    ; Set the destination register (VRAM write register)
    sta $4301
    lda #$01    ; Initiate DMA transfer (channel 1)
    sta $420B

    rts         ; return
;============================================================================

;============================================================================
; DMAPalette -- Load entire palette using DMA
;----------------------------------------------------------------------------
; In: A:X  -- points to the data
;      Y   -- Size of data
;----------------------------------------------------------------------------
; Out: None
;----------------------------------------------------------------------------
; Modifies: none
;----------------------------------------------------------------------------
DMAPalette:
    stx $4302   ; Store data offset into DMA source offset
    sta $4304   ; Store data bank into DMA source bank
    sty $4305   ; Store size of data block

    stz $4300  ; Set DMA Mode (byte, normal increment)
    lda #$22    ; Set destination register ($2122 - CGRAM Write)
    sta $4301
    lda #$01    ; Initiate DMA transfer
    sta $420B

    rts         ; return from subroutine


.ENDS

;============================================================================
; Character Data
;============================================================================
.BANK 1 SLOT 0
.ORG 0
.SECTION "CharacterData"

    .INCLUDE "tiles.inc"
    .INCLUDE "maps.inc"

.ENDS

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: Lesson 01 - fail :(
« Reply #7 on: March 04, 2010, 04:41:25 AM »
I didn't look at all the code, but I did notice that you're not making X and Y 16-bit here either, unless you've modified the InitSNES macro to do that.
You should step through the code in a debugger to see if it actually does what you were expecting it to.

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1751
  • Just a coding machine.
Re: Lesson 01 - fail :(
« Reply #8 on: March 05, 2010, 02:27:08 AM »
3. This would be far easier in BASIC :P

Why don't you try the C compiler in the snes-sdk mentioned in the sticky thread? Most people usually don't have too much trouble using C, and it's WAY easier than 65816 assembly.
 ~sm-37.gif~

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: Lesson 01 - fail :(
« Reply #9 on: March 05, 2010, 02:31:50 AM »
That's true.  But 65816 assembly isn't really that complicated, you just have to be very careful about the register sizes and the addressing modes.
For someone who hasn't programmed in any assembly language before, C would obviously help that person get started faster.

Offline spinal

  • Coder of DSision
  • Neo MOD
  • Hero Member
  • *
  • Posts: 796
    • spinalcode
Re: Lesson 01 - fail :(
« Reply #10 on: March 07, 2010, 01:17:52 AM »
... Do tile maps need to be formatted any particular way?
My map is not loading properly and I cant find any info about how the map should be formatted. I assumed just a plain old array with the 1024 entries in it, but when I copy the map to [what I assume is] the correct location, it seems to be only half as wide with most of the tiles not showing. In fact, the only tile that seems to work is 0, not so useful for anything but clearing the map :(

test.rar <- source

So, do the map entries need more than just the tile number to be set, or have I set up the bg wrong or something?

Also, slightly unrelated, how do I go about using the joypads?

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: Lesson 01 - fail :(
« Reply #11 on: March 07, 2010, 02:13:27 AM »
There you go

and another doc

Look up registers $4218 and $4016 in the docs to see how to read the controllers.

Offline spinal

  • Coder of DSision
  • Neo MOD
  • Hero Member
  • *
  • Posts: 796
    • spinalcode
Re: Lesson 01 - fail :(
« Reply #12 on: March 14, 2010, 06:08:00 AM »
 I am trying to add a tile to my map, where each tile is 16x16px, making each of my gfx 2x2 tiles.

So I need to do the equivalent of

Code: [Select]
Void Drawblock(int t, int x, int y)
{
 MapBuffer(32*y + x) = t*2;
 MapBuffer(32*y + x+1) = t*2+1;
 ...etc.
}


 I came up with the following...

Code: [Select]
.MACRO DrawBlock
; \1 = tile, \2 = x, \3 = y

LDA #32*\3 + \2 + MapBuffer
STA Temp

LDA #\1 ; A = tile#
ASL A ; A << 1 (A = A * 2) (Tiles are 16x16px)

LDX Temp
STA MapBuffer,X ; Map(X) = A (Should shot top left of tile at location \2,\3)
.ENDM

...BUT, I get the following error -

INPUT_NUMBER: Out of 8bit range.
ERROR: Couldn't parse "LDA".

1. What am I doing wrong?
2. Is this the correct way to attempt what I want to do?

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: Lesson 01 - fail :(
« Reply #13 on: March 14, 2010, 04:58:51 PM »
You're getting this error because at some place where you're using the macro the assembler thinks that A is 8-bit, so you obviously can't load a 16-bit value into it. You could fix this by inserting a REP #$20 as the first instruction in the macro. But there's no reason why you need A and Temp to "calculate" the address since it's a constant, so you could rather do something like this:

Code: [Select]
.MACRO DrawBlock
; \1 = tile, \2 = xpos, \3 = ypos
; Precondition: 8-bit A, 16-bit X,Y

   LDA #\1      ; A = tile#
   ASL A      ; A << 1 (A = A * 2) (Tiles are 16x16px)

   LDX #32*\3 + \2   ; Why add MapBuffer here as well if it's used in the STA below?
   STA MapBuffer,X   ; Map(X) = A (Should shot top left of tile at location \2,\3)
.ENDM

What's still unclear here is where is MapBuffer? If you're writing to it, it can't be in ROM. So is it a long address (like $7F0000)? If it's a word address then you'll have to set DBR to point to RAM ($7F) using the PHB/PLB instructions.


Offline spinal

  • Coder of DSision
  • Neo MOD
  • Hero Member
  • *
  • Posts: 796
    • spinalcode
Re: Lesson 01 - fail :(
« Reply #14 on: March 14, 2010, 05:39:09 PM »
... Of all the things to get wrong, adding MapBuffer twice, how stupid.
Thanks mic_. This learning ASM business is much slower than I first thought.