Page 1 of 3

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

Posted: Sun Sep 10, 2017 10:22 am
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

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

Posted: Sun Sep 10, 2017 11:33 am
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

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

Posted: Sun Sep 10, 2017 12:39 pm
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

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

Posted: Sun Sep 10, 2017 6:59 pm
by sirmorris
Also,

Code: Select all

L0237:  LD      B,(HL)          ; (7) Note. Harmless Nonsensical Timing weight.
Is exactly it :D

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

Posted: Sun Sep 10, 2017 10:22 pm
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)

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

Posted: Sun Sep 10, 2017 10:35 pm
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

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

Posted: Sun Sep 10, 2017 10:49 pm
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

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

Posted: Mon Sep 11, 2017 6:55 am
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

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

Posted: Mon Sep 11, 2017 8:31 am
by sirmorris
I personally like the Ant. I shall call her Claire. Claire Sinclive.
claire.jpg
claire.jpg (12.75 KiB) Viewed 5946 times

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

Posted: Mon Sep 11, 2017 11:25 am
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*