Vertical scrolling routine (MSX1)

Page 2/12
1 | | 3 | 4 | 5 | 6 | 7

By santiontanon

Paladin (850)

santiontanon's picture

27-12-2018, 20:32

As for how to measure CPU usage, I use a custom version of a script written by Grauw (https://bitbucket.org/grauw/neonlib/src/996d553/tools/profil...), which is amazingly useful!

My own version is this, to get minimum, maximum and average time:

#
# Profiling utility
#
# Start profiling with out (2ch),a, end profiling with out (2dh),a.
# Run the profile command in the openMSX console to see the result.
#
namespace eval profile {
	variable min_time  -1;
	variable max_time  -1;
	variable total_time  0;
	variable CPU_frequency  3579545;
	variable start_time  -1;
	variable count  0;
	variable ignored  0;
	debug set_watchpoint write_io 0x2C {} {profile::start}
	debug set_watchpoint write_io 0x2D {} {profile::stop}
	
	proc start {} {
		variable start_time
		variable ignored
		variable CPU_frequency
		set CPU_frequency [expr [machine_info z80_freq]]
		set out_cycles [expr {"[cpuregs::get_active_cpu]" eq "z80"} ? 12.0 : 5.0]
		set overhead [expr $out_cycles / $CPU_frequency]
		if {$start_time == -1} {
			set start_time [expr [machine_info time] + $overhead]
		} else {
			set start_time [expr $start_time + $overhead]
			incr ignored
		}
	}
	
	proc stop {} {
		variable min_time
		variable max_time
		variable total_time
		variable start_time
		variable count
		variable ignored
		variable time
		if {$start_time != -1} {
			set time [expr [machine_info time] - $start_time]
			if {$min_time == -1} {
				set min_time $time
				set max_time $time
			} else {
				if {$time < $min_time} {
					set min_time $time
				}
				if {$time > $max_time} {
					set max_time $time
				}
			}
			set total_time [expr $time + $total_time]
			set start_time -1
			incr count
		} else {
			incr ignored
		}
	}
	
	proc profile {} {
		variable total_time
		variable min_time
		variable max_time
		variable count
		variable ignored
		variable CPU_frequency
		variable time_in_cycles 
		variable average_time
		variable average_time_in_cycles
		variable min_time_in_cycles
		variable max_time_in_cycles
		set average_time [expr $total_time/$count]
		set time_in_cycles [expr $total_time*$CPU_frequency]
		set average_time_in_cycles [expr $time_in_cycles/$count]
		set min_time_in_cycles [expr $min_time*$CPU_frequency]
		set max_time_in_cycles [expr $max_time*$CPU_frequency]
		puts "Avg Time: $average_time, count: $count, ignored: $ignored"
		puts "Avg Cycles: $average_time_in_cycles, min Cyles: $min_time_in_cycles, max Cyles: $max_time_in_cycles"
	}
	
	namespace export profile
}

namespace import profile::*

By thegeps

Champion (279)

thegeps's picture

27-12-2018, 23:57

Cool, is that C? Never used and know nothing about It. I canali use Basic, Amos (a basic for Amiga) and trying to do something with Assembly Z80 for my beloved MSX. Anyway, before test anything, I'll improve (or rewrite)my scrolling routine using the hints received Wink
I really love MSX1 and I was sure (since eighties) that a smooth nice scrolling was possible.
I'm doing this for love ❤

By TomH

Champion (327)

TomH's picture

28-12-2018, 00:19

I think it's TCL, openMSX's preferred scripting language — it's a script that adds profiling to openMSX through use of its debugging interface.

By thegeps

Champion (279)

thegeps's picture

28-12-2018, 00:28

Ok, thx Wink

By santiontanon

Paladin (850)

santiontanon's picture

28-12-2018, 09:43

Yep, it's TCL. Testing this is actually very easy, you just need to do this:

- copy that routine into a file "profile.tcl" inside of the "share/scripts" folder inside of OpenMSX. For example, in Mac/Linux that is in "~/.openMSX/share/scripts".
- In your assembler code, right before the piece of code you want to measure put "out (#2c),a", and right after put "out (#2d),a".
- Then just play your game in openMSX for a while, and then open the console (CMD + L in Mac), and type "profile"

I find it extremely useful, and use it to optimize my code all the time. So, if you have any questions about it, happy to answer Smile

(btw, really looking forward to see progress in your routine! my current MSXDev entry also uses a similar smooth scrolling routine, but in increments of 2 pixels, so I'm very curious to see other people's solutions! I will hopefully have a demo version of the game soon Smile)

By thegeps

Champion (279)

thegeps's picture

28-12-2018, 10:27

It's really far away to be a game
As I said, I'm still learning. Now I have to implement sprites, moviment patterns, missles. I have some ideas, but It is first time I'm doing something like this. And What about sounds or music?
Far away, as I said...

By santiontanon

Paladin (850)

santiontanon's picture

29-12-2018, 06:59

Haha, sure! Looking forward to seeing your progress! Looks very promising so far!

By thegeps

Champion (279)

thegeps's picture

29-12-2018, 12:30

Thank you, I'll do my best! Cool

By thegeps

Champion (279)

thegeps's picture

30-12-2018, 00:39

Santiontanon, btw I wrote a 2pixel scrolling routine in april (with precalculated tiles). More fast (and simple) but I prefere mi actual routine and really want to improve It. Here's the 2pixel scrolling video:
https://m.facebook.com/groups/25612789952?view=permalink&id=...

By santiontanon

Paladin (850)

santiontanon's picture

30-12-2018, 09:43

nice! I'm using 2 pixel scroll since I also have precalculated tiles as in this last video you show, and I don't have enough space for all the tiles I'd need with 1pixel scroll!!! It's my first attempt at smooth scroll on an MSX, so, I'm not sure I'm using the best solution, but it's working pretty well so far. Will show it soon I hope Smile

Page 2/12
1 | | 3 | 4 | 5 | 6 | 7