It is currently Fri Dec 15, 2017 1:35 am

All times are UTC - 7 hours



Forum rules


Related:



Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Sun Jan 03, 2016 9:42 pm 
Offline
User avatar

Joined: Mon Sep 15, 2014 4:35 pm
Posts: 3153
Location: Nacogdoches, Texas
I don't even know how or why, but when I changed everything to where I assembly one file instead of multiple, I noticed that what I made kept crashing. (I haven't messed with anything over the whole winter break, so I'm just now noticing.) Basically, what it does is in the first millisecond, a sprite (or multiple sprites layered over each other) appears, and then move sporadically and flips and the back ground also moves and then it just stops.

In my "Object Identifier" code where it identifies an object and then jumps to its corresponding code, it first sets direct page to be the address of the beginning of the first object slot (and also stores the address in "ObjectOffset" to know what it is if direct page has been changed. Seeing this now, I might actually get rid of that, but I doubt it has anything to do with the problem)

Code:
.proc start_object_identifier
  rep #$30    ; A=16, X/Y=16
  lda #ObjectTable
  sta a:ObjectOffset
  tcd

It then looks for the identity of the first object, and seeing that in the main code I crossed out what I was uploading,

Code:
;  rep #$30                  ; A=16, X/Y=16
;  lda #Object1
;  sta NewObjectRequest
;  jsr start_object_spawner
;
;  lda #Player1MetaspriteTable
;  sta ObjectTable+MetaspriteTableOffset,x

The whole object table should be zero filled, and thus the "object identifier" code should then just look at the next object, and then the next object, and then eventually it would be done. (I've verified that "start_metasprite" and "start_process_oam" aren't causing the problem, because I've deleted the jumps to them and the game still runs the same way)

Quote:
object_identifier_loop:
lda Identity ;load the object identification byte of the object we're currently on
beq next_object
tax ;put the result in x so we can offset the object identification table to see what the object is
jsr (ObjectIdentificationTable-2,x) ;jump to the code that corresponds with the object
rep #$30 ; A=16, X/Y=16
next_object:
lda a:ObjectOffset ;says how many objects have been identified
clc
adc #$0030 ;add 48 to look at the next object
sta a:ObjectOffset ;store the result for the next time we go through the loop
tcd ;transfer the accumulator to y for "cpy #8192" and "lda ObjectTable,y"
cmp #ObjectTableSize+ObjectTable ;sees if all objects have been identified (each object is 128 bytes)
bne object_identifier_loop ;if so, quit searching
lda #ObjectTable
tcd
jsr start_metasprite
lda #$0000
tcd
jsr start_process_oam
rts

.endproc

;====================================================================================
; ObjectIdentificationTable
;====================================================================================

ObjectIdentificationTable:
.word object1,object2

I'm guessing that the object table is for some reason not filled out with zeros like it must have been earlier and that it's loading a number that is beyond what I've made in the object table and jumping somewhere crazy, (and not coming back obviously) because I put an "rts" and then later a "brk" at "next_object" (where it should be jumping, because I never even spawned an object) and neither changed it. However, I did erase the line "jsr (ObjectIdentificationTable-2,x)", and it worked like it should (no object appeared onscreen, aside for the first frame where a sprite does, but it did that even when it was working), which further roots my suspicion.

Anyway, if anyone wants to try and find the problem, here you go. I don't think it should be a difficult fix, I'm just kind of confused.

Attachment:
SNES Game.zip [305.43 KiB]
Downloaded 75 times


Top
 Profile  
 
PostPosted: Mon Jan 04, 2016 2:47 pm 
Offline

Joined: Wed May 19, 2010 6:12 pm
Posts: 2427
I think I found the mistake. When jumping to an object's routine it looks up the object's routine address from a list that is pointed at by the "identity" register. When you spawned your object, you placed the address number of the object's routine in the "identity" register instead of the pointer number.


Top
 Profile  
 
PostPosted: Mon Jan 04, 2016 4:45 pm 
Offline
User avatar

Joined: Mon Sep 15, 2014 4:35 pm
Posts: 3153
Location: Nacogdoches, Texas
Well, I've had this written:

Code:
Object1 = 2

But the name of the procedure is...

Code:
.proc object1

That could mess it up if it's not case sensitive, but I actually crossed out the object, so it should just read it as zero, but it still doesn't work:

Code:
;  rep #$30                  ; A=16, X/Y=16
;  lda #Object1
;  sta NewObjectRequest
;  jsr start_object_spawner
;
;  lda #Player1MetaspriteTable
;  sta ObjectTable+MetaspriteTableOffset,x

I will probably go and differentiate the names, because I just noticed how ridiculous it is. I should maybe say "object1_code" and or "Object1Number"

I don't get it though, I didn't have this problem before. Maybe I should actually try to zero fill the whole object table prior and see if it works then, but I thought ram started filled with zeroes?


Top
 Profile  
 
PostPosted: Mon Jan 04, 2016 7:27 pm 
Offline

Joined: Fri Jul 04, 2014 9:31 pm
Posts: 818
Espozo wrote:
I thought ram started filled with zeroes?

It does if your initialization routine filled it with zeroes. Are you using a real system or an emulator?


Top
 Profile  
 
PostPosted: Mon Jan 04, 2016 7:38 pm 
Offline
User avatar

Joined: Mon Sep 15, 2014 4:35 pm
Posts: 3153
Location: Nacogdoches, Texas
93143 wrote:
It does if your initialization routine filled it with zeroes. Are you using a real system or an emulator?

Emulator. I use bsnes-debugger, if that helps any. Now that I think about it, I thought I originally had a initialization routine or something like that, but I guess I don't... I'm not sure why it decided to stop working all of the sudden, but whatever.

Does anyone have a "standard" initialization routine made? I don't really want to go reinventing the wheel...


Top
 Profile  
 
PostPosted: Mon Jan 04, 2016 8:02 pm 
Offline
User avatar

Joined: Thu Dec 25, 2014 10:26 pm
Posts: 309
Location: Canada
I've been using one from one of the tutorials. This:
Code:
;------------------------------------------------------------------------
;-  Written by: Neviksti
;-     If you use my code, please share your creations with me
;-     as I am always curious :)
;------------------------------------------------------------------------


;----------------------------------------------------------------------------
; InitSNES -- my "standard" initialization of SNES memory and registers
;----------------------------------------------------------------------------
.MACRO InitSNES
  sei                     ;disable interrupts
  clc                     ;switch to native mode
  xce

  REP #$38      ; mem/A = 16 bit, X/Y = 16 bit
         ;decimal mode off

  LDX #$1FFF   ;Setup the stack
  TXS         ;Transfer Index X to Stack Pointer Register

  ;do the rest of the initialization in a routine
  JSL $008000

  SEP #$20      ; mem/A = 8 bit
.ENDM

;----------------------------------------------------------------------------

.BANK 0 SLOT 0
.ORG 0
.SECTION "InitializeSNESCode" FORCE

InitializeSNES:
  PHK         ;set Data Bank = Program Bank
  PLB

  LDA #$0000   ;set Direct Page = $0000
  TCD         ;Transfer Accumulator to Direct Register

  LDX $1FFD      ;we clear all the mem at one point ...
  STX $4372     ;so save the return address in a place that won't get overwritten
  LDX $1FFF
  STX $4374

  SEP #$20      ; mem/A = 8 bit
  REP #$10

  LDA #$8F
  STA $2100      ;turn screen off for now, set brightness to normal

  LDX #$2101
_Loop00:      ;regs $2101-$210C
  STZ $00,X      ;set Sprite,Character,Tile sizes to lowest, and set addresses to $0000
  INX
  CPX #$210D
  BNE _Loop00

_Loop01:      ;regs $210D-$2114
  STZ $00,X      ;Set all BG scroll values to $0000
  STZ $00,X
  INX
  CPX #$2115
  BNE _Loop01

  LDA #$80      ;reg $2115
  STA $2115      ; Initialize VRAM transfer mode to word-access, increment by 1

  STZ $2116      ;regs $2117-$2117
  STZ $2117      ;VRAM address = $0000

         ;reg $2118-$2119
         ;VRAM write register... don't need to initialize

  STZ $211A      ;clear Mode7 setting

  LDX #$211B
_Loop02:      ;regs $211B-$2120
  STZ $00,X      ;clear out the Mode7 matrix values
  STZ $00,X
  INX
  CPX #$2121
  BNE _Loop02

         ;reg $2121 - Color address, doesn't need initilaizing
         ;reg $2122 - Color data, is initialized later

  LDX #$2123
_Loop03:      ;regs $2123-$2133
  STZ $00,X      ;turn off windows, main screens, sub screens, color addition,
  INX         ;fixed color = $00, no super-impose (external synchronization),
  CPX #$2134   ;no interlaced mode, normal resolution
  BNE _Loop03

         ;regs $2134-$2136  - multiplication result, no initialization needed
         ;reg $2137 - software H/V latch, no initialization needed
         ;reg $2138 - Sprite data read, no initialization needed
         ;regs $2139-$213A  - VRAM data read, no initialization needed
         ;reg $213B - Color RAM data read, no initialization needed
         ;regs $213C-$213D  - H/V latched data read, no initialization needed

  STZ $213E      ;reg $213E - might not be necesary, but selects PPU master/slave mode
         ;reg $213F - PPU status flag, no initialization needed

         ;reg $2140-$2143 - APU communication regs, no initialization required

         ;reg $2180  -  read/write WRAM register, no initialization required
         ;reg $2181-$2183  -  WRAM address, no initialization required

         ;reg $4016-$4017  - serial JoyPad read registers, no need to initialize


  STZ $4200      ;reg $4200  - disable timers, NMI,and auto-joyread

  LDA #$FF
  STA $4201      ;reg $4201  - programmable I/O write port, initalize to allow reading at in-port

         ;regs $4202-$4203  - multiplication registers, no initialization required
         ;regs $4204-$4206  - division registers, no initialization required

         ;regs $4207-$4208  - Horizontal-IRQ timer setting, since we disabled this, it is OK to not init
         ;regs $4209-$420A  - Vertical-IRQ timer setting, since we disabled this, it is OK to not init

  STZ $420B      ;reg $420B  - turn off all general DMA channels
  STZ $420C      ;reg $420C  - turn off all H-MA channels

  STZ $420D      ;reg $420D  - ROM access time to slow (2.68Mhz)

  LDA $4210      ;reg $4210  - NMI status, reading resets

         ;reg $4211  - IRQ status, no need to initialize
         ;reg $4212  - H/V blank and JoyRead status, no need to initialize
         ;reg $4213  - programmable I/O inport, no need to initialize

         ;reg $4214-$4215  - divide results, no need to initialize
         ;reg $4216-$4217  - multiplication or remainder results, no need to initialize

         ;regs $4218-$421f  - JoyPad read registers, no need to initialize

         ;regs $4300-$437F
         ;no need to intialize because DMA was disabled above
         ;also, we're not sure what all of the registers do, so it is better to leave them at
         ;their reset state value

  JSR ClearVRAM      ;Reset VRAM
  JSR ClearPalette   ;Reset colors

  ;**** clear Sprite tables ********

  STZ $2102   ;sprites initialized to be off the screen, palette 0, character 0
  STZ $2103
  LDX #$0080
  LDA #$F0
_Loop08:
  STA $2104   ;set X = 240
  STA $2104   ;set Y = 240
  STZ $2104   ;set character = $00
  STZ $2104   ;set priority=0, no flips
  DEX
  BNE _Loop08

  LDX #$0020
_Loop09:
  STZ $2104      ;set size bit=0, x MSB = 0
  DEX
  BNE _Loop09

  ;**** clear WRAM ********

  STZ $2181      ;set WRAM address to $000000
  STZ $2182
  STZ $2183

  LDX #$8008
  STX $4300         ;Set DMA mode to fixed source, BYTE to $2180
  LDX #wram_fill_byte
  STX $4302         ;Set source offset
  LDA #:wram_fill_byte
  STA $4304         ;Set source bank
  LDX #$0000
  STX $4305         ;Set transfer size to 64k bytes
  LDA #$01
  STA $420B         ;Initiate transfer

  LDA #$01          ;now set the next 64k bytes
  STA $420B         ;Initiate transfer

  PHK         ;make sure Data Bank = Program Bank
  PLB

  CLI         ;enable interrupts again

  LDX $4372     ;get our return address...
  STX $1FFD
  LDA $4374
  STA $1FFF
  RTL

wram_fill_byte:
.db $00

;----------------------------------------------------------------------------
; ClearVRAM -- Sets every byte of VRAM to zero
; In: None
; Out: None
; Modifies: flags
;----------------------------------------------------------------------------
ClearVRAM:
   pha
   phx
   php

   REP #$30      ; mem/A = 8 bit, X/Y = 16 bit
   SEP #$20

   LDA #$80
   STA $2115         ;Set VRAM port to word access
   LDX #$1809
   STX $4300         ;Set DMA mode to fixed source, WORD to $2118/9
   LDX #$0000
   STX $2116         ;Set VRAM port address to $0000
   STX $0000         ;Set $00:0000 to $0000 (assumes scratchpad ram)
   STX $4302         ;Set source address to $xx:0000
   LDA #$00
   STA $4304         ;Set source bank to $00
   LDX #$FFFF
   STX $4305         ;Set transfer size to 64k-1 bytes
   LDA #$01
   STA $420B         ;Initiate transfer

   STZ $2119         ;clear the last byte of the VRAM

   plp
   plx
   pla
   RTS

;----------------------------------------------------------------------------
; ClearPalette -- Reset all palette colors to zero
; In: None
; Out: None
; Modifies: flags
;----------------------------------------------------------------------------
ClearPalette:
   PHX
   PHP
   REP #$30      ; mem/A = 8 bit, X/Y = 16 bit
   SEP #$20

   STZ $2121
   LDX #$0100
ClearPaletteLoop:
   STZ $2122
   STZ $2122
   DEX
   BNE ClearPaletteLoop

   PLP
   PLX
   RTS

.ENDS


Top
 Profile  
 
PostPosted: Mon Jan 04, 2016 8:16 pm 
Offline
User avatar

Joined: Mon Sep 15, 2014 4:35 pm
Posts: 3153
Location: Nacogdoches, Texas
Actually, I noticed I already have one... Look in "Macros.asm" if you have downloaded the zip file. I even call it...

Code:
.proc Main
  ;
  ; Initialize SNES, which includes setting up CPU registers properly,
  ; zeroing out RAM contents, setting up SNES registers per official
  ; Nintendo documentation, and many other things.
  ;
  InitializeSNES

What the heck.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group