Skip to content

Commit

Permalink
Add struct
Browse files Browse the repository at this point in the history
  • Loading branch information
tkers committed Sep 11, 2019
1 parent 9bdcbcb commit 19468be
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
39 changes: 25 additions & 14 deletions examples/sprite-demo/sprite-demo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,27 @@ require gbhw.fs
require input.fs
require lcd.fs
require ibm-font.fs

require struct.fs
( program start )

_OAM 0 + constant player.y
_OAM 1 + constant player.x
_OAM 2 + constant player.tile
_OAM 3 + constant player.opts
:m new CREATE allot ;
:m sprite 4 * _OAM + CONSTANT ;

ROM

struct
1 chars field spr-y
1 chars field spr-x
1 chars field spr-tile
1 chars field spr-opts
end-struct sprite%

0 SPRITE player

: v! lcd-wait-vblank c! ;

: playerX+! player.x lcd-wait-vblank +! ;
: playerY+! player.y lcd-wait-vblank +! ;
: playerX+! player spr-x lcd-wait-vblank +! ;
: playerY+! player spr-y lcd-wait-vblank +! ;

: handle-input
begin
Expand All @@ -23,16 +34,16 @@ _OAM 3 + constant player.opts
dup k-left and if -1 playerX+! then
dup k-up and if -1 playerY+! then
dup k-down and if 1 playerY+! then
dup k-a and if 1 player.tile lcd-wait-vblank c! then
dup k-b and if 2 player.tile lcd-wait-vblank c! then
dup k-a and if 1 player spr-tile v! then
dup k-b and if 2 player spr-tile v! then
\ If there no key pressed, wait for one
0= if halt then
again ;

: enable-sprites
[ LCDCF_ON
LCDCF_BG8000 or
LCDCF_BGOFF or
LCDCF_BGON or
LCDCF_OBJ8 or
LCDCF_OBJON or ]L
rLCDC c! ;
Expand All @@ -44,10 +55,10 @@ _OAM 3 + constant player.opts
_OAM [ 40 4 * ]L erase ;

: init-player-sprite
#1 player.tile c!
%00000000 player.opts c!
#80 player.y c!
#50 player.x c! ;
#1 player spr-tile c!
%00000000 player spr-opts c!
#80 player spr-y c!
#50 player spr-x c! ;

: main
init-input
Expand Down
6 changes: 6 additions & 0 deletions lib/struct.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:m struct 0 ;
:m field over + swap CREATE , DOES> @ + ;
:m end-struct constant ;

:m c-field 1 chars field ;
:m a-field 1 cells field ;

0 comments on commit 19468be

Please sign in to comment.