mirror of
https://github.com/lscharen/iigs-game-engine.git
synced 2025-02-20 05:29:10 +00:00
Checkpoint; blitter failing
This commit is contained in:
parent
e378dc6e26
commit
3fce46872d
@ -58,6 +58,8 @@ appTmp0 equ 28
|
||||
|
||||
; Load a tileset
|
||||
|
||||
pea 0
|
||||
pea 256
|
||||
pea #^tiledata
|
||||
pea #tiledata
|
||||
_GTELoadTileSet
|
||||
|
@ -37,6 +37,8 @@ MaxBG0X equ 20
|
||||
MaxBG0Y equ 22
|
||||
OldOneSecondCounter equ 26
|
||||
appTmp0 equ 28
|
||||
appTmp1 equ 30
|
||||
appTmp2 equ 32
|
||||
|
||||
phk
|
||||
plb
|
||||
@ -50,15 +52,39 @@ appTmp0 equ 28
|
||||
lda #ENGINE_MODE_USER_TOOL+ENGINE_MODE_TWO_LAYER
|
||||
jsr GTEStartUp ; Load and install the GTE User Tool
|
||||
|
||||
; Initialize local variables
|
||||
pea $0000 ; Set the first two tiles
|
||||
pea $0002
|
||||
pea #^TileData
|
||||
pea #TileData
|
||||
_GTELoadTileSet
|
||||
|
||||
; pea $0000
|
||||
; pea #^TileSetPalette
|
||||
; pea #TileSetPalette
|
||||
; _GTESetPalette
|
||||
pea $0000
|
||||
pea #^TileSetPalette
|
||||
pea #TileSetPalette
|
||||
_GTESetPalette
|
||||
|
||||
; Set up our level data
|
||||
; Fill in the field with a checkboard pattern
|
||||
|
||||
stz appTmp1
|
||||
|
||||
:tloop0 stz appTmp0
|
||||
:tloop1 lda appTmp0 ; X
|
||||
pha
|
||||
pei appTmp1 ; Y
|
||||
eor appTmp1
|
||||
and #$0001
|
||||
pha ; tile ID
|
||||
_GTESetTile
|
||||
|
||||
inc appTmp0
|
||||
lda #40
|
||||
cmp appTmp0
|
||||
bcs :tloop1
|
||||
|
||||
inc appTmp1
|
||||
lda #25
|
||||
cmp appTmp1
|
||||
bcs :tloop0
|
||||
|
||||
; Set up a very specific test. First, we draw a sprite into the sprite plane, and then
|
||||
; leave it alone. We are just testing the ability to merge sprite plane data into
|
||||
@ -70,7 +96,8 @@ EvtLoop
|
||||
|
||||
jsr HandleKeys ; Do the generic key handlers
|
||||
|
||||
pea RENDER_PER_SCANLINE ; Scanline rendering
|
||||
pea #RENDER_PER_SCANLINE ; Scanline rendering
|
||||
; pea $0000
|
||||
_GTERender
|
||||
|
||||
brl EvtLoop
|
||||
@ -88,9 +115,12 @@ qtRec adrl $0000
|
||||
da $00
|
||||
|
||||
; Color palette
|
||||
TileSetPalette dw $0000,$0FFF,$0FFF,$0FFF,$0FFF,$0FFF,$0FFF,$0FFF,$0FFF,$0FFF,$0FFF,$0FFF,$0FFF,$0FFF,$0FFF,$0FFF
|
||||
|
||||
MyDirectPage ds 2
|
||||
|
||||
; Stub
|
||||
SetLimits rts
|
||||
|
||||
PUT ../kfest-2022/StartUp.s
|
||||
PUT Tiles.s
|
||||
|
@ -5,7 +5,7 @@ REM
|
||||
REM Pass the path of the Cadius tool as the first argument (%1)
|
||||
|
||||
set CADIUS="%1"
|
||||
set IMAGE="..\\..\\..\\emu\\Target.2mg"
|
||||
set IMAGE="..\\..\\emu\\Target.2mg"
|
||||
set FOLDER="/GTEDEV/TF4"
|
||||
|
||||
REM Cadius does not overwrite files, so clear the root folder first
|
||||
@ -14,4 +14,4 @@ REM Cadius does not overwrite files, so clear the root folder first
|
||||
|
||||
REM Now copy files and folders as needed
|
||||
%CADIUS% ADDFILE %IMAGE% %FOLDER% .\GTETF4
|
||||
%CADIUS% ADDFILE %IMAGE% %FOLDER% ..\src\Tool160
|
||||
%CADIUS% ADDFILE %IMAGE% %FOLDER% ..\..\src\Tool160
|
||||
|
@ -126,6 +126,9 @@ _GTEClearBG1Buffer MAC
|
||||
_GTESetBG1Scale MAC
|
||||
UserTool $2B00+GTEToolNum
|
||||
<<<
|
||||
_GTEGetAddress MAC
|
||||
UserTool $2C00+GTEToolNum
|
||||
<<<
|
||||
|
||||
; EngineMode definitions
|
||||
; Script definition
|
||||
@ -155,6 +158,8 @@ RENDER_BG1_VERT_OFFSET equ $0004
|
||||
RENDER_BG1_ROTATION equ $0008
|
||||
RENDER_PER_SCANLINE equ $0010
|
||||
|
||||
; GetAddress table IDs
|
||||
scanlineHorzOffset equ $0001
|
||||
|
||||
; Tile constants
|
||||
; TILE_RESERVED_BIT equ $8000
|
||||
|
@ -233,6 +233,7 @@ EngineReset
|
||||
sta tmp15
|
||||
stz tmp14
|
||||
|
||||
; Rebuild all of the bank blitters
|
||||
:loop
|
||||
ldx #BlitBuff
|
||||
lda #^BlitBuff
|
||||
@ -247,6 +248,15 @@ EngineReset
|
||||
dec tmp15
|
||||
bne :loop
|
||||
|
||||
; Set the scanline tables to reasonable default values
|
||||
ldx #{416*2}-2
|
||||
lda #0
|
||||
:sxm_loop
|
||||
sta StartXMod164Arr,x
|
||||
dex
|
||||
dex
|
||||
bpl :sxm_loop
|
||||
|
||||
rts
|
||||
|
||||
|
||||
|
@ -184,6 +184,9 @@ DIRTY_BIT_BG0_REFRESH equ $0010
|
||||
DIRTY_BIT_BG1_REFRESH equ $0020
|
||||
DIRTY_BIT_SPRITE_ARRAY equ $0040
|
||||
|
||||
; GetAddress table IDs
|
||||
scanlineHorzOffset equ $0001 ; table of 416 wors, a double-array of scanline offset values. Must be 0, 163
|
||||
|
||||
; Script definition
|
||||
YIELD equ $8000
|
||||
JUMP equ $4000
|
||||
|
53
src/Render.s
53
src/Render.s
@ -39,7 +39,6 @@ _Render
|
||||
beq *+5
|
||||
jmp _RenderScanlines ; Do the scanline-based renderer
|
||||
|
||||
|
||||
jsr _ApplyBG0YPos ; Set stack addresses for the virtual lines to the physical screen
|
||||
|
||||
lda #RENDER_BG1_ROTATION
|
||||
@ -57,7 +56,7 @@ _Render
|
||||
jsr _RenderSprites ; Once the BG0 X and Y positions are committed, update sprite data
|
||||
|
||||
jsr _UpdateBG0TileMap ; and the tile maps. These subroutines build up a list of tiles
|
||||
; jsr _UpdateBG1TileMap ; that need to be updated in the code field
|
||||
jsr _UpdateBG1TileMap ; that need to be updated in the code field
|
||||
|
||||
jsr _ApplyTiles ; This function actually draws the new tiles into the code field
|
||||
|
||||
@ -155,61 +154,63 @@ _DoOverlay
|
||||
:disp jsl $000000
|
||||
rts
|
||||
|
||||
|
||||
; Use the per-scanline tables to set the screen. This is really meant to be used without the built-in tilemap
|
||||
; support and is more of a low-level way to control the background rendering
|
||||
_RenderScanlines
|
||||
|
||||
jsr _ApplyBG0YPos ; Set stack addresses for the virtual lines to the physical screen
|
||||
; jsr _ApplyBG1YPos ; Set the y-register values of the blitter
|
||||
jsr _ApplyBG1YPos ; Set the y-register values of the blitter
|
||||
|
||||
; _ApplyBG0Xpos need to be split because we have to set the offsets, then draw in any updated tiles, and
|
||||
; finally patch out the code field. Right now, the BRA operand is getting overwritten by tile data.
|
||||
|
||||
jsr _ApplyBG0XPosPre
|
||||
; jsr _ApplyBG1XPosPre
|
||||
jsr _ApplyBG1XPosPre
|
||||
|
||||
; jsr _RenderSprites ; Once the BG0 X and Y positions are committed, update sprite data
|
||||
|
||||
; jsr _ApplyTiles ; This function actually draws the new tiles into the code field
|
||||
|
||||
jsr _ScanlineBG0XPos ; Patch the code field instructions with exit BRA opcode
|
||||
jsr _ScanlineBG0XPos ; Patch the code field instructions with exit BRA opcode
|
||||
|
||||
; jsr _ApplyBG1XPos ; Update the direct page value based on the horizontal position
|
||||
|
||||
; The code fields are locked in now and ready to be rendered. See if there is an overlay or any
|
||||
; other reason to render with shadowing off. Otherwise, just do things quickly.
|
||||
|
||||
lda Overlays
|
||||
beq :no_ovrly
|
||||
; lda Overlays
|
||||
; beq :no_ovrly
|
||||
|
||||
jsr _ShadowOff
|
||||
; jsr _ShadowOff
|
||||
|
||||
; Shadowing is turned off. Render all of the scan lines that need a second pass. One
|
||||
; optimization that can be done here is that the lines can be rendered in any order
|
||||
; since it is not shown on-screen yet.
|
||||
|
||||
ldx Overlays+2 ; Blit the full virtual buffer to the screen
|
||||
ldy Overlays+4
|
||||
jsr _BltRange
|
||||
; ldx Overlays+2 ; Blit the full virtual buffer to the screen
|
||||
; ldy Overlays+4
|
||||
; jsr _BltRange
|
||||
|
||||
; Turn shadowing back on
|
||||
|
||||
jsr _ShadowOn
|
||||
; jsr _ShadowOn
|
||||
|
||||
; Now render all of the remaining lines in top-to-bottom (or bottom-to-top) order
|
||||
|
||||
ldx #0
|
||||
ldy Overlays+2
|
||||
beq :skip
|
||||
jsr _BltRange
|
||||
; ldx #0
|
||||
; ldy Overlays+2
|
||||
; beq :skip
|
||||
; jsr _BltRange
|
||||
:skip
|
||||
jsr _DoOverlay
|
||||
; jsr _DoOverlay
|
||||
|
||||
ldx Overlays+4
|
||||
cpx ScreenHeight
|
||||
beq :done
|
||||
ldy ScreenHeight
|
||||
jsr _BltRange
|
||||
bra :done
|
||||
; ldx Overlays+4
|
||||
; cpx ScreenHeight
|
||||
; beq :done
|
||||
; ldy ScreenHeight
|
||||
; jsr _BltRange
|
||||
; bra :done
|
||||
|
||||
:no_ovrly
|
||||
ldx #0 ; Blit the full virtual buffer to the screen
|
||||
@ -217,9 +218,9 @@ _RenderScanlines
|
||||
jsr _BltRange
|
||||
:done
|
||||
|
||||
ldx #0
|
||||
ldy ScreenHeight
|
||||
jsr _BltSCB
|
||||
; ldx #0
|
||||
; ldy ScreenHeight
|
||||
; jsr _BltSCB
|
||||
|
||||
lda StartYMod208 ; Restore the fields back to their original state
|
||||
ldx ScreenHeight
|
||||
|
29
src/Tiles.s
29
src/Tiles.s
@ -1,20 +1,29 @@
|
||||
; Basic tile functions
|
||||
|
||||
; Copy tileset data from a pointer in memory to the tiledata back
|
||||
; X = high word
|
||||
; A = low word
|
||||
;
|
||||
; tmp0 = Pointer to tile data
|
||||
; X = first tile
|
||||
; Y = last tile
|
||||
;
|
||||
; To copy in three tiles starting at tile 5, for example, X = 5 and Y = 9
|
||||
_LoadTileSet
|
||||
sta tmp0
|
||||
stx tmp1
|
||||
txa
|
||||
_Mul128 ; Jump to the target location
|
||||
tax
|
||||
tya
|
||||
_Mul128
|
||||
sta tmp2 ; This is the terminating byte
|
||||
|
||||
ldy #0
|
||||
tyx
|
||||
:loop lda [tmp0],y
|
||||
stal tiledata,x
|
||||
dex
|
||||
dex
|
||||
dey
|
||||
dey
|
||||
bne :loop
|
||||
inx
|
||||
inx
|
||||
iny
|
||||
iny
|
||||
cpx tmp2
|
||||
bne :loop ; Use BNE so when Y=512 => $0000, we wait for wrap-around
|
||||
rts
|
||||
|
||||
|
||||
|
45
src/Tool.s
45
src/Tool.s
@ -96,6 +96,7 @@ _CallTable
|
||||
|
||||
adrl _TSClearBG1Buffer-1
|
||||
adrl _TSSetBG1Scale-1
|
||||
adrl _TSGetAddress-1
|
||||
_CTEnd
|
||||
_GTEAddSprite MAC
|
||||
UserTool $1000+GTEToolNum
|
||||
@ -183,7 +184,9 @@ _TSShutDown
|
||||
jsr _CoreShutDown ; Shut down the library
|
||||
plb
|
||||
|
||||
pea $8000
|
||||
lda EngineMode ; $0000 = system tool, $8000 = user tool set
|
||||
and #$8000
|
||||
pha
|
||||
pei ToolNum
|
||||
pea $0000 ; Set WAP to null
|
||||
pea $0000
|
||||
@ -303,18 +306,27 @@ _TSRenderDirty
|
||||
jsr _RenderDirty
|
||||
_TSExit #0;#2
|
||||
|
||||
; LoadTileSet(Pointer)
|
||||
; LoadTileSet(Start, Finish, Pointer)
|
||||
_TSLoadTileSet
|
||||
TSPtr equ FirstParam
|
||||
:TSPtr equ FirstParam
|
||||
:finish equ FirstParam+4
|
||||
:start equ FirstParam+6
|
||||
|
||||
_TSEntry
|
||||
|
||||
lda TSPtr+2,s
|
||||
lda :TSPtr+2,s ; stuff the pointer in the direct page
|
||||
sta tmp1
|
||||
lda :TSPtr,s
|
||||
sta tmp0
|
||||
|
||||
lda :start,s ; put the range in the registers
|
||||
tax
|
||||
lda TSPtr,s
|
||||
lda :finish,s
|
||||
tay
|
||||
|
||||
jsr _LoadTileSet
|
||||
|
||||
_TSExit #0;#4
|
||||
_TSExit #0;#8
|
||||
|
||||
; CreateSpriteStamp(spriteDescriptor: Word, vbuffAddr: Word)
|
||||
_TSCreateSpriteStamp
|
||||
@ -805,6 +817,27 @@ _TSSetBG1Scale
|
||||
sta BG1Scaling
|
||||
_TSExit #0;#2
|
||||
|
||||
_TSGetAddress
|
||||
:output equ FirstParam+0
|
||||
:tblId equ FirstParam+4
|
||||
|
||||
_TSEntry
|
||||
lda #0
|
||||
sta :output,s
|
||||
sta :output+2,s
|
||||
|
||||
lda :value,s
|
||||
cmp #scanlineHorzOffset
|
||||
bne :out
|
||||
|
||||
lda #StartXMod164Arr
|
||||
sta :output,s
|
||||
lda #^StartXMod164Arr
|
||||
sta :output+2,s
|
||||
|
||||
:out
|
||||
_TSExit #0;#2
|
||||
|
||||
; Insert the GTE code
|
||||
|
||||
put Math.s
|
||||
|
@ -57,7 +57,9 @@ _BltRange
|
||||
lda EngineMode
|
||||
bit #ENGINE_MODE_TWO_LAYER
|
||||
beq :skip_bank
|
||||
|
||||
|
||||
; TODO: Switch to loading the selected BG1 bank. No special "Alt" bank
|
||||
|
||||
lda RenderFlags
|
||||
bit #RENDER_ALT_BG1
|
||||
beq :primary
|
||||
@ -81,7 +83,7 @@ _BltRange
|
||||
_R0W1
|
||||
tsc ; save the stack pointer
|
||||
stal stk_save+1
|
||||
|
||||
|
||||
blt_entry jml $000000 ; Jump into the blitter code $XX/YY00
|
||||
|
||||
blt_return _R0W0
|
||||
|
@ -205,9 +205,8 @@ _ApplyBG0XPos
|
||||
; where the exit will be patched in
|
||||
|
||||
dec ; (a - 1) % 164
|
||||
bpl :hop1
|
||||
bpl *+5
|
||||
lda #163
|
||||
:hop1
|
||||
|
||||
; If the exit byte is odd, then the left edge is even-aligned and we round down and exit at at
|
||||
; that word.
|
||||
@ -243,7 +242,7 @@ _ApplyBG0XPos
|
||||
dec ; to get the index of the first on-screen byte
|
||||
|
||||
cmp #164 ; Keep the value in range
|
||||
bcc :hop2
|
||||
bcc *+5
|
||||
sbc #164
|
||||
:hop2
|
||||
|
||||
|
@ -19,7 +19,8 @@ _ScanlineBG0XPos
|
||||
:base_address equ tmp8
|
||||
:opcode equ tmp9
|
||||
:odd_entry_offset equ tmp10
|
||||
|
||||
|
||||
brk $AB
|
||||
lda StartYMod208 ; This is the base line of the virtual screen
|
||||
asl
|
||||
sta :virt_line_x2 ; Keep track of it
|
||||
@ -38,8 +39,8 @@ _ScanlineBG0XPos
|
||||
|
||||
:loop
|
||||
ldx :virt_line_x2
|
||||
lda StartXMod164Arr,x ; Get the offset for this line
|
||||
|
||||
lda StartXMod164Arr,x ; Get the offset for this line
|
||||
dec ; The exit point is one byte sooner
|
||||
bpl *+5
|
||||
lda #163
|
||||
@ -100,7 +101,7 @@ _ScanlineBG0XPos
|
||||
sta :opcode
|
||||
:prep_complete
|
||||
|
||||
; Not patch in the code field line
|
||||
; Now patch in the code field line
|
||||
|
||||
ldy BTableLow,x ; Get the address of the first code field line
|
||||
clc
|
||||
@ -124,9 +125,9 @@ _ScanlineBG0XPos
|
||||
sta: OPCODE_SAVE+$0000,y
|
||||
|
||||
;SetConst
|
||||
txy ; ldy :exit_address -- starting at this address
|
||||
ldx :exit_bra ; Copy this value into all of the lines
|
||||
sta: $0000,y
|
||||
; txy ; ldy :exit_address -- starting at this address
|
||||
lda :exit_bra ; Copy this value into all of the lines
|
||||
sta: $0000,x
|
||||
|
||||
; Next, patch in the CODE_ENTRY value, which is the low byte of a JMP instruction. This is an
|
||||
; 8-bit operation and, since the PEA code is bank aligned, we use the entry_offset value directly
|
||||
@ -135,7 +136,7 @@ _ScanlineBG0XPos
|
||||
|
||||
; SetCodeEntry
|
||||
lda :entry_offset
|
||||
ldy :base_address
|
||||
; ldy :base_address
|
||||
sta: CODE_ENTRY+$0000,y
|
||||
|
||||
; SetCodeEntryOpcode
|
||||
@ -151,11 +152,11 @@ _ScanlineBG0XPos
|
||||
; SetOddCodeEntry
|
||||
sta: ODD_ENTRY+$0000,y
|
||||
; SaveHighOperand
|
||||
ldx :exit_address
|
||||
; ldx :exit_address
|
||||
lda: $0002,x
|
||||
sta: OPCODE_HIGH_SAVE+$0000,y
|
||||
:not_odd
|
||||
rep #$21 ; clear the carry
|
||||
rep #$20 ; clear the carry
|
||||
|
||||
; Do the end of the loop -- update the virtual line counter and reduce the number
|
||||
; of lines left to render
|
||||
@ -193,18 +194,19 @@ _RestoreScanlineBG0Opcodes
|
||||
|
||||
:loop
|
||||
ldx :virt_line_x2
|
||||
ldy BTableLow,x ; Get the address of the first code field line
|
||||
|
||||
lda BTableHigh,x
|
||||
ora :src_bank
|
||||
pha
|
||||
|
||||
lda LastPatchOffsetArr,x
|
||||
lda BTableLow,x ; Get the address of the first code field line
|
||||
clc
|
||||
adc LastPatchOffsetArr,x
|
||||
tax
|
||||
|
||||
plb
|
||||
lda OPCODE_SAVE+$0000,y
|
||||
sta $0000,x
|
||||
lda: OPCODE_SAVE+$0000,y
|
||||
sta: $0000,x
|
||||
|
||||
; Do the end of the loop -- update the virtual line counter and reduce the number
|
||||
; of lines left to render
|
||||
|
@ -5,12 +5,12 @@
|
||||
DP_ADDR equ entry_1-base+1 ; offset to patch in the direct page for dynamic tiles
|
||||
BG1_ADDR equ entry_2-base+1 ; offset to patch in the Y-reg for BG1 (dp),y addressing
|
||||
STK_ADDR equ entry_3-base+1 ; offset to patch in the stack (SHR) right edge address
|
||||
BNK_ADDR equ entry_0-base+1 ; offset to patch in the address of a Bank 0 memory location to load the bank register
|
||||
; BNK_ADDR equ entry_0-base+1 ; offset to patch in the address of a Bank 0 memory location to load the bank register
|
||||
|
||||
DP_ENTRY equ entry_1-base
|
||||
TWO_LYR_ENTRY equ entry_2-base
|
||||
ONE_LYR_ENTRY equ entry_3-base
|
||||
BANK_ENTRY equ entry_0-base
|
||||
; BANK_ENTRY equ entry_0-base
|
||||
|
||||
CODE_ENTRY_OPCODE equ entry_jmp-base
|
||||
CODE_ENTRY equ entry_jmp-base+1 ; low byte of the page-aligned jump address
|
||||
@ -68,9 +68,9 @@ BankPatchNum equ *-BankPatches
|
||||
; the code is assembled on a page boundary to help with alignment
|
||||
ds \,$00 ; pad to the next page boundary
|
||||
base
|
||||
entry_0 lda #0000 ; Used to set per-scanline bank register
|
||||
tcs
|
||||
plb
|
||||
;entry_0 lda #0000 ; Used to set per-scanline bank register
|
||||
; tcs
|
||||
; plb
|
||||
entry_1 ldx #0000 ; Used for LDA 00,x addressing (Dynamic Tiles)
|
||||
entry_2 ldy #0000 ; Used for LDA (00),y addressing (Second Layer; BG1)
|
||||
entry_3 lda #0000 ; Sets screen address (right edge)
|
||||
|
Loading…
x
Reference in New Issue
Block a user