Add GPL3 notices and a copy of the GPL3.
[zx-fizzbuzz] / fizzbuzz.s
index 58d4928..57f262d 100644 (file)
@@ -1,21 +1,25 @@
 ;;; -*-asm-*-
+;;; (c) 2021 Mark Wooding
 ;;;
 ;;; Best not to ask why.
 
-       org     0xf000
-
-print_a: equ   0x10
-tvflag:        equ     0x5c3c
-
-entry:
-       ;; Initialize the buffer.
-       ld      a, 1
-       ld      (buf), a
-       ld      (len), a
-
-       ;; Use the main screen.
-       xor     a
-       ld      (tvflag), a
+;;;----- Licensing notice ---------------------------------------------------
+;;;
+;;; This file is part of ZX Fizzbuzz.
+;;;
+;;; ZX Fizzbuzz is free software: you can redistribute it and/or modify it
+;;; under the terms of the GNU Lesser General Public License as published
+;;; by the Free Software Foundation; either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; ZX Fizzbuzz is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;;; Lesser General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU Lesser General Public
+;;; License along with ZX Fizzbuzz.  If not, see
+;;; <https://www.gnu.org/licenses/>.
 
        ;; Look at the buffer and decide what to do.
 again: ld      e, 0
@@ -42,7 +46,7 @@ mod3_1:       djnz    mod3
        call    squish
        call    squish
 
-       cp      0
+       and     a
        jr      z, prfizz
        cp      3
        jr      z, prfizz
@@ -68,14 +72,12 @@ prbuzz:     ld      hl, buzz
 
        ;; Not a multiple of five.  Skip ahead if it was a multiple of three.
 nobuzz:        ld      a, e
-       cp      0
+       and     a
        jr      nz, prnl
 
        ;; OK, so just print the value.
-       ld      a, (len)
-       ld      b, 0
-       ld      c, a
        ld      hl, buf - 1
+       ld      bc, (len)
        add     hl, bc
        ld      b, c
 
@@ -86,12 +88,12 @@ nobuzz:     ld      a, e
        srl     a
        srl     a
        jr      z, skiplz
-       or      0x30
-       rst     print_a
+       fixdig
+       print_a
 skiplz:        ld      a, d
        and     0x0f
-       or      0x30
-       rst     print_a
+       fixdig
+       print_a
        dec     b
        jr      z, prnl
 
@@ -102,17 +104,17 @@ prdig:    dec     hl
        srl     a
        srl     a
        srl     a
-       or      0x30
-       rst     print_a
+       fixdig
+       print_a
        ld      a, d
        and     0x0f
-       or      0x30
-       rst     print_a
+       fixdig
+       print_a
        djnz    prdig
 
        ;; Print the newline.
-prnl:  ld      a, ' '
-       rst     print_a
+prnl:  ld      a, spc
+       print_a
 
        ;; Increment the counter.
        ld      hl, buf
@@ -128,14 +130,9 @@ incr:      ld      a, (hl)
        djnz    incr
 
        ;; Carry out.
-       ld      a, (len)
-       ld      b, 0
-       ld      c, a
-       ld      hl, buf
-       add     hl, bc
        ld      (hl), 1
-       inc     a
-       ld      (len), a
+       ld      hl, len
+       inc     (hl)
        jp      again
 
 squish:
@@ -153,14 +150,13 @@ squish:
 print:
        ;; Print the string at hl.
        ld      a, (hl)
-       cp      0
+       endstrp
        ret     z
-       rst     print_a
+       print_a
        inc     hl
        jr      print
 
-fizz:  defb    "fizz", 0
-buzz:  defb    "buzz", 0
-
-len:   defb    0
-buf:   defs    256
+       ;; Initial state.  The buffer notionally continues for another 254
+       ;; bytes, but there's no point in including them in the image.
+len:   db      1, 0
+buf:   db      1