From d1a3affa1dbc612ad07774fcb01d2a527cfe4230 Mon Sep 17 00:00:00 2001 From: Christophe Meneboeuf Date: Wed, 14 Apr 2021 23:26:21 +0200 Subject: [PATCH] 5 levels to explore --- Makefile | 8 +- escape.dsk | Bin 143360 -> 143360 bytes src/builder/builder.asm | 186 +++++++++++++++++++++++++++++++++++----- src/builder/maze.asm | 5 +- src/builder/rooms.asm | 6 +- src/builder/rooms.inc | 2 + src/builder/unite.asm | 20 ++--- src/debug.asm | 17 ++++ src/display.asm | 3 +- src/display_map.asm | 2 +- src/escape.cfg | 4 +- src/game_loop.asm | 94 +++++++++++++++----- src/main.asm | 41 ++------- src/memory.inc | 13 ++- src/player.asm | 51 ++++++++++- src/random.asm | 42 +++++++-- src/random.inc | 4 + src/tiles.asm | 38 +++++++- src/tiles.inc | 1 - 19 files changed, 426 insertions(+), 111 deletions(-) diff --git a/Makefile b/Makefile index 23b4fbd..6cf4de3 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ APPLE2_CL := $(CC65_HOME)/bin/cl65 APPLE2_SRC := src/main.asm src/math.asm src/memory.asm src/random.asm \ - src/game_loop.asm src/display.asm src/tiles.asm src/world.asm src/player.asm \ - src/builder/builder.asm src/builder/rooms.asm src/builder/maze.asm src/builder/unite.asm \ + src/game_loop.asm src/display.asm src/tiles.asm src/player.asm \ + src/world/world.asm src/world/level.asm \ + src/builder/builder.asm src/builder/actors.asm src/builder/rooms.asm src/builder/maze.asm src/builder/unite.asm \ + src/actors/reactions.asm \ src/debug.asm src/display_map.asm \ src/io/title.asm src/io/textio.asm src/io/gr.asm APPLE2_MAP := escape.map @@ -17,4 +19,4 @@ apple2: $(APPLE2_SRC) $(APPLE2_CL) -m $(APPLE2_MAP) -o $(APPLE2_OUT) $? $(APPLE2_CFLAGS) -C src/escape.cfg clean: $(SRC) - rm -f $(APPLE2_MAP) src/*.o src/*.s src/builder/*.o src/builder/*.s src/io/*.s src/io/*.s gmon.out & rm -r bin/ + rm -f $(APPLE2_MAP) src/*.o src/builder/*.o src/io/*.o src/world/*.o src/actors/*.o gmon.out & rm -r bin/ diff --git a/escape.dsk b/escape.dsk index 1d2b78d977d6890d35120fa34fc709f10cfaf833..aaa068e50b5ba031e78bdf887875bf866c629970 100644 GIT binary patch delta 4324 zcmaJ^3ve678Qwd^*6Crz#(CVyk~k6yNq9_B2)Kk996~7sg#-vCB{St(qQ;`(;e>YL zmQ?a%g)M7^;%kdDAP|R7;}fxq>rP8%5I6%4mYUet#32Qesb^ffc4fOtaMEDMcK7LIVayV>-52+Se{~ zU`}yiyMl0uB47v5Q_5=mDgSMTA9e7p3~v`7Ucc2>>!omh65&czi;YPXs6-e)nnW*G zqCg89XXHosfq`k-hcFvAX}n30^U3p!Y$Pu*GD9jD*+h0T5(=Z*Fv4LJ2&0#W+2m}E zw;+mYle4wnA4L&P&SEbYMSA`QP|pa`Y!aF40F+k$nM8FR6irhd^oALW4|KY< zHj3(Wqs9n-=Py_lM5qRSe*yoS628&Ox0>2^1P^+Ge6y98%=~6^E9xwqB88p&cTKHy zLyA(z`9hm}nMp{cvPG$*S$pb_+2yHp_U2T5_8uYUT*r4<+;7hHGz`Mpd8zwKQ#vQi zk0tP`U67tuW(lf~qI$7v^O8G)Y4u_h1qB6x!2(=PmhMy_>Y&nHIzr)TMHoSNMnZw{ zz?eLadz9a9p|0~;q`mwPobKDLFsrl{Q=c`!VS5ZI%%8Xjt7*eKf{I1jKMwvk@YM86=aC5e3GPZk~_SP^sF z0dX`t0S(hV2tGM-*^AQSy$6)TfHUA;eua2^^Q~LkryzsPv)w7?-Msi@T0IpX8}7eP zZG&91&+e$l8D-bAo_ai5Drd%GW}J~n$KEpIQU0V!K?yt^L$#NZD0l|dXRWYWcrq}+ zzb|gxbKSNTOiPgUaAZe)lNS+By&zATVcyRWhlMP+kX074#zMYrA#MwK%tD^DB&lbJ z(?YJdkee*zn-+4vg>15rtroJ~qL^`yJgrTc39@ffG}ZVMyJ6e+o)js1K>Df42US3Y zprJ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zfYGcn*MiZG<*aAJgmgRBcVCyY~#cD(TpOnjgR128C{&c zRc#xe#k0~Zg|onC6h4D9Qij60(8#f2<)%tO1)auBXf7s=j21Gt-NX+oncHFF>k4^w z=#yG$IMWXc(eDZG%t8i)z&DJZG2Ppz<%!bXwgtP>X92`H== zl)V);3OkCXNbBXVuDi(P`5Eettsci5W+Y@!dq4lCp3> zaMod1Dm>VExAI6j)VWSqxeVW^9~m&28?)m)YEU}|(DY?*}J-W%fzYnOjf zf$osYf-Rve=x|l< z^M%#B_(S#fdT)KC9yQn-ybX~Cc)uiiUN8ve7wp2N7uNJV-z6M=9@rQEE~H=7D~}xU z6++OzbOkP0y`Vn?W%AA%Vxx+h_mP^<=u=s4pXgt>>y% zXZEjZax^{NbfoD*Q>tlM^LLwfH+MC^+5Fe$qLy_n_qQ~)9BX;61%{9nxVQH8oZBjF zJ%7IEEe>MQ!qM=<0&%`ZFueAm@WV5o^&3UI_QB#sADRC^0R1BI|4Tv;N$k_UZWPsR K?}XkVp7;-{X|?G9 diff --git a/src/builder/builder.asm b/src/builder/builder.asm index 183f530..d77316b 100644 --- a/src/builder/builder.asm +++ b/src/builder/builder.asm @@ -20,14 +20,18 @@ .include "rooms.inc" .include "maze.inc" .include "unite.inc" +.include "actors.inc" .include "../io/textio.inc" +.include "../math.inc" .include "../monitor.inc" -.include "../world.inc" .include "../memory.inc" +.include "../world/world.inc" +.include "../world/level.inc" .import World .import Random8 .import Grow_Maze ; to patch +.import Compute_Maze_Addr .export Get_Size_Maze .export Init_Dimensions_Maze @@ -37,8 +41,6 @@ .export WIDTH_MAZE .export HEIGHT_MAZE -.define MAX_NB_ROOMS 64 ; MAX_NB_ROOMS *MUST BE* <= 64 - .BSS ; Describes a room to be built @@ -65,9 +67,12 @@ STR_MAZE: ASCIIZ "GROWING THE MAZE..." STR_DOORS: ASCIIZ "OPENING DOORS..." STR_DEADENDS: ASCIIZ "FILLING DEAD ENDS..." STR_UNITE: ASCIIZ "UNITING THE ROOMS..." +STR_ACTORS: ASCIIZ "PLACING ACTORS..." .CODE + +; DEPRECATED!!! ; @brief Asks for the size of the maze ; Returns Width in X and Height in Y Get_Size_Maze: @@ -82,32 +87,32 @@ choice_size_maze: tst_tiny: cmp #$C1 bne tst_small - ldx #20 - ldy #20 + ldx #LEVELSIZE::TINY + ldy #LEVELSIZE::TINY rts tst_small: cmp #$C2 bne tst_medium - ldx #24 - ldy #24 + ldx #LEVELSIZE::SMALL + ldy #LEVELSIZE::SMALL rts tst_medium: cmp #$C3 bne tst_big - ldx #32 - ldy #32 + ldx #LEVELSIZE::NORMAL + ldy #LEVELSIZE::NORMAL rts tst_big: cmp #$C4 bne tst_huge - ldx #48 - ldy #48 + ldx #LEVELSIZE::BIG + ldy #LEVELSIZE::BIG rts tst_huge: cmp #$C5 bne bad_size - ldx #64 - ldy #64 + ldx #LEVELSIZE::HUGE + ldy #LEVELSIZE::HUGE rts bad_size: PRINT STR_SIZE_MAZE_3 @@ -180,25 +185,20 @@ Init_Dimensions_Maze: stx _build_fences + $9 stx _build_fences + $23 stx _build_fences + $3D - ; dex - ; dex - ; dex - ; stx Grow_Maze + $C ; patch HEIGHT_MAZE usage NO MORE PATCH: comment to be removed sty HEIGHT_MAZE dey dey sty _build_fences + $12 - ; dey - ; dey - ; sty Grow_Maze + $19 rts ; @brief Builds a whole level +; @param Uses NextLevel to get the conf +; @return player position in X and Y .define DST_WORLD World .define ADDR_TO_PATCH init_world_line + 3 -.define NB_ROOMS ZERO_8_2 +.define NB_ROOMS ZERO_9_9 Build_Level: ; Filling World with ACTORS::WALL_1 @@ -221,6 +221,11 @@ Build_Level: sta ADDR_TO_PATCH + 1 dey bne init_world + ; patching back for a future execution + lda #DST_WORLD + sta ADDR_TO_PATCH+1 PRINT STR_ROOMS lda #MAX_NB_ROOMS+1 @@ -229,7 +234,7 @@ Build_Level: lda #ACTORS::FLOOR_1 jsr _build_fences - + PRINT STR_MAZE jsr Grow_Maze @@ -248,5 +253,142 @@ Build_Level: PRINT STR_UNITE jsr Unite_Rooms + PRINT STR_ACTORS + ; the two following defines must be the same as in Place_Actors + .define POS_X ZERO_3 ; ROOM_X in Place_Actors + .define POS_Y ZERO_2_4 ; ROOM_Y in Place_Actors + .define POS_STARDOWN_X ZERO_5_1 + .define POS_STARDOWN_Y ZERO_5_2 + .define ACTOR ZERO_4_1 + .define ACTOR_NB ZERO_4_2 + .define CURR_ACTOR_OFFSET ZERO_4_3 + .define POS_PLAYER_OFFSET ZERO_4_4 + .define LEVEL_CONF_OFFSET ZERO_5_3 + .define ADDR_ACTOR ZERO_4_3 ; 2 bytes + + lda #0 + sta ACTOR + ldx NextLevel + stx FAC1 + ldx #SIZEOF_CONF_LEVEL + stx FAC2 + jsr mul8 ; A = offset to level conf + txa + sta LEVEL_CONF_OFFSET + clc + adc #7 ; A = offset to pos_player_enter + sta POS_PLAYER_OFFSET + tax + inx + inx ; offset to actors[AA_NB] + loop_actors: + stx CURR_ACTOR_OFFSET + lda Levels, X ; actors[AA_NB] + sta ACTOR_NB + loop_actor_nb: + beq end_loop_actor_nb + + ldx ACTOR + lda ActiveActor_Tiles, X + ldx NB_ROOMS + jsr Place_Actors + + ; save stair down position + lda ACTOR + cmp #eACTORSREACTIVE::AA_STAIRDOWN + bne not_stair_down + lda POS_X + sta POS_STARDOWN_X + lda POS_Y + sta POS_STARDOWN_Y + not_stair_down: + + dec ACTOR_NB ; next + jmp loop_actor_nb + end_loop_actor_nb: + + ldx CURR_ACTOR_OFFSET + inx + inc ACTOR + ldy ACTOR + cpy #eACTORSREACTIVE::AA_NB + bne loop_actors + + ; Set the 1st position of the player in the level + ldx POS_PLAYER_OFFSET + lda Levels, X + cmp #$FF + bne not_first_entry + ; Very first entrance in the level + lda NextLevel + cmp #0 + bne not_first_level + ; Special case: first level + ; TODO avoid non empty floor... + ldx Rooms+2 ; Rooms[0].x + ldy Rooms+3 ; Rooms[0].y + rts + not_first_level: + ldx POS_STARDOWN_X + ldy POS_STARDOWN_Y + jsr Compute_Maze_Addr + ; addr offseted by - witdh_maze to access all tiles with offset + sta ADDR_ACTOR+1 + txa + sec + sbc #WIDTH_WORLD + sta ADDR_ACTOR + lda ADDR_ACTOR+1 + sbc #0 + sta ADDR_ACTOR+1 + ldx POS_STARDOWN_X + ; NOTE: There is at least one solution, the tile is not surrounded! + ; if (World[pos_stair_down.y][pos_stair_down.x - 1] == FLOOR_2) + ldy #(WIDTH_WORLD - 1) + lda (ADDR_ACTOR), Y + cmp #ACTORS::FLOOR_2 + bne not_x_minus + ldy POS_STARDOWN_Y + dex + rts + not_x_minus: + ; if (World[pos_stair_down.y - 1][pos_stair_down.x] == FLOOR_2) + ldy #0 + lda (ADDR_ACTOR), Y + cmp #ACTORS::FLOOR_2 + bne not_y_minus + ldy POS_STARDOWN_Y + dey + rts + not_y_minus: + ; if (World[pos_stair_down.y + 1][pos_stair_down.x] == FLOOR_2) + ldy #(WIDTH_WORLD * 2) + lda (ADDR_ACTOR), Y + cmp #ACTORS::FLOOR_2 + bne not_y_plus + ldy POS_STARDOWN_Y + iny + rts + not_y_plus: + ldy POS_STARDOWN_Y + inx + rts + not_first_entry: + pha ; pos_player_enter.x + inx + lda Levels, X ; pos_player_enter.y + tay + pla + tax + rts + + + ; ldx NB_ROOMS + ; lda #ACTORS::STAIR_DOWN + ; jsr Place_Actors + ; lda #ACTORS::STAIR_UP + ; ldx NB_ROOMS + ; jsr Place_Actors + rts diff --git a/src/builder/maze.asm b/src/builder/maze.asm index cf1b8f4..1c1f80f 100644 --- a/src/builder/maze.asm +++ b/src/builder/maze.asm @@ -14,9 +14,10 @@ ; along with this program. If not, see . .include "../memory.inc" -.include "../world.inc" .include "../random.inc" .include "../math.inc" +.include "../common.inc" +.include "../world/world.inc" .export Grow_Maze @@ -30,8 +31,6 @@ ; using HGR2 space as the stack ; Stack contains pointers to tiles (2 byte long) .define STACK_ADDR $3FFE ; Will be 2 byte incremented before 1st push -.define FALSE #0 -.define TRUE #1 .define Y_TILE ZERO_2_4 diff --git a/src/builder/rooms.asm b/src/builder/rooms.asm index e0fa857..f91942d 100644 --- a/src/builder/rooms.asm +++ b/src/builder/rooms.asm @@ -16,8 +16,9 @@ .include "../memory.inc" .include "../random.inc" -.include "../world.inc" .include "../math.inc" +.include "../common.inc" +.include "../world/world.inc" .export Carve_Rooms .export Connect_Rooms @@ -29,9 +30,6 @@ .import HEIGHT_MAZE -.define TRUE #1 -.define FALSE #0 - .BSS ; Configration to build rooms diff --git a/src/builder/rooms.inc b/src/builder/rooms.inc index c974a52..285a050 100644 --- a/src/builder/rooms.inc +++ b/src/builder/rooms.inc @@ -16,3 +16,5 @@ .import Carve_Rooms .import Connect_Rooms + +.define MAX_NB_ROOMS 64 ; MAX_NB_ROOMS *MUST BE* <= 64 and a power of 2 diff --git a/src/builder/unite.asm b/src/builder/unite.asm index 2eff48a..d7834fe 100644 --- a/src/builder/unite.asm +++ b/src/builder/unite.asm @@ -19,9 +19,10 @@ .include "rooms.inc" .include "maze.inc" .include "../io/textio.inc" -.include "../world.inc" .include "../memory.inc" .include "../math.inc" +.include "../common.inc" +.include "../world/world.inc" .import World .import Rooms @@ -45,9 +46,6 @@ .define CPT_Y ZERO_2_6 -.define FALSE #0 -.define TRUE #1 - .define QUEUE_ADDR $4000 @@ -361,13 +359,13 @@ Unite_Rooms: sta address2+9 ; sbc #0 .endmacro -.define DELTA_X ZERO_5_2 -.define DELTA_Y ZERO_5_3 -.define DELTA_X_2 ZERO_5_5 -.define DELTA_Y_2 ZERO_5_6 -.define ROOM_Y ZERO_8_1 -.define ROOM_X ZERO_8_2 -.define D ZERO_3 +.define DELTA_X ZERO_9_1 +.define DELTA_Y ZERO_9_2 +.define DELTA_X_2 ZERO_9_3 +.define DELTA_Y_2 ZERO_9_4 +.define ROOM_Y ZERO_9_5 +.define ROOM_X ZERO_9_6 +.define D ZERO_9_7 .define ROOM_FOUND SAVE_X _Connect_Room: diff --git a/src/debug.asm b/src/debug.asm index 8f82f8b..28f1ce2 100644 --- a/src/debug.asm +++ b/src/debug.asm @@ -1,3 +1,20 @@ +; Copyright (C) 2020 Christophe Meneboeuf +; +; This program is free software: you can redistribute it and/or modify +; it under the terms of the GNU General Public License as published by +; the Free Software Foundation, either version 3 of the License, or +; (at your option) any later version. +; +; This program is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program. If not, see . + + + .include "memory.inc" ; nb of bytes to be displayed in DBG_TRACES[0] diff --git a/src/display.asm b/src/display.asm index aa0d117..3e0e191 100644 --- a/src/display.asm +++ b/src/display.asm @@ -14,9 +14,8 @@ ; You should have received a copy of the GNU General Public License ; along with this program. If not, see . - +.include "world/world.inc" .include "display.inc" -.include "world.inc" .include "tiles.inc" .include "math.inc" .include "memory.inc" diff --git a/src/display_map.asm b/src/display_map.asm index ae81e14..07c6e28 100644 --- a/src/display_map.asm +++ b/src/display_map.asm @@ -15,7 +15,7 @@ ; along with this program. If not, see . -.include "world.inc" +.include "world/world.inc" .include "memory.inc" .include "math.inc" .include "monitor.inc" diff --git a/src/escape.cfg b/src/escape.cfg index 5dfb500..cac66a7 100644 --- a/src/escape.cfg +++ b/src/escape.cfg @@ -12,8 +12,8 @@ MEMORY { HEADER: file = %O, start = %S - 4, size = $0004; MAIN: file = %O, define = yes, start = %S, size = $2000 - %S; HGR: file = "", define = no, start = $2000, size = $4000; - DATA: file = %O, define = yes, start = $6000, size = $2000; - BSSMEM: file = "", define = no, start = __DATA_LAST__, size = $9600 - __DATA_LAST__; + DATA: file = %O, define = yes, start = $6000, size = $3000; + BSSMEM: file = "", define = no, start = __DATA_LAST__, size = $9600 - __DATA_LAST__; } SEGMENTS { ZEROPAGE: load = ZP, type = zp, optional = yes; diff --git a/src/game_loop.asm b/src/game_loop.asm index ebc0901..af29d7c 100644 --- a/src/game_loop.asm +++ b/src/game_loop.asm @@ -14,12 +14,13 @@ ; along with this program. If not, see . - -.include "world.inc" +.include "world/level.inc" +.include "world/world.inc" .include "display.inc" .include "display_map.inc" .include "memory.inc" .include "monitor.inc" +.include "common.inc" .export game_loop @@ -28,6 +29,7 @@ .import set_view_coords .import view_refresh ; player +.import player_move .import player_move_inx .import player_move_iny .import player_move_dex @@ -36,6 +38,13 @@ ; world .import world_set_player +; ************ +.include "builder/builder.inc" +.import world_init +.import player_init +.import view_init +; ************ + .define KEY_UP $C9 .define KEY_LEFT $CA @@ -46,7 +55,6 @@ .CODE - nop ; Main can jump to a wrong game_loop's addr without this nop :/ ; ########### GAME ########## @@ -54,23 +62,49 @@ ; @brief Main game loop game_loop: - ldx Player_XY - ldy Player_XY+1 + jsr levels_init - jsr world_set_player - jsr set_view_coords - jsr view_refresh + lda #0 + sta NextLevel - ; waiting for a key to be pressed -kbd_loop: - lda KEYBD - bpl kbd_loop ; bit #8 is set when a character is present (thus A < 0) - sta KEYBD_STROBE + level_loop: + jsr level_enter ; Uses NextLevel as level number - jsr key_action - jmp kbd_loop + ; ***************** + ; jsr Build_Level + jsr Display_Map_Init + ; ldx Rooms+2 ; Rooms[0].x + ; ldy Rooms+3 ; Rooms[0].y + ; jsr player_init + jsr world_init + jsr view_init + ; ***************** - rts + + ldx Player_XY + ldy Player_XY+1 + + jsr world_set_player + jsr set_view_coords + jsr view_refresh + + ; waiting for a key to be pressed + kbd_loop: + lda KEYBD + bpl kbd_loop ; bit #8 is set when a character is present (thus A < 0) + sta KEYBD_STROBE + + jsr key_action + + lda ExitLevel + cmp TRUE + bne kbd_loop + + jsr level_exit + + jmp level_loop + + rts ; action on key pressed key_action: @@ -87,24 +121,42 @@ key_action: rts move_up: - jsr player_move_dey + ldx Player_XY + ldy Player_XY+1 + dey + jsr player_move + ; jsr player_move_dey jmp end_action_move move_right: - jsr player_move_inx + ldx Player_XY + ldy Player_XY+1 + inx + jsr player_move + ; jsr player_move_inx jmp end_action_move move_down: - jsr player_move_iny + ldx Player_XY + ldy Player_XY+1 + iny + jsr player_move + ; jsr player_move_iny jmp end_action_move move_left: - jsr player_move_dex + ldx Player_XY + ldy Player_XY+1 + dex + jsr player_move + ; jsr player_move_dex jmp end_action_move end_action_move: ; update player/view coordinates and refresh the display jsr world_set_player jsr set_view_coords ; coords of the player in XY after player_move_* - jsr view_refresh + jsr view_refresh rts + + display_map: jsr Map_Loop rts diff --git a/src/main.asm b/src/main.asm index 3abeef0..186cde1 100644 --- a/src/main.asm +++ b/src/main.asm @@ -56,43 +56,20 @@ _main: sta SIZEH jsr memcpy - lda #$0 - sta SEED0 - lda #$0 - sta SEED1 - lda #$0 - sta SEED2 - lda #$0 - sta SEED3 jsr Title ; will init the seed ; overwrite the seed to debug - ; lda #$55 - ; sta SEED0 - ; lda #$67 - ; sta SEED1 - ; lda #$8C - ; sta SEED2 - ; lda #$5F - ; sta SEED3 + ;lda #$0 + ;sta SEED0 + ;lda #$0 + ;sta SEED1 + ;lda #$0 + ;sta SEED2 + ;lda #$0 + ;sta SEED3 jsr Random8_Init - - jsr Get_Size_Maze - jsr Init_Dimensions_Maze - jsr Build_Level - - - ; Init - jsr Display_Map_Init - ldx Rooms+2 ; Rooms[0].x - ldy Rooms+3 ; Rooms[0].y - jsr player_init - jsr world_init - jsr view_init - ; Run - jsr game_loop - + jsr game_loop rts diff --git a/src/memory.inc b/src/memory.inc index 7ad327c..1f7dbf3 100644 --- a/src/memory.inc +++ b/src/memory.inc @@ -57,7 +57,18 @@ .define ZERO_7_2 $CF .define ZERO_8_1 $D6 -.define ZERO_8_2 $D7 +.define ZERO_8_2 $D7 + +.define ZERO_9_1 $F0 +.define ZERO_9_2 $F1 +.define ZERO_9_3 $F2 +.define ZERO_9_4 $F3 +.define ZERO_9_5 $F4 +.define ZERO_9_6 $F5 +.define ZERO_9_7 $F6 +.define ZERO_9_8 $F7 +.define ZERO_9_9 $F8 +.define ZERO_9_10 $F9 ; ************ I/O ************ .define KEYBD $C000 diff --git a/src/player.asm b/src/player.asm index 259b59c..2e8e55f 100644 --- a/src/player.asm +++ b/src/player.asm @@ -14,15 +14,21 @@ ; You should have received a copy of the GNU General Public License ; along with this program. If not, see . -.include "world.inc" + +.include "common.inc" .include "memory.inc" .include "monitor.inc" .include "io/textio.inc" +.include "world/world.inc" ; init the player's structures .export player_init +; exectutes the tile's reaction and updates the player's position if possible +; Destroys ZEROS_2_1 -> 2_5 +.export player_move + ; All the following functions returns the new player position: ; x in X and y in Y ; They may be unmodified ;) @@ -41,6 +47,8 @@ .export Player_XY .import Compute_Maze_Addr +.import Reactions_lsb +.import Reactions_msb .BSS @@ -64,11 +72,50 @@ player_init: sty Player_XY+1 rts +; @param X target tile's x +; @param Y target tile's y +; @return TRUE in A if the player can move to the tile, FALE otherwise +.define ADDR_IN_MAZE ZERO_2_1 ; 2 bytes +.define NEW_PLAYER_XY ZERO_2_4 ; 2 bytes +player_move: + + stx NEW_PLAYER_XY + sty NEW_PLAYER_XY+1 + + jsr Compute_Maze_Addr + + ; get the actor + stx ADDR_IN_MAZE + sta ADDR_IN_MAZE+1 + ldy #0 + lda (ADDR_IN_MAZE), Y + tax + + ; get the reaction address + lda Reactions_lsb, X + sta FUNC_REACTION + 1 + lda Reactions_msb, X + sta FUNC_REACTION+2 + + FUNC_REACTION : jsr 0 + + cmp TRUE + bne end_player_move + ldx NEW_PLAYER_XY + stx Player_XY + ldy NEW_PLAYER_XY+1 + sty Player_XY+1 + +end_player_move: + ldx Player_XY + ldy Player_XY+1 + + rts + ; !!! ALL THE MOVE FUNCTION HAVE TO BE GROUPED TOGHETHER ; AS THERE IS A COMMON RETURN POINT TO WHICH THEY BRANHC (KEEP PC's DISTANCE < 127) !!! -.define ADDR_IN_MAZE ZERO_2_1 player_move_inx: ; test that x+1 is "WALKABLE" diff --git a/src/random.asm b/src/random.asm index 4bcc56c..d346efb 100644 --- a/src/random.asm +++ b/src/random.asm @@ -5,6 +5,8 @@ .export Random8 .export Random8_Init +.export Random8_RestoreRandomness +.export Random8_SaveRandomness .export DBG_SEED .define TMP RESERVED01 @@ -12,10 +14,11 @@ .BSS .align 256 -T0: .res 256 -T1: .res 256 -T2: .res 256 -T3: .res 256 +T0: .res 256 +T1: .res 256 +T2: .res 256 +T3: .res 256 +T0COPY: .res 256 .CODE @@ -50,7 +53,8 @@ DBG_SEED: .byte 0,0,0,0 ; MUST NOT BE RELOCATED! ; 1024 bytes for the tables ; Speed: JSR RAND takes 94 cycles ; -Random8: CLC ; compute lower 32 bits of: +Random8: + CLC ; compute lower 32 bits of: LDX SEED0 ; 1664525 * ($100 * SEED1 + SEED0) + 1 LDY SEED1 LDA T0,X @@ -123,3 +127,31 @@ GT1: LDA T0-1,X ; add 1664525 to previous entry to get next entry BNE GT1 RTS + + +Random8_RestoreRandomness: + + ldx #$FF +restore_loop: + lda T0COPY, X + sta T0, X + dex + bne restore_loop + lda T0COPY, X + sta T0, X + + rts + + +Random8_SaveRandomness: + + ldx #$FF +save_loop: + lda T0, X + sta T0COPY, X + dex + bne save_loop + lda T0, X + sta T0COPY, X + + rts diff --git a/src/random.inc b/src/random.inc index 7606123..56f5284 100644 --- a/src/random.inc +++ b/src/random.inc @@ -4,3 +4,7 @@ .import Random8 .import Random8_Init + +.import Random8_RestoreRandomness + +.import Random8_SaveRandomness diff --git a/src/tiles.asm b/src/tiles.asm index 8d90b2c..31e7298 100644 --- a/src/tiles.asm +++ b/src/tiles.asm @@ -104,6 +104,40 @@ FLOOR_4: .byte $D5, $AA, $D5, $AA .byte $D5, $AA, $D5, $AA .byte $D5, $AA, $D5, $AA +STAIR_DOWN: +.byte $55, $2A, $55, $2A +.byte $01, $AA, $D4, $00 +.byte $01, $8A, $D4, $82 +.byte $71, $01, $C0, $82 +.byte $71, $79, $00, $00 +.byte $71, $79, $3C, $00 +.byte $71, $79, $3C, $1E +.byte $71, $79, $3C, $1E +.byte $71, $79, $3C, $1E +.byte $71, $79, $3C, $1E +.byte $71, $79, $3C, $1E +.byte $71, $79, $3C, $1E +.byte $71, $79, $3C, $1E +.byte $71, $79, $3C, $1E +.byte $71, $7F, $7F, $1F +.byte $01, $8A, $95, $A8 +STAIR_UP: +.byte $55, $2A, $55, $2A +.byte $71, $7F, $7F, $1F +.byte $71, $79, $D4, $82 +.byte $71, $79, $3C, $8A +.byte $71, $79, $3C, $88 +.byte $71, $79, $3C, $1E +.byte $71, $79, $3C, $1E +.byte $71, $79, $3C, $1E +.byte $71, $79, $3C, $1E +.byte $71, $79, $3C, $1E +.byte $70, $79, $3C, $1E +.byte $70, $79, $3C, $1E +.byte $70, $79, $3C, $1E +.byte $90, $78, $3C, $1E +.byte $D0, $A8, $3C, $1E +.byte $D0, $A0, $94, $1E WALL_1: .byte 197, 138, 213, 168 .byte 197, 138, 213, 168 @@ -160,4 +194,6 @@ UNKNOWN: .ALIGN 256 ; DON"T FORGET TO UPDATE NB_TILES!! TILES: -.word PLAYER, FLOOR_1, FLOOR_2, FLOOR_3, FLOOR_4, WALL_1, WALL_2, UNKNOWN +.word PLAYER +.word FLOOR_1, FLOOR_2, FLOOR_3, FLOOR_4, FLOOR_4, FLOOR_4, STAIR_DOWN, STAIR_UP +.word WALL_1, WALL_2, UNKNOWN diff --git a/src/tiles.inc b/src/tiles.inc index 77f2dbf..24b3627 100644 --- a/src/tiles.inc +++ b/src/tiles.inc @@ -18,7 +18,6 @@ .import TILES -.define NB_TILES 8