;;; Subroutine to add bcd
;;; Call: HL: Base of first number
;;; DE: Base of second number
;;; B: Length of bigger number
;;; Result: HL+DE in IY register
;;; Code borrowed from http://www.mct.net/download/zilog/z80cpu.pdf and http://icarus.ticalc.org/articles/z80_faq.html
;;; and banged on til it actually worked
Add_BCD:
ld A, B ; Check length
or A
ret z ; Get out if we've finished
and A ; clear carry? wat
addloop:
ld A, (DE) ; get second-number byte
add A, (HL) ; adc it to first
daa ; BCDify
ld (IY+0), A ; save back
dec HL ; next number
dec DE
inc IY ;grr
djnz addloop ; continue until all bytes summed
ret