Advertisement
Guest User

Videojuegos 1 Sesion 2 Amstrad Z80 Assembler 2018

a guest
Sep 18th, 2018
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;-----------------------------LICENSE NOTICE------------------------------------
  2. ;;  This file is part of CPCtelera: An Amstrad CPC Game Engine
  3. ;;  Copyright (C) 2018 ronaldo / Fremos / Cheesetea / ByteRealms (@FranGallegoBR)
  4. ;;
  5. ;;  This program is free software: you can redistribute it and/or modify
  6. ;;  it under the terms of the GNU Lesser General Public License as published by
  7. ;;  the Free Software Foundation, either version 3 of the License, or
  8. ;;  (at your option) any later version.
  9. ;;
  10. ;;  This program is distributed in the hope that it will be useful,
  11. ;;  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;;  GNU Lesser General Public License for more details.
  14. ;;
  15. ;;  You should have received a copy of the GNU Lesser General Public License
  16. ;;  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. ;;-------------------------------------------------------------------------------
  18.  
  19. ;; Include all CPCtelera constant definitions, macros and variables
  20. .include "cpctelera.h.s"
  21.  
  22. ;;
  23. ;; Start of _DATA area
  24. ;;  SDCC requires at least _DATA and _CODE areas to be declared, but you may use
  25. ;;  any one of them for any purpose. Usually, compiler puts _DATA area contents
  26. ;;  right after _CODE area contents.
  27. ;;
  28. .area _DATA
  29. .area _CODE
  30.  
  31. .macro DefineEntity _name, _x, _y, _vx, _vy, _w, _h, _col, _upd
  32. _name:
  33.    .db    _x, _y     ;; X, Y
  34.    .db   _vx, _vy     ;; VX, VY
  35.    .db    _w, _h     ;; W, H
  36.    .db   _col           ;; Color
  37.    .dw   _upd        ;; Update
  38. .endm
  39. e_x = 0
  40. e_y = 1
  41. e_vx = 2
  42. e_vy = 3
  43. e_w = 4
  44. e_h = 5
  45. e_col = 6
  46. e_up_l = 7
  47. e_up_h = 8
  48.  
  49. DefineEntity hero_data, 0x14, 0x21, 0x01, 0x01, 0x02, 0x08, 0x0F, ent_moveKeyboard
  50. DefineEntity enemy_data, 0x20, 0x01, 0xFF, 0x00, 0x02, 0x08, 0xFF, ent_move
  51.  
  52.  
  53. ;;
  54. ;; Declare all function entry points as global symbols for the compiler.
  55. ;; (The linker will know what to do with them)
  56. ;; WARNING: Every global symbol declared will be linked, so DO NOT declare
  57. ;; symbols for functions you do not use.
  58. ;;
  59. .globl cpct_disableFirmware_asm
  60. .globl cpct_drawSolidBox_asm
  61. .globl cpct_getScreenPtr_asm
  62. .globl cpct_waitVSYNC_asm
  63. .globl cpct_setVideoMode_asm
  64.  
  65. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  66. ;; DIBUJAR UNA ENTIDAD
  67. ;; REGISTROS DESTRUIDOS: AF, BC, DE, HL
  68. ;; ENTRADA: IX -> Puntero a entidad
  69. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  70. ent_draw:
  71.    ld    de, #0xC000       ;;Comienzo memoria de video
  72.    ld     c, e_x(ix)         ;; C = Entity Y
  73.    ld     b, e_y(ix)         ;; B = Entity X
  74.    call cpct_getScreenPtr_asm
  75.  
  76.    ex    de, hl   ;; DE = Puntero a memoria
  77.    ld  a, e_col(ix)   ;; Color
  78.    ld  b, e_h(ix)   ;; alto
  79.    ld  c, e_w(ix)   ;; Ancho
  80.  
  81.    call cpct_drawSolidBox_asm
  82.  
  83.    ret
  84.  
  85. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  86. ;; BORRA UNA ENTIDAD
  87. ;; REGISTROS DESTRUIDOS: AF, BC, DE, HL
  88. ;; ENTRADA: IX -> Puntero a entidad
  89. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  90. ent_clear:
  91.    ld  a, e_col(ix)
  92.    ex af, af'
  93.  
  94.   ld  e_col(ix), #0
  95.  
  96.   call ent_draw
  97.   ex af, af'
  98.    ld e_col(ix), a
  99.  
  100.    ret
  101.  
  102. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  103. ;; ACTUALIZAR UNA ENTIDAD
  104. ;; REGISTROS DESTRUIDOS:
  105. ;; ENTRADA: IX -> Puntero a entidad
  106. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  107. ent_update:
  108.    ld     h, e_up_h(ix)
  109.    ld     l, e_up_l(ix)
  110.    jp    (hl)
  111.  
  112. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  113. ;; MOVER UNA ENTIDAD CON TECLADO
  114. ;; REGISTROS DESTRUIDOS:
  115. ;; ENTRADA: IX -> Puntero a entidad
  116. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  117. ent_moveKeyboard:
  118.  
  119.      
  120.  
  121.    ret
  122.  
  123.  
  124. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  125. ;; MOVER UNA ENTIDAD
  126. ;; REGISTROS DESTRUIDOS:
  127. ;; ENTRADA: IX -> Puntero a entidad
  128. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  129. ent_move:
  130.    ld    a, e_x(ix)
  131.    add   e_vx(ix)
  132.    ld    e_x(ix), a
  133.  
  134.    ld    a, e_y(ix)
  135.    add   e_vy(ix)
  136.    ld    e_y(ix), a
  137.    
  138.    ret
  139.  
  140. ;;
  141. ;; MAIN function. This is the entry point of the application.
  142. ;;    _main:: global symbol is required for correctly compiling and linking
  143. ;;
  144. _main::
  145.    ;; Disable firmware to prevent it from interfering with string drawing
  146.    call cpct_disableFirmware_asm
  147.  
  148.    ld    c, #0
  149.    call cpct_setVideoMode_asm
  150.  
  151. loop:
  152.    ld    ix, #hero_data
  153.    call ent_clear
  154.    call ent_update
  155.    call ent_draw
  156.  
  157.    ld    ix, #enemy_data
  158.    call ent_clear
  159.    call ent_update
  160.    call ent_draw
  161.  
  162.    call cpct_waitVSYNC_asm
  163.  
  164.    ;; Loop forever
  165.    jr    loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement