Experiments with the Spectrum ROM Font

The place for codemasters or beginners to talk about programming any language for the Spectrum.
highrise
Manic Miner
Posts: 305
Joined: Fri Mar 20, 2020 11:29 pm

Re: Experiments with the Spectrum ROM Font

Post by highrise »

I made a few changes and with a bit of help this routine is a bit smaller (70 bytes I think). It seems that it's really only necessary to detect two bits next to each other.

Code: Select all

		device zxspectrum48
	org $c000

drawtext:
		ld hl,text
		ld de,18432+(3*32) ; start pos		
textloop:
		ld a,(hl)
		and a
		ret z
		push hl ; store text address
		ld bc,$3C00 ; rom font
		ld h,c
		add a,a
		ld l,a
		add hl,hl
		add hl,hl
		add hl,bc
		; keep screen address
		push de
		ld b,8
charloop:
		ld a,(hl) ; value
		ld c,a ; keep for later
		;look for 2 contiguous bits
bitloop:
		cp #C0
		jr nc,twobits
		add a,a
		jr nz,bitloop
		scf
		jr secondline
twobits: ; found two bits together, display previous line
		dec hl
		ld c,(hl) ; get next line above instead
		inc hl
secondline:
		ld a,c
		ld (de),a ; write
		call linedown
		ld a,(hl)
		ld (de),a
		call linedown
linedone:
		inc hl ; next byte
		djnz charloop
		pop de
		inc de
		pop hl
		inc hl
		jr textloop		
linedown:
		inc d		 ; one line down
		ld a,d
		and 7
	    ret nz
		ld a,e				   ; else add 32
	    add a,32
	    ld e,a
	    ret c
		ld a,d				 ; else sub 8 from h
		sub 8
		ld d,a
		ret
			
text:
	defb "Loading ",0x22,"ChuckieEgg",0x22," Please Wait",0
		savetap "bitfont.tap",drawtext
Image
highrise
Manic Miner
Posts: 305
Joined: Fri Mar 20, 2020 11:29 pm

Re: Experiments with the Spectrum ROM Font

Post by highrise »

by the way, if you want to know if a number has two contiguous bits in BASIC, I think something like this will work. Apologies as I haven't written anything in BASIC for a very long time.

LET A=PEEK(charaddr)
LET B=0
FOR I=1 to 7
IF A>191 THEN LET B=1
LET A=A+A
if A>255 THEN LET A=A-256
NEXT I

what this does is check for a number > 191, which means the last two bits of A are set. It then shifts A to the left by doubling it and removing the carry. If there are two bits next to each other then sooner or later the number will be greater than 191.

...I think!
User avatar
Kweepa
Manic Miner
Posts: 311
Joined: Sat Feb 03, 2018 6:14 pm
Location: Albuquerque, New Mexico

Re: Experiments with the Spectrum ROM Font

Post by Kweepa »

That is almost exactly what I did in the super slow version :)
Post Reply