2017-12-11 14:01:57 +00:00
|
|
|
// ****************************
|
|
|
|
// * Demo Game for SixtyPical *
|
|
|
|
// ****************************
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------
|
2017-12-12 10:58:59 +00:00
|
|
|
// System Locations
|
2017-12-11 14:01:57 +00:00
|
|
|
// ----------------------------------------------------------------
|
|
|
|
|
2017-12-11 14:40:30 +00:00
|
|
|
byte vic_border @ 53280
|
|
|
|
byte vic_bg @ 53281
|
|
|
|
|
2017-12-11 14:09:55 +00:00
|
|
|
byte table screen1 @ 1024
|
|
|
|
byte table screen2 @ 1274
|
|
|
|
byte table screen3 @ 1524
|
|
|
|
byte table screen4 @ 1774
|
|
|
|
|
|
|
|
byte table colormap1 @ 55296
|
|
|
|
byte table colormap2 @ 55546
|
|
|
|
byte table colormap3 @ 55796
|
|
|
|
byte table colormap4 @ 56046
|
|
|
|
|
2017-12-07 16:14:02 +00:00
|
|
|
buffer[2048] screen @ 1024
|
|
|
|
byte joy2 @ $dc00
|
|
|
|
|
2017-12-12 10:58:59 +00:00
|
|
|
// ----------------------------------------------------------------
|
|
|
|
// Global Variables
|
|
|
|
// ----------------------------------------------------------------
|
|
|
|
|
2017-12-07 16:14:02 +00:00
|
|
|
pointer ptr @ 254
|
|
|
|
word pos
|
|
|
|
word delta
|
2017-12-12 10:58:59 +00:00
|
|
|
byte button_down : 0 // effectively static-local to check_button
|
2017-12-07 16:14:02 +00:00
|
|
|
|
2017-12-11 14:40:30 +00:00
|
|
|
//
|
|
|
|
// Points to the routine that implements the current game state.
|
|
|
|
//
|
|
|
|
|
|
|
|
vector dispatch_game_state
|
2017-12-12 10:58:59 +00:00
|
|
|
inputs joy2, pos, button_down, dispatch_game_state
|
|
|
|
outputs delta, pos, screen, screen1, button_down, dispatch_game_state
|
2017-12-11 14:40:30 +00:00
|
|
|
trashes a, x, y, c, z, n, v, ptr
|
|
|
|
|
2017-12-07 16:14:02 +00:00
|
|
|
//
|
|
|
|
// The constraints on these 2 vectors are kind-of sort-of big fibs.
|
|
|
|
// They're only written this way so they can be compatible with our
|
|
|
|
// routine. In fact, CINV is an interrupt routine where it doesn't
|
|
|
|
// really matter what you trash anyway, because all registers were
|
|
|
|
/// saved by the caller (the KERNAL) and will be restored by the end
|
|
|
|
// of the code of the saved origin cinv routine that we goto.
|
|
|
|
//
|
|
|
|
// I wonder if this could be arranged somehow to be less fibby, in
|
|
|
|
// a future version of SixtyPical.
|
|
|
|
//
|
|
|
|
|
|
|
|
vector cinv
|
2017-12-12 10:58:59 +00:00
|
|
|
inputs joy2, pos, button_down, dispatch_game_state
|
|
|
|
outputs delta, pos, screen, screen1, button_down, dispatch_game_state
|
2017-12-07 16:14:02 +00:00
|
|
|
trashes a, x, y, c, z, n, v, ptr
|
|
|
|
@ 788
|
|
|
|
|
|
|
|
vector save_cinv
|
2017-12-12 10:58:59 +00:00
|
|
|
inputs joy2, pos, button_down, dispatch_game_state
|
|
|
|
outputs delta, pos, screen, screen1, button_down, dispatch_game_state
|
2017-12-07 16:14:02 +00:00
|
|
|
trashes a, x, y, c, z, n, v, ptr
|
|
|
|
|
2017-12-11 14:01:57 +00:00
|
|
|
// ----------------------------------------------------------------
|
2017-12-11 14:09:55 +00:00
|
|
|
// Utility Routines
|
2017-12-11 14:01:57 +00:00
|
|
|
// ----------------------------------------------------------------
|
|
|
|
|
2017-12-07 16:14:02 +00:00
|
|
|
routine read_stick
|
|
|
|
inputs joy2
|
|
|
|
outputs delta
|
|
|
|
trashes a, x, z, n
|
|
|
|
{
|
|
|
|
ld x, joy2
|
|
|
|
ld a, x
|
|
|
|
and a, 1 // up
|
|
|
|
if z {
|
|
|
|
copy $ffd8, delta // -40
|
|
|
|
} else {
|
|
|
|
ld a, x
|
|
|
|
and a, 2 // down
|
|
|
|
if z {
|
|
|
|
copy word 40, delta
|
|
|
|
} else {
|
|
|
|
ld a, x
|
|
|
|
and a, 4 // left
|
|
|
|
if z {
|
|
|
|
copy $ffff, delta // -1
|
|
|
|
} else {
|
|
|
|
ld a, x
|
|
|
|
and a, 8 // right
|
|
|
|
if z {
|
|
|
|
copy word 1, delta
|
|
|
|
} else {
|
|
|
|
copy word 0, delta
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-12 10:58:59 +00:00
|
|
|
// You can repeatedly (i.e. as part of actor logic or an IRQ handler)
|
|
|
|
// call this routine.
|
|
|
|
// Upon return, if carry is set, the button was pressed then released.
|
|
|
|
|
|
|
|
routine check_button
|
|
|
|
inputs joy2, button_down
|
|
|
|
outputs c, button_down
|
|
|
|
trashes a, z, n
|
|
|
|
{
|
|
|
|
ld a, button_down
|
|
|
|
if z {
|
|
|
|
ld a, joy2
|
|
|
|
and a, $10
|
|
|
|
if z {
|
|
|
|
ld a, 1
|
|
|
|
st a, button_down
|
|
|
|
}
|
|
|
|
st off, c
|
|
|
|
} else {
|
|
|
|
ld a, joy2
|
|
|
|
and a, $10
|
|
|
|
if not z {
|
|
|
|
ld a, 0
|
|
|
|
st a, button_down
|
|
|
|
st on, c
|
|
|
|
} else {
|
|
|
|
st off, c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-11 14:09:55 +00:00
|
|
|
routine clear_screen
|
|
|
|
outputs screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
|
|
|
|
trashes a, y, c, n, z
|
|
|
|
{
|
|
|
|
ld y, 0
|
|
|
|
repeat {
|
|
|
|
ld a, 1
|
|
|
|
st a, colormap1 + y
|
|
|
|
st a, colormap2 + y
|
|
|
|
st a, colormap3 + y
|
|
|
|
st a, colormap4 + y
|
|
|
|
|
|
|
|
ld a, 32
|
|
|
|
st a, screen1 + y
|
|
|
|
st a, screen2 + y
|
|
|
|
st a, screen3 + y
|
|
|
|
st a, screen4 + y
|
|
|
|
|
|
|
|
inc y
|
|
|
|
cmp y, 250
|
|
|
|
} until z
|
|
|
|
}
|
|
|
|
|
2017-12-11 14:01:57 +00:00
|
|
|
// ----------------------------------------------------------------
|
|
|
|
// Game States
|
|
|
|
// ----------------------------------------------------------------
|
|
|
|
|
2017-12-12 10:10:58 +00:00
|
|
|
//
|
|
|
|
// Because these all `goto save_cinv` at the end, they must have the same signature as that routine.
|
|
|
|
//
|
|
|
|
|
2017-12-11 14:01:57 +00:00
|
|
|
routine game_state_play
|
2017-12-12 10:58:59 +00:00
|
|
|
inputs joy2, pos, button_down, dispatch_game_state
|
|
|
|
outputs delta, pos, screen, screen1, button_down, dispatch_game_state
|
2017-12-07 16:14:02 +00:00
|
|
|
trashes a, x, y, c, z, n, v, ptr
|
|
|
|
{
|
|
|
|
call read_stick
|
|
|
|
|
|
|
|
st off, c
|
|
|
|
add pos, delta
|
|
|
|
|
|
|
|
copy ^screen, ptr
|
|
|
|
st off, c
|
|
|
|
add ptr, pos
|
|
|
|
|
|
|
|
ld y, 0
|
|
|
|
copy 81, [ptr] + y
|
|
|
|
|
|
|
|
goto save_cinv
|
|
|
|
}
|
|
|
|
|
2017-12-11 14:40:30 +00:00
|
|
|
routine game_state_title_screen
|
2017-12-12 10:58:59 +00:00
|
|
|
inputs joy2, pos, button_down, dispatch_game_state
|
|
|
|
outputs delta, pos, screen, screen1, button_down, dispatch_game_state
|
2017-12-11 14:40:30 +00:00
|
|
|
trashes a, x, y, c, z, n, v, ptr
|
|
|
|
{
|
2017-12-12 10:58:59 +00:00
|
|
|
ld y, 10
|
2017-12-11 14:40:30 +00:00
|
|
|
repeat {
|
2017-12-12 10:58:59 +00:00
|
|
|
ld a, 90
|
2017-12-11 14:40:30 +00:00
|
|
|
st a, screen1 + y
|
|
|
|
inc y
|
2017-12-12 10:58:59 +00:00
|
|
|
cmp y, 20
|
|
|
|
} until z
|
2017-12-11 14:40:30 +00:00
|
|
|
|
|
|
|
st off, c
|
2017-12-12 10:58:59 +00:00
|
|
|
call check_button
|
2017-12-11 14:40:30 +00:00
|
|
|
|
|
|
|
if c {
|
|
|
|
// call clear_screen
|
2017-12-12 10:58:59 +00:00
|
|
|
// call init_game
|
2017-12-12 09:59:43 +00:00
|
|
|
copy game_state_play, dispatch_game_state
|
|
|
|
} else {
|
2017-12-12 10:58:59 +00:00
|
|
|
// This is sort of a hack. FIXME: let `if` branches diverge this much.
|
|
|
|
copy dispatch_game_state, dispatch_game_state
|
2017-12-11 14:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
goto save_cinv
|
|
|
|
}
|
|
|
|
|
2017-12-11 14:01:57 +00:00
|
|
|
// *************************
|
|
|
|
// * Main Game Loop Driver *
|
|
|
|
// *************************
|
|
|
|
|
|
|
|
routine our_cinv
|
2017-12-12 10:58:59 +00:00
|
|
|
inputs joy2, pos, button_down, dispatch_game_state
|
|
|
|
outputs delta, pos, screen, screen1, button_down, dispatch_game_state
|
2017-12-11 14:01:57 +00:00
|
|
|
trashes a, x, y, c, z, n, v, ptr
|
|
|
|
{
|
|
|
|
goto dispatch_game_state
|
|
|
|
}
|
|
|
|
|
2017-12-07 16:14:02 +00:00
|
|
|
routine main
|
|
|
|
inputs cinv
|
2017-12-11 14:09:55 +00:00
|
|
|
outputs cinv, save_cinv, pos, dispatch_game_state,
|
|
|
|
screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
|
2017-12-11 14:40:30 +00:00
|
|
|
trashes a, y, n, c, z, vic_border, vic_bg
|
2017-12-07 16:14:02 +00:00
|
|
|
{
|
2017-12-11 15:21:40 +00:00
|
|
|
ld a, 5
|
|
|
|
st a, vic_border
|
|
|
|
ld a, 0
|
|
|
|
st a, vic_bg
|
|
|
|
ld y, 0
|
|
|
|
|
2017-12-11 14:09:55 +00:00
|
|
|
call clear_screen
|
2017-12-11 15:21:40 +00:00
|
|
|
|
2017-12-12 09:59:43 +00:00
|
|
|
copy game_state_title_screen, dispatch_game_state
|
2017-12-11 14:01:57 +00:00
|
|
|
|
2017-12-07 16:49:43 +00:00
|
|
|
copy word 0, pos
|
2017-12-07 16:14:02 +00:00
|
|
|
with interrupts off {
|
|
|
|
copy cinv, save_cinv
|
|
|
|
copy our_cinv, cinv
|
|
|
|
}
|
2017-12-11 14:21:32 +00:00
|
|
|
// FIXME: find out why `repeat { } forever` does not analyze OK
|
|
|
|
repeat {
|
|
|
|
ld a, 0
|
|
|
|
} until not z
|
2017-12-07 16:14:02 +00:00
|
|
|
}
|