From 19468be9fb4222290813c11b9f4feea22959818b Mon Sep 17 00:00:00 2001 From: Tijn Kersjes Date: Wed, 11 Sep 2019 23:31:50 +0300 Subject: [PATCH] Add struct --- examples/sprite-demo/sprite-demo.fs | 39 ++++++++++++++++++----------- lib/struct.fs | 6 +++++ 2 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 lib/struct.fs diff --git a/examples/sprite-demo/sprite-demo.fs b/examples/sprite-demo/sprite-demo.fs index 9bcd3699..76f5b868 100644 --- a/examples/sprite-demo/sprite-demo.fs +++ b/examples/sprite-demo/sprite-demo.fs @@ -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 @@ -23,8 +34,8 @@ _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 ; @@ -32,7 +43,7 @@ _OAM 3 + constant player.opts : enable-sprites [ LCDCF_ON LCDCF_BG8000 or - LCDCF_BGOFF or + LCDCF_BGON or LCDCF_OBJ8 or LCDCF_OBJON or ]L rLCDC c! ; @@ -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 diff --git a/lib/struct.fs b/lib/struct.fs new file mode 100644 index 00000000..1e5a8aaf --- /dev/null +++ b/lib/struct.fs @@ -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 ;