New program: Analyze Z80 databus safely!

Page 1/2
| 2

By NYYRIKKI

Enlighted (6067)

NYYRIKKI's picture

28-09-2004, 01:52

Ok, here is once again something that you really don't need! Smile

This program will read value from Z80 databus during one SINGLE interrupt. This means, that you can now safely monitor databus with any hardware without worry of your computer hanging.

This program might not be size optimized too well, but I'm pretty proud of the result anyway. Feel free to use it how ever you like, but what ever you do, do not ask how it works. :9

Good thing is, that this needs only about 5KB of memory because of very tight fitted self generating code.

; DATABUS.GEN Ver 2.0 for MSX homecomputers (Made By: NYYRIKKI)
;
; This program reads a value from databus when Z80 leaves databus control to peripherals.
;
; Usage from MSX-BASIC:
;
;	BLOAD "DATABUS.BIN",R:PRINT USR(0)
;
;
; Ps. Unmodifyed MSX should give value #FF allways. (according to my knowledge)
;
; Changes:
;
;  This new version will need only one interrupt. 
;  You can not hang your computer anymore by changeing databus value between interrupts.
;-----------------------------------------------------------------------------------------

USR:	EQU #F7F8
USR0:	EQU #F39A

	DEFB #FE
	DEFW BEGIN
	DEFW END
	DEFW START

	ORG #B000

BEGIN:
START:
	LD HL,CODE
	LD (USR0),HL
	RET
CODE:
	DI
	LD HL,#BF00
	LD BC,0

NEXT:
	LD A,C
	ADD A,B
	CP #10
	JP NC,NOMORE

	LD (HL),A
	INC HL

	CP #F
	JP Z,SKIP
	LD (HL),B
	INC HL

SKIP:
	INC C
	LD A,C
	CP #10
	JP NZ,NEXT

NOMORE:
	LD C,0
	INC B
	LD A,B
	CP #10
	JP NZ,NEXT

	LD (HL),#C0

	LD HL,#BF00
	LD DE,#BE00
	LD BC,0

FIXL:
	LD A,(HL)
	LD C,A
	OR #C0
	LD (HL),A
	INC HL
	LD A,(HL)
	RLCA
	RLCA
	RLCA
	RLCA
	OR C
	LD E,A
	EX DE,HL
	LD A,E
	DEC A
	LD (HL),A
	EX DE,HL
	DJNZ FIXL

	LD HL,#C0C0
	LD DE,#C0C1
	LD B,#F

MAKEPROG:
	PUSH BC
	LD BC,#F
	PUSH HL
	PUSH DE
	LD (HL),4	;INC B
	LDIR
	LD (HL),#CD	;CALL
	INC HL
	LD DE,CALCUT
	LD (HL),E
	INC HL
	LD (HL),D
	POP DE
	POP HL
	POP BC
	INC H
	INC D
	DJNZ MAKEPROG

	LD A,#BF
	LD I,A

	IM 2
	EI
	NOP
	HALT	; Any interrupt will be accepted.

	IM 1
	LD L,A
	LD H,#BE
	LD A,(HL)
	LD (USR),A
	XOR A
	LD (USR+1),A
	RET


CALCUT:
	POP AF
	AND #F
	RLCA
	RLCA
	RLCA
	RLCA
	OR B
	XOR #F
	RETI

END:
Login or register to post comments

By ricbit

Champion (438)

ricbit's picture

28-09-2004, 01:58

Nice program!


; Ps. Unmodifyed MSX should give value #FF allways. (according to my knowledge)

Some models don't give #FF always. This is only true for machines with pull-up resistores in their data bus. The Expert 1.0, for instance, doesn't have, so values as random. I have seen some programs using IM 2 lock due to this bug/feature of Expert.

By NYYRIKKI

Enlighted (6067)

NYYRIKKI's picture

28-09-2004, 20:28

Oh, I didn't know that, but cool, then there is at least one usage for this program. You can record noice from Expert databus :-9

I think, that there should be competition, who makes most advanced software, that is totally useless and has practically no entertaining or educational value. I think, that I would have plenty of good candidates. :-)

By anonymous

incognito ergo sum (116)

anonymous's picture

29-09-2004, 00:36

Oh, I didn't know that, but cool, then there is at least one usage for this program. You can record noice from Expert databus :-9
Sounds like a great source for random numbers Wink

By ricbit

Champion (438)

ricbit's picture

29-09-2004, 06:33

Sounds like a great source for random numbers Wink

Or, at least, a way to detect if a machine is an Expert 1.0 or not.

By ro

Scribe (4964)

ro's picture

15-07-2006, 15:28

not really sure if I understand this... hmmmz

By NYYRIKKI

Enlighted (6067)

NYYRIKKI's picture

16-07-2006, 13:24

ro: I know that this program is small but quite a complicated to understand. I don't think that you can "solve" this by looking at the code. I think it is better to take some memory monitor (like Super-x) and check out the tables that this code generates. This is more like solution to a big Sudoku puzzle. Smile

The idea is that the code generates a set of bytes where low nibbles in bytes following each other make a pointer to 16*16 table so that each 0-255 value made by combining these low nibbles appear only once. In other words there is only one pointer to each shell in the 16*16 table no matter was the nibble hi or low. There exists no many possibilitys to order bytes like this.

The result is, that when this pointer table is used in IM2 mode the Z80 will jump somewhere in to the 16*16 table. This table is full of INC B operations and end of each table row there is CALL to CALCUT routine that uses the address where the routine was called from and the register B to get X and Y coordinates. After this these coordinates are converted to databus value by using another generated table.

~NYYRIKKI

By AuroraMSX

Paragon (1902)

AuroraMSX's picture

17-07-2006, 13:40

I think, that there should be competition, who makes most advanced software, that is totally useless and has practically no entertaining or educational value.
That's already out there. It's called Windows XP Tongue

By hap

Paragon (2042)

hap's picture

01-04-2009, 19:40

Hmm hmm, it's probably too long ago for you to fix it, but a few databus values cause a reset (such as hex $13). The program will also lock up on some computers due to: [interrupt line low already] -> EI -> NOP -> [int here] -> HALT -> lalala.
Or could you paste DATABUS.GEN v1.0 if you still have it? I assume that one loops and modifies the 'jumptable' after every int?

By NYYRIKKI

Enlighted (6067)

NYYRIKKI's picture

01-04-2009, 23:06

Oops... fixed it (I hope) One table was a bit short and now it should not hang in case of early int...

I could not find the first version, but I'm pretty sure it should be somewhere here in the forums... How ever I think it may have the same problem...

; DATABUS.GEN Ver 2.1 for MSX homecomputers (Made By: NYYRIKKI)
;
; This program reads a value from databus when Z80 leaves databus control to peripherals.
;
; Usage from MSX-BASIC:
;
;	BLOAD "DATABUS.BIN",R:PRINT USR(0)
;
;
; Ps. Unmodifyed MSX should give value #FF allways. (according to my knowledge)
;
; Changes:
;
;  Bug fixed version... I hope...
;-----------------------------------------------------------------------------------------

USR:	EQU #F7F8
USR0:	EQU #F39A

	DEFB #FE
	DEFW BEGIN
	DEFW END
	DEFW START

	ORG #B000

BEGIN:
START:
	LD HL,CODE
	LD (USR0),HL
	RET
CODE:
	DI
	LD HL,#BF00
	LD BC,0

NEXT:
	LD A,C
	ADD A,B
	CP #10
	JP NC,NOMORE

	LD (HL),A
	INC HL

	CP #F
	JP Z,SKIP
	LD (HL),B
	INC HL

SKIP:
	INC C
	LD A,C
	CP #10
	JP NZ,NEXT

NOMORE:
	LD C,0
	INC B
	LD A,B
	CP #10
	JP NZ,NEXT

	LD (HL),#C0

	LD HL,#BF00
	LD DE,#BE00
	LD BC,0

FIXL:
	LD A,(HL)
	LD C,A
	OR #C0
	LD (HL),A
	INC HL
	LD A,(HL)
	RLCA
	RLCA
	RLCA
	RLCA
	OR C
	LD E,A
	EX DE,HL
	LD A,E
	DEC A
	LD (HL),A
	EX DE,HL
	DJNZ FIXL

	LD HL,#C0C0
	LD DE,#C0C1
	LD B,#10

MAKEPROG:
	PUSH BC
	LD BC,#F
	PUSH HL
	PUSH DE
	LD (HL),4	;INC B
	LDIR
	LD (HL),#CD	;CALL
	INC HL
	LD DE,CALCUT
	LD (HL),E
	INC HL
	LD (HL),D
	POP DE
	POP HL
	POP BC
	INC H
	INC D
	DJNZ MAKEPROG

	LD A,#BF
	LD I,A

	IM 2
	EI
	NOP
	HALT	; Any interrupt will be accepted.

	LD L,A
	LD H,#BE
	LD A,(HL)
	LD (USR),A
	XOR A
	LD (USR+1),A
	RET


CALCUT:
	POP AF
	AND #F
	RLCA
	RLCA
	RLCA
	RLCA
	OR B
	XOR #F
	IM 1
	EI
	RETI

END:

By hap

Paragon (2042)

hap's picture

01-04-2009, 23:26

It works, thanks for the fast fix Smile The result is 0 on my weird (but unmodified) Canon V-20 MSX1 btw (unrelated to the nop (0) at the int).

Page 1/2
| 2