mirror of
https://github.com/lscharen/iigs-game-engine.git
synced 2024-11-19 22:31:15 +00:00
361 lines
8.9 KiB
ArmAsm
361 lines
8.9 KiB
ArmAsm
REL
|
|
DSK MAINSEG
|
|
|
|
use Locator.Macs
|
|
use Load.Macs
|
|
use Mem.Macs
|
|
use Misc.Macs
|
|
use Util.Macs
|
|
use EDS.GSOS.Macs
|
|
use GTE.Macs
|
|
|
|
use ../../src/Defs.s
|
|
|
|
mx %00
|
|
|
|
TSZelda EXT ; tileset buffer
|
|
|
|
MAX_SPRITES equ 1
|
|
|
|
ScreenX equ 0
|
|
ScreenY equ 2
|
|
Tmp0 equ 4
|
|
Tmp1 equ 6
|
|
|
|
; Typical init
|
|
phk
|
|
plb
|
|
|
|
sta MyUserId ; GS/OS passes the memory manager user ID for the aoplication into the program
|
|
_MTStartUp ; GTE requires the miscellaneous toolset to be running
|
|
|
|
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
|
|
|
|
; 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
|
|
|
|
; Create stamps for the sprites we are going to use
|
|
HERO_SPRITE equ SPRITE_16X16+1
|
|
|
|
pea HERO_SPRITE ; sprint id
|
|
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
|
|
_GTEAddSprite
|
|
|
|
pei Tmp1 ; update the sprite in this slot
|
|
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
|
|
|
|
; Manually fill in the 41x26 tiles of the TileStore with a test pattern of trees
|
|
;
|
|
; Tile 65 Tile 66
|
|
; Tile 97 Tile 98
|
|
stz 0 ; X
|
|
stz 2 ; Y
|
|
|
|
:tloop
|
|
ldx 0
|
|
ldy 2
|
|
|
|
phx
|
|
phy
|
|
pea #65
|
|
|
|
inx
|
|
phx
|
|
phy
|
|
pea #66
|
|
|
|
iny
|
|
phx
|
|
phy
|
|
pea #98
|
|
|
|
dex
|
|
phx
|
|
phy
|
|
pea #97
|
|
|
|
_GTESetTile
|
|
_GTESetTile
|
|
_GTESetTile
|
|
_GTESetTile
|
|
|
|
lda 0
|
|
inc
|
|
inc
|
|
sta 0
|
|
cmp #40
|
|
bcc :tloop
|
|
|
|
stz 0
|
|
lda 2
|
|
inc
|
|
inc
|
|
sta 2
|
|
cmp #25
|
|
bcc :tloop
|
|
|
|
; Initialize the frame counter
|
|
|
|
stz FrameCount
|
|
|
|
; Set the screen coordinates
|
|
|
|
lda #8
|
|
sta ScreenX
|
|
sta ScreenY
|
|
|
|
; Very simple actions
|
|
:evt_loop
|
|
pha ; space for result, with pattern
|
|
_GTEReadControl
|
|
pla
|
|
and #$00FF
|
|
cmp #'q'
|
|
bne :3
|
|
brl :exit
|
|
:3
|
|
cmp #'s'
|
|
bne :4
|
|
inc PlayerY
|
|
brl :next
|
|
:4
|
|
cmp #'w'
|
|
bne :5
|
|
dec PlayerY
|
|
brl :next
|
|
:5
|
|
cmp #'d'
|
|
bne :6
|
|
inc PlayerX
|
|
brl :next
|
|
:6
|
|
cmp #'a'
|
|
bne :7
|
|
dec PlayerX
|
|
brl :next
|
|
:7
|
|
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
|
|
|
|
:9 cmp #$0B
|
|
bne :10
|
|
inc ScreenY
|
|
brl :next
|
|
|
|
:10 cmp #$0A
|
|
bne :next
|
|
dec ScreenY
|
|
|
|
:next
|
|
inc ScreenX
|
|
|
|
pei ScreenX
|
|
pei ScreenY
|
|
_GTESetBG0Origin
|
|
|
|
stz Tmp0
|
|
stz Tmp1
|
|
|
|
ldx Tmp0
|
|
loopX
|
|
lda PlayerX,x
|
|
clc
|
|
adc PlayerU,x
|
|
sta PlayerX,x
|
|
bpl is_posx
|
|
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
|
|
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
|
|
pei Tmp1
|
|
lda PlayerX,x
|
|
pha
|
|
lda PlayerY,x
|
|
pha
|
|
_GTEMoveSprite
|
|
|
|
inc Tmp1
|
|
ldx Tmp0
|
|
inx
|
|
inx
|
|
stx Tmp0
|
|
cpx #MAX_SPRITES*2
|
|
bcc loopX
|
|
|
|
_GTERender
|
|
inc FrameCount
|
|
|
|
; Debug stuff
|
|
pha
|
|
_GTEGetSeconds
|
|
pla
|
|
cmp LastSecond
|
|
beq :no_fps
|
|
sta LastSecond
|
|
|
|
lda FrameCount
|
|
ldx #0
|
|
ldy #$FFFF
|
|
jsr DrawWord
|
|
|
|
stz FrameCount
|
|
:no_fps
|
|
|
|
; tdc
|
|
; ldx #160*32
|
|
; jsr DrawWord
|
|
|
|
brl :evt_loop
|
|
|
|
; Shut down everything
|
|
:exit
|
|
_GTEShutDown
|
|
_QuitGS qtRec
|
|
qtRec adrl $0000
|
|
da $00
|
|
|
|
; Array of sprite positions and velocities
|
|
PlayerX dw 0,14,29,34,45,67,81,83,92,101,39,22,7,74,111,9
|
|
PlayerY dw 7,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
|
|
|
|
; 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
|
|
|
|
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
|
|
pea $0000 ; No extra capabilities
|
|
lda MyUserId ; Pass the userId for memory allocation
|
|
pha
|
|
_GTEStartUp
|
|
bcc :ok3
|
|
brk $03
|
|
|
|
:ok3
|
|
rts
|
|
|
|
MyUserId ds 2
|
|
ToolPath str '1/Tool160'
|
|
FrameCount ds 2
|
|
LastSecond dw 0
|
|
|
|
PUT App.Msg.s
|
|
PUT font.s
|