git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

gbdk-lib/libc/asm/z80/__uitobcd.s

      1 ;--------------------------------------------------------------------------
      2 ;  __uitobcd.s
      3 ;
      4 ;  Copyright (C) 2020, Sergey Belyashov
      5 ;
      6 ;  This library is free software; you can redistribute it and/or modify it
      7 ;  under the terms of the GNU General Public License as published by the
      8 ;  Free Software Foundation; either version 2, or (at your option) any
      9 ;  later version.
     10 ;
     11 ;  This library is distributed in the hope that it will be useful,
     12 ;  but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 ;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     14 ;  GNU General Public License for more details.
     15 ;
     16 ;  You should have received a copy of the GNU General Public License 
     17 ;  along with this library; see the file COPYING. If not, write to the
     18 ;  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
     19 ;   MA 02110-1301, USA.
     20 ;
     21 ;  As a special exception, if you link this library with other files,
     22 ;  some of which are compiled with SDCC, to produce an executable,
     23 ;  this library does not by itself cause the resulting executable to
     24 ;  be covered by the GNU General Public License. This exception does
     25 ;  not however invalidate any other reasons why the executable file
     26 ;   might be covered by the GNU General Public License.
     27 ;--------------------------------------------------------------------------
     28 
     29 	.area   _CODE
     30 
     31 	.globl ___uitobcd
     32 ;
     33 ; void __uitobcd (unsigned int v, unsigned char bcd[3])
     34 ; __uitobcd converts v to BCD representation to the bcd.
     35 ; bcd[] will contain BCD value.
     36 ;
     37 ___uitobcd:
     38 	push	ix
     39 	ld	ix, #0
     40 	add	ix, sp
     41 ;
     42 	ld	bc, #0x1000
     43 	ld	d, c
     44 	ld	e, c
     45 	ld	l, 4 (ix)
     46 	ld	h, 5 (ix)
     47 ;
     48 ;--- begin speed optimization
     49 ;
     50 	ld	a, h
     51 	or	a, a
     52 	jr	NZ, 100$
     53 ;
     54 	ld	h, l
     55 	srl	b
     56 ;
     57 ;--- end speed optimization
     58 ;
     59 ; HL - binary value
     60 ; CDE - future BCD value
     61 ; B - bits count (16)
     62 100$:
     63 	add	hl, hl
     64 	ld	a, e
     65 	adc	a, a
     66 	daa
     67 	ld	e, a
     68 	ld	a, d
     69 	adc	a, a
     70 	daa
     71 	ld	d, a
     72 	ld	a, c
     73 	adc	a, a
     74 	daa
     75 	ld	c, a
     76 	djnz	100$
     77 ;
     78 	ld	l, 6 (ix)
     79 	ld	h, 7 (ix)
     80 	ld	(hl), e
     81 	inc	hl
     82 	ld	(hl), d
     83 	inc	hl
     84 	ld	(hl), c
     85 ;
     86 	pop	ix
     87 	ret

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.