Page 3 of 20

Re: SNES Splatoon (Not Even A Demo Yet Though...)

Posted: Wed Feb 24, 2016 7:33 am
by Drew Sebastino
I'm fairly certain this should work (if I actually build the jump table, of course.) I just got rid of the indexing on the "SplatRequestTable" because I'm only loading one splat right now, but I'll add it back latter. I'm just trying to take baby steps.

Code: Select all

start_draw_splat:
  rep #$30   ;A=16, X/Y=16

  lda SplatRequestTable+YPosition
  and #$0000000000000111
  asl
  bne continue_calculating_vertical_offset
  sta SplatSubTileYPosition

continue_calculating_vertical_offset:
  lda SplatRequestTable+YPosition
  ror
  ror
  ror
  sep #$20   ;A=8
  sta $4202
  lda DataPerRowInBuffer
  sta $4203   ;Apparently, there's some sort of waiting time for this?

  lda SplatRequestTable+Height
  sta FullTileSplatHeight
  asl
  asl
  asl
  asl
  asl
  sta DataSplatHeight
  lda SplatRequestTable+Width
  sta TileSplatWidth

  rep #$30   ;A=16, X/Y=16
  lda $4216
  sta SplatBufferPosition

;======================================================================

  lda SplatRequestTable+XPosition
  ror
  ror
  and #%0011111111111111
  clc
  adc SplatBufferPosition
  sta SplatBufferPosition

  lda SplatRequestTable+XPosition
  and #%0000000000000111
  bne continue_calculating_x_offset
  inc TileSplatWidth
  lda SplatRequestTable+XPosition
  and #%0000000000000111

continue_calculating_x_offset:
  
  clc
  adc SplatRequestTable+GraphicOffset
  sta SplatGraphicOffset

  lda SplatSubTileYPosition
  asl
  tax
  jsr (VariableYOffsetCodeJumpTable,x)

;======================================================================

  VariableYOffsetCodeJumpTable:	(I don't remember the structure for
 				tables... I'm using the school's computer)

;======================================================================

start_draw_offset_3_splat:
  ldx SplatBufferPosition
  cpx EndOfBuffer
  bcs draw_offset_3_splat_done
  ldy SplatGraphicOffset
  lda SplatGraphicOffset
  clc
  adc #$0014
  sta SplatGraphicOffset

draw_offset_3_splat_first_rows:
  lda Buffer+6,x
  and #$0000,y
  ora #$0002,y
  sta Buffer+6,x

  lda Buffer+8,x
  and #$0004,y
  ora #$0006,y
  sta Buffer+8,x

  lda Buffer+10,x
  and #$0008,y
  ora #$000A,y
  sta Buffer+10,x

  lda Buffer+12,x
  and #$000C,y
  ora #$000E,y
  sta Buffer+12,x

  lda Buffer+14,x
  and #$0010,y
  ora #$0012,y
  sta Buffer+14,x

  inc TilesDrawnHorizontally
  cmp SplatTileWidth
  bcs start_offset_3_splat_middle_rows
  txa
  clc
  adc #$0010
  tax
  tya
  clc
  adc SplatDataHeight
  tay
  bra draw_offset_3_splat_first_rows

;======================================================================

start_draw_offset_3_splat_middle_rows:
  ldx SplatBufferPosition
  stz TilesDrawnHorizontally
  txa
  clc
  adc DataPerRowInBuffer
  tax
  ldy SplatGraphicOffset

draw_offset_3_splat_middle_rows:
  lda Buffer,x
  and #$0000,y
  ora #$0002,y
  sta Buffer,x

  lda Buffer+2,x
  and #$0004,y
  ora #$0006,y
  sta Buffer+2,x

  lda Buffer+4,x
  and #$0008,y
  ora #$000A,y
  sta Buffer+4,x

  lda Buffer+6,x
  and #$000C,y
  ora #$000E,y
  sta Buffer+6,x

  lda Buffer+8,x
  and #$0010,y
  ora #$0012,y
  sta Buffer+8,x

  lda Buffer+10,x
  and #$0014,y
  ora #$0016,y
  sta Buffer+10,x

  lda Buffer+12,x
  and #$0018,y
  ora #$001A,y
  sta Buffer+12,x

  lda Buffer+14,x
  and #$001C,y
  ora #$001E,y
  sta Buffer+14,x

  lda FullTilesDrawnVertically
  cmp FullTileSplatHeight
  bcs start_draw_offset_3_splat_last_rows
  inc TilesDrawnHorizontally
  cmp SplatTileWidth
  bcs offset_3_splat_next_row
  txa
  clc
  adc #$0010
  tax
  tya
  clc
  adc SplatDataHeight
  tay
  bra draw_offset_3_splat_middle_rows

offset_3_splat_next_row:
  cpx EndOfBuffer
  bcs draw_offset_3_splat_done
  inc FullTilesDrawnVertically
  inc TilesDrawnHorizontally
  txa
  clc
  adc DataPerRowInBuffer
  tax
  lda SplatGraphicOffset
  clc
  adc #$0020
  sta SplatGraphicOffset
  tay
  bra draw_offset_3_splat_middle_rows

;======================================================================

start_draw_offset_3_splat_last_rows:
  ldx SplatBufferPosition
  cpx EndOfBuffer
  bcs draw_offset_3_splat_done
  stz TilesDrawnHorizontally
  txa
  clc
  adc DataPerRowInBuffer
  tax
  ldy SplatGraphicOffset

draw_offset_3_splat_last_rows:
  lda Buffer,x
  and #$0000,y
  ora #$0002,y
  sta Buffer,x

  lda Buffer+2,x
  and #$0004,y
  ora #$0006,y
  sta Buffer+2,x

  lda Buffer+4,x
  and #$0008,y
  ora #$000A,y
  sta Buffer+4,x

  inc TilesDrawnHorizontally
  cmp SplatTileWidth
  bcs draw_offset_3_splat_done
  txa
  clc
  adc #$0010
  tax
  tya
  clc
  adc SplatDataHeight
  tay
  bra draw_offset_3_splat_last_rows

;======================================================================

draw_offset_3_splat_done:
  stz FullTilesDrawnVertically
  rts

Re: SNES Splatoon (Not Even A Demo Yet Though...)

Posted: Wed Feb 24, 2016 1:08 pm
by psycopathicteen
Espozo wrote:I know. Where did I get that wrong?

Also, you actually read it?
You indexed Y by an immediate. I didn't read the whole thing, I just noticed the repetitive part.

Re: SNES Splatoon (Not Even A Demo Yet Though...)

Posted: Wed Feb 24, 2016 1:19 pm
by tokumaru
psycopathicteen wrote:You indexed Y by an immediate.
Several times. I was wondering if this wasn't a 65816 thing...

Re: SNES Splatoon (Not Even A Demo Yet Though...)

Posted: Wed Feb 24, 2016 4:24 pm
by Drew Sebastino
Oh, I see now, when I was loading from $0000 which was indexed to get me the address of where the splat graphic is for drawing it... Yeah, I wasn't thinking. :lol: It's an easy fix though.

I'll correct it, and then I'll make the jump table and then I'll make a 16x16 block graphic. I'll upload the tiles manually at first, and if it works, I'll go from there. I wonder how slow this will be... At least although there will be plenty of splats, there shouldn't be way too many appearing on the same frame. It's not like the guns shoot every frame. (The charger is a wide line of splats though.) I just thought about something, and it's that the roller is really going to suck trying to make.

Re: SNES Splatoon (Not Even A Demo Yet Though...)

Posted: Wed Feb 24, 2016 9:41 pm
by Drew Sebastino
Yeah, I fixed it now, and I actually noticed that I left part of my code unfinished, (the part where it decides on what graphics to choose based on the sub tile x position) so I fixed that along with some other mess ups. I finished the graphics for 8 copies of a 16x16 block, but it's so large and you already know how it's going to look so I won't bother showing it here. (I'm really going to need a tool for it if I ever get anywhere...) Hopefully, I'll have something show up onscreen soon.

Code: Select all

start_draw_splat:
  rep #$30   ;A=16, X/Y=16

  lda SplatRequestTable+YPosition
  and #$0000000000000111
  asl
  bne continue_calculating_vertical_offset
  sta SplatSubTileYPosition

continue_calculating_vertical_offset:
  lda SplatRequestTable+YPosition
  ror
  ror
  ror
  sep #$20	;A=8
  sta $4202
  lda DataPerRowInBuffer
  sta $4203	;Apparently, there's some sort of waiting time for this?
  rep #$30	;A=16, X/Y=16

  lda SplatRequestTable+Height
  sta FullTileSplatHeight
  asl
  asl
  asl
  asl
  asl
  sta SplatDataHeight
  lda SplatRequestTable+Width
  sta TileSplatWidth

  lda $4216
  sta SplatBufferPosition

;======================================================================

  lda SplatRequestTable+XPosition
  and #%0000000000000111
  bne continue_calculating_x_offset
  inc TileSplatWidth
  lda SplatRequestTable+XPosition
  and #%0000000000000111

  sep #$20	;A=8
  sta $4202
  lda SplatRequestTable+DataSize
  sta $4203	;Apparently, there's some sort of waiting time for this?
  rep #$30	;A=16, X/Y=16

  lda SplatRequestTable+XPosition
  ror
  ror
  and #%0011111111111111
  clc
  adc SplatBufferPosition
  sta SplatBufferPosition

  lda $4216
  sec
  sbc SplatDataHeight
continue_calculating_x_offset:
  clc
  adc SplatRequestTable+GraphicOffset
  sta SplatGraphicOffset

  lda SplatSubTileYPosition
  asl
  tax
  jsr (VariableYOffsetCodeJumpTable,x)

;======================================================================

VariableYOffsetCodeJumpTable:
  .word start_draw_offset_3_splat,start_draw_offset_3_splat
  .word start_draw_offset_3_splat,start_draw_offset_3_splat
  .word start_draw_offset_3_splat,start_draw_offset_3_splat
  .word start_draw_offset_3_splat,start_draw_offset_3_splat

;======================================================================

start_draw_offset_3_splat:
  ldx SplatBufferPosition
  cpx EndOfBuffer
  bcs draw_offset_3_splat_done
  ldy SplatGraphicOffset
  lda SplatGraphicOffset
  clc
  adc #$0014
  sta SplatGraphicOffset

draw_offset_3_splat_first_rows:
  lda Buffer+6,x
  and $0000,y
  ora $0002,y
  sta Buffer+6,x

  lda Buffer+8,x
  and $0004,y
  ora $0006,y
  sta Buffer+8,x

  lda Buffer+10,x
  and $0008,y
  ora $000A,y
  sta Buffer+10,x

  lda Buffer+12,x
  and $000C,y
  ora $000E,y
  sta Buffer+12,x

  lda Buffer+14,x
  and $0010,y
  ora $0012,y
  sta Buffer+14,x

  inc TilesDrawnHorizontally
  cmp SplatTileWidth
  bcs start_offset_3_splat_middle_rows
  txa
  clc
  adc #$0010
  tax
  tya
  clc
  adc SplatDataHeight
  tay
  bra draw_offset_3_splat_first_rows

;======================================================================

start_draw_offset_3_splat_middle_rows:
  ldx SplatBufferPosition
  stz TilesDrawnHorizontally
  txa
  clc
  adc DataPerRowInBuffer
  tax
  ldy SplatGraphicOffset

draw_offset_3_splat_middle_rows:
  lda Buffer,x
  and $0000,y
  ora $0002,y
  sta Buffer,x

  lda Buffer+2,x
  and $0004,y
  ora $0006,y
  sta Buffer+2,x

  lda Buffer+4,x
  and $0008,y
  ora $000A,y
  sta Buffer+4,x

  lda Buffer+6,x
  and $000C,y
  ora $000E,y
  sta Buffer+6,x

  lda Buffer+8,x
  and $0010,y
  ora $0012,y
  sta Buffer+8,x

  lda Buffer+10,x
  and $0014,y
  ora $0016,y
  sta Buffer+10,x

  lda Buffer+12,x
  and $0018,y
  ora $001A,y
  sta Buffer+12,x

  lda Buffer+14,x
  and $001C,y
  ora $001E,y
  sta Buffer+14,x

  lda FullTilesDrawnVertically
  cmp FullTileSplatHeight
  bcs start_draw_offset_3_splat_last_rows
  inc TilesDrawnHorizontally
  cmp SplatTileWidth
  bcs offset_3_splat_next_row
  txa
  clc
  adc #$0010
  tax
  tya
  clc
  adc SplatDataHeight
  tay
  bra draw_offset_3_splat_middle_rows

offset_3_splat_next_row:
  cpx EndOfBuffer
  bcs draw_offset_3_splat_done
  inc FullTilesDrawnVertically
  inc TilesDrawnHorizontally
  txa
  clc
  adc DataPerRowInBuffer
  tax
  lda SplatGraphicOffset
  clc
  adc #$0020
  sta SplatGraphicOffset
  tay
  bra draw_offset_3_splat_middle_rows

;======================================================================

start_draw_offset_3_splat_last_rows:
  ldx SplatBufferPosition
  cpx EndOfBuffer
  bcs draw_offset_3_splat_done
  stz TilesDrawnHorizontally
  txa
  clc
  adc DataPerRowInBuffer
  tax
  ldy SplatGraphicOffset

draw_offset_3_splat_last_rows:
  lda Buffer,x
  and $0000,y
  ora $0002,y
  sta Buffer,x

  lda Buffer+2,x
  and $0004,y
  ora $0006,y
  sta Buffer+2,x

  lda Buffer+4,x
  and $0008,y
  ora $000A,y
  sta Buffer+4,x

  inc TilesDrawnHorizontally
  cmp SplatTileWidth
  bcs draw_offset_3_splat_done
  txa
  clc
  adc #$0010
  tax
  tya
  clc
  adc SplatDataHeight
  tay
  bra draw_offset_3_splat_last_rows

;======================================================================

draw_offset_3_splat_done:
  stz FullTilesDrawnVertically
  rts

Re: SNES Splatoon (Not Even A Demo Yet Though...)

Posted: Thu Feb 25, 2016 10:27 pm
by Drew Sebastino
Wait, I forgot, what's the difference between "BSS" and "BSS7E"? I wanted to make a screen sized, 2bpp buffer, but it said there was a memory overflow so I moved it and it hasn't said anything else.

I was beginning to think about actual graphics, and there's no way to have individual clothes and stuff that aren't one color without overlaying 4 sprites over each other for one character, and even then, I'm not sure. I'd have all the clothes be the same for each character, but I'd have different weapons that would be separate sprites. I'll figure it all out when if I get there.

Re: SNES Splatoon (Not Even A Demo Yet Though...)

Posted: Thu Feb 25, 2016 10:35 pm
by tepples
My linker script has three BSS segments.
  • BSS: $000000-$001FFF
  • BSS7E: $7E2000-$7EFFFF
  • BSS7F: $7F0000-$7FFFFF
I split out BSS from BSS7E because only the first 8K of RAM is mirrored into LoROM banks ($00-$3F and $80-$BF).

Re: SNES Splatoon (Not Even A Demo Yet Though...)

Posted: Thu Feb 25, 2016 10:46 pm
by Drew Sebastino
Ah, so it's fine. Thanks. :)
tepples wrote:the first 8K of RAM is mirrored into LoROM banks ($00-$3F and $80-$BF).
What's the point of that?

Re: SNES Splatoon (Not Even A Demo Yet Though...)

Posted: Thu Feb 25, 2016 11:00 pm
by tepples
It's mirrored into $00 to allow the direct page and stack to work, as the 65816 requires them to be in bank $00.

It's mirrored into $00-$3F and $80-$BF so that LoROM programs have some RAM to use no matter what the data bank register is set to.

Re: SNES Splatoon (Not Even A Demo Yet Though...)

Posted: Sun Feb 28, 2016 5:10 pm
by Drew Sebastino
Something that I'm trying to do that's making no sense to me is I'm trying to load the buffer position in ram (the begining of BSS7E) + the size of the buffer (the screen, so 256x224/4=14336) and it's saying that there's a range error, but I'm pretty sure they don't add up to 65536...

The first line is what's (somehow) problematic:

Code: Select all

  lda #InkBuffer+InkBufferSize
  sta EndOfBuffer

Re: SNES Splatoon (Not Even A Demo Yet Though...)

Posted: Sun Feb 28, 2016 5:15 pm
by tepples
$7E2000 is already greater than $00FFFF. Try using only the low 16 bits if necessary.

Re: SNES Splatoon (Not Even A Demo Yet Though...)

Posted: Sun Feb 28, 2016 5:26 pm
by Drew Sebastino
Oh, I was thinking about the whole first 8KB thing... :lol: I never really thought about it though, and that's how do you do 24 bit addressing? I mean, I remember on the Irem M92, you had the different registers for it. I think it was ds? Anyway, yeah.

Re: SNES Splatoon (Not Even A Demo Yet Though...)

Posted: Sun Feb 28, 2016 5:30 pm
by lidnariq
Much as the M92's V33 (8086) has CS, DS, and SS segment registers, the SNES's 65816 has K, B, and 0 bank registers.

Re: SNES Splatoon (Not Even A Demo Yet Though...)

Posted: Sun Feb 28, 2016 5:31 pm
by Drew Sebastino
Could I have a rundown of what each does? :lol:

Re: SNES Splatoon (Not Even A Demo Yet Though...)

Posted: Mon Feb 29, 2016 11:11 am
by adam_smasher
Before you get knee-deep in 65816 coding, I'd highly recommend you at least take a gander at the classic Programming The 65816, available for free download on our very own Wiki.

AFAICT, lidnariq's nomenclature is non-standard. I'm also, TBH, not exactly sure which three registers they're talking about - there's only two bank registers on the 65816, the data bank register and the program bank register. At risk of stating the obvious, the data bank is used for data accesses and the program bank can be thought of as the most significant byte of the 24-bit PC.

On the 65816, many (most?) instructions have long addressing modes that let you use a full 24-bit address. But this is slower and less space-efficient than taking advantage of the bank registers - if you use a 16-bit address, the 65816 will generate the full address by automatically tacking the relevant 8-bit bank register onto the front. This will save a byte in the instruction stream and execute in fewer cycles. Moreover, not every addressing mode for every instruction can be made long, so if you really want to take advantage of everything the chip can do you need to be bank-aware.

I think I recall reading a post here from someone who disassembled some early SNES games and found that one of the reasons for all of their slowdown was that they basically used 24-bit addresses for everything, since their programmers hadn't quite grasped how to effectively use the banks or something.