HSP Programming Language

Last Update : 2007/11/xx

English | Trad. Chinese

Hot Soup Processor (HSP)

Hot Soup Processor (aka "HSP") is a programming tool for Windows, developed by Onitama (ONION software) in Japan. It allows you to create a game, application, and so on. Now HSP is released version 3.x.

HSP2/HSP3 Related links:

^

HSP Script Comments

/*
	multi-line comments
*/

	/* inline comments */
;	single-line comments

//	single-line comments

^

Draw Text

/*
	draw string text

	mes "text to draw"
*/
	mes "Hello Word!"
	mes "HSP programming!"
/*
	set text color (RGB value 0-255)

	color red color, green color, blue color
*/
	color 255, 0, 0
	mes "Hello Word!"

	color 0, 128, 0
	mes "HSP programming!"
/*
	set text font

	font "font name", height size, font style

	font style:
	0=default, 1=bold, 2=italic, 4=underline, 8=strikeout,
	16=antialiased font (not supported on Windows 9x)
*/
	font "Arial", 20, 1
	mes "Hello Word!"

	font "MS Sans Serif", 40, 1 | 8
	mes "HSP programming!"
/*
	set text position (in pixel)

	pos x-coordinate position, y-coordinate position
*/	
	pos 100, 150
	mes "Hellow Word!"

	pos 200, 300
	mes "Windows HSP programming!"

^

Draw Figure

/*
	draw a dot point

	pset x-coordinate position, y-coordinate position
*/
	pset 100, 100

	pset 100, 200
/*
	draw a line

	line x-coordinate of starting point, y-coordinate of starting point,
		x-coordinate of ending point, y-coordinate of ending point
*/
	line 100, 100, 400, 100

	color 0, 0, 255
	line 200, 300, 300, 400
/*
	draw a rectangle

	boxf x-coordinate of upper-left, y-coordinate of upper-left,
		x-coordinate of lower-right, y-coordinate of lower-right
*/
	boxf 10, 10, 100, 100

	color 255
	boxf 50, 50, 200, 200
/*
	draw a circle

	circle x-coordinate of upper-left, y-coordinate of upper-left,
		x-coordinate of lower-right, y-coordinate of lower-right,
			draw mode

	draw mode: 0=edge only, 1=fill (default)
*/
	color 255
	circle 100, 100, 200, 200

	color 0, 255
	circle 300, 200, 400, 400, 0

^

Show Time

/*
	gettime(mode)

	mode: 0=year, 1=month, 2=day of the week, 3=day,
		4=hour, 5=minute, 6=second, 7=msecond
*/

;	set font and size
	font "Arial", 50

;	infinity loops
	repeat
;		temporarily stop drawing
		redraw 0

;		paint out quadrangle (black color)
		color
		boxf 50, 50, 300, 100

;		display time (white color)
		color $FF, $FF, $FF
		pos 50, 50
		mes ""+gettime(4)+":"+gettime(5)+":"+gettime(6)

;		restart drawing
		redraw 1

;		temporarily waiting (10ms)
		wait 100
	loop

^

Basic Operation

	mes "1+1= "+(1 + 1)

	a = 10 * 10 - 1
	mes a

	b = 100
	a = b * (100 + 1)
	mes a

;	division
	mes 100 / 2

;	remainder "%"
	mes 10 \ 3
	c = 1
	c++
	mes c

	d = 5
	d += 2
	mes d
;	double + double -> double
;	double + int -> double
;	int + double -> int
	mes 1.1 + 2.4
	mes 2.2 + 1
	mes 1 + 2.4
	a = 9

	if a > 10 {
		mes "big"
	} else {
		mes "small"
	}
	a = 5

	if a != 4 : mes "no ["+a+"]"

^

GUI Control (Object)

/*	
	button object

	button "string on button", *label name
*/

	button "PUSH!", *label_1
	stop

*label_1
	mes "Hi!"
/*
	checkbox object

	chkbox "string on checkbox", variable
*/

;	first button with check mark
	a = 1

	chkbox "X", a
	chkbox "Y", b

;	object position
	pos 100, 20

;	obuject size
	objsize 50, 50

	button "Check!", *check
	stop

*check
	mes "X:"+a+" / Y:"+b+""
/*
	single-line edit object

	input variable, object size, object height, max string length
*/

	a = "Hello!"
	input a, 200, 20

	button "Check!", *check
	stop

*check
	mes a
/*	
	listbox object (single selection)

	listbox variable, object height, "string list per '\n'"
*/

	listbox a, 50, "A\nB\nC\nD\nE"

	button "Check!", *label
	stop

*label
	mes a
/*
	combobox object

	combox variable, doropdown height, "string list per '\n'"
*/

	objsize 100
	combox a, 100, "HSP\ncombobox\ncontrole"

	button "Check!", *label2
	stop

*label2
	mes a
	stop

^

Win32 API

#include "user32.as"

;	Normal Beep
	MessageBeep 0

	wait 100

;	Error Beep
	MessageBeep $10

	wait 100

;	Question Beep
	MessageBeep $20

	wait 100

;	Exclamation Beep
	MessageBeep $30

	wait 100

;	Information Beep
	MessageBeep $40

	mes "done"
/*
	MessageBox API and bulit-in dialog function
*/

#uselib "user32.dll"
#func MessageBox "MessageBoxA" int, str, str, int

	MessageBox hwnd, "Hello World!", "HSP :)", $40

;	return value
	mes stat

;	Built-in HSP function
	dialog "\"dialog\" (mode 0) function displays a infobox", 0, "HSP"
/*
	Simple Color Code Picker Sample for HSP3
	by Kpan
*/

#include "user32.as"
#include "gdi32.as"

#define ctype GetRValue(%1) %1 & $FF
#define ctype GetGValue(%1) (%1 >> 8) & $FF
#define ctype GetBValue(%1) (%1 >> 16) & $FF

;	main window (Window ID : 0)
	screen 0, 130, 50
	title "Color Code Picker"

;	jump label for WM_CLOSE
	onexit gosub *exit

;	always window on top
	gsel 0, 2

;	one-line edit control (Object ID : 0)
	pos 50, 15
	input value, 70, 20

;	get a handle to device context
	GetDC 0
	hdc_display = stat

	repeat
;		temporarily stop drawing
		redraw 0

		color 255, 255, 255
		boxf 0, 0, 50, 50

;		get rgb color value
		GetPixel hdc_display, ginfo(0), ginfo(1)
		clr_rgb = stat

		color GetRValue(clr_rgb), GetGValue(clr_rgb), GetBValue(clr_rgb)
		boxf 10, 10, 40, 40

;		update edit control
		objprm 0, strf("#%06X", clr_rgb)

;		restart drawing
		redraw 1

		wait 10
	loop


*exit
	ReleaseDC 0, hdc_display

	end
/*
	Simple Color Code Checker Sample for HSP3
	by Kpan
*/

	screen 0, 230, 80
	title "Color Code Checker"

;	jump label for WM_HSCROLL
	oncmd gosub *hscroll, $114

	dim value_color, 3

;	trackbar
	pos 65, 10
	repeat 3
		winobj "msctls_trackbar32", "", , $50000000 | $100, 150, 20
		hTrackbar.cnt = objinfo(stat, 2)

;		TBM_SETRANGEMAX (0-255)
		sendmsg hTrackbar.cnt, $408, , 255
	loop

	gosub *draw_circle

	stop


*hscroll
	if lparam = hTrackbar.0 {
;		TBM_GETPOS
		sendmsg lparam, $400
		value_color.0 = stat

		gosub *draw_circle

		return
	}

	if lparam = hTrackbar.1 {
		sendmsg lparam, $400
		value_color.1 = stat

		gosub *draw_circle

		return
	}

	if lparam = hTrackbar.2 {
		sendmsg lparam, $400
		value_color.2 = stat

		gosub *draw_circle

		return
	}

	return


*draw_circle
	color value_color.0, value_color.1, value_color.2
	circle 10, 20, 55, 65

	return
/*
	Simple Password Generator
	by Kpan
*/

#include "user32.as"

#define ctype MAKELONG(%1,%2) (%1) & $FFFF | (%2) << 16

	screen , 350, 90
	title "Simple Password Generator"

	randomize

	sdim pass
	dim character, 20

	objmode 2
	font "Arial", 26, 16 | 1

;	inputbox to show a generated password
	pos 10, 10
	input pass, 330, 38
	SetWindowLong objinfo(stat, 2), -16, $50010080 | $2

	objmode 1

;	inputbox to set a figure number
	pos 220, 61
	input figure, 40, 22, 2

;	Up-down Control
	winobj "msctls_updown32", "", , $50000012 | $4
	sendmsg objinfo(stat, 2), $465, , MAKELONG(20, 8)
	objprm 1, 8

	objsize 70, 22

	pos 270, 60
	button "Create", *create

	stop

*create
	if figure < 8 : stop

;	create password string
	repeat figure
		repeat 20
			if rnd(2) {
;				for Number
				character.cnt = rnd(10) + $30
			} else {
;				for Alphabet
				character.cnt = rnd(26) + $61
			}
		loop

		poke pass, cnt, strf("%c", character.rnd(20))
	loop

	objprm 0, pass

^

Copyright 2005-2010 . All rights reserved.