The Name Game: Difference between revisions

Line 2,881:
Steve!
</pre>
 
=={{header|Z80 Assembly}}==
{{trans|MIPS Assembly}}
<lang z80>;;;;;;;;;;;;;;;;;;; HEADER ;;;;;;;;;;;;;;;;;;;
read "\SrcCPC\winape_macros.asm"
read "\SrcCPC\MemoryMap.asm"
read "\SrcALL\winapeBuildCompat.asm"
;;;;;;;;;;;;;;;;;;; PROGRAM ;;;;;;;;;;;;;;;;;;;
 
org &1000
 
ld hl,namegame
ld de,name1
call PrintString_NameGame
 
 
ld hl,namegame
ld de,name2
call PrintString_NameGame
 
 
ld hl,namegame
ld de,name3
call PrintString_NameGame
ret ;return to basic
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintString_NameGame:
ld a,(hl)
or a ;compare to zero
ret z ;exit on null terminator
cp '?'
jr z,printNameAsIs
cp '%'
jr z,insertName
;else, just print what you see.
call &bb5a ;amstrad CPC kernel will print the contents of A as an ascii character
 
 
continue_NameGame:
inc hl
jr PrintString_NameGame
 
printNameAsIs:
ex de,hl
push hl
call PrintString
pop hl
ex de,hl
jr continue_NameGame
 
insertName:
push hl
dec hl
dec hl
dec hl
ld c,(hl) ;get the b in "bo-%", or the f in "fo-%", etc.
pop hl
ex de,hl ;swap to the name we wish to print
push hl
ld a,(hl)
cp c
jr z,dontPrintC
cp 'a'
jr z,beginsWithVowel
cp 'e'
jr z,beginsWithVowel
cp 'i'
jr z,beginsWithVowel
cp 'o'
jr z,beginsWithVowel
cp 'u'
 
ld a,c
call PrintChar
dontPrintC:
inc hl
call PrintString
pop hl
ex de,hl
jr continue_NameGame
 
beginsWithVowel:
;if name begins with vowel, we print C then the name as-is
ld a,c
call PrintChar
call PrintString ;print name as is
 
pop hl
ex de,hl
jr continue_NameGame
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintString:
ld a,(hl)
or a
ret z
call &BB5A
inc hl
jr PrintString
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
name1:
db "gary",0
name2:
db "earl",0
name3:
db "billy",0
 
namegame:
db "?, ?, bo-%",13,10
db "banana-fana fo-%",13,10
db "fee-fi-mo-%",13,10
db "?!",13,10,13,10
db 0</lang>
{{out}}
<pre>gary, gary, bo-bary
banana-fana fo-fary
fee-fi-mo-mary
gary!
 
earl, earl, bo-bearl
banana-fana fo-fearl
fee-fi-mo-mearl
earl!
 
billy, billy, bo-illy
banana-fana fo-filly
fee-fi-mo-milly
billy!</pre>
 
=={{header|zkl}}==
1,489

edits