;MIT License

;Copyright (c) 2021 Fedora Adventures Pixeltronics

;Permission is hereby granted, free of charge, to any person obtaining a copy
;of this software and associated documentation files (the "Software"), to deal
;in the Software without restriction, including without limitation the rights
;to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;copies of the Software, and to permit persons to whom the Software is
;furnished to do so, subject to the following conditions:

;The above copyright notice and this permission notice shall be included in all
;copies or substantial portions of the Software.

;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;SOFTWARE.

.include "sys/render.h.s"
.include "man/entity.h.s"
.include "sys/input.h.s"
.include "sys/physics.h.s"
.include "cpct_functions.h.s"
.include "sys/game.h.s"
.include "man/levels.h.s"


.area _DATA
.area _CODE

.globl _entity_array
.globl _num_entities


_main::
   
      call cpct_disableFirmware_asm

      call rendersys_init
      call mainMenu

      ld de, #_song_game
      call cpct_akp_musicInit_asm
  

   ;; Loop forever
loop:
      call cpct_waitVSYNC_asm
      call cpct_akp_musicPlay_asm
;      cpctm_setBorder_asm  HW_BLUE
      ld ix, #_entity_array
      ld a, (_num_entities)
      call rendersys_update
;      cpctm_setBorder_asm HW_PASTEL_YELLOW
      call man_entity_put_player_in_ix
      call sys_game_update
;      cpctm_setBorder_asm  HW_GREEN
      call sys_input_update
;      cpctm_setBorder_asm  HW_YELLOW
      call sys_physics_update
;      cpctm_setBorder_asm  HW_WHITE
      call cpct_waitVSYNC_asm
   jr    loop
   