Here's a quick z80 implementation of plain merthese with a quirk:
Code:
The quirk is with the T command; it sometimes underflows for some reason and I'm too tired to debug. The input comes from ANS. I don't bother to do any type checking so make sure ANS is actually a string =p
Code:
.nolist
#include "ti83plus.inc"
.list
.org $9D93
.db $bb, $6d
LD HL,OP1 ;Spell out the Ans variable
LD (HL),StrngObj ;...
INC HL ;...
LD (HL),tAns ;...
INC HL ;...
LD (HL),0 ;...
INC HL ;...
LD (HL),0 ;...
B_CALL(_FindSym) ;Load the pointer to a string in to DE
LD L,E ;Get the strings length in to HL
INC DE ;...
LD H,D ;...
INC DE ;...
ADD HL,DE ;Move HL to the end of the string
LD (HL),0 ;Null-terminate it
LD H,D ;Now we have our input in HL
LD L,E ;...
mainloop:
ld A,(HL)
cp $4D
call z,c_m
ld A,(HL)
cp $45
call z,c_e
ld A,(HL)
cp $52
call z,c_r
ld A,(HL)
cp $54
call z,c_t
ld A,(HL)
cp $48
call z,c_h
ld A,(HL)
cp 0
jp z,endh
inc HL
jp mainloop
c_m:
push HL
ld hl,str_merth
b_call(_putS)
pop HL
ret
c_e:
push HL
b_call(_NewLine)
pop HL
ret
c_r:
push HL
ld A,$20
b_call(_putC)
pop HL
ret
c_t:
push HL
b_call( _Random )
ld hl, (seed1+5)
ld A,L
and $0f
cp 13
jp c,checkfail0
sub 13
checkfail0:
inc B
ld B,A
loopstart:
push BC
b_call( _Random )
ld hl, (seed1+5)
ld A,L
and %00011111
cp 26
jp c,checkfail
sub 26
checkfail:
add A,$41
b_call(_putC)
pop BC
dec B
ld A,B
cp 0
jp nz,loopstart
pop HL
ret
c_h:
inc HL
ld A,(HL)
cp $48
jp Z,endh
or A
jp Z,endh
jp c_h
endh:
ret
str_merth:
.db "merth",0
.end
.end
The quirk is with the T command; it sometimes underflows for some reason and I'm too tired to debug. The input comes from ANS. I don't bother to do any type checking so make sure ANS is actually a string =p