So it occurred to me that if I stuck with my slightly less efficient bottom line message display code (i.e. not using lddr) I could use kmurta's cunning plan of rotating the message but with a much more simplified message rotating function.
Code: Select all
main
ld hl,happyBirthday ;load the address of the message
ld de,(D_FILE) ;load the base of screen memory
inc de ;increase it by one to bypass the $76
ld bc,12 ;ready for 12 loops
ldir ;transfer HL to DE 12 times and increase both accordingly
ex de,hl ;put HL into DE (HL was the message position)
ld b,4 ;prepare to loop 4 times
dec hl ;decrease HL (screen location) by 1 to step back from the $76 char
rightVertical
push de ;save the character position
ld de,13 ;load 13 (for the next line)
add hl,de ;add to HL
pop de ;get the message position back
ld a,(de) ;load the character into A
ld (hl),a ;save it to HL
inc de ;increase the character position
djnz rightVertical ;repeat until B = 0
dec hl ;decrease HL (screen location) by 1 to step back from the $76 char
ld b,11 ;prepare for 11 loops
lastLine
ld a,(de) ;load the current character into A
ld (hl),a ;save to the screen
dec hl ;decrease the screen position (as we are going backwards)
inc de ;increase character position
djnz lastLine ;repeat until B = 0
ld b,3 ;get ready for the left vertical
inc hl ;increase the screen position by 1 as we have gone 1 too far to the left and wrapped to the line above
leftVertical
push de ;save the character position
ld de,13 ;load 13 (for the next line)
sbc hl,de ;subtract it to move up a line in memory
pop de ;get the character pos back
ld a,(de) ;load the character
ld (hl),a ;save it to the screen
inc de ;next character
djnz leftVertical ;repeat until B = 0
delayCode
ld hl,FRAMES ;fetch timer
ld a,(hl) ;load into A
sub 10 ;wait 10 full frames (0.1 of a second)
delayLoop
cp (hl) ;compare HL to 0
jr nz,delayLoop ;if not 0 then repeat until it is
shuffleMessage
ld a, (happyBirthday) ;load the first character of the message
push af ;save the first character of the message
ld hl, happyBirthday ;load the address of the message
inc hl ;increase by one to get the second char
ld de, happyBirthday ;load the start of the message
ld bc, 29 ;number of times to loop
ldir ;load HL (char 2) into DE (char 1) and repeat
pop af ;get char 1 back
ld (de),a ;out it at the end of the string
jr main ;repeat
happyBirthday
DEFB _H,_A,_P,_P,_Y,__,_B,_I,_R,_T,_H,_D,_A,_Y,__,_R,_A,_F,_F,_A,_E,_L,_E,__,_C,_E,_C,_C,_O,__
Now in a total of 130 bytes!
I can't feel any real sense of achievement though as I would have never have thought of rotating the message as opposed to some complex process of extracting the correct character based on rotation phase and character position. Sometimes I guess I overthink things.
