auto loader

This commit is contained in:
Christophe Meneboeuf 2021-04-16 23:50:38 +02:00
parent 5bbb62f36a
commit 7c90129e9b
14 changed files with 846 additions and 8 deletions

Binary file not shown.

View File

@ -10,10 +10,16 @@ if (( $# != 3 )); then
exit
fi
echo " . removing previous instance of ESCAPE form the disk"
# ###
# NOTE:
# The loader must have the same basename as the game loaded
# ###
echo " . removing previous instance of ESCAPE from the disk"
java -jar ${1} -d ${3} ESCAPE
java -jar ${1} -d ${3} ESCAPE.SYSTEM
echo " .. adding ESCAPE to the disk"
echo " .. adding ESCAPE and its loader to the disk"
java -jar ${1} -cc65 ${3} ESCAPE BIN < ${2}
java -jar ${1} -p ${3} ESCAPE.SYSTEM SYS < ${CC65_HOME}/target/apple2/util/loader.system
echo "DONE."

133
src/actors/reactions.asm Normal file
View File

@ -0,0 +1,133 @@
; Copyright (C) 2020 Christophe Meneboeuf <christophe@xtof.info>
;
; 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 <http://www.gnu.org/licenses/>.
.include "../world/level.inc"
.include "../io/textio.inc"
.include "../common.inc"
.export Reactions_lsb
.export Reactions_msb
.export ReactionStairUp
.export ReactionStairDown
.DATA
STR_REATION_WALL: ASCIIZ "YOU HIT A WALL"
STR_REATION_STAIR_UP: ASCIIZ "YOU GO UPSTAIRS TO THE PREVIOUS LEVEL"
STR_REATION_STAIR_DOWN: ASCIIZ "YOU GO DOWNSTAIRS TO THE NEXT LEVEL"
.align 256
; functions address seperated in LSB / MSB to use the same X/Y offset
Reactions_lsb:
.byte 0, <ReactionFloor, <ReactionFloor, <ReactionFloor, <ReactionFloor, <ReactionFloor, <ReactionFloor, <ReactionStairDown
.byte <ReactionStairUp, <ReactionWall, <ReactionWall, <ReactionWall, <ReactionWall, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
Reactions_msb:
.byte 0, >ReactionFloor, >ReactionFloor, >ReactionFloor, >ReactionFloor, >ReactionFloor, >ReactionFloor, >ReactionStairDown
.byte >ReactionStairUp, >ReactionWall, >ReactionWall, >ReactionWall, >ReactionWall, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.byte 0, 0, 0, 0, 0, 0, 0, 0
.CODE
ReactionFloor:
lda TRUE
rts
ReactionWall:
PRINT STR_REATION_WALL
lda FALSE
rts
ReactionStairUp:
PRINT STR_REATION_STAIR_UP
lda CurrentLevel
sta NextLevel
inc NextLevel
lda TRUE
sta ExitLevel
lda FALSE
rts
ReactionStairDown:
PRINT STR_REATION_STAIR_DOWN
lda CurrentLevel
sta NextLevel
dec NextLevel
lda TRUE
sta ExitLevel
lda FALSE
rts

107
src/builder/actors.asm Normal file
View File

@ -0,0 +1,107 @@
.include "../common.inc"
.include "../random.inc"
.include "../memory.inc"
.include "../math.inc"
.include "../world/world.inc"
.include "actors_private.inc"
.import Rooms
.import World
.import Compute_Maze_Addr
; code
.export Place_Actors
; data
.export ActiveActor_Tiles
.DATA
ActiveActor_Tiles: .byte ACTORS::STAIR_UP, ACTORS::STAIR_DOWN, ACTORS::FLOOR_1 ; DEBUg: placeholder for future map
.CODE
.define PTR_ROOM ZERO_2_1 ; 2 bytes
.define PTR_TILE ZERO_2_1 ; 2 bytes
; the two following defines must be the same as in Build_Level
.define ROOM_X ZERO_3
.define ROOM_Y ZERO_2_4
.define ROOM_W ZERO_2_5
.define ROOM_H ZERO_2_6
.define NB_ROOMS ZERO_9_9
.define ACTOR ZERO_9_10
; A : ACTOR
; X : NB_ROOMS
Place_Actors:
sta ACTOR
stx NB_ROOMS
loop_find_location:
jsr Random8
ldx NB_ROOMS
jsr Modulus
; sizeof(room_t) == 4
asl
asl
clc
adc #<Rooms
sta PTR_ROOM
lda #0
adc #>Rooms
sta PTR_ROOM+1
ldy #0
lda (PTR_ROOM), Y
sta ROOM_H
iny
lda (PTR_ROOM), Y
sta ROOM_W
iny
lda (PTR_ROOM), Y
sta ROOM_X
iny
lda (PTR_ROOM), Y
sta ROOM_Y
; x = room->x + rand() % (room->width - 2) + 1;
sec
lda ROOM_W
sbc #2
sta ROOM_W
jsr Random8
ldx ROOM_W
jsr Modulus
clc
adc ROOM_X
adc #1
sta ROOM_X
; y = room->y + rand() % (room->height - 2) + 1;
sec
lda ROOM_H
sbc #2
sta ROOM_H
jsr Random8
ldx ROOM_H
jsr Modulus
clc
adc ROOM_Y
adc #1
sta ROOM_Y
tay
ldx ROOM_X
jsr Compute_Maze_Addr
stx PTR_TILE
sta PTR_TILE+1
ldy #0
lda (PTR_TILE), Y
cmp #ACTORS::FLOOR_2
bne loop_find_location
lda ACTOR
sta (PTR_TILE), Y
rts

7
src/builder/actors.inc Normal file
View File

@ -0,0 +1,7 @@
.include "actors_private.inc"
; code
.import Place_Actors
; data
.import ActiveActor_Tiles

View File

@ -0,0 +1,7 @@
; @brief All kind of reactive actors that can be in a level
.enum eACTORSREACTIVE
AA_STAIRUP = 0
AA_STAIRDOWN
AA_MAP
AA_NB
.endenum

17
src/common.inc Normal file
View File

@ -0,0 +1,17 @@
; Copyright (C) 2020 Christophe Meneboeuf <christophe@xtof.info>
;
; 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 <http://www.gnu.org/licenses/>.
.define TRUE #1
.define FALSE #0

View File

@ -2,7 +2,7 @@
# APPLESOFT required
# HGR1 & HGR2 segment reserved
FEATURES {
STARTADDRESS: default = $0803;
STARTADDRESS: default = $0800;
}
SYMBOLS {
__EXEHDR__: type = import;
@ -12,13 +12,15 @@ 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 = $3000;
CODE2: file = %O, define = yes, start = $6000, size = $100;
DATA: file = %O, define = yes, start = __CODE2_LAST__,size = $3000;
BSSMEM: file = "", define = no, start = __DATA_LAST__, size = $9600 - __DATA_LAST__;
}
SEGMENTS {
ZEROPAGE: load = ZP, type = zp, optional = yes;
EXEHDR: load = HEADER, type = ro;
CODE: load = MAIN, type = rw;
CODE2: load = CODE2, type = rw, optional = yes;
RODATA: load = DATA, type = ro, optional = yes, align = $100;
DATA: load = DATA, type = rw, optional = yes, align = $100;
BSS: load = BSSMEM, type = bss, optional = yes, define = yes, align = $100;

View File

@ -33,19 +33,33 @@
.import __MAIN_LAST__
.import __DATA_START__
.import __DATA_SIZE__
.import __CODE2_START__
.import __CODE2_LAST__
.CODE
_main:
; Relocate DATA from its freshly loaded location to __DATA_START__
; computing DATA actual starting address
lda #<__MAIN_LAST__
sta FROM
lda #>__MAIN_LAST__
sta FROM+1
lda #<__CODE2_START__
sta TO
lda #>__CODE2_START__
sta TO+1
lda #<(__CODE2_LAST__ - __CODE2_START__)
sta SIZEL
lda #>(__CODE2_LAST__ - __CODE2_START__)
sta SIZEH
jsr memcpy
; Relocate DATA from its freshly loaded location to __DATA_START__
; computing DATA actual starting address
lda #<(__MAIN_LAST__ + __CODE2_LAST__ - __CODE2_START__)
sta FROM
lda #>(__MAIN_LAST__ + __CODE2_LAST__ - __CODE2_START__)
sta FROM+1
lda #<__DATA_START__
sta TO
lda #>__DATA_START__

265
src/world/level.asm Normal file
View File

@ -0,0 +1,265 @@
; Copyright (C) 2021 Christophe Meneboeuf <christophe@xtof.info>
;
; 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 <http://www.gnu.org/licenses/>.
.include "../common.inc"
.include "../memory.inc"
.include "../random.inc"
.include "../builder/actors.inc"
.include "../builder/builder.inc"
.include "level_private.inc"
; code
.export levels_init
.export level_enter
.export level_exit
; data
.export Levels
.export CurrentLevel
.export NextLevel
.export ExitLevel
.import player_init
.BSS
CurrentLevel: .res 1
NextLevel: .res 1
ExitLevel: .res 1
.align 256 ; to be sure it is accessible with an offset
Levels: .res SIZEOF_CONF_LEVEL * NB_LEVELS
.CODE
.define NR_ACTORS ZERO_4_1
.define NR_LEVELS ZERO_4_2
; TODO Load a configuration file from disk!
levels_init:
ldx #0
ldy #0
lda #NB_LEVELS
sta NR_LEVELS
level_conf_default:
; level_nr
tya
iny
sta Levels, X
; is_built
lda FALSE
sta Levels+1, x
; seed
lda #0
sta Levels+2, X
sta Levels+3, X
sta Levels+4, X
sta Levels+5, X
; size
; pos_player_enter
lda #$FF
sta Levels+7, X
sta Levels+8, X
; actors
txa
clc
adc #9
tax
lda #eACTORSREACTIVE::AA_NB
sta NR_ACTORS
lda #0
level_conf_actors:
sta Levels, X
inx
dec NR_ACTORS
bne level_conf_actors
dec NR_LEVELS
bne level_conf_default
; level #0
ldx #0
lda #1
sta Levels + 9 + eACTORSREACTIVE::AA_STAIRUP, X
lda #LEVELSIZE::TINY
sta Levels+6, X ; size
; level #1
clc
txa
adc #SIZEOF_CONF_LEVEL
tax
lda #1
sta Levels + 9 + eACTORSREACTIVE::AA_STAIRUP, X
sta Levels + 9 + eACTORSREACTIVE::AA_STAIRDOWN, X
lda #LEVELSIZE::SMALL
sta Levels+6, X ; size
; level #2
clc
txa
adc #SIZEOF_CONF_LEVEL
tax
lda #1
sta Levels + 9 + eACTORSREACTIVE::AA_STAIRUP, X
sta Levels + 9 + eACTORSREACTIVE::AA_STAIRDOWN, X
lda #LEVELSIZE::NORMAL
sta Levels+6, X ; size
; level #3
clc
txa
adc #SIZEOF_CONF_LEVEL
tax
lda #1
sta Levels + 9 + eACTORSREACTIVE::AA_STAIRUP, X
sta Levels + 9 + eACTORSREACTIVE::AA_STAIRDOWN, X
lda #LEVELSIZE::BIG
sta Levels+6, X ; size
; level #4
clc
txa
adc #SIZEOF_CONF_LEVEL
tax
lda #1
sta Levels + 9 + eACTORSREACTIVE::AA_STAIRDOWN, X
lda #LEVELSIZE::HUGE
sta Levels+6, X ; size
; global vars
lda #0
sta CurrentLevel
lda FALSE
sta ExitLevel
rts
; @param: Uses NextLevel as level number
.define LEVEL_CONF_OFFSET ZERO_3
level_enter:
; debug:
; lda NextLevel
; cmp #0
; bne debug_end
; jsr Random8
; debug_end:
jsr Random8_SaveRandomness
; get the level conf
lda #0
ldx #0
clc
get_level_conf:
tay
lda Levels, X
cmp NextLevel
beq end_idx_level
tya
adc #SIZEOF_CONF_LEVEL
tax
bcc get_level_conf
end_idx_level:
stx LEVEL_CONF_OFFSET
; init seed for the level if not already built
lda Levels+1, X ; is_built
cmp FALSE
bne end_init_seed
jsr Random8
ldx LEVEL_CONF_OFFSET
sta Levels+2, X ; seed[0]
jsr Random8
ldx LEVEL_CONF_OFFSET
sta Levels+3, X ; seed[1]
jsr Random8
ldx LEVEL_CONF_OFFSET
sta Levels+4, X ; seed[2]
jsr Random8
ldx LEVEL_CONF_OFFSET
sta Levels+5, X ; seed[3]
end_init_seed:
; init the randomness with the values for the level
lda Levels+2, X ; seed[0]
sta SEED0
lda Levels+3, X ; seed[1]
sta SEED1
lda Levels+4, X ; seed[2]
sta SEED2
lda Levels+5, X ; seed[3]
sta SEED3
jsr Random8_Init
; init maze size
ldx LEVEL_CONF_OFFSET
txa
pha ; save LEVEL_CONF_OFFSET as its ZP will be overwritten
lda Levels+6, X ; size
tax
tay
jsr Init_Dimensions_Maze
; player position returned in X and Y
jsr Build_Level
jsr player_init ; param: player pos in X and Y
jsr Random8_RestoreRandomness
pla ; restore LEVEL_CONF_OFFSET
tax
lda TRUE
sta Levels+1, X; is_built
lda FALSE
sta ExitLevel
lda NextLevel
sta CurrentLevel
rts
.import Player_XY
level_exit:
; get the level conf
lda #0
ldx #0
clc
get_level_conf_2:
tay
lda Levels, X
cmp CurrentLevel
beq end_idx_level_2
tya
adc #SIZEOF_CONF_LEVEL
tax
bcc get_level_conf_2
end_idx_level_2:
; save player pos in conf
lda Player_XY
sta Levels+7, X
lda Player_XY + 1
sta Levels+8, X
rts

27
src/world/level.inc Normal file
View File

@ -0,0 +1,27 @@
; Copyright (C) 2021 Christophe Meneboeuf <christophe@xtof.info>
;
; 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 <http://www.gnu.org/licenses/>.
.include "level_private.inc"
.import levels_init
.import level_enter ; param: A = level_nr
.import level_exit
.import CurrentLevel
.import NextLevel
.import ExitLevel
.import Levels

View File

@ -0,0 +1,42 @@
; Copyright (C) 2021 Christophe Meneboeuf <christophe@xtof.info>
;
; 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 <http://www.gnu.org/licenses/>.
; typedef struct
; {
; uint8_t level_nr;
; uint8_t is_built;
; uint8_t seed[4]; //< seed used to build the level
; uint8_t size; //< eLEVELSIZE
; coords_t pos_player_enter; //< position of player when entering the level (x,y)
; uint8_t actors[AA_NB]; //< number of reactive actors of each kind in the level
; }
; level_conf_t;
; BEWARE: NB_LEVELS * SIZEOF_CONF_LEVEL shall not be > 256
.define SIZEOF_CONF_LEVEL 12
.define NB_LEVELS 5
.enum LEVELSIZE
TINY = 20
SMALL = 24
NORMAL = 32
BIG = 48
HUGE = 64
.endenum

154
src/world/world.asm Normal file
View File

@ -0,0 +1,154 @@
; Copyright (C) 2018 Christophe Meneboeuf <christophe@xtof.info>
;
; 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 <http://www.gnu.org/licenses/>.
.include "world.inc"
.include "../tiles.inc"
.include "../random.inc"
.include "../math.inc"
.include "../memory.inc"
.export World
; initializes the world
; DESTROYS A,X,Y, ZERO_2_1, ZERO_2_2, ZERO_2_3
.export world_init
; sets the player's position onto the Maze
; in: X = x coord in the maze
; in: Y = y coord in the maze
; out : X and Y as they where given
; DESTROYS A,X,Y, ZERO_2_1, ZERO_2_2, ZERO_2_4, ZERO_2_5
.export world_set_player
; Computes the adress corresponding to the coordinates in the maze
; in: X = x coord in the maze
; in: Y = y coord in the maze
; out: AX = Address corresponding to (x,y) in the World array
; DESTROYS A,X,Y, ZERO_2_1, ZERO_2_2, ZERO_2_3
.export Compute_Maze_Addr
.define TILE_NR ZERO_2_1
.define COORD_X ZERO_2_1
.define COORD_Y ZERO_2_2
.define OFFSET ZERO_2_2
.BSS
; The tile where the player stands
.struct Tile_player_standing
addr .word ; adress of the location
actor .byte ; actor on the location tile
.endstruct
.CODE
; @param X Player's x
; @param Y Player's y
world_init:
; Saving the first tile on which the player stands
; FIXME player could be standing anywhere on any type of floor
jsr Compute_Maze_Addr
stx Tile_player_standing::addr
sta Tile_player_standing::addr+1
stx ZERO_2_1
sta ZERO_2_1+1
ldy #0
lda (ZERO_2_1), Y
sta Tile_player_standing::actor
rts
; sets the player's position onto the World
world_set_player:
stx ZERO_2_4
sty ZERO_2_5
; restore the previous tile
ldx Tile_player_standing::addr
lda Tile_player_standing::addr+1
stx ZERO_2_1
sta ZERO_2_1+1
ldy #0
lda Tile_player_standing::actor
sta (ZERO_2_1), Y
; save the next tile
ldx ZERO_2_4
ldy ZERO_2_5
jsr Compute_Maze_Addr ; get's player's position address in memory
stx Tile_player_standing::addr
sta Tile_player_standing::addr+1
stx ZERO_2_1
sta ZERO_2_1+1
ldy #0
lda (ZERO_2_1), y
sta Tile_player_standing::actor
; sets the player on the tile
lda #ACTORS::PLAYER
sta (ZERO_2_1), y
; restore the given locations
ldx ZERO_2_4
ldy ZERO_2_5
rts
; Destroys ZERO_2_1, ZERO_2_2, ZERO_2_3 ZERO_7_1 and ZERO_7_2
Compute_Maze_Addr:
stx COORD_X
; offset due to Y coord
sty FAC1
lda #WIDTH_WORLD
sta FAC2
jsr mul8
tay ; high part of the mul
txa ; low part of the mul
; adding offset due to X
clc
adc COORD_X
sta OFFSET
tya
adc #0
sta OFFSET+1
; adding the offset to the address
lda #<World
clc
adc OFFSET
tax ; low part of address to be returned in X
lda #>World
adc OFFSET+1 ; high part of address to be returned in A
rts
.DATA
.align 256
World: .res (WIDTH_WORLD) * (HEIGHT_WORLD)

57
src/world/world.inc Normal file
View File

@ -0,0 +1,57 @@
; Copyright (C) 2018-2021 Christophe Meneboeuf <christophe@xtof.info>
;
; 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 <http://www.gnu.org/licenses/>.
; The world contains a Maze, filled with Actors
; Actors can be static, such a a floor or a wall,
; dynamic such as a door
; or alive, such as a monster
.define MAXIMUM_WIDTH_MAZE 64 ; must be a power of 2
.define MAXIMUM_HEIGHT_MAZE 64 ; must be a power of 2
.define WIDTH_WORLD 64
.define NEG_WIDTH_WORLD $C0
.define HEIGHT_WORLD 64
.define NEG_HEIGHT_WORLD 64 $C0
.enum ACTORS
PLAYER = 0
FLOOR_1 = 1
FLOOR_2 ; FLOOR BY DEFAULT
FLOOR_3
FLOOR_4
FLOOR_5
FLOOR_6
STAIR_DOWN
STAIR_UP
WALKABLE = STAIR_UP ; Player won't be allowed to go on anything > WALKABLE
NOT_TRANSPARENT = STAIR_UP
NOT_WALKABLE
WALL_1 = NOT_WALKABLE
WALL_2
UNKNOWN
NB_ACTORS
.endenum