TCL: how to step + log reg PC?

Página 1/2
| 2

Por andrear1979

Expert (96)

imagem de andrear1979

13-11-2016, 12:06

Hi guys, here's a OpenMSX-TCL-newbie question. From the OpenMSX interactive console I'd like to get a succession of values of the Z80 register PC, so I type something like this (example1):

for {variable i 0} { $i<4 } { incr i } { step_in; message [reg pc]; }

but it doesn't work as expected. The CPU actually steps, but something in the OpenMSX machinery seems to "cache" the initial PC value until the for statement is completed, so the result on standard output is:

info: 3437
info: 3437
info: 3437
info: 3437

Counterexample: it works as expected/desired if I type four times the command

step_in; message [reg pc];

standard output shows

info: 2975
info: 2978
info: 2980
info: 3441

Any clue about what's wrong in example1, or how could I obtain the desired output? Thanks everyone, kindest regards.

PS: I'm aware of the command "reg_log" and tried to use it, but values only update at every VDP frame, not at every CPU step.

Entrar ou registrar-se para comentar

Por Manuel

Ascended (15691)

imagem de Manuel

14-11-2016, 23:29

The problem is that openMSX doesn't get any time to execute something while the Tcl loop is running. What you can do is decouple it with an after command (that allows openMSX to do stuff).

This test works here:

variable count 0
variable maxcount 4
proc do_step {} { 
  variable count
  variable maxcount
  step_in
  message [reg PC]
  incr count
  if {$count < $maxcount } {after realtime 0 do_step}
}
do_step

Por Vampier

Prophet (2296)

imagem de Vampier

15-11-2016, 08:00

great to see that people are coding in TcL for openMSX Smile

Por wouter_

Champion (417)

imagem de wouter_

15-11-2016, 10:51

Manuel's answer is correct. I just wanted to add that openMSX has built-in functionality for CPU (PC) tracing. See the cputrace setting. This will print (a lot) of output on stdout, so you probably want to start openMSX from the commandline and redirect stdout to a file.

Por andrear1979

Expert (96)

imagem de andrear1979

15-11-2016, 13:52

Aha! Thanks guys, both the solutions are valuable resources, I'll play with them tonight. Some explanation is probably due: I'm a complete rookie at TCL and have no MSX big plan in mind Nishi, so please don't hold your breath for "this year's OpenMSX killer-app plugin"... Smile

Cheers!

Por hit9918

Prophet (2866)

imagem de hit9918

17-11-2016, 20:21

I tried this

	proc dbsn { count } {
                message $count
                debug step
                incr count -1
                if {$count > 0 } { after realtime 0 [dbsn $count] }
	}
	namespace export dbsn

it never steps more than one time

Por Manuel

Ascended (15691)

imagem de Manuel

17-11-2016, 21:10

That is because [] means "execute and put the result here". And the result there is some string. You also get an error if you run this. Try double quotes instead:

	proc dbsn { count } {
                message $count
                debug step
                incr count -1
                if {$count > 0 } { after realtime 0 "dbsn $count" }
	}
	namespace export dbsn

Por hit9918

Prophet (2866)

imagem de hit9918

17-11-2016, 22:39

cool it steps.
now I got the problem that with after one seems to loose stdout, cant display disasm.
is there a command to print to the F10 shell?

meanwhile I got this compromise to message
problem is when the catapult scrolls sometimes it doesnt repaint and the screen is empty

        proc dbsn { count } {
                debug step
                incr count -1
                if {$count == 0} { message [disasm][cpuregs] }
                if {$count > 0 } { after realtime 0 "dbsn $count" }
                return
	}
	namespace export dbsn

and the disasm step still seems one step too old.

Por hit9918

Prophet (2866)

imagem de hit9918

17-11-2016, 22:42

it would be nice to have the command
debug sync
that gives emu the cpu till it has done the step and then write it all in easy scripts Smile

Por hit9918

Prophet (2866)

imagem de hit9918

17-11-2016, 22:46

but yeah now it is possible to just step 1000 instructions further when one has a bad bug and no idea in which place happens the corruption.

Por Manuel

Ascended (15691)

imagem de Manuel

17-11-2016, 22:49

To print in the console use the puts command.

Página 1/2
| 2