iigs-game-engine/demos/tool/App.Main.s

613 lines
15 KiB
ArmAsm
Raw Normal View History

REL
DSK MAINSEG
use Locator.Macs
use Load.Macs
use Mem.Macs
use Misc.Macs
use Util.Macs
use EDS.GSOS.Macs
2022-04-24 19:45:07 +00:00
use GTE.Macs
2022-05-20 04:39:19 +00:00
use ../../src/Defs.s
mx %00
TSZelda EXT ; tileset buffer
2022-06-09 12:41:03 +00:00
MAX_SPRITES equ 16
ScreenX equ 0
ScreenY equ 2
Tmp0 equ 4
Tmp1 equ 6
2022-06-09 12:41:03 +00:00
KeyState equ 8
Selected equ 10
Flips equ 12
; Typical init
phk
plb
2022-06-09 12:41:03 +00:00
sta MyUserId ; GS/OS passes the memory manager user ID for the application into the program
2022-04-24 19:45:07 +00:00
_MTStartUp ; GTE requires the miscellaneous toolset to be running
2022-04-24 19:45:07 +00:00
jsr GTEStartUp ; Load and install the GTE User Tool
; Initialize the graphics screen to a 256x160 playfield
pea #256
pea #160
_GTESetScreenMode
; Load a tileset
pea #^TSZelda
pea #TSZelda
_GTELoadTileSet
2022-06-01 18:55:04 +00:00
; Set the palette
ldx #11*2
:ploop
lda palette,x
stal $E19E00,x
dex
dex
bpl :ploop
bra sprt
palette dw $0000,$08C1,$0C41,$0F93,$0777,$0FDA,$00A0,$0000,$0D20,$0FFF,$023E
sprt
2022-05-27 00:36:40 +00:00
; Create stamps for the sprites we are going to use
HERO_SPRITE equ SPRITE_16X16+1
2022-05-27 00:36:40 +00:00
pea HERO_SPRITE ; sprint id
2022-05-27 00:36:40 +00:00
pea VBUFF_SPRITE_START ; vbuff address
_GTECreateSpriteStamp
; Create sprites
stz Tmp0
stz Tmp1
ldx Tmp0
:sloop
pea HERO_SPRITE ; sprite id
lda PlayerX,x
pha
lda PlayerY,x
pha
pei Tmp1
2022-05-27 00:36:40 +00:00
_GTEAddSprite
pei Tmp1 ; update the sprite in this slot
2022-05-27 00:36:40 +00:00
pea $0000 ; with these flags (h/v flip)
pea VBUFF_SPRITE_START ; and use this stamp
_GTEUpdateSprite
inc Tmp1
ldx Tmp0
inx
inx
stx Tmp0
cpx #MAX_SPRITES*2
bcc :sloop
2022-06-21 12:29:18 +00:00
; Manually fill in the 41x26 tiles of the TileStore with a test pattern of trees
2022-06-21 12:29:18 +00:00
jsr _fillTileStore
2022-06-01 18:55:04 +00:00
2022-06-21 12:29:18 +00:00
ldx #0
ldy #0
jsr _drawTree
2022-06-21 12:29:18 +00:00
ldx #3
ldy #0
jsr _drawTreeH
2022-06-21 12:29:18 +00:00
ldx #0
ldy #3
jsr _drawTreeV
ldx #3
ldy #3
jsr _drawTreeHV
ldx #9
ldy #0
jsr _drawTree
ldx #9
ldy #3
jsr _drawTree
ldx #12
ldy #0
jsr _drawTree
ldx #12
ldy #3
jsr _drawTree
ldx #6
ldy #0
jsr _drawTreeFront
ldx #6
ldy #3
jsr _drawTreeFront
ldx #6
ldy #6
jsr _drawTreeFront
ldx #3
ldy #6
jsr _drawTreeFront
ldx #0
ldy #6
jsr _drawTreeFront
; Initialize the frame counter
stz FrameCount
2022-06-01 18:55:04 +00:00
; Set the screen coordinates
2022-05-20 04:39:19 +00:00
2022-06-09 12:41:03 +00:00
lda #128
2022-06-01 18:55:04 +00:00
sta ScreenX
2022-06-09 12:41:03 +00:00
lda #128
2022-06-01 18:55:04 +00:00
sta ScreenY
2022-05-20 04:39:19 +00:00
2022-06-09 12:41:03 +00:00
stz Selected
stz Flips
2022-04-24 19:45:07 +00:00
; Very simple actions
2022-05-20 04:39:19 +00:00
:evt_loop
2022-04-24 19:45:07 +00:00
pha ; space for result, with pattern
_GTEReadControl
pla
and #$00FF
cmp #'q'
2022-06-09 12:41:03 +00:00
bne :2
brl :exit
2022-06-09 12:41:03 +00:00
:2
; cmp KeyState
; beq :evt_loop
; sta KeyState
; cmp #0
; beq :evt_loop
; cmp #' '
; bne :evt_loop ; only advance one frame at a time
; brl :next
:3
2022-06-09 12:41:03 +00:00
cmp #'1'
bcc :3a
cmp #'9'
bcs :3a
sec
sbc #'1'
asl
sta Selected
brl :next
:3a
cmp #'r'
bne :3b
lda Flips
clc
adc #SPRITE_HFLIP
and #SPRITE_VFLIP+SPRITE_HFLIP
sta Flips
pei Selected ; update the sprite in this slot
pei Flips ; with these flags (h/v flip)
pea VBUFF_SPRITE_START ; and use this stamp
_GTEUpdateSprite
:3b
cmp #'x'
bne :3d
ldx Selected
lda PlayerX,x
clc
adc PlayerU,x
sta PlayerX,x
lda PlayerY,x
clc
adc PlayerV,x
sta PlayerY,x
brl :next
:3d
cmp #'z'
bne :3e
ldx Selected
lda PlayerX,x
sec
sbc PlayerU,x
sta PlayerX,x
lda PlayerY,x
sec
sbc PlayerV,x
sta PlayerY,x
brl :next
:3e
cmp #'s'
bne :4
2022-06-09 12:41:03 +00:00
ldx Selected
inc PlayerY,x
brl :next
:4
cmp #'w'
bne :5
2022-06-09 12:41:03 +00:00
ldx Selected
dec PlayerY,x
brl :next
:5
cmp #'d'
bne :6
2022-06-09 12:41:03 +00:00
ldx Selected
inc PlayerX,x
brl :next
:6
cmp #'a'
bne :7
2022-06-09 12:41:03 +00:00
ldx Selected
dec PlayerX,x
brl :next
:7
2022-05-20 04:39:19 +00:00
cmp #$15 ; left = $08, right = $15, up = $0B, down = $0A
bne :8
inc ScreenX
bra :next
:8 cmp #$08
bne :9
dec ScreenX
brl :next
2022-05-20 04:39:19 +00:00
:9 cmp #$0B
bne :10
inc ScreenY
brl :next
2022-05-20 04:39:19 +00:00
:10 cmp #$0A
bne :next
dec ScreenY
:next
2022-06-09 12:41:03 +00:00
; inc ScreenX
2022-04-29 17:38:04 +00:00
pei ScreenX
pei ScreenY
_GTESetBG0Origin
2022-06-09 12:41:03 +00:00
; brl no_animate
stz Tmp0
stz Tmp1
ldx Tmp0
loopX
lda PlayerX,x
clc
adc PlayerU,x
sta PlayerX,x
bpl is_posx
2022-06-09 12:41:03 +00:00
cmp #-15
bcs do_y
lda PlayerU,x
eor #$FFFF
inc
sta PlayerU,x
bra do_y
is_posx cmp #128
bcc do_y
lda PlayerU,x
eor #$FFFF
inc
sta PlayerU,x
do_y
lda PlayerY,x
clc
adc PlayerV,x
sta PlayerY,x
bpl is_posy
2022-06-09 12:41:03 +00:00
cmp #-15
bcs do_z
lda PlayerV,x
eor #$FFFF
inc
sta PlayerV,x
bra do_z
is_posy cmp #160
bcc do_z
lda PlayerV,x
eor #$FFFF
inc
sta PlayerV,x
do_z
2022-06-09 12:41:03 +00:00
inc Tmp1
ldx Tmp0
inx
inx
stx Tmp0
cpx #MAX_SPRITES*2
bcc loopX
no_animate
stz Tmp0
stz Tmp1
ldx Tmp0
loopY
pei Tmp1
lda PlayerX,x
pha
lda PlayerY,x
pha
_GTEMoveSprite
inc Tmp1
ldx Tmp0
inx
inx
stx Tmp0
cpx #MAX_SPRITES*2
2022-06-09 12:41:03 +00:00
bcc loopY
_GTERender
inc FrameCount
2022-05-20 04:39:19 +00:00
; Debug stuff
pha
_GTEGetSeconds
pla
cmp LastSecond
beq :no_fps
sta LastSecond
lda FrameCount
2022-05-20 04:39:19 +00:00
ldx #0
ldy #$FFFF
2022-05-20 04:39:19 +00:00
jsr DrawWord
stz FrameCount
:no_fps
2022-05-20 04:39:19 +00:00
; tdc
; ldx #160*32
; jsr DrawWord
2022-05-20 04:39:19 +00:00
brl :evt_loop
; Shut down everything
:exit
2022-04-24 19:45:07 +00:00
_GTEShutDown
_QuitGS qtRec
qtRec adrl $0000
da $00
; Array of sprite positions and velocities
2022-06-09 12:41:03 +00:00
PlayerX dw 8,14,29,34,45,67,81,83,92,101,39,22,7,74,111,9
PlayerY dw 72,24,13,56,35,72,23,8,93,123,134,87,143,14,46,65
PlayerU dw 1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4
PlayerV dw 1,1,1,1,2,2,2,4,3,3,3,3,4,4,4,4
2022-04-24 19:45:07 +00:00
; Load the GTE User Tool and install it
GTEStartUp
pea $0000
_LoaderStatus
pla
pea $0000
pea $0000
pea $0000
pea $0000
pea $0000 ; result space
2022-05-20 04:39:19 +00:00
lda MyUserId
pha
pea #^ToolPath
pea #ToolPath
pea $0001 ; do not load into special memory
_InitialLoad
bcc :ok1
brk $01
:ok1
ply
pla ; Address of the loaded tool
plx
ply
ply
pea $8000 ; User toolset
pea $00A0 ; Set the tool set number
phx
pha ; Address of function pointer table
_SetTSPtr
bcc :ok2
brk $02
:ok2
clc ; Give GTE a page of direct page memory
tdc
adc #$0100
pha
2022-04-24 19:45:07 +00:00
pea $0000 ; No extra capabilities
2022-05-20 04:39:19 +00:00
lda MyUserId ; Pass the userId for memory allocation
pha
_GTEStartUp
bcc :ok3
brk $03
:ok3
rts
2022-06-21 12:29:18 +00:00
_fillTileStore
stz Tmp0
:oloop
stz Tmp1
:iloop
pei Tmp1
pei Tmp0
pea #129
_GTESetTile
lda Tmp1
inc
sta Tmp1
cmp #41
bcc :iloop
lda Tmp0
inc
sta Tmp0
cmp #26
bcc :oloop
rts
; Tile 65 Tile 66
; Tile 97 Tile 98
_drawTreeFront
phx
phy
pea #65+TILE_PRIORITY_BIT
inx
phx
phy
pea #66+TILE_PRIORITY_BIT
iny
phx
phy
pea #98+TILE_PRIORITY_BIT
dex
phx
phy
pea #97+TILE_PRIORITY_BIT
_GTESetTile
_GTESetTile
_GTESetTile
_GTESetTile
rts
_drawTree
phx
phy
pea #65
inx
phx
phy
pea #66
iny
phx
phy
pea #98
dex
phx
phy
pea #97
_GTESetTile
_GTESetTile
_GTESetTile
_GTESetTile
rts
_drawTreeH
phx
phy
pea #66+TILE_HFLIP_BIT
inx
phx
phy
pea #65+TILE_HFLIP_BIT
iny
phx
phy
pea #97+TILE_HFLIP_BIT
dex
phx
phy
pea #98+TILE_HFLIP_BIT
_GTESetTile
_GTESetTile
_GTESetTile
_GTESetTile
rts
_drawTreeV
phx
phy
pea #97+TILE_VFLIP_BIT
inx
phx
phy
pea #98+TILE_VFLIP_BIT
iny
phx
phy
pea #66+TILE_VFLIP_BIT
dex
phx
phy
pea #65+TILE_VFLIP_BIT
_GTESetTile
_GTESetTile
_GTESetTile
_GTESetTile
rts
_drawTreeHV
phx
phy
pea #98+TILE_VFLIP_BIT+TILE_HFLIP_BIT
inx
phx
phy
pea #97+TILE_VFLIP_BIT+TILE_HFLIP_BIT
iny
phx
phy
pea #65+TILE_VFLIP_BIT+TILE_HFLIP_BIT
dex
phx
phy
pea #66+TILE_VFLIP_BIT+TILE_HFLIP_BIT
_GTESetTile
_GTESetTile
_GTESetTile
_GTESetTile
rts
2022-05-20 04:39:19 +00:00
MyUserId ds 2
ToolPath str '1/Tool160'
FrameCount ds 2
LastSecond dw 0
2022-05-20 04:39:19 +00:00
PUT App.Msg.s
PUT font.s