123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- #include "memmap.i65"
- #include "dma.i65"
- GAME_MAIN:
- sep #$20 : .as
- lda #$00
- sta @AVR_CMD
- rep #$20 : .al
- lda #$0000
- sta @AVR_PARAM
- sta @AVR_PARAM+2
- sep #$20 : .as
- stz $4200 ; inhibit VBlank NMI
- jsr killdma
- jsr waitblank
- jsr snes_init
- lda #$01
- sta $420d ; fast cpu
- jsr setup_gfx
- jsr colortest
- jsr setup_hdma
- jsr menu_init
- jsr tests
- sep #$20 : .as
- lda @RTC_STATUS
- beq +
- jsl time_init
- +
- jsr menuloop
- cli
- stz $4200
- jmp @infloop ;infinite loop in WRAM
- killdma:
- stz $420b
- stz $420c
- stz $4310
- stz $4311
- stz $4312
- stz $4313
- stz $4314
- stz $4320
- stz $4321
- stz $4322
- stz $4323
- stz $4324
- stz $4330
- stz $4331
- stz $4332
- stz $4333
- stz $4334
- stz $4340
- stz $4341
- stz $4342
- stz $4343
- stz $4344
- stz $4350
- stz $4351
- stz $4352
- stz $4353
- stz $4354
- stz $4360
- stz $4361
- stz $4362
- stz $4363
- stz $4364
- rts
- waitblank:
- - lda $4212
- and #$80
- bne -
- - lda $4212
- and #$80
- beq -
- rts
- colortest:
- sep #$20 : .as
- rep #$10 : .xl
- stz $2130
- rts
- setup_gfx:
- sep #$20 : .as
- rep #$10 : .xl
- stz $4200
- stz $420b
- stz $420c
- ;clear tilemap buffers
- ldx #$0000
- stx $2181
- lda #$01
- sta $2183
- DMA0(#$08, #0, #^zero, #!zero, #$80)
- ;copy 2bpp font (can be used as 4-bit lores font!)
- ldx #$4000
- stx $2116
- DMA0(#$01, #$2000, #^font2, #!font2, #$18)
- ;copy 4bpp font
- ldx #$0000
- stx $2116
- DMA0(#$01, #$4000, #^font4, #!font4, #$18)
- ;clear BG1 tilemap
- ldx #BG1_TILE_BASE
- stx $2116
- DMA0(#$09, #$1000, #^zero, #!zero, #$18)
- ;clear BG2 tilemap
- ldx #BG2_TILE_BASE
- stx $2116
- DMA0(#$09, #$1000, #^zero, #!zero, #$18)
- ;clear OAM tables
- ldx #$0000
- stx $2102
- DMA0(#$08, #$544, #^zero, #!zero, #$04)
- ;copy logo tiles
- ldx #$2000
- stx $2116
- DMA0(#$01, #$4000, #^logo, #!logo, #$18)
- ;copy logo tilemap
- ldx #BG1_TILE_BASE
- stx $2116
- DMA0(#$01, #$280, #^logomap, #!logomap, #$18)
- ;copy sprites tiles
- ldx #OAM_TILE_BASE
- stx $2116
- DMA0(#$01, #$400, #^logospr, #!logospr, #$18)
- ;set OAM tables
- ldx #$0000
- stx $2102
- DMA0(#$00, #$5C, #^oam_data_l, #!oam_data_l, #$04)
- ldx #$0100
- stx $2102
- DMA0(#$00, #$08, #^oam_data_h, #!oam_data_h, #$04)
- ;set palette
- stz $2121
- DMA0(#$00, #$200, #^palette, #!palette, #$22)
- ;copy hdma tables so we can work "without" the cartridge
- ;palette
- lda #^hdma_pal
- ldx #!hdma_pal
- stx $2181
- sta $2183
- DMA0(#$00, #52, #^hdma_pal_src, #!hdma_pal_src, #$80)
- ;CG addr for palette
- lda #^hdma_cg_addr
- ldx #!hdma_cg_addr
- stx $2181
- sta $2183
- DMA0(#$00, #227, #^hdma_cg_addr_src, #!hdma_cg_addr_src, #$80)
- ;screen mode
- lda #^hdma_mode
- ldx #!hdma_mode
- stx $2181
- sta $2183
- DMA0(#$00, #5, #^hdma_mode_src, #!hdma_mode_src, #$80)
- ;bg scroll
- lda #^hdma_scroll
- ldx #!hdma_scroll
- stx $2181
- sta $2183
- DMA0(#$00, #11, #^hdma_scroll_src, #!hdma_scroll_src, #$80);
- ;color math
- lda #^hdma_math
- ldx #!hdma_math
- stx $2181
- sta $2183
- DMA0(#$00, #19, #^hdma_math_src, #!hdma_math_src, #$80);
- ;copy infinite loop to WRAM
- lda #$80
- sta infloop
- lda #$fe
- sta infloop+1
- lda #^wram_fadeloop
- ldx #!wram_fadeloop
- stx $2181
- sta $2183
- DMA0(#$00, #$6C, #^fadeloop, #!fadeloop, #$80);
- rts
- tests:
- sep #$20 : .as ;8-bit accumulator
- rep #$10 : .xl ;16-bit index
- lda #$03 ;mode 3, mode 5 via HDMA :D
- sta $2105
- lda #$58 ;Tilemap addr 0xB000
- ora #$02 ;SC size 32x64
- sta $2107 ;for BG1
- lda #$50 ;Tilemap addr 0xA000
- ora #$02 ;SC size 32x64
- sta $2108 ;for BG2
- lda #$40 ;chr base addr:
- sta $210b ;BG1=0x0000, BG2=0x8000
- lda #$13 ;enable BG1+BG2+OBJ
- sta $212c ;BG Main
- lda #$13 ;enable BG1+BG2+OBJ
- sta $212d ;BG Sub
- lda #$20 ;Window 1 for color
- sta $2125 ;Color window
- lda #$01 ;cut off leftmost subscreen pixel garbage
- sta $2126
- lda #$fe
- sta $2127
- jsr setup_224
- lda #$10
- sta $2130
- lda #$1f
- sta $212e
- sta $212f
- stz $2121
- lda #$0f
- sta $2100 ;screen on, full brightness
- lda #9
- sta bar_yl
- rts
-
- snes_init:
- sep #$20 : .as ;8-bit accumulator
- rep #$10 : .xl ;16-bit index
- stz $4200 ;
- lda #$ff
- sta $4201 ;
- stz $4202 ;
- stz $4203 ;
- stz $4204 ;
- stz $4205 ;
- stz $4206 ;
- stz $4207 ;
- stz $4208 ;
- stz $4209 ;
- stz $420a ;
- stz $420b ;
- stz $420c ;
- lda #$01
- sta $420d ; FAAAAAST
- lda #$8f
- sta $2100 ;INIDISP: force blank
- lda #$03 ; 8x8+16x16; name=0; base=3
- sta $2101 ;
- stz $2102 ;
- stz $2103 ;
- ; stz $2104 ; (OAM Data?!)
- ; stz $2104 ; (OAM Data?!)
- stz $2105 ;
- stz $2106 ;
- stz $2107 ;
- stz $2108 ;
- stz $2109 ;
- stz $210a ;
- stz $210b ;
- stz $210c ;
- stz $210d ;
- stz $210d ;
- stz $210e ;
- stz $210e ;
- stz $210f ;
- stz $210f ;
- lda #$05
- sta $2110 ;
- stz $2110 ;
- stz $2111 ;
- stz $2111 ;
- stz $2112 ;
- stz $2112 ;
- stz $2113 ;
- stz $2113 ;
- stz $2114 ;
- stz $2114 ;
- lda #$80
- sta $2115 ;
- stz $2116 ;
- stz $2117 ;
- ; stz $2118 ;(VRAM Data?!)
- ; stz $2119 ;(VRAM Data?!)
- stz $211a ;
- stz $211b ;
- lda #$01
- sta $211b ;
- stz $211c ;
- stz $211c ;
- stz $211d ;
- stz $211d ;
- stz $211e ;
- sta $211e ;
- stz $211f ;
- stz $211f ;
- stz $2120 ;
- stz $2120 ;
- stz $2121 ;
- ; stz $2122 ; (CG Data?!)
- ; stz $2122 ; (CG Data?!)
- stz $2123 ;
- stz $2124 ;
- stz $2125 ;
- stz $2126 ;
- stz $2127 ;
- stz $2128 ;
- stz $2129 ;
- stz $212a ;
- stz $212b ;
- stz $212c ;
- stz $212d ;
- stz $212e ;
- stz $212f ;
- lda #$30
- sta $2130 ;
- stz $2131 ;
- lda #$e0
- sta $2132 ;
- stz $2133 ;
- ;clear WRAM lower page
- ; ldx #$0200
- ; stx $2181
- ; lda #$00
- ; sta $2183
- ; DMA0(#$08, #$FF00, #^zero, #!zero, #$80)
- ; ldx #$0000
- ; stx $2181
- ; lda #$00
- ; sta $2183
- ; DMA0(#$08, #$1e0, #^zero, #!zero, #$80)
- rts
- fadeloop:
- sep #$30 : .as : .xs
- ldx #$0f
- and #$00
- pha
- plb
- lda #$7f
- sta hdma_math_selection+2
- lda #$30
- sta hdma_math_selection+1
- lda #$bf
- sta hdma_math+1
- sta hdma_math+4
- sta hdma_math+16
- lda #$e0
- sta hdma_math+2
- sta hdma_math+5
- sta hdma_math+17
- fadeloop_start
- lda $4212
- and #$80
- bne fadeloop_start
- - lda $4212
- and #$80
- bne +
- bra -
- + lda hdma_math+2
- inc
- inc
- sta hdma_math+2
- sta hdma_math+5
- sta hdma_math+17
- txa
- dec
- sta $2100
- tax
- bne fadeloop_start
- stz $2126
- stz $212e
- stz $2131
- stz $2130
- lda #$00
- sta @hdma_math
- stz $2100
- - bra -
- fadeloop_end:
- .byt $ff
|