Support the sprite palette select bits in OAM

This commit is contained in:
Lucas Scharenbroich 2023-05-17 12:59:07 -05:00
parent 25c82cc44b
commit 310c3487ca
4 changed files with 169 additions and 95 deletions

View File

@ -22,6 +22,7 @@ MyUserId equ 0
ROMStk equ 2
ROMZeroPg equ 4
LastScroll equ 6
RenderCtr equ 8
Tmp0 equ 240
Tmp1 equ 242
Tmp2 equ 244
@ -33,10 +34,12 @@ Tmp3 equ 246
_MTStartUp ; GTE requires the miscellaneous toolset to be running
stz LastScroll
stz RenderCtr
; The next two direct pages will be used by GTE, so get another 2 pages beyond that for the ROM. We get
; 4K of DP/Stack space by default, so there is plenty to share
tdc
sta DPSave
clc
adc #$300
sta ROMZeroPg
@ -91,6 +94,8 @@ Tmp3 equ 246
pea #128
pea #200
; pea #80
; pea #144
_GTESetScreenMode
pea $0000
@ -175,15 +180,24 @@ Tmp3 equ 246
jsr romxfer
EvtLoop
:spin lda ppustatus ; Set the bit that the VBL has started
bit #$80
:spin lda nmiCount
beq :spin
and #$FF7F
sta ppustatus
stz nmiCount
jsr triggerNMI
; lda ppustatus ; Set the bit that the VBL has started
; bit #$80
; beq :spin
; and #$FF7F
; sta ppustatus
; jsr triggerNMI
; lda RenderCtr
; bne :no_render
; lda #5
; sta RenderCtr
lda #$2000
jsr CopyNametable
lda ppuscroll+1
@ -199,6 +213,9 @@ EvtLoop
pea $FFFF ; NES mode
_GTERender
:no_render
dec RenderCtr
pha
_GTEReadControl
pla
@ -278,6 +295,9 @@ Greyscale dw $0000,$5555,$AAAA,$FFFF
dw $0000,$5555,$AAAA,$FFFF
dw $0000,$5555,$AAAA,$FFFF
nmiCount dw 0
DPSave dw 0
; Copy the tile and attribute bytes into the GTE buffer
;
; A = Nametable address ($2000, $2400, $2800, or $2C00)
@ -401,9 +421,9 @@ triggerNMI
bit #$80
beq :skip
lda ppustatus ; Set the bit that the VBL has started
ldal ppustatus ; Set the bit that the VBL has started
ora #$80
sta ppustatus
stal ppustatus
ldx #NonMaskableInterrupt
jmp romxfer
@ -730,16 +750,24 @@ StkSave lda #$0000
; VBL Interrupt task (called in native 8-bit mode)
mx %11
nmiTask
ldal ppustatus ; Set the bit that the VBL has started
ora #$80
stal ppustatus
ldal ppuctrl
bit #$80 ; Should an NMI be generated with the VBL?
beq :skip
ldal nmiCount
inc
stal nmiCount
php
; jsr triggerNMI
rep #$30
phb
phd
phk
plb
lda DPSave
tcd
jsr triggerNMI
pld
plb
plp
:skip
rtl

View File

@ -298,11 +298,13 @@ palTbl dw ppu_3F00,ppu_3F01,ppu_3F02,ppu_3F03
dw ppu_3F18,ppu_3F19,ppu_3F1A,ppu_3F1B
dw ppu_3F1C,ppu_3F1D,ppu_3F1E,ppu_3F1F
; Background color
ppu_3F00
lda PPU_MEM+$3F00
ldx #0
brl extra_out
; Background Palette 0
ppu_3F01
lda PPU_MEM+$3F01
ldx #2
@ -318,75 +320,95 @@ ppu_3F03
ldx #6
brl extra_out
ppu_3F05
lda PPU_MEM+$3F05
ldx #8
brl extra_out
ppu_3F06
lda PPU_MEM+$3F06
ldx #10
brl extra_out
ppu_3F07
lda PPU_MEM+$3F07
ldx #12
brl extra_out
ppu_3F09
lda PPU_MEM+$3F05
ldx #14
brl extra_out
ppu_3F0A
lda PPU_MEM+$3F06
ldx #16
brl extra_out
ppu_3F0B
lda PPU_MEM+$3F07
ldx #18
brl extra_out
ppu_3F0D
lda PPU_MEM+$3F05
ldx #20
brl extra_out
ppu_3F0E
lda PPU_MEM+$3F06
ldx #22
brl extra_out
ppu_3F0F
lda PPU_MEM+$3F07
ldx #24
brl extra_out
; Shadow for background color
ppu_3F10
lda PPU_MEM+$3F10
ldx #0
brl extra_out
ppu_3F04
ppu_3F08
ppu_3F0C
; Sprite Palette 0
ppu_3F11
ppu_3F12
ppu_3F13
ppu_3F14
ppu_3F15
ppu_3F16
ppu_3F17
ppu_3F18
ppu_3F19
ppu_3F1A
ppu_3F1B
ppu_3F1C
ppu_3F1D
ppu_3F1E
ppu_3F1F
lda PPU_MEM+$3F11
ldx #8
brl extra_out
ppu_3F12
lda PPU_MEM+$3F12
ldx #10
brl extra_out
ppu_3F13
lda PPU_MEM+$3F13
ldx #12
brl extra_out
; Sprite Palette 1
ppu_3F15
lda PPU_MEM+$3F15
ldx #14
brl extra_out
ppu_3F16
lda PPU_MEM+$3F16
ldx #16
brl extra_out
ppu_3F17
lda PPU_MEM+$3F17
ldx #18
brl extra_out
; Sprite Palette 2
ppu_3F19
lda PPU_MEM+$3F19
ldx #20
brl extra_out
ppu_3F1A
lda PPU_MEM+$3F1A
ldx #22
brl extra_out
ppu_3F1B
lda PPU_MEM+$3F1B
ldx #24
brl extra_out
; Sprite Palette 3
ppu_3F1D
lda PPU_MEM+$3F1D
ldx #26
brl extra_out
ppu_3F1E
lda PPU_MEM+$3F1E
ldx #28
brl extra_out
ppu_3F1F
lda PPU_MEM+$3F1F
ldx #30
brl extra_out
ppu_3F04
ppu_3F05
ppu_3F06
ppu_3F07
ppu_3F08
ppu_3F09
ppu_3F0A
ppu_3F0B
ppu_3F0C
ppu_3F0D
ppu_3F0E
ppu_3F0F
ppu_3F14
ppu_3F18
ppu_3F1C
brl no_pal
; Exit code to set a IIgs palette entry from the PPU memory
;
; A = NES palette value
@ -400,6 +422,7 @@ extra_out
ply
stal $E19E00,x
no_pal
sep #$30
plx
pla
@ -443,6 +466,7 @@ x_offset equ 16
drawOAMSprites
:tmp equ 238
; 248 is reserved for the blitter
phb
php
@ -510,7 +534,9 @@ drawOAMSprites
:noflip
pla
and #$0080 ; Set the vflip bit
asl
; and #$0080 ; Set the vflip bit
and #$0106 ; Set the vflip bit and palette select bits
drawTilePatch
jsl $000000 ; Draw the tile on the graphics screen

View File

@ -191,27 +191,38 @@ swizzle
* plb
* rtl ; special exit
pal_select dw $3333,$6666,$9999,$CCCC
_DrawTileToScreen
:palette equ 248
phb
pea $0101
plb
plb
bit #$0080
bit #$0100
jne _DrawTileToScreenV
phx
and #$0006
tax
ldal pal_select,x
sta :palette
plx
clc
]line equ 0
lup 8
lda: {]line*SHR_LINE_WIDTH}+2,y
eorl tiledata+{]line*4}+2,x
eor #$8888
ldal tiledata+{]line*4}+2,x
adc :palette
eor: {]line*SHR_LINE_WIDTH}+2,y
andl tiledata+{]line*4}+32+2,x
eor: {]line*SHR_LINE_WIDTH}+2,y
sta: {]line*SHR_LINE_WIDTH}+2,y
lda: {]line*SHR_LINE_WIDTH},y
eorl tiledata+{]line*4},x
eor #$8888
ldal tiledata+{]line*4},x
adc :palette
eor: {]line*SHR_LINE_WIDTH},y
andl tiledata+{]line*4}+32,x
eor: {]line*SHR_LINE_WIDTH},y
sta: {]line*SHR_LINE_WIDTH},y
@ -221,18 +232,27 @@ _DrawTileToScreen
rtl ; special exit
_DrawTileToScreenV
:palette equ 248
phx
and #$0006
tax
ldal pal_select,x
sta :palette
plx
clc
]line equ 0
lup 8
lda: {]line*SHR_LINE_WIDTH}+2,y
eorl tiledata+{{7-]line}*4}+2,x
eor #$8888
ldal tiledata+{{7-]line}*4}+2,x
eor :palette
eor: {]line*SHR_LINE_WIDTH}+2,y
andl tiledata+{{7-]line}*4}+32+2,x
eor: {]line*SHR_LINE_WIDTH}+2,y
sta: {]line*SHR_LINE_WIDTH}+2,y
lda: {]line*SHR_LINE_WIDTH},y
eorl tiledata+{{7-]line}*4},x
eor #$8888
ldal tiledata+{{7-]line}*4},x
eor :palette
eor: {]line*SHR_LINE_WIDTH},y
andl tiledata+{{7-]line}*4}+32,x
eor: {]line*SHR_LINE_WIDTH},y
sta: {]line*SHR_LINE_WIDTH},y

View File

@ -367,9 +367,9 @@ _SetTile
tax
lda TileStore+TS_TILE_ID,x
; cmp newTileId ; Lift this up to the caller
; bne :changed
; rts
cmp newTileId ; Lift this up to the caller
bne :changed
rts
:changed sta oldTileId
lda newTileId