I'll start the ball rolling with a pair of functions to change the case of strings as BBC BASIC does not have the UCASE$() or LCASE$() functions you may be familiar with from other dialects of BASIC.
String case conversion
Code: Select all
DIM CS 67:FOR Q%=0TO1:P%=CS
[OPT Q%*2
LD A,(IX+0):OR A:RET Z:LD C,A
.CS_LP LD L,(IX+2):LD H,(IX+3):LD A,(IX+1):CP 128:JR NZ,CS_NFIX:LD B,0:LD E,L:LD D,H
.CS_LEN LD A,(DE):CP 13:JR Z,CS_GO:INC B:INC DE:JR CS_LEN
.CS_NFIX LD B,(HL):INC HL:INC HL:LD E,(HL):INC HL:LD D,(HL):EX DE,HL:CP 129:JR NZ,CS_SKIP
.CS_GO LD A,(HL):.CS_MIN CP 97:JR C,CS_NX:.CS_MAX CP 123:JR NC,CS_NX:.CS_OFF SUB 32:LD (HL),A
.CS_NX INC HL:DJNZ CS_GO
.CS_SKIP INC IX:INC IX:INC IX:DEC C:RET Z:JR CS_LP:]
NEXT
DEFFN_UCASE$(s$)CS_MIN?1=97:CS_MAX?1=123:CS_OFF?1=32:CALLCS,s$:=s$
DEFFN_LCASE$(s$)CS_MIN?1=65:CS_MAX?1=91:CS_OFF?1=-32:CALLCS,s$:=s$
The easiest way to use the code is to call either the FN_UCASE$() or FN_LCASE$() function.
Code: Select all
PRINT FN_UCASE$("Hello, World!") : REM Prints "HELLO, WORLD!"
PRINT FN_LCASE$("BBC BASIC Z80") : REM Prints "bbc basic z80"
Code: Select all
A$="The"
B$="Quick"
DIM C 100:$C="Brown"
DIM D 100:$D="Fox"
CALL CS,A$,B$,$C,$D
Code: Select all
A$=FN_LCASE$(A$):CALL CS,B$,$C,$D
You must not modify the variables CS, CS_MIN, CS_MAX or CS_OFF. Doing so is likely to crash the calculator.