Let's calculate! - renewed arithmetic routines

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
User avatar
siggi
Posts: 849
Joined: Thu May 08, 2008 9:30 am
Location: Dauernheim, Germany
Contact:

Re: Let's calculate! - renewed arithmetic routines

Post by siggi » Sun Jun 10, 2018 8:23 pm

Maybe Pokemon could fix that in his ZxMore Master program? He seems to be busy at the moment, but meanwhile a "patch" for running your new ROMs at ZxMore would help? Changing some bytes in the beginning of the ROM should not be too complicated (man POKE ;) )

Siggi

Edit: I have sent a PM to Pokemon
My ZX81 web-server: online since 2007
http://zx81-siggi.endoftheinternet.org/index.html

User avatar
siggi
Posts: 849
Joined: Thu May 08, 2008 9:30 am
Location: Dauernheim, Germany
Contact:

Re: Let's calculate! - renewed arithmetic routines

Post by siggi » Mon Jun 11, 2018 3:07 pm

olofsen wrote:
Sun Jun 10, 2018 9:29 am
The LD HL,($400C) in the NMI routine is three bytes earlier, at $0071, so that there is no display.
If that is the only reason: maybe it would be sufficient to leave the "NMI-CONT" routine at its original place? That would not waste time, only some bytes space ...

Siggi
My ZX81 web-server: online since 2007
http://zx81-siggi.endoftheinternet.org/index.html

olofsen
Posts: 153
Joined: Wed Jan 08, 2014 12:29 pm

Re: Let's calculate! - renewed arithmetic routines

Post by olofsen » Mon Jun 11, 2018 5:54 pm

While the NMI routine is shorter and faster, NMI-CONT is (three bytes) longer and also slower. I guess it will be hard for the ZXmaster to check for the number of T states taken by the original or modified NMI-CONT...

User avatar
zsolt
Posts: 179
Joined: Wed Apr 20, 2011 11:43 am
Location: Fót, Hungary

Re: Let's calculate! - renewed arithmetic routines

Post by zsolt » Mon Jun 11, 2018 7:57 pm

Hi,
This is not so simple:

Code: Select all

; ------------------------------------
; THE 'NON MASKABLE INTERRUPT' ROUTINE
; ------------------------------------
;
;   ( It takes 29 clock cycles while incrementing towards zero - it was 32TS). 

;; NMI
L0066:
	  EX AF,AF'			; (4) switch in the NMI's copy of the 
					;		accumulator.
	  INC A				; (4) increment.
;
; JP M,L006D (10) was removed for faster NMI-service:  the user application gets +3TS/NMI
;
	  JR Z,L006C			; (12) forward to NMI-CONT
					; when line count has incremented to zero.
;
;; NMI-RET				 (7!!!) else
;				
	  EX AF,AF'			; (4)  switch out the incremented line counter
					; or test result $80
	  RET 				; (10) return to User application for a while.
; ---
;   This branch is taken when the 55 (or 31) lines have been drawn.

;; NMI-CONT (its address was L006F) 
L006C:
	  EX AF,AF'			; (4) restore the main accumulator.

	  PUSH AF			; (11) *  Save Main Registers
	  PUSH BC			; (11) **
	  PUSH DE			; (11) ***
	  PUSH HL			; (11) ****

;   the next set-up procedure is only really applicable when the top set of 
;   blank lines have been generated.

	  LD HL,($400C)			; (16) fetch start of Display File from D_FILE
					; points to the HALT at beginning.
	  SET 7,H			; (8) point to upper 32K 'echo display file'

	  HALT				; (1) HALT synchronizes with NMI.  
					; Used with special hardware connected to the
					; Z80 HALT and WAIT lines to take 1 clock cycle.

	  OUT ($FD),A			; (11) Stop the NMI generator.

	  JP IX_to_PC			; (10) Delay because of the removed 'JP M,...'
IX_to_PC
	  JP (IX) 			; (8) forward to L0281 (after top) or L028F
In the original code (after the 'HALT') the NMI service requires 4+4+10(!)+7+4+10=39 T states, because A'=1 (positive, nonzero).
In case of the patched routine: 4+4+7+4+10=29 T states. So the 'JP IX_to_PC' is necessary for the correct displaying.
Is it possible to see the "master"-code?

Zsolt
ZX81 (8K), ENTERPRISE 128, [ZX SPECTRUM (48K,+,+128K,+2,+2A), TS1000, TS1500, TS2068, Cambridge Z88, PRIMO A64 (red)]

User avatar
siggi
Posts: 849
Joined: Thu May 08, 2008 9:30 am
Location: Dauernheim, Germany
Contact:

Re: Let's calculate! - renewed arithmetic routines

Post by siggi » Tue Jun 12, 2018 11:45 am

Hi Zsolt
zsolt wrote:
Mon Jun 11, 2018 7:57 pm
Is it possible to see the "master"-code?
Pokemon has not published this code, so currently the answer is NO. But I will ask Pokemon (but he is very busy at the moment).

My assumption is, that the master code "catches" the NMI and executes it in its own ROM (to check for task switch conditions and for double-shift-keys).
After that is done it probably jumps back to the application ROM to execute the application NMI routine (if necessary). The well known address in the ZX81 ROM is NMI-CONT at L006F.

So maybe moving NMI-CONT from $006C to $006F would solve that problem?
Maybe the display timing would be a little bit distorted (caused by the different runtime in SG81G, which the master software does not expect), but maybe the display would be back again?

Code: Select all

;; NMI
L0066:
	  EX AF,AF'			; (4) switch in the NMI's copy of the 
					;		accumulator.
	  INC A				; (4) increment.
;
; JP M,L006D (10) was removed for faster NMI-service:  the user application gets +3TS/NMI
;
	  JR Z,L006C			; (12) forward to NMI-CONT
					; when line count has incremented to zero.
;
;; NMI-RET				 (7!!!) else
;				
	  EX AF,AF'			; (4)  switch out the incremented line counter
					; or test result $80
	  RET 				; (10) return to User application for a while.
; ---
;   This branch is taken when the 55 (or 31) lines have been drawn.
Add here some NOPs (which will NOT be executed!) to move NMI-CONT down of $006F ..

Code: Select all

;; NMI-CONT (its address was L006F) 
L006C:
	  EX AF,AF'			; (4) restore the main accumulator.

	  PUSH AF			; (11) *  Save Main Registers
	  PUSH BC			; (11) **
	  PUSH DE			; (11) ***
	  PUSH HL			; (11) ****

;   the next set-up procedure is only really applicable when the top set of 
;   blank lines have been generated.

	  LD HL,($400C)			; (16) fetch start of Display File from D_FILE
					; points to the HALT at beginning.
	  SET 7,H			; (8) point to upper 32K 'echo display file'

	  HALT				; (1) HALT synchronizes with NMI.  
					; Used with special hardware connected to the
					; Z80 HALT and WAIT lines to take 1 clock cycle.

	  OUT ($FD),A			; (11) Stop the NMI generator.

	  JP IX_to_PC			; (10) Delay because of the removed 'JP M,...'
IX_to_PC
	  JP (IX) 			; (8) forward to L0281 (after top) or L028F
Currently I do not have setup an environment to compile (and modify for own tests) your ROM ....

Siggi
My ZX81 web-server: online since 2007
http://zx81-siggi.endoftheinternet.org/index.html

User avatar
zsolt
Posts: 179
Joined: Wed Apr 20, 2011 11:43 am
Location: Fót, Hungary

Re: Let's calculate! - renewed arithmetic routines

Post by zsolt » Tue Jun 12, 2018 3:58 pm

HI,
:D :D :D I think I've found a better solution :D :D :D
sg81g_mod.png
though a bit slower (-0.1%)
sg81g_mod.png (4.68 KiB) Viewed 861 times
Please help in testing,
Zsolt
Attachments
SG81_G_mod.zip
(76.23 KiB) Downloaded 20 times
ZX81 (8K), ENTERPRISE 128, [ZX SPECTRUM (48K,+,+128K,+2,+2A), TS1000, TS1500, TS2068, Cambridge Z88, PRIMO A64 (red)]

User avatar
siggi
Posts: 849
Joined: Thu May 08, 2008 9:30 am
Location: Dauernheim, Germany
Contact:

Re: Let's calculate! - renewed arithmetic routines

Post by siggi » Tue Jun 12, 2018 7:13 pm

Hi Zsolt,
now the display is working :mrgreen:
But it is a little bit disturbed: the first 3 pixel lines are shifted right:
IMG_0703_640x480.JPG
IMG_0704_640x480.JPG

Thus there seems to be a small timing difference.

Siggi
My ZX81 web-server: online since 2007
http://zx81-siggi.endoftheinternet.org/index.html

User avatar
zsolt
Posts: 179
Joined: Wed Apr 20, 2011 11:43 am
Location: Fót, Hungary

Re: Let's calculate! - renewed arithmetic routines

Post by zsolt » Tue Jun 12, 2018 7:27 pm

Hi Siggi,

How it looks using this sgmore?
Thx,
Zsolt
ZX81 (8K), ENTERPRISE 128, [ZX SPECTRUM (48K,+,+128K,+2,+2A), TS1000, TS1500, TS2068, Cambridge Z88, PRIMO A64 (red)]

User avatar
siggi
Posts: 849
Joined: Thu May 08, 2008 9:30 am
Location: Dauernheim, Germany
Contact:

Re: Let's calculate! - renewed arithmetic routines

Post by siggi » Tue Jun 12, 2018 7:42 pm

Using the SGMORE.ROM the display is OK (no shifted pixels).

I think I should use this rom for further math tests, until Pokemon has time to help.

Siggi
My ZX81 web-server: online since 2007
http://zx81-siggi.endoftheinternet.org/index.html

olofsen
Posts: 153
Joined: Wed Jan 08, 2014 12:29 pm

Re: Let's calculate! - renewed arithmetic routines

Post by olofsen » Wed Jun 13, 2018 11:24 pm

The attached version is Zsolt's latest, with a first try to make the BASIC LOAD and SAVE commands work using USB, even in compatibility mode. In the filename, only A-Z are allowed, and .P is added automatically.
Attachments
sgmls.zip
(6.83 KiB) Downloaded 18 times

Post Reply