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

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

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

Post by dr beep » Sun Sep 10, 2017 9:22 am

sirmorris wrote:
Sun Sep 10, 2017 8: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 7:29 pm, edited 1 time in total.

User avatar
Andy Rea
Posts: 1243
Joined: Fri May 09, 2008 1:48 pm
Location: notts UK

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

Post by Andy Rea » Sun Sep 10, 2017 10:33 am

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
6 x ZX81, 1 x TS1500 , 1 x +3e, 1 x timex 2040 printer, 1 x timex 2020 cassette deck, siclair printer and some spectrum

User avatar
1024MAK
Posts: 1717
Joined: Mon Sep 26, 2011 9: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 » Sun Sep 10, 2017 11:39 am

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

User avatar
sirmorris
Posts: 2597
Joined: Thu May 08, 2008 4:45 pm
Location: oxon, uk

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

Post by sirmorris » Sun Sep 10, 2017 5:59 pm

Also,

Code: Select all

L0237:  LD      B,(HL)          ; (7) Note. Harmless Nonsensical Timing weight.
Is exactly it :D
--=== ZXpand+ ... A more moderner all-in-one upgrade solution for ZX81 ===--
* SD/MMC storage * 32K Hires-capable RAM * AY sound chip * Joystick port * Serial *
* BASIC enhancements - plug & play * Reset button * Auto-boot facility *

dr beep
Posts: 1043
Joined: Thu Jun 16, 2011 7:35 am
Location: Boxmeer

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

Post by dr beep » Sun Sep 10, 2017 9:22 pm

sirmorris wrote:
Sun Sep 10, 2017 5: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: 1243
Joined: Fri May 09, 2008 1:48 pm
Location: notts UK

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

Post by Andy Rea » Sun Sep 10, 2017 9:35 pm

dr beep wrote:
Sun Sep 10, 2017 9:22 pm
sirmorris wrote:
Sun Sep 10, 2017 5: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
6 x ZX81, 1 x TS1500 , 1 x +3e, 1 x timex 2040 printer, 1 x timex 2020 cassette deck, siclair printer and some spectrum

User avatar
1024MAK
Posts: 1717
Joined: Mon Sep 26, 2011 9: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 » Sun Sep 10, 2017 9:49 pm

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

dr beep
Posts: 1043
Joined: Thu Jun 16, 2011 7:35 am
Location: Boxmeer

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

Post by dr beep » Mon Sep 11, 2017 5:55 am

Andy Rea wrote:
Sun Sep 10, 2017 9:35 pm
dr beep wrote:
Sun Sep 10, 2017 9:22 pm
sirmorris wrote:
Sun Sep 10, 2017 5: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

User avatar
sirmorris
Posts: 2597
Joined: Thu May 08, 2008 4:45 pm
Location: oxon, uk

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

Post by sirmorris » Mon Sep 11, 2017 7:31 am

I personally like the Ant. I shall call her Claire. Claire Sinclive.
claire.jpg
claire.jpg (12.75 KiB) Viewed 337 times
--=== ZXpand+ ... A more moderner all-in-one upgrade solution for ZX81 ===--
* SD/MMC storage * 32K Hires-capable RAM * AY sound chip * Joystick port * Serial *
* BASIC enhancements - plug & play * Reset button * Auto-boot facility *

User avatar
Andy Rea
Posts: 1243
Joined: Fri May 09, 2008 1:48 pm
Location: notts UK

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

Post by Andy Rea » Mon Sep 11, 2017 10:25 am

dr beep wrote:
Mon Sep 11, 2017 5:55 am
Andy Rea wrote:
Sun Sep 10, 2017 9:35 pm
dr beep wrote:
Sun Sep 10, 2017 9: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*
6 x ZX81, 1 x TS1500 , 1 x +3e, 1 x timex 2040 printer, 1 x timex 2020 cassette deck, siclair printer and some spectrum

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest