Charlie's Red Ant - a ROM instruction that reads throughout memory

Discussion about ZX80 / ZX81 Software
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Charlie's Red Ant - a ROM instruction that reads throughout memory

Post by dr beep »

sirmorris wrote: Sun Sep 10, 2017 9:42 am
* Yes, the ZX81 appears to have a pet - a restless red 'ant' (escaped from the classic game?) which relentlessly patrols RAM from the end to the start. It's (most likely) a read instruction in the display routine. I've fleetingly looked into the emulation but I suspect it's a genuine access by the ROM rather than a bug. Kudos points to anyone tracking it down ;)
That is standard behaviour. It is the reason why my ZX81-emulator on the ZX Spectrum needs a reset button and RST 0 won't work. By heard first 5 bytes are overwritten. Since my emulator is coded in RAM the start gets corrupted.

Edit: This is a split and continuation from this post
Mark
Last edited by 1024MAK on Mon Sep 11, 2017 8:29 pm, edited 1 time in total.
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: Charlie's Red Ant - a ROM instruction that reads throughout memory

Post by Andy Rea »

The Red Ant seems to bee the Frames counter...

Code: Select all

0229 DISPLAY-1	LD	HL,(FRAMES)
		DEC	HL
022D DISPLAY-P	LD	A,+7F
		AND	H
		OR	L
		LD	A,H
		JR	NZ,0237,ANOTHER
		RLA
		JR	0239,OVER-NC
0237 ANOTHER	LD	B,(HL)
		SCF
0239 OVER-NC	LD	H,A
		LD	(FRAMES),HL
		RET	NC
specifically the line at $0237 LD B,(HL)

regards Andy
what's that Smell.... smells like fresh flux and solder fumes...
User avatar
1024MAK
Posts: 5103
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Charlie's Red Ant - a ROM instruction that reads throughout memory

Post by 1024MAK »

Geoff Wearmouth's former web site (on the Internet Archive Wayback Machine here) has:-

Code: Select all

; -----------------------
; THE 'MAIN DISPLAY' LOOP
; -----------------------
; This routine is executed once for every frame displayed.

;; DISPLAY-1
L0229:  LD      HL,($4034)      ; fetch two-byte system variable FRAMES.
        DEC     HL              ; decrement frames counter.

;; DISPLAY-P
L022D:  LD      A,$7F           ; prepare a mask
        AND     H               ; pick up bits 6-0 of H.
        OR      L               ; and any bits of L.
        LD      A,H             ; reload A with all bits of H for PAUSE test.

;   Note both branches must take the same time.

        JR      NZ,L0237        ; (12/7) forward if bits 14-0 are not zero 
                                ; to ANOTHER

        RLA                     ; (4) test bit 15 of FRAMES.
        JR      L0239           ; (12) forward with result to OVER-NC

; ---

;; ANOTHER
L0237:  LD      B,(HL)          ; (7) Note. Harmless Nonsensical Timing weight.
        SCF                     ; (4) Set Carry Flag.

; Note. the branch to here takes either (12)(7)(4) cyles or (7)(4)(12) cycles.

;; OVER-NC
L0239:  LD      H,A             ; (4)  set H to zero
        LD      ($4034),HL      ; (16) update system variable FRAMES 
        RET     NC              ; (11/5) return if FRAMES is in use by PAUSE 
                                ; command.
Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: Charlie's Red Ant - a ROM instruction that reads throughout memory

Post by sirmorris »

Also,

Code: Select all

L0237:  LD      B,(HL)          ; (7) Note. Harmless Nonsensical Timing weight.
Is exactly it :D
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Charlie's Red Ant - a ROM instruction that reads throughout memory

Post by dr beep »

sirmorris wrote: Sun Sep 10, 2017 6:59 pm Also,

Code: Select all

L0237:  LD      B,(HL)          ; (7) Note. Harmless Nonsensical Timing weight.
Is exactly it :D
So the fix should be LD H, (HL)
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: Charlie's Red Ant - a ROM instruction that reads throughout memory

Post by Andy Rea »

dr beep wrote: Sun Sep 10, 2017 10:22 pm
sirmorris wrote: Sun Sep 10, 2017 6:59 pm Also,

Code: Select all

L0237:  LD      B,(HL)          ; (7) Note. Harmless Nonsensical Timing weight.
Is exactly it :D
So the fix should be LD H, (HL)
i think that would break the frames counter all together, since as hl is stored after this instruction
what's that Smell.... smells like fresh flux and solder fumes...
User avatar
1024MAK
Posts: 5103
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Charlie's Red Ant - a ROM instruction that reads throughout memory

Post by 1024MAK »

Fix?
Why, what's broken?
I can't see the harm in that bit of code reading throughout memory.
You never know, it may help a bit with the refresh of any dynamic RAM in a RAM pack...

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Charlie's Red Ant - a ROM instruction that reads throughout memory

Post by dr beep »

Andy Rea wrote: Sun Sep 10, 2017 10:35 pm
dr beep wrote: Sun Sep 10, 2017 10:22 pm
sirmorris wrote: Sun Sep 10, 2017 6:59 pm Also,

Code: Select all

L0237:  LD      B,(HL)          ; (7) Note. Harmless Nonsensical Timing weight.
Is exactly it :D
So the fix should be LD H, (HL)
i think that would break the frames counter all together, since as hl is stored after this instruction
No, see command after SCF
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: Charlie's Red Ant - a ROM instruction that reads throughout memory

Post by sirmorris »

I personally like the Ant. I shall call her Claire. Claire Sinclive.
claire.jpg
claire.jpg (12.75 KiB) Viewed 5728 times
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: Charlie's Red Ant - a ROM instruction that reads throughout memory

Post by Andy Rea »

dr beep wrote: Mon Sep 11, 2017 6:55 am
Andy Rea wrote: Sun Sep 10, 2017 10:35 pm
dr beep wrote: Sun Sep 10, 2017 10:22 pm

So the fix should be LD H, (HL)
i think that would break the frames counter all together, since as hl is stored after this instruction
No, see command after SCF
Oops you are right my bad.... *runs off in shame*
what's that Smell.... smells like fresh flux and solder fumes...
Post Reply