Continuamos nuestra serie abordando los costes ocultos al usar arrays de estructuras en C
en Amstrad CPC. Las posiciones en memoria son relativas al inicio de los arrays, y el compilador produce código para calcular dónde está cada elemento. Las estructuras funcionan similar: cada miembro está a una distancia en bytes del inicio de la estructura. Trabajamos sobre un ejemplo en CPCtelera que vamos optimizando progresivamente. Primero entendemos cómo son estos cálculos y el código que el compilador genera para realizarlos. Vemos las limitadas posibilidades que tiene el compilador para optimizar, debido a los pocos registros del procesador Z80. Finalmente, le vamos facilitando la vida, simplificando los cálculos y ganando bytes y tiempo de CPU con sencillos cambios en el código.
amstrad
Superman (Fremos, 1996)
Superman is an Amstrad CPC 464 game developed in BASIC. It was developed by Fremos in summer 1996. All the game was completely programmed in a real Amstrad CPC 464 and stored in casete tape. After its creation, the game remained stored for almost 30 years. Then, it was finally submitted to a BASIC programming contest created by the RetroAcción association from Zaragoza, in november 2014.
#CPCtelera Animation Flip Mode 2 Demo
This example shows how horizontal flipping works in #CPCtelera 1.4. using mode 2 graphics (640×200, 2 colours). A 6-sprites animation is hold in memory and is horizontally flipped completely to look right or left whenever the user presses a key. #CPCtelera 1.4. will include many flavours of this functionality to match either performance or compactness requirements (The version shown in this video is the compact one, 86 bytes). Full source code for this example and #CPCtelera engine can be found at Github.
#CPCtelera Sprite Flipping Mode 1 Demo
This example shows how horizontal flipping works in #CPCtelera 1.4. using mode 1 graphics (320×200, 4 colours). There are 2 sprites in memory and they are horizontally flipped to look right and left. #CPCtelera 1.4. will include many flavours of this functionality to match either performance or compactness requirements (The version shown in this video is the compact one, 83 bytes). Full source code for this example and #CPCtelera engine can be found at Github.