0

I'm "emulating" the Nintendo Gameboy logo demo in an Amstrad CPC Emulator (WinApe) in mode video 1, encoded in assembly for the Z80.

When I "paint" only the logo (until the line 25 and comment the others lines in main loop), It paints good, but when I try to create the animation (paint, erase, paint, etc.), appears some "garbage" pixels not painted previously.

This is my code:

;; testlogo.asm
;;
.cls    equ &BC14   ;; Clear screen
org &4000
run &4000
;;
call cls
ld hl, #c020        ;; initial position of video
ld a,#05        ;; times logo down      
call loop1      ;; call main loop
jr $
;;
loop1:
   ld bc,logo       ;; initial position of logo
                    ;; bc remains until logo
                    ;; is fully painted
   ld e,#08
   call loop_paint
   ld de, #c050
   add hl,de
                    ;; the second 8 row group pixels
   ld e,#08
   call loop_paint
   ld de,#c050
   add hl,de
                    ;; wait until 'down' logo
   ld b,#cc
   call wait
   ld de, #ff60     ;; recover hl position 
                    ;; to 'erase' upward logo
   add hl,de
   ld e,#08
   call loop_erase1 ;; call to 'erase' pixels
                    ;; from logo
                    ;; (it could be optimized in one calling)
   ld de, #c050
   add hl,de
   ld e,#08
   call loop_erase1
   ld de, #c050
   add hl,de
   dec a
jr nz, loop1
ret
;;
loop_paint:
   ld d,#0b
   call loop_logo   ;; call to paint logo
   push bc          ;; save bc in stack
                    ;; for using adding in bc
   ld bc,#07f5      ;; 800 for next row (minus) 0b last column
   add hl,bc
   pop bc 
   dec e
jr nz, loop_paint
ret
;;
loop_logo:          ;; finally 'paints' logo
                    ;; in memory video
   push af          ;; save 'a' register
                    ;; because is used
                    ;; as counter in main loop
   ld a, (bc)
   ld (hl), a
   pop af
   inc l
   inc c
   dec d
jr nz,loop_logo
ret
;;
loop_erase1:        ;; row by row in mode 1 video
   ld d,#0b     
   call loop_erase2
   ld bc,#07f5      ;;800 next row - 0b last column
   add hl,bc
   dec e
jr nz,loop_erase1
ret
;;
loop_erase2:        ;; column by column in mode 1 video
   ld (hl), #00 
   inc l
   dec d
jr nz,loop_erase2
ret
;;
logo:
db #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00
db #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00
db #00, #FF, #FF, #FF, #FF, #FF, #FF, #FF, #FF, #88, #00
db #33, #FF, #FF, #FF, #FF, #FF, #FF, #FF, #FF, #EE, #00
db #33, #F0, #F0, #F0, #F0, #F0, #F0, #F0, #F0, #E6, #00
db #FC, #F0, #F0, #F0, #F0, #F0, #F0, #F0, #F0, #F1, #88
db #FD, #F5, #FB, #F5, #FE, #FF, #F3, #F3, #FB, #FD, #88
db #FD, #F9, #FB, #FD, #F0, #F8, #F4, #FA, #F1, #F1, #88
db #FD, #F1, #FA, #FD, #F6, #FF, #F4, #FB, #F9, #F1, #88
db #FD, #F9, #FA, #F5, #F2, #F1, #F4, #FA, #F1, #F1, #88
db #FD, #F5, #FA, #F5, #FE, #FF, #F3, #F2, #F1, #F1, #88
db #FC, #F0, #F0, #F0, #F0, #F0, #F0, #F0, #F0, #F1, #88
db #33, #F0, #F0, #F0, #F0, #F0, #F0, #F0, #F0, #E6, #00
db #33, #FF, #FF, #FF, #FF, #FF, #FF, #FF, #FF, #EE, #00
db #00, #FF, #FF, #FF, #FF, #FF, #FF, #FF, #FF, #88, #00
db #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00
ret
;;
wait:
  halt
  dec b
jr nz,wait
ret

And this is the result in the emulator window:

enter image description here

Last line of logo must be in red only and no contains another color, logo is in red and yellow.

reymagnus
  • 327
  • 2
  • 17
  • 2
    Did you check that you have no 8-bit overflow? All your pointer increments are only 8 bit wide. Why don't you use 16-bit increments for the pointers? – the busybee Sep 07 '22 at 09:16

1 Answers1

3

Problem was resolved when I change from 8 to 16-bit increments for the pointers: "inc l" for "inc hl", "inc c" for "inc bc".

Thanks to "the busybee" user.

enter image description here

reymagnus
  • 327
  • 2
  • 17
  • Just a little tip, you can actually use 8-bit increments if you align your table so that its beginning address has a low byte of `00`. Then, as long as your table is less than 256 bytes in size you only need 8-bit increments, and you also only need the high byte of its base pointer. This can easily triple your lookup speed if done properly. – puppydrum64 Feb 01 '23 at 15:25