z80 coding; what am i doing wrong?

By flok

Rookie (26)

flok's picture

17-08-2010, 08:55

Hi,

I'm trying to find the start of a second in assembler. For that I look at the RTC.
Now when I run my code it seems as if it looks at I/O port 0x00 instead of 0xb5. Does a IN A,(C) change the C-register as well?


	ORG	0xc000

db 0x0FE
dw start, endadr, start

start:
; wait for counter to change; that'll be the start of a second
	; select seconds low register
	DI
	LD	C,0xb4
	LD	A,0x00
	OUT	(C),A

	LD	C,0xb5
	IN	B,(C)
startwait:
	IN	A,(C)
	CP	B
	JP Z, startwait
	EI

	RET
endadr:
Login or register to post comments

By PingPong

Prophet (2563)

PingPong's picture

17-08-2010, 12:59


Does a IN A,(C) change the C-register as well?

No, change only the accu

By norakomi

Paladin (961)

norakomi's picture

18-08-2010, 00:33

Hi

DI
LD C,0xb4
XOR A
OUT (C),A
LD C,0xb5
IN B,(C)
.loop:
IN A,(C)
CP B
JR Z,.loop
EI

you clearly look at I/O port (C), which you gave the value 0xb5, why do you think you look at 0x00 ?
and why exactly do you look at port 0xb5 ? wouldnt a framecounter (using halts is you need) be easier / faster ?

By flyguille

Prophet (2265)

flyguille's picture

18-08-2010, 05:19

for a FPS control (KONAMI way)

you needs, to call the game-play routine inside the INTERRUPT handler.

then you control the FPS in this way.

EI
label: HALT
JR label

in this way, one gameplay sequence will be executed per VDP's frame (50/60 FPS)

if your gameplay routine takes between 1 > & <2 VDP frames for its execution. this routine will go for a (25FPS fixed)

so, every milisecond that you don't use in the execution of your routine, will be wasted by the HALT instruction.

make sure that in your code and the BIOS routines that you calls don't have "DI" or "EI" instructions.

My MSX profile