///////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1 
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.apache.org/licenses/LICENSE-1.1>.
// Unless required by applicable law or agreed to in writing, software distributed under 
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 
// ANY KIND, either express or implied. See the License for the specific language 
// governing permissions and limitations under the License.
///////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////
// Handy constants.
const FALSE = 0
const TRUE  = 1
const NULL  = 0
const INT_MAX = 32767
const INT_MIN = -32768

///////////////////////////////////////////////////////////////////////////////////////////////////
// IO locations
const kbd       = $C000
const kbdStrobe = $C010

///////////////////////////////////////////////////////////////////////////////////////////////////
// Window dimensions
const BIGWIN_TOP    = 9
const BIGWIN_BOTTOM = 183
const BIGWIN_LEFT   = 14
const BIGWIN_RIGHT  = 267
const BIGWIN_WIDTH  = BIGWIN_RIGHT - BIGWIN_LEFT
const BIGWIN_HEIGHT = BIGWIN_BOTTOM - BIGWIN_TOP

///////////////////////////////////////////////////////////////////////////////////////////////////
// Memory manager definitions

// Resource types
const RES_TYPE_CODE       = 1
const RES_TYPE_2D_MAP     = 2
const RES_TYPE_3D_MAP     = 3
const RES_TYPE_TILESET    = 4
const RES_TYPE_TEXTURE    = 5
const RES_TYPE_SCREEN     = 6
const RES_TYPE_FONT       = 7
const RES_TYPE_MODULE     = 8
const RES_TYPE_BYTECODE   = 9
const RES_TYPE_FIXUP      = 10
const RES_TYPE_PORTRAIT   = 11
const RES_TYPE_SONG       = 12
const RES_TYPE_STORY      = 13
const RES_TYPE_SM_TILESET = 14

// Command codes
const RESET_MEMORY   = $10
const REQUEST_MEMORY = $11
const LOCK_MEMORY    = $12
const UNLOCK_MEMORY  = $13
const SET_MEM_TARGET = $14
const START_LOAD     = $15
const QUEUE_LOAD     = $16
const FINISH_LOAD    = $17
const FREE_MEMORY    = $18
const CALC_FREE      = $19
const DEBUG_MEM      = $1A
const CHECK_MEM      = $1B
const ADVANCE_ANIMS  = $1C
const FIND_IN_MEM    = $1D
const FATAL_ERROR    = $1F
const HEAP_SET       = $20
const HEAP_ADD_TYPE  = $21
const HEAP_ALLOC     = $22
const HEAP_INTERN    = $23
const HEAP_COLLECT   = $24

// Heap location in memory
const HEAP_BOTTOM    = $DA00
const HEAP_SIZE      = $1200

// Event code
const EVENT_ENTER    = 1
const EVENT_LEAVE    = 2
const EVENT_USE_ITEM = 3

// Party size
const MAX_PARTY = 3

// Combat speed
const DEFAULT_COMBAT_PAUSE_CT = 800

// Signals to Jace, if present.
const EMUSIG_FULL_COLOR = $C049 // e.g. title screen
const EMUSIG_FULL_TEXT  = $C04A // e.g. inventory - big text window w/ graphics border
const EMUSIG_2D_MAP     = $C04B // e.g. wilderness
const EMUSIG_3D_MAP     = $C04C // e.g. in town
const EMUSIG_AUTOMAP    = $C04D // all color except the map title
const EMUSIG_STORY      = $C04E // all text except a portrait
const EMUSIG_TITLE      = $C04F // all color except title screen menu area
const EMUSOUND_PLAY     = $C069 // num | ($40=repeat) | ($80=SFX)

// Game load/save
const RWTS_SEEK  = 0
const RWTS_READ  = 1
const RWTS_WRITE = 2

const RWTS_DRV1  = 0
const RWTS_DRV2  = $80

const RWTS_RDWRPART = (0<<8)
const RWTS_OPENDIR  = (3<<8)
const RWTS_READDIR  = (13<<8)

const LOAD_SAVE_BUF = $4C00
