ASxxxx Assembler V02.00 + NoICE + SDCC mods  (Zilog Z80 / Hitachi HD64180), page 1.
Hexadecimal [16-Bits]



                              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 .module cpct_strings
                             19 
                             20 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                             21 ;;
                             22 ;; Function: cpct_drawCharM0
                             23 ;;
                             24 ;;    Draws a ROM character to the screen or hardware back-buffer in Mode 0 format
                             25 ;; (160x200 px, 16 colours).
                             26 ;;
                             27 ;; C Definition:
                             28 ;;    void <cpct_drawCharM0> (void* *video_memory*, <u8> *ascii*) __z88dk_callee
                             29 ;;
                             30 ;; Input Parameters (3 Bytes):
                             31 ;;  (2B HL) video_memory - Video memory location where the character will be drawn
                             32 ;;  (1B E ) ascii        - Character to be drawn (ASCII code)
                             33 ;;
                             34 ;; Assembly call (Input parameters on registers):
                             35 ;;    > call cpct_drawCharM0_asm
                             36 ;;
                             37 ;; Parameter Restrictions:
                             38 ;;  * *video_memory* could theoretically be any 16-bit memory location. It will work
                             39 ;; outside current screen memory boundaries, which is useful if you use any kind of
                             40 ;; double buffer. However, be careful where you use it, as it does no kind of check
                             41 ;; or clipping, and it could overwrite data if you select a wrong place to draw.
                             42 ;;  * *ascii* could be any 8-bit value, as 256 characters are available in ROM.
                             43 ;;
                             44 ;; Requirements and limitations:
                             45 ;;  * *Do not put this function's code below 0x4000 in memory*. In order to read
                             46 ;; characters from ROM, this function enables Lower ROM (which is located 0x0000-0x3FFF),
                             47 ;; so CPU would read code from ROM instead of RAM in first bank, effectively shadowing
                             48 ;; this piece of code. This would lead to undefined results (typically program would
                             49 ;; hang or crash).
                             50 ;;  * Screen must be configured in Mode 0 (160x200 px, 16 colours)
                             51 ;;  * This function *disables interrupts* during main loop (character printing), and
                             52 ;; re-enables them at the end.
                             53 ;;  * This function *will not work from ROM*, as it uses self-modifying code.
                             54 ;;
                             55 ;; Details:
ASxxxx Assembler V02.00 + NoICE + SDCC mods  (Zilog Z80 / Hitachi HD64180), page 2.
Hexadecimal [16-Bits]



                             56 ;;    This function reads a character from ROM and draws it at a given byte-aligned 
                             57 ;; video memory location, that corresponds to the upper-left corner of the 
                             58 ;; character. As this function assumes screen is configured for Mode 0
                             59 ;; (160x200, 16 colours), it means that the character can only be drawn at even 
                             60 ;; pixel columns (0, 2, 4, 8...), because each byte contains 2 pixels in Mode 0.
                             61 ;;
                             62 ;;    The character will be drawn using preconfigured foreground (FG) and 
                             63 ;; background (BG) colours (by default BG=0, FG=1). Both colours can be set
                             64 ;; calling <cpct_setDrawCharM0> before calling this function. Colours get set
                             65 ;; by modifying and internal 4-byte array called _dc_2pxtableM0_. This means
                             66 ;; that once colours are set they stay. You may set them once and call 
                             67 ;; this function as many times as you want to draw with the same set of colours.
                             68 ;;
                             69 ;;    Next code example shows how to use this function in conjunction with
                             70 ;; <cpct_setDrawCharM0>,
                             71 ;; (start code)
                             72 ;;    void drawSomeCharacters(u8* pscreen) {
                             73 ;;       cpct_setDrawCharM0(5, 0);        // Foreground colour 5, Background 0
                             74 ;;
                             75 ;;       // Draw A, B, C consecutive
                             76 ;;       cpct_drawCharM0(pscreen + 0, 'A');
                             77 ;;       cpct_drawCharM0(pscreen + 4, 'B');
                             78 ;;       cpct_drawCharM0(pscreen + 8, 'C');
                             79 ;;
                             80 ;;       // Set video inverse (inverted colours from before)
                             81 ;;       cpct_setDrawCharM0(0, 5);        // Foreground colour 0, Background 5
                             82 ;;
                             83 ;;       // Draw D, E, F consecutive in inverse video
                             84 ;;       cpct_drawCharM0(pscreen + 16, 'D');
                             85 ;;       cpct_drawCharM0(pscreen + 20, 'E');
                             86 ;;       cpct_drawCharM0(pscreen + 24, 'F');
                             87 ;;    }
                             88 ;; (end code)
                             89 ;;
                             90 ;; Destroyed Register values: 
                             91 ;;    C bindings     - AF, BC, DE, HL
                             92 ;;    ASM bindings   - AF, BC, DE, HL, IX
                             93 ;;
                             94 ;; Required memory:
                             95 ;;    C bindings   - 35 bytes (+100 from cpct_drawCharM0_inner_asm = 135 bytes)
                             96 ;;    ASM bindings - 23 bytes (+100 from cpct_drawCharM0_inner_asm = 123 bytes)
                             97 ;;
                             98 ;; Time Measures:
                             99 ;; (start code)
                            100 ;;   Case     | microSecs | CPU Cycles 
                            101 ;; -------------------------------------
                            102 ;;   Best     |    880    |    3520
                            103 ;;   Worst    |    888    |    3552
                            104 ;; -------------------------------------
                            105 ;; Asm saving |    -25    |    -100
                            106 ;; -------------------------------------
                            107 ;; (end code)
                            108 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                            109 
                            110 .globl _myDrawCharInner
ASxxxx Assembler V02.00 + NoICE + SDCC mods  (Zilog Z80 / Hitachi HD64180), page 3.
Hexadecimal [16-Bits]



                            111 
ASxxxx Assembler V02.00 + NoICE + SDCC mods  (Zilog Z80 / Hitachi HD64180), page 4.
Hexadecimal [16-Bits]



                            112 .include "strings/strings.s"
                              1 ;;-----------------------------LICENSE NOTICE------------------------------------
                              2 ;;  This file is part of CPCtelera: An Amstrad CPC Game Engine 
                              3 ;;  Copyright (C) 2014-2015 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 ;### MODULE: Strings                                               ###
                             20 ;#####################################################################
                             21 ;### Routines to print and manage characters and strings           ###
                             22 ;#####################################################################
                             23 ;
                             24 .module cpct_strings
                             25 
                             26 ;;
                             27 ;; Compilation control directives
                             28 ;;
                             29 ;; If true, interrupts can be disabled to get function parameters faster
                     0000    30 .equ let_disable_interrupts_for_function_parameters, 0  
                             31 
                             32 ;;
                             33 ;; Constant values
                             34 ;;
                     3800    35 .equ char0_ROM_address, 0x3800   ;; Address where definition of character 0 starts in ROM
                     007F    36 .equ GA_port_byte,      0x7F     ;; 8-bit Port of the Gate Array
                             37 
                             38 ;;
                             39 ;; External values
                             40 ;;
                             41 .globl _cpct_mode_rom_status       ;; defined in cpc_mode_rom_status.s
ASxxxx Assembler V02.00 + NoICE + SDCC mods  (Zilog Z80 / Hitachi HD64180), page 5.
Hexadecimal [16-Bits]



                            113 
                            114 
   6BB3                     115 _myDrawCharM0::
                            116 
                            117    ;; Draw the character
   6BB3 7B            [ 4]  118    ld     a, e                       ;; [1] A = ASCII Value of the character
   6BB4 CD DB 6B      [17]  119    call   _myDrawCharInner  ;; [828/837] Does the actual drawing to screen
                            120 
   6BB7 C9            [10]  121    ret               ;; [3] Return
