News:

11 March 2016 - Forum Rules

Main Menu

Questions for prog a homebrew on SNES

Started by Hacker65xx, February 22, 2022, 05:37:39 PM

Previous topic - Next topic

Hacker65xx

Hi,

What is the code for init and display a image 256*224 with a palette 16colors, on background 1 and tiles priority 0 (mode 1)

For example the image 256*224 is stored to $8000 , and the palette to $A000





February 23, 2022, 09:12:40 PM - (Auto Merged - Double Posts are not allowed before 7 days.)





Is it a good beginning ?

XCE
Rep #10 ; Set xy to 16 bit
#MACRO STZ REGISTERS#
LDA #8F
STA $2100 ; Forced Blank and Adjust Brightness
LDA #80
STA $2115 ; Vmainc
LDA #01
STA $212C ; BG1 activation
LDA #01
STA $2105 ; Set BG in 8x8 and mode 1
LDA #80
STA $2107 ; Address of BG1's tiles ($8000)






zarby89

You need many things first to init the snes like settings the Vectors so the snes know where the starting/nmi code is at, and rom properties
you also need a tilemap not just and image of 256x224, you can use the tool SnesGFX to create the tilemap, gfx, and palette file

for the bgs/vram addresses you can experiment with bsnes+ (debugger for the snes), if you don't know what you are doing :P
since it displays everything in the tileviewer and the tilemap viewer you see if you setted mode properly, what addresses tiles are at, gfx, etc...


here's a complete example code (using Asar assembler)

;#=====================================================================
;Snes Intializations Vectors
;#=====================================================================
lorom ;Define the type of ROM we are writing the game on

org $00FFC0 ;Title up to 21 characters in ASCII
db "SNES BG IMAGE TEST   "

org $00FFD5 ;Is the game fastrom or not ? is it lorom or hirom
db #$00 ; Lorom not fastrom

org $00FFD6 ;ROM Type, ($02) ROM + RAM + SRAM
db #$02

org $00FFD7 ;Set rom size to 2MB ;0B = 2MB
db #$0B

org $00FFD8 ;Set SRAM Size 2048 bytes?
db #$02

org $00FFF4 ;COP
dw $0000

org $00FFF8 ;ABORT
dw $0000

org $00FFEA ;NMI - Native Move
dw NMICode

org $00FFFC ;RESET - Emulation Mode since the snes start in emulation mode
dw RESETVector

org $00FFFE ;IRQ/BRK
dw $0000

org $3FFFFF ;Fill the rom with 00 up to 2MB size
db #$00


;#=====================================================================
;Snes Reset Vector
;#=====================================================================
org $008000
RESETVector:

SEI
CLC
XCE
STZ $4200 ; Set the interrupt Mask
REP #$20

LDA #$0100 ; Set the stack
TCS
LDA #$0000 ; Set the Direct Page
TCD

SEP #$30
REP #$10  ; X 16bit, A 8bit

LDA #$80  ; Set Force blank
STA $2100

LDA #$80  ; Set increment mode when writing into vram
STA $2115
LDA #$01
STA $212C ; BG1 activation
LDA #$01
STA $2105 ; Set BG in 8x8 and mode 1
LDA #$40  ; Address is divided by 2 so #$40 for #$8000
STA $2107 ; Address of BG1's tiles ($8000)

LDA #$00  ; Address of GFX
STA $210B

LDX #$4000 ; Set Writing position in VRAM at position $8000 (divided by 2)
STX $2116
; Usually you will do DMAs inside the NMI but if you just want to init
; An image you can do your DMAs here in the reset code
LDX #MyTiles     ; Source Offset into source bank
STX $4302       
LDA #MyTiles>>16 ; Source bank
STA $4304       
LDX #$0800       ; Nbr of bytes to copy (SIZE OF YOUR TILEMAP FILE)
STX $4305       
LDA #$18         ; Register destination ($2118)
STA $4301       
LDA #$01         ; DMA Transfer Mode (2 register write once)
STA $4300
LDA #$01         ; Fire DMA 0
STA $420B       


LDX #$0000 ; Set Writing position in VRAM at position $0000 for GFX
STX $2116

LDX #MyGfx       ; Source Offset into source bank
STX $4302       
LDA #MyGfx>>16   ; Source bank
STA $4304       
LDX #$3C00       ; Nbr of bytes to copy (SIZE OF YOUR GFX FILE)
STX $4305       
LDA #$18         ; Register destination ($2118)
STA $4301       
LDA #$01         ; DMA Transfer Mode (2 register write once)
STA $4300
LDA #$01         ; Fire DMA 0
STA $420B


LDA #$00 ; Set Writing position in CGRAM at position $00 for Palette
STA $2121

LDX #MyPal       ; Source Offset into source bank
STX $4302       
LDA #MyPal>>16   ; Source bank
STA $4304       
LDX #$0200       ; Nbr of bytes to copy (SIZE OF YOUR PALETTE FILE)
STX $4305       
LDA #$22         ; Register destination ($2122)
STA $4301       
LDA #$02         ; DMA Transfer Mode (1 register write twice)
STA $4300
LDA #$01         ; Fire DMA 0
STA $420B 


LDA #$0F
STA $2100
LDA #$80 : STA $4200


.MainLoop
WAI ; Wait for interrupts to run then loop
JML .MainLoop


;#=====================================================================
;Snes NMI Vector
;#=====================================================================
NMICode:
LDA $4210 ; Read NMI Status (necessary)
; Main Code Here
RTI ; Return


org $018000 ; Bank01 : 8000
MyTiles:
incbin mytiles.bin
MyGfx:
incbin mygfx.bin
MyPal:
incbin mypal.bin


the 3 files needed to build that code (you can use your own file generated from SnesGFX) :
https://cdn.discordapp.com/attachments/607707764319584285/946592698293436416/mytiles.bin
https://cdn.discordapp.com/attachments/607707764319584285/946592698465419324/mygfx.bin
https://cdn.discordapp.com/attachments/607707764319584285/946592698620583956/mypal.bin

Good Luck !

Hacker65xx