mirror of
https://github.com/lscharen/iigs-game-engine.git
synced 2025-02-23 11:29:02 +00:00
Misc odds-and-ends
This commit is contained in:
parent
3063ab88f9
commit
8aa816037c
@ -96,4 +96,99 @@ HandleKeys
|
||||
:unhandled pla
|
||||
sec
|
||||
rts
|
||||
|
||||
|
||||
_Deref MAC
|
||||
phb ; save caller's data bank register
|
||||
pha ; push high word of handle on stack
|
||||
plb ; sets B to the bank byte of the pointer
|
||||
lda |$0002,x ; load the high word of the master pointer
|
||||
pha ; and save it on the stack
|
||||
lda |$0000,x ; load the low word of the master pointer
|
||||
tax ; and return it in X
|
||||
pla ; restore the high word in A
|
||||
plb ; pull the handle's high word high byte off the
|
||||
; stack
|
||||
plb ; restore the caller's data bank register
|
||||
<<<
|
||||
|
||||
AllocBank PushLong #0
|
||||
PushLong #$10000
|
||||
PushWord MyUserId
|
||||
PushWord #%11000000_00011100
|
||||
PushLong #0
|
||||
_NewHandle
|
||||
plx ; base address of the new handle
|
||||
pla ; high address 00XX of the new handle (bank)
|
||||
_Deref
|
||||
rts
|
||||
|
||||
; Shared I/O
|
||||
; Basic I/O function to load files
|
||||
LoadFile
|
||||
stx openRec+4 ; X=File, A=Bank (high word) assumed zero for low
|
||||
stz readRec+4
|
||||
sta readRec+6
|
||||
phb
|
||||
phb
|
||||
pla
|
||||
and #$00FF
|
||||
sta openRec+6
|
||||
|
||||
:openFile _OpenGS openRec
|
||||
bcs :openReadErr
|
||||
lda openRec+2
|
||||
sta eofRec+2
|
||||
sta readRec+2
|
||||
|
||||
_GetEOFGS eofRec
|
||||
lda eofRec+4
|
||||
sta readRec+8
|
||||
lda eofRec+6
|
||||
sta readRec+10
|
||||
|
||||
_ReadGS readRec
|
||||
bcs :openReadErr
|
||||
|
||||
:closeFile _CloseGS closeRec
|
||||
clc
|
||||
lda eofRec+4 ; File Size
|
||||
rts
|
||||
|
||||
:openReadErr jsr :closeFile
|
||||
nop
|
||||
nop
|
||||
|
||||
PushWord #0
|
||||
PushLong #msgLine1
|
||||
PushLong #msgLine2
|
||||
PushLong #msgLine3
|
||||
PushLong #msgLine4
|
||||
_TLTextMountVolume
|
||||
pla
|
||||
cmp #1
|
||||
bne :loadFileErr
|
||||
brl :openFile
|
||||
:loadFileErr sec
|
||||
rts
|
||||
|
||||
msgLine1 str 'Unable to load File'
|
||||
msgLine2 str 'Press a key :'
|
||||
msgLine3 str ' -> Return to Try Again'
|
||||
msgLine4 str ' -> Esc to Quit'
|
||||
|
||||
openRec dw 2 ; pCount
|
||||
ds 2 ; refNum
|
||||
ds 4 ; pathname
|
||||
|
||||
eofRec dw 2 ; pCount
|
||||
ds 2 ; refNum
|
||||
ds 4 ; eof
|
||||
|
||||
readRec dw 4 ; pCount
|
||||
ds 2 ; refNum
|
||||
ds 4 ; dataBuffer
|
||||
ds 4 ; requestCount
|
||||
ds 4 ; transferCount
|
||||
|
||||
closeRec dw 1 ; pCount
|
||||
ds 2 ; refNum
|
@ -78,6 +78,7 @@ appTmp0 equ 28
|
||||
jsr BG0SetUp
|
||||
jsr SetLimits
|
||||
|
||||
lda #193 ; Tile ID of '0'
|
||||
jsr InitOverlay ; Initialize the status bar
|
||||
pha
|
||||
_GTEGetSeconds
|
||||
@ -147,6 +148,7 @@ EvtLoop
|
||||
:not_w
|
||||
|
||||
:do_render
|
||||
pea $0000
|
||||
_GTERender
|
||||
|
||||
; Update the performance counters
|
||||
|
@ -19,7 +19,7 @@
|
||||
"build:all": "npm run build:tiles && npm run build:map && npm run build:tool && npm run build:sys16 && npm run build:image",
|
||||
"build:map": "node %npm_package_config_tiled2iigs% ./assets/tiled/world_1-1.json --empty-tile 33 --no-gen-tiles --output-dir ./gen",
|
||||
"build:map:masked": "node %npm_package_config_tiled2iigs% ./assets/tiled/world_1-1.json --force-masked --empty-tile 33 --no-gen-tiles --output-dir ./gen",
|
||||
"build:tiles": "node %npm_package_config_png2iigs% ./assets/tilesets/smb-256-128-4bpp.png --max-tiles 360 --as-tile-data --transparent-color FF00FF --background-color 6B8CFF > ./gen/App.TileSet.s",
|
||||
"build:tiles": "node %npm_package_config_png2iigs% ./assets/tilesets/smb-256-128-4bpp.png --max-tiles 360 --as-tile-data --transparent-color FF00FF --background-color 6B8CFF --verbose > ./gen/App.TileSet.s",
|
||||
"build:sys16": "%npm_package_config_merlin32% -V %npm_package_config_macros% App.s",
|
||||
"build": "npm run build:tool && npm run build:sys16",
|
||||
"build:tool": "%npm_package_config_merlin32% -V %npm_package_config_macros% ../../../src/Master.s",
|
||||
|
@ -79,6 +79,7 @@ appTmp0 equ 28
|
||||
jsr TileAnimInit
|
||||
jsr SetLimits
|
||||
|
||||
lda #193 ; Tile ID of '0'
|
||||
jsr InitOverlay ; Initialize the status bar
|
||||
pha
|
||||
_GTEGetSeconds
|
||||
@ -148,6 +149,7 @@ EvtLoop
|
||||
:not_w
|
||||
|
||||
:do_render
|
||||
pea $0000
|
||||
_GTERender
|
||||
|
||||
; Update the performance counters
|
||||
|
@ -87,6 +87,7 @@ appTmp2 equ 32
|
||||
jsr BG0SetUp
|
||||
jsr SetLimits
|
||||
|
||||
lda #193 ; Tile ID of '0'
|
||||
jsr InitOverlay ; Initialize the status bar
|
||||
pha
|
||||
_GTEGetSeconds
|
||||
@ -158,6 +159,7 @@ EvtLoop
|
||||
:do_render
|
||||
jsr SetDynTiles
|
||||
|
||||
pea $0000
|
||||
_GTERender
|
||||
|
||||
; Update the performance counters
|
||||
|
@ -94,6 +94,7 @@ appTmp2 equ 32
|
||||
pea $0000 ; default flags
|
||||
_GTECopyPicToBG1
|
||||
|
||||
lda #193 ; Tile ID of '0'
|
||||
jsr InitOverlay ; Initialize the status bar
|
||||
pha
|
||||
_GTEGetSeconds
|
||||
|
@ -107,6 +107,7 @@ appTmp2 equ 32
|
||||
pea $0001 ; Copy to alternate BG1 buffer
|
||||
_GTECopyPicToBG1
|
||||
|
||||
lda #193 ; Tile ID of '0'
|
||||
jsr InitOverlay ; Initialize the status bar
|
||||
pha
|
||||
_GTEGetSeconds
|
||||
|
@ -39,6 +39,17 @@ OldOneSecondCounter equ 26
|
||||
appTmp0 equ 28
|
||||
appTmp1 equ 30
|
||||
appTmp2 equ 32
|
||||
PlayerX equ 34
|
||||
PlayerY equ 36
|
||||
PlayerXVel equ 38
|
||||
PlayerYVel equ 40
|
||||
PlayerStanding equ 42
|
||||
PlayerGlobalX equ 44
|
||||
PlayerGlobalY equ 46
|
||||
LastHFlip equ 48
|
||||
SpriteFrame equ 50
|
||||
SpriteToggle equ 52
|
||||
SpriteCount equ 54
|
||||
|
||||
phk
|
||||
plb
|
||||
@ -58,6 +69,9 @@ appTmp2 equ 32
|
||||
stz StartY
|
||||
stz frameCount
|
||||
stz bg1offset
|
||||
stz LastHFlip
|
||||
stz SpriteCount
|
||||
stz SpriteToggle
|
||||
|
||||
; Initialize the graphics screen playfield
|
||||
|
||||
@ -111,6 +125,74 @@ appTmp2 equ 32
|
||||
_GTEAddTimer
|
||||
pla
|
||||
|
||||
; Initialize the sprite's global position (this is tracked outside of the tile engine)
|
||||
|
||||
lda #16
|
||||
sta PlayerGlobalX
|
||||
sta PlayerX
|
||||
lda MaxGlobalY
|
||||
sec
|
||||
sbc #64 ; 32 for tiles, 16 for sprite
|
||||
sta PlayerGlobalY
|
||||
sta PlayerY
|
||||
|
||||
stz PlayerXVel
|
||||
stz PlayerYVel
|
||||
|
||||
; Create the sprites
|
||||
|
||||
HERO_FRAME_1 equ {SPRITE_16X16+1}
|
||||
HERO_VBUFF_1 equ VBUFF_SPRITE_START+0*VBUFF_SPRITE_STEP
|
||||
HERO_FRAME_2 equ {SPRITE_16X16+7}
|
||||
HERO_VBUFF_2 equ VBUFF_SPRITE_START+1*VBUFF_SPRITE_STEP
|
||||
HERO_FRAME_3 equ {SPRITE_16X8+65}
|
||||
HERO_VBUFF_3 equ VBUFF_SPRITE_START+2*VBUFF_SPRITE_STEP
|
||||
HERO_FRAME_4 equ {SPRITE_16X8+71}
|
||||
HERO_VBUFF_4 equ VBUFF_SPRITE_START+3*VBUFF_SPRITE_STEP
|
||||
HERO_SLOT_1 equ 1
|
||||
HERO_SLOT_2 equ 2
|
||||
|
||||
pea HERO_FRAME_1
|
||||
pea HERO_VBUFF_1
|
||||
_GTECreateSpriteStamp
|
||||
|
||||
pea HERO_FRAME_2
|
||||
pea HERO_VBUFF_2
|
||||
_GTECreateSpriteStamp
|
||||
|
||||
pea HERO_FRAME_3
|
||||
pea HERO_VBUFF_3
|
||||
_GTECreateSpriteStamp
|
||||
|
||||
pea HERO_FRAME_4
|
||||
pea HERO_VBUFF_4
|
||||
_GTECreateSpriteStamp
|
||||
|
||||
pea HERO_FRAME_1
|
||||
pei PlayerX
|
||||
pei PlayerY
|
||||
pea HERO_SLOT_1 ; Put the player in slot 1
|
||||
_GTEAddSprite
|
||||
|
||||
pea HERO_SLOT_1
|
||||
pea $0000
|
||||
pea HERO_VBUFF_1 ; and use this stamp
|
||||
_GTEUpdateSprite
|
||||
|
||||
pea HERO_FRAME_2
|
||||
pei PlayerX
|
||||
lda PlayerY
|
||||
clc
|
||||
adc #16
|
||||
pha
|
||||
pea HERO_SLOT_2 ; Put the player in slot 1
|
||||
_GTEAddSprite
|
||||
|
||||
pea HERO_SLOT_2
|
||||
pea $0000
|
||||
pea HERO_VBUFF_3 ; and use this stamp
|
||||
_GTEUpdateSprite
|
||||
|
||||
EvtLoop
|
||||
pha
|
||||
_GTEReadControl
|
||||
@ -118,58 +200,96 @@ EvtLoop
|
||||
|
||||
jsr HandleKeys ; Do the generic key handlers
|
||||
bcs :do_more
|
||||
brl :do_render
|
||||
brl do_render
|
||||
|
||||
:do_more
|
||||
bit #PAD_BUTTON_A
|
||||
beq :no_a
|
||||
pha
|
||||
jsr handle_a
|
||||
pla
|
||||
:no_a
|
||||
and #$007F
|
||||
cmp #LEFT_ARROW
|
||||
bne *+5
|
||||
jmp handle_left
|
||||
|
||||
cmp #RIGHT_ARROW
|
||||
bne *+5
|
||||
jmp handle_right
|
||||
|
||||
cmp #' '
|
||||
bne :not_stop
|
||||
stz PlayerXVel
|
||||
bra do_render
|
||||
|
||||
:not_stop
|
||||
cmp #'d'
|
||||
bne :not_d
|
||||
lda StartX
|
||||
cmp MaxBG0X
|
||||
bcc *+5
|
||||
brl :do_render
|
||||
brl do_render
|
||||
inc StartX
|
||||
pei StartX
|
||||
pei StartY
|
||||
_GTESetBG0Origin
|
||||
brl :do_render
|
||||
brl do_render
|
||||
:not_d
|
||||
|
||||
cmp #'a'
|
||||
bne :not_a
|
||||
lda StartX
|
||||
bne *+5
|
||||
brl :do_render
|
||||
brl do_render
|
||||
dec StartX
|
||||
pei StartX
|
||||
pei StartY
|
||||
_GTESetBG0Origin
|
||||
brl :do_render
|
||||
brl do_render
|
||||
:not_a
|
||||
|
||||
cmp #'s'
|
||||
bne :not_s
|
||||
lda StartY
|
||||
cmp MaxBG0Y
|
||||
bcs :do_render
|
||||
bcs do_render
|
||||
inc StartY
|
||||
pei StartX
|
||||
pei StartY
|
||||
_GTESetBG0Origin
|
||||
bra :do_render
|
||||
bra do_render
|
||||
:not_s
|
||||
|
||||
cmp #'w'
|
||||
bne :not_w
|
||||
lda StartY
|
||||
beq :do_render
|
||||
beq do_render
|
||||
dec StartY
|
||||
pei StartX
|
||||
pei StartY
|
||||
_GTESetBG0Origin
|
||||
bra :do_render
|
||||
bra do_render
|
||||
:not_w
|
||||
|
||||
:do_render
|
||||
do_render
|
||||
jsr UpdatePlayerPos ; Apply forces
|
||||
jsr ApplyCollisions ; Check if we run into things
|
||||
jsr UpdateCameraPos ; Moves the screen
|
||||
|
||||
pea HERO_SLOT_1
|
||||
pei PlayerX
|
||||
pei PlayerY
|
||||
_GTEMoveSprite ; Move the sprite to this local position
|
||||
|
||||
pea HERO_SLOT_2
|
||||
pei PlayerX
|
||||
lda PlayerY
|
||||
clc
|
||||
adc #16
|
||||
pha
|
||||
_GTEMoveSprite
|
||||
|
||||
lda StartX
|
||||
lsr
|
||||
pha
|
||||
@ -195,6 +315,197 @@ EvtLoop
|
||||
:noudt
|
||||
brl EvtLoop
|
||||
|
||||
|
||||
handle_a
|
||||
lda PlayerStanding
|
||||
beq :no_jump
|
||||
lda #-9
|
||||
sta PlayerYVel
|
||||
:no_jump rts
|
||||
|
||||
handle_left
|
||||
lda PlayerXVel
|
||||
bpl :ok
|
||||
cmp #-4
|
||||
bcc :out
|
||||
:ok
|
||||
dec PlayerXVel
|
||||
:out
|
||||
jmp do_render
|
||||
|
||||
handle_right lda PlayerXVel
|
||||
bmi :ok
|
||||
cmp #6
|
||||
bcs :out
|
||||
:ok
|
||||
inc PlayerXVel
|
||||
:out
|
||||
jmp do_render
|
||||
|
||||
|
||||
; Simple updates with gravity and collisions. It's important that eveything in this
|
||||
; subroutine be done against the VBL tick count
|
||||
UpdatePlayerPos
|
||||
lda PlayerGlobalY
|
||||
clc
|
||||
adc PlayerYVel
|
||||
bpl :not_neg_y
|
||||
lda #0
|
||||
|
||||
:not_neg_y
|
||||
cmp MaxGlobalY
|
||||
bcc *+4
|
||||
lda MaxGlobalY
|
||||
sta PlayerGlobalY
|
||||
|
||||
lda PlayerGlobalX
|
||||
clc
|
||||
adc PlayerXVel
|
||||
bpl :not_neg
|
||||
lda #0
|
||||
|
||||
:not_neg
|
||||
cmp MaxGlobalX
|
||||
bcc *+4
|
||||
lda MaxGlobalX
|
||||
sta PlayerGlobalX
|
||||
rts
|
||||
|
||||
ApplyCollisions
|
||||
|
||||
; Convert global to local coordinates
|
||||
|
||||
lda PlayerGlobalX
|
||||
sec
|
||||
sbc StartX
|
||||
sta PlayerX
|
||||
|
||||
lda PlayerGlobalY
|
||||
sec
|
||||
sbc StartY
|
||||
sta PlayerY
|
||||
|
||||
; Collision testing
|
||||
|
||||
inc PlayerYVel
|
||||
stz PlayerStanding
|
||||
|
||||
; Check if the player is standing on the ground at their current local position
|
||||
|
||||
pha ; space for result
|
||||
pei PlayerX
|
||||
lda PlayerY
|
||||
clc
|
||||
adc #24
|
||||
pha
|
||||
_GTEGetTileAt
|
||||
pla
|
||||
|
||||
; Decide if mario's feet are on a "ground" tile (blocks, pipes, etc.)
|
||||
and #TILE_ID_MASK
|
||||
cmp #64
|
||||
bcc :not_ground
|
||||
|
||||
lda PlayerYVel
|
||||
bmi :not_ground
|
||||
|
||||
lda PlayerGlobalY
|
||||
and #$fff8
|
||||
sta PlayerGlobalY
|
||||
stz PlayerYVel ; Stop falling when we hit the ground
|
||||
lda #1
|
||||
sta PlayerStanding
|
||||
bra :y_ok
|
||||
|
||||
:not_ground
|
||||
lda PlayerYVel
|
||||
bmi :y_ok
|
||||
cmp #8
|
||||
bcc :y_ok
|
||||
lda #7
|
||||
sta PlayerYVel
|
||||
:y_ok
|
||||
|
||||
ldx LastHFlip ; Update sprite frame based on actions
|
||||
lda PlayerXVel
|
||||
beq :no_dxv
|
||||
bpl :pos_dxv
|
||||
ldx #SPRITE_HFLIP
|
||||
bra :no_dxv
|
||||
:pos_dxv
|
||||
ldx #0
|
||||
:no_dxv
|
||||
sta PlayerXVel
|
||||
stx LastHFlip
|
||||
|
||||
lda SpriteCount
|
||||
eor SpriteToggle
|
||||
sta SpriteCount
|
||||
|
||||
; If the player is standing and XVel != 0, pick a frame
|
||||
|
||||
ldx #2
|
||||
lda PlayerXVel
|
||||
beq :frame
|
||||
|
||||
jsr _GetVBLTicks
|
||||
and #$0006
|
||||
tax
|
||||
:frame
|
||||
pea HERO_SLOT_1
|
||||
pei LastHFlip
|
||||
lda HeroFrames1,x
|
||||
pha
|
||||
|
||||
pea HERO_SLOT_2
|
||||
pei LastHFlip
|
||||
lda HeroFrames2,x
|
||||
pha
|
||||
|
||||
_GTEUpdateSprite
|
||||
_GTEUpdateSprite
|
||||
|
||||
rts
|
||||
|
||||
HeroFrames1 dw HERO_VBUFF_2,HERO_VBUFF_1,HERO_VBUFF_2,HERO_VBUFF_1
|
||||
HeroFrames2 dw HERO_VBUFF_4,HERO_VBUFF_3,HERO_VBUFF_4,HERO_VBUFF_3
|
||||
|
||||
; Set the scroll position based on the global coordinates of the player
|
||||
; Try to center the player on the screen
|
||||
|
||||
UpdateCameraPos
|
||||
lda ScreenWidth
|
||||
lsr
|
||||
sta appTmp0
|
||||
lda PlayerGlobalX
|
||||
sec
|
||||
sbc appTmp0
|
||||
bpl :x_pos
|
||||
lda #0
|
||||
:x_pos cmp MaxBG0X
|
||||
bcc :x_ok
|
||||
lda MaxBG0X
|
||||
:x_ok sta StartX
|
||||
|
||||
lda ScreenHeight
|
||||
lsr
|
||||
sta appTmp0
|
||||
lda PlayerGlobalY
|
||||
sec
|
||||
sbc appTmp0
|
||||
bpl :y_pos
|
||||
lda #0
|
||||
:y_pos cmp MaxBG0Y
|
||||
bcc :y_ok
|
||||
lda MaxBG0Y
|
||||
:y_ok sta StartY
|
||||
|
||||
pei StartX
|
||||
pei StartY
|
||||
_GTESetBG0Origin
|
||||
|
||||
rts
|
||||
|
||||
; Timer callback to animate the background
|
||||
UpdateBG1Offset
|
||||
ldal bg1offset
|
||||
@ -297,6 +608,13 @@ DoLoadBG1
|
||||
_GTECopyPicToBG1
|
||||
rts
|
||||
|
||||
_GetVBLTicks
|
||||
PushLong #0
|
||||
_GetTick
|
||||
pla
|
||||
plx
|
||||
rts
|
||||
|
||||
BG1DataFile strl '1/bg1.bin'
|
||||
|
||||
frameCount equ 24
|
||||
|
@ -13,27 +13,31 @@
|
||||
STATE_REG equ $E0C068
|
||||
|
||||
_R0W0 mac ; Read Bank 0 / Write Bank 0
|
||||
sep #$20
|
||||
ldal STATE_REG
|
||||
and #$FFCF
|
||||
and #$CF
|
||||
stal STATE_REG
|
||||
rep #$20
|
||||
<<<
|
||||
|
||||
_R0W1 mac ; Read Bank 0 / Write Bank 1
|
||||
sep #$20
|
||||
ldal STATE_REG
|
||||
ora #$0010
|
||||
ora #$10
|
||||
stal STATE_REG
|
||||
rep #$20
|
||||
<<<
|
||||
|
||||
_R1W1 mac ; Read Bank 0 / Write Bank 1
|
||||
_R1W1 mac ; Read Bank 1 / Write Bank 1
|
||||
sep #$20
|
||||
ldal STATE_REG
|
||||
ora #$0030
|
||||
ora #$30
|
||||
stal STATE_REG
|
||||
rep #$20
|
||||
<<<
|
||||
|
||||
; Initialize the overlay be drawing in static content that will not change over time
|
||||
|
||||
CHAR_TILE_BASE equ 193 ; set this to the real tile id that starts an ASCII run starting at '0' through 'Z'
|
||||
|
||||
; Define the sizes of the left and right overlay buffers
|
||||
R_CHAR_COUNT equ 8 ; "TICK:XXX"
|
||||
L_CHAR_COUNT equ 7 ; "FPS:XXX"
|
||||
@ -55,8 +59,11 @@ MASK_OFFSET equ {ovrly_mask-ovrly_buff}
|
||||
TileDataPtr equ $FC
|
||||
TileMaskPtr equ $F8
|
||||
|
||||
InitOverlay
|
||||
; set this to the real tile id that starts an ASCII run starting at '0' through 'Z'
|
||||
CHAR_TILE_BASE equ $F6
|
||||
|
||||
InitOverlay
|
||||
sta CHAR_TILE_BASE
|
||||
pha
|
||||
pha
|
||||
_GTEGetTileDataAddr
|
||||
@ -306,7 +313,7 @@ _DrawChar
|
||||
sec
|
||||
sbc #'0'
|
||||
clc
|
||||
adc #CHAR_TILE_BASE
|
||||
adc CHAR_TILE_BASE
|
||||
jsr _GetTileAddr
|
||||
tay
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user