;mode800
; ======================================================================
; Saya no Uta Proportional ONScripter Script File
;
; Original © 2004 Nitro+. All Rights Reserved.
;
; http://www.nitroplus.co.jp/
;
; English translation © 2008-2009 tsukuru.info. Fansub.
;
; http://tsukuru.info/tlwiki/index.php?title=Saya_no_Uta
;
; Proportional ONScripter port © 2009 WinKiller Studio. Fansub.
;
; http://sl.criminalrussia.ru/dsp2003/saya_no_uta.htm
; ======================================================================

; ======================================================================
; Changes:
;
; 2009/05/04
; [dsp2003]: work started
;
; 2009/05/17
; [dsp2003]: initial alpha release.
;            Dedicated to my imouto. Happy birthday, Natasha! ^_^
;
; 2009/06/10
; [dsp2003]: release candidate 1.
;            Fixed several page-wrapping issues
;            Fixed logic bugs with unopenable CGs and Sound Library
; ======================================================================

; ======================================================================
; * Definition block *
; ======================================================================
*define

; Turning on global variables
globalon

; BGM aliases
stralias s01,"sound\s01.ogg"
stralias s02,"sound\s02.ogg"
stralias s03,"sound\s03.ogg"
stralias s04,"sound\s04.ogg"
stralias s05,"sound\s05.ogg"
stralias s05_psycho,"sound\s05_psycho.ogg"
stralias s06,"sound\s06.ogg"
stralias s07,"sound\s07.ogg"
stralias s08,"sound\s08.ogg"
stralias s09,"sound\s09.ogg"
stralias s09_2,"sound\s09_2.ogg"
stralias s10,"sound\s10.ogg"
stralias s11,"sound\s11.ogg"
stralias sayanouta,"sound\sayanouta.ogg"           ; A mixed version of 沙耶の唄 and s05
stralias song_of_saya,"sound\song_of_saya.ogg"     ;沙耶の唄
stralias shoes_of_glass,"sound\shoes_of_glass.ogg" ;ガラスの靴
stralias spectacle,"sound\sound0204.ogg"           ;郁紀光景

numalias scene,222  ; Scene name for savegame

numalias badend,10  ; Bad end trigger
numalias ending,900 ; Ending trigger
numalias end1_clear,901 ; White ending trigger
numalias end2_clear,902 ; "Bad" end trigger
numalias end3_clear,903 ; "Mad" end trigger

numalias cgset_0,904 ; Beginning
numalias cgset_1,905 ; White end
numalias cgset_2,906 ; Middle
numalias cgset_3,907 ; Blossoming end
numalias cgset_4,908 ; Mad end

numalias lic_accepted,999

; Aliases for OST menu
numalias track_num,11
numalias repeat,12

; Aliases for CG menu
numalias cgpage,13
numalias cg_sel,14

; Aliases for config menu
numalias gro,500 ; Grotesque image switcher

numalias vol0,501
numalias vol1,502
numalias vol2,503
numalias vol3,504
numalias vol4,505
numalias vol5,506
numalias vol6,507
numalias vol7,508
numalias vol8,509
numalias vol9,510
numalias vol10,511
numalias vol11,512
numalias vol12,513
numalias volsfx,514
numalias volvoice,515
numalias volmp3,516

numalias fullscr,8

numalias movplay,517

numalias textspeed,518
numalias autospeed,519

; Use archive mode (if possible)
nsa

; Effects section
effectcut
effect 10,10,500                    ;Fade out
effect 11,18,2000,"data\effect.png" ;Cloud effect

effect 19,10,150

savename "^~~ Сохранить игру ~~","^~~ Загрузить игру ~~","#"
savenumber 20

; This is it, no fancy right-click menus :(
rmenu "^~~ Сохранить игру ~~",save,"^~~ Загрузить игру ~~",load,"^",,"^~~ История ~~",lookback,"^",,"^~~ Вернуться в главное меню ~~",reset

menusetwindow 17,17,0,0,0,1,#ffffff
menuselectcolor #ff9999,#99ff99,#ffffff
selectcolor #ff0000,#ffffff

windoweffect 10,250

lookbackbutton ":a;system\uoncur.bmp",":a;system\uoffcur.bmp",":a;system\doncur.bmp",":a;system\doffcur.bmp"

;h_mapfont 0,"fonts\DejaVuSansCondensed.ttf"
h_mapfont 0,"fonts\SazanamiGothic-Cyrillic.ttf"
h_mapfont 1,"fonts\DejaVuSansCondensed-Oblique.ttf"

; Game caption
caption "Saya no Uta - PONScripter Edition"

; Game version
versionstr "Saya no Uta PONScripter","(c) Nitro+"

; Game logics section begin
game

; Allowing GUI buttons to be drawn normally
;windowback
; 0 - 8 sprites are used for GUI
;humanz 8

; ======================================================================
; * Endings checkup *
; ======================================================================
*checkends
 mov %ending,0
 if %end1_clear=1 inc %ending
 if %end2_clear=1 inc %ending
 if %end3_clear=1 inc %ending
return

; ======================================================================
; * Custom effects block *
; ======================================================================

; White flash, 3 times
*flash1
 for %0=1 to 3

  lsp 85,":a;system\ffffff.png",0,0:print 1
  delay 1
  csp 85:print 1

  add %0,1

 next

 return

; White flash, 1 time
*flash2
  lsp 85,":a;system\ffffff.png",0,0:print 1
  delay 1
  csp 85:print 1
 return

; Red flash, 1 time
*flash3
  lsp 85,":a;system\ff0000.png",0,0:print 1
  delay 1
  csp 85:print 1
 return

; ======================================================================
; * Sound processing block *
; ======================================================================

; Quick mute: voices
*mute
  for %0=0 to 9
   dwavestop %0
  next
 return
 
; Quick mute: sound effects
*mute_se
  for %0=10 to 12
   dwavestop %0
  next 
 return
 
; ======================================================================
; * Game User Interface logical block *
; ======================================================================

; Box 0 (Default Window)
*box0
  setcursor 0,":a/7,160,0;data\cur00.png",0,0
  setcursor 1,":a/5,160,0;data\cur01.png",0,0
; setwindow3 60,70,34,20,20,20,0,4,24,1,1,":a;data\f05.png",40,50 ;720,500
  setwindow3 60,70,34,20,20,20,0,4,%textspeed,1,1,":a;data\f05.png",40,50 ;720,500
 return

; Box 5
*box5
  setcursor 0,":a/7,160,0;data\cur00.png",0,0
  setcursor 1,":a/5,160,0;data\cur01.png",0,0
; setwindow3 240,200,20,15,20,20,0,4,24,1,1,":a;data\f05.png",40,50
  setwindow3 240,200,20,15,20,20,0,4,%textspeed,1,1,":a;data\f05.png",40,50
 return

; Box 8
*box8
; setwindow3 60,410,34,6,20,20,0,4,24,1,1,":a;data\f03.png",40,400
  setwindow3 60,410,34,6,20,20,0,4,%textspeed,1,1,":a;data\f03.png",40,400
 return

; Box 9 (Default Window \ Copy)
*box9
  setcursor 0,":a/7,160,0;data\cur00.png",0,0
  setcursor 1,":a/5,160,0;data\cur01.png",0,0
; setwindow3 60,70,34,20,20,20,0,4,24,1,1,":a;data\f05.png",40,50 ;720,500
  setwindow3 60,70,34,20,20,20,0,4,%textspeed,1,1,":a;data\f05.png",40,50 ;720,500
 return

; Fullscreen text window
*windowfs
 setcursor 0,":a/7,160,0;data\cur00.png",0,0
 setcursor 1,":a/5,160,0;data\cur01.png",0,0
;setwindow3 60,70,34,20,20,20,0,4,24,1,1,":a;data\f05.png",40,50 ;720,500
 setwindow3 60,70,34,20,20,20,0,4,%textspeed,1,1,":a;data\f05.png",40,50 ;720,500
 return

; ======================================================================
; * Port & localisation warning *
; ======================================================================
*warning

 rmode 0

 if %lic_accepted=1 goto *warning_end

 dwave 0,"sound\se_ch_warning.ogg"

 gosub *box9

^ Этот порт и интегрированный перевод являются фансабом.@
^ Используя этот порт и интегрированный перевод, вы соглашаетесь со  следующими условиями:@
br
^- Вы НЕ можете взимать плату в любой форме за использование любой части этого порта и интегрированного перевода.@
^- Так же вы НЕ имеете права изменять и распространять любые части этого программного обеспечения без предварительного уведомления команды TLWiki и WinKiller Studio.@
br
^Вы согласны с этими условиями?
br
 select "^Согласны",*accepted,"^Не согласны",*not_accepted

 *accepted
  mov %lic_accepted,1

  skipoff

  dwave 0,"sound\se_ch_click.ogg"
  delay 500
  
 goto *warning_end 

 *not_accepted
 
  skipoff

lsp 1,":s#ffffff^Плохая концовка.",320,290:print 10,500

  dwave 0,"sound\se_ch_out.ogg"
  delay 1000
  end

 *warning_end

 rmode 1

 return

; ======================================================================
; * Nitro+ startup logos block *
; ======================================================================
*logo
 bg "cg\media_a.jpg",10,1000
 delay 1000
 bg "cg\media_b.jpg",10,1000
 delay 1000
 bg black,10,1000
 bg "cg\tlwiki.png",10,1000
 delay 1000
 bg black,10,1000
 bg "cg\winki.png",10,1000
 delay 1000
 bg black,10,1000
 if %movplay=1 mpegplay "mpeg\nitro_logo.mpg",1
 return

; ======================================================================
; * Staff roll block *
; ======================================================================

; Original staff roll
*staff
 bg black:csp -1:print 1 
 lsp 1,":a;cg\staff.png",0,600:print 1
 for %0=0 to 9439 step 3
 msp 1,0,-3:print 1
 delay 10
 next
 delay 2000
 csp -1:print 10,2000
 delay 1000
 lsp 1,":a;cg\staff_eng.png",0,0:print 10,2000
 delay 5000
 csp -1:print 10,2000
 delay 1000
 lsp 1,":a;cg\staff_pon.png",0,0:print 10,2000
 delay 5000
 csp -1:print 10,2000
 delay 1000
 return

; ======================================================================
; * Main menu block *
; ======================================================================
*main_menu

  gosub *checkends

  if %volmp3<>-1 mp3loop s02

  *main_loop

  csp -1:bg "cg\MENU\title_back01.png"
  lsp 133,":a;cg\MENU\title02.png",0,0
  lsp 132,":a;cg\MENU\title01.png",0,0
  print 10,1000

  lsp 120,":c/5,400,2;data\start.png",59,163
  lsp 121,":c/5,410,2;data\load.png",137,262
  if %ending>0 lsp 122,":c/5,395,2;data\cgl.png",576,325
  if %ending=3 lsp 123,":c/5,415,2;data\sl.png",38,456
  if %ending=3 lsp 124,":a/5,405,2;data\staffa.png",643,572
  lsp 125,":c/5,390,2;data\exit.png",691,467
  ; New config button
  lsp 126,":c/5,385,2;data\config.png",591,168

  print 1

  lsp 110,":l/2,0,3;data\startover.png",59,163
  lsp 111,":l/2,0,3;data\loadover.png",137,262
  if %ending>0 lsp 112,":l/2,0,3;data\cglover.png",576,325
  if %ending=3 lsp 113,":l/2,0,3;data\slover.png",38,456
  if %ending=3 lsp 114,":a/2,0,3;data\staff.png",643,572
  lsp 115,":l/2,0,3;data\exitover.png",691,467
  ; New config button
  lsp 116,":a/2,0,3;data\configover.png",591,168

  *main_loop2

	spbtn 110,1
	spbtn 111,2
	if %ending>0 spbtn 112,3
  if %ending=3 spbtn 113,4
  if %ending=3 spbtn 114,5
	spbtn 115,6
	spbtn 116,7

	btnwait %111
  if %111=-1 goto *main_loop2
	if %111=0  goto *main_loop2

	if %111=1  goto *saya_start
	if %111=2 gosub *saya_load
	if %111=3 gosub *saya_cg
  if %111=4 gosub *saya_ost
  if %111=5 gosub *saya_staff
	if %111=6  goto *saya_exit
	if %111=7 gosub *saya_config

  goto *main_loop  
  
 return

; ======================================================================
; * Load menu block *
; ======================================================================
*saya_load

; csp -1
 
 lsp 9,":c;cg\menu\title2.png",0,0:print 10,1000
 lsp 8,":a;data\f05.png",40,50:print 10,1000

 systemcall load

; csp -1:print 10,1000

 csp 9
 csp 8

 print 10,1000

 return

; ======================================================================
; * Save menu block *
; ======================================================================
*saya_save

; csp -1

 lsp 9,":c;cg\menu\title2.png",0,0:print 10,1000
 lsp 8,":a;data\f05.png",40,50:print 10,1000

 systemcall save

 csp 9
 csp 8

; csp -1:print 10,1000

 print 10,1000

 return

; ======================================================================
; * Configuration block *
; ======================================================================

; Setting volume
*saya_setvol

 ; Making them stop
 if %volsfx=-1 dwavestop 1
 if %volmp3=-1 mp3stop
 if %volvoice=-1 dwavestop 0

 sevol 0   :if %volsfx  >-1 sevol    %volsfx 
 bgmvol 0  :if %volmp3  >-1 bgmvol   %volmp3
 voicevol 0:if %volvoice>-1 voicevol %volvoice

return

; Configuration check for first run
*saya_config_chk
 if %gro=0 && %volsfx=0 && %volvoice=0 && %volmp3=0 && %movplay=0 && %textspeed=0 && %autospeed=0 && %textspeed=0 gosub *saya_config_def:gosub *saya_setvol
return

*saya_config_def
 mov %gro,0

 mov %volsfx,50
 mov %volvoice,100
 mov %volmp3,60

 mov %vol0,0
 mov %vol1,0
 mov %vol2,0
 mov %vol3,0
 mov %vol4,0
 mov %vol5,0
 mov %vol6,0
 mov %vol7,0
 mov %vol8,0

 mov %movplay,1

 mov %textspeed,24
 mov %autospeed,25

 textspeed %textspeed

 gosub *saya_aspeed_set

 gosub *saya_setvol

return

; Autospeed recalc
*saya_aspeed_set
 mov %2,%autospeed
 mul %2,30
 automode_time %2
return

; Main config function
*saya_config

 lsp 79,":a;data\f05.png",40,50
 lsp 78,":a;data\config_main.png",40,50

 btndef ""

 *saya_config_loop

 ; Voices config
 
 ; Sakisaka Fuminori
 lsp 77,":c/2,0,3;data\check.png",98,173
 lsp 76,":c;data\checked.png",98,173:vsp 76,0
 if %vol0>-1 vsp 76,1
 spbtn 77,1
 
 ; Saya
 lsp 75,":c/2,0,3;data\check.png",98,199
 lsp 74,":c;data\checked.png",98,199:vsp 74,0
 if %vol1>-1 vsp 74,1
 spbtn 75,2
 
 ; Takahata Oumi
 lsp 73,":c/2,0,3;data\check.png",98,225
 lsp 72,":c;data\checked.png",98,225:vsp 72,0
 if %vol2>-1 vsp 72,1
 spbtn 73,3

 ; Tonoh Kouji
 lsp 71,":c/2,0,3;data\check.png",98,251
 lsp 70,":c;data\checked.png",98,251:vsp 70,0
 if %vol3>-1 vsp 70,1
 spbtn 71,4

 ; Tsukuba Yoh
 lsp 69,":c/2,0,3;data\check.png",98,277
 lsp 68,":c;data\checked.png",98,277:vsp 68,0
 if %vol4>-1 vsp 68,1
 spbtn 69,5

 ; Tanbo Ryouko
 lsp 67,":c/2,0,3;data\check.png",98,303
 lsp 66,":c;data\checked.png",98,303:vsp 66,0
 if %vol5>-1 vsp 66,1
 spbtn 67,6

 ; Suzumi Yousuke
 lsp 65,":c/2,0,3;data\check.png",98,329
 lsp 64,":c;data\checked.png",98,329:vsp 64,0
 if %vol6>-1 vsp 64,1
 spbtn 65,7

 ; Others
 lsp 63,":c/2,0,3;data\check.png",98,355
 lsp 62,":c;data\checked.png",98,355:vsp 62,0
 if %vol7>-1 vsp 62,1
 spbtn 63,8


 ; BGM
 lsp 61,":c/2,0,3;data\check.png",98,426
 lsp 60,":c;data\checked.png",98,426:vsp 60,0
 if %volmp3>0 vsp 60,1
 spbtn 61,9
 
 ; SFX
 lsp 59,":c/2,0,3;data\check.png",98,452
 lsp 58,":c;data\checked.png",98,452:vsp 58,0
 if %volsfx>0 vsp 58,1
 spbtn 59,10
 
 ; VOICE
 lsp 57,":c/2,0,3;data\check.png",98,478
 lsp 56,":c;data\checked.png",98,478:vsp 56,0
 if %volvoice>0 vsp 56,1
 spbtn 57,11

 bar 0,%volmp3,  274,426,100,12,100,#ffffff
 btn 27,274,426,100,12,0,0
 bar 1,%volsfx,  274,452,100,12,100,#ffffff
 btn 28,274,452,100,12,0,0
 bar 2,%volvoice,274,478,100,12,100,#ffffff
 btn 29,274,478,100,12,0,0

 lsp 47,":a/2,0,3;data\0.png",260,424
 spbtn 47,16

 lsp 46,":a/2,0,3;data\100.png",378,424
 spbtn 46,17
 
 lsp 45,":a/2,0,3;data\0.png",260,450
 spbtn 45,18

 lsp 44,":a/2,0,3;data\100.png",378,450
 spbtn 44,19
  
 lsp 43,":a/2,0,3;data\0.png",260,476
 spbtn 43,20

 lsp 42,":a/2,0,3;data\100.png",378,476
 spbtn 42,21


 ; Window / Fullscreen
 isfull %fullscr ; Check
 
 lsp 55,":c/2,0,3;data\check.png",458,173
 lsp 54,":c;data\checked.png",458,173:vsp 54,0
 if %fullscr=0 vsp 54,1
 spbtn 55,12

 lsp 53,":c/2,0,3;data\check.png",458,199
 lsp 52,":c;data\checked.png",458,199:vsp 52,0
 if %fullscr=1 vsp 52,1 
 spbtn 53,13
 
 
 ; Movie playback
 lsp 51,":c/2,0,3;data\check.png",458,269
 lsp 50,":c;data\checked.png",458,269:vsp 50,0
 if %movplay=1 vsp 50,1
 spbtn 51,14
 
 
 ; Grotesque images
 lsp 49,":c/2,0,3;data\check.png",458,336
 lsp 48,":c;data\checked.png",458,336:vsp 48,0
 if %gro=1 vsp 48,1
 spbtn 49,15


 ; Text speed
 bar 3,%textspeed,600,415,100,12,100,#ffffff
 btn 30,600,415,100,12,0,0
 bar 4,%autospeed,600,441,100,12,100,#ffffff
 btn 31,600,441,100,12,0,0

 lsp 41,":a/2,0,3;data\0.png",588,413
 spbtn 41,22
 
 lsp 40,":a/2,0,3;data\100.png",704,413
 spbtn 40,23
 
 lsp 39,":a/2,0,3;data\0.png",588,439
 spbtn 39,24

 lsp 38,":a/2,0,3;data\100.png",704,439
 spbtn 38,25
 
 lsp 37,":a/2,0,3;data\defaults.png",555,473
 spbtn 37,26

 btnwait %111

 if %111=-1 goto *saya_config_end
 if %111=0  goto *saya_config_loop
 
 ; Voice: Sakisaka Fuminori 
 if %111=1  && %vol0>-1     mov %vol0,-1:gosub *saya_setvol:goto *saya_config_loop
 if %111=1  && %vol0=-1     mov %vol0,0 :gosub *saya_setvol:goto *saya_config_loop
 ; Voice: Saya
 if %111=2  && %vol1>-1     mov %vol1,-1:gosub *saya_setvol:goto *saya_config_loop
 if %111=2  && %vol1=-1     mov %vol1,0 :gosub *saya_setvol:goto *saya_config_loop
 ; Voice: Takahata Oumi
 if %111=3  && %vol2>-1     mov %vol2,-1:gosub *saya_setvol:goto *saya_config_loop
 if %111=3  && %vol2=-1     mov %vol2,0 :gosub *saya_setvol:goto *saya_config_loop
 ; Voice: Tonoh Kouji
 if %111=4  && %vol3>-1     mov %vol3,-1:gosub *saya_setvol:goto *saya_config_loop
 if %111=4  && %vol3=-1     mov %vol3,0 :gosub *saya_setvol:goto *saya_config_loop
 ; Voice: Tsukuba Yoh
 if %111=5  && %vol4>-1     mov %vol4,-1:gosub *saya_setvol:goto *saya_config_loop
 if %111=5  && %vol4=-1     mov %vol4,0 :gosub *saya_setvol:goto *saya_config_loop
 ; Voice: Tanbo Ryouko
 if %111=6  && %vol5>-1     mov %vol5,-1:gosub *saya_setvol:goto *saya_config_loop
 if %111=6  && %vol5=-1     mov %vol5,0 :gosub *saya_setvol:goto *saya_config_loop
 ; Voice: Suzumi Yousuke
 if %111=7  && %vol6>-1     mov %vol6,-1:gosub *saya_setvol:goto *saya_config_loop
 if %111=7  && %vol6=-1     mov %vol6,0 :gosub *saya_setvol:goto *saya_config_loop
 ; Voice: Others
 if %111=8  && %vol7>-1     mov %vol7,-1:mov %vol8,-1:gosub *saya_setvol:goto *saya_config_loop
 if %111=8  && %vol7=-1     mov %vol7,0 :mov %vol8,0 :gosub *saya_setvol:goto *saya_config_loop

 ; BGM
 if %111=9  && %volmp3>0    mov %volmp3,-1     :gosub *saya_setvol:goto *saya_config_loop
 if %111=9  && %volmp3=-1   mov %volmp3,100    :gosub *saya_setvol:goto *saya_config_loop
 ; SFX
 if %111=10 && %volsfx>0    mov %volsfx,-1     :gosub *saya_setvol:goto *saya_config_loop
 if %111=10 && %volsfx=-1   mov %volsfx,100    :gosub *saya_setvol:goto *saya_config_loop
 ; VOICES
 if %111=11 && %volvoice>0  mov %volvoice,-1   :gosub *saya_setvol:goto *saya_config_loop
 if %111=11 && %volvoice=-1 mov %volvoice,100  :gosub *saya_setvol:goto *saya_config_loop

 getmousepos %3,%4

 ; BGM, SFX and VOICES sliders ^3^
 if %111=27 mov %volmp3,  %3-274:gosub *saya_setvol:goto *saya_config_loop
 if %111=28 mov %volsfx,  %3-274:gosub *saya_setvol:goto *saya_config_loop
 if %111=29 mov %volvoice,%3-274:gosub *saya_setvol:goto *saya_config_loop

 ; ...and 0...100 buttons
 if %111=16 mov %volmp3,-1 :gosub *saya_setvol:goto *saya_config_loop
 if %111=17 mov %volmp3,100:gosub *saya_setvol:goto *saya_config_loop
 
 if %111=18 mov %volsfx,-1 :gosub *saya_setvol:goto *saya_config_loop
 if %111=19 mov %volsfx,100:gosub *saya_setvol:goto *saya_config_loop
 
 if %111=20 mov %volvoice,-1:gosub *saya_setvol:goto *saya_config_loop
 if %111=21 mov %volvoice,100:gosub *saya_setvol:goto *saya_config_loop

 ; WINDOW / FULLSCREEN switcher
 if %111=12 menu_window:goto *saya_config_loop
 if %111=13 menu_full:goto *saya_config_loop

 ; Movie playback
 if %111=14 && %movplay=1 mov %movplay,0:goto *saya_config_loop
 if %111=14 && %movplay=0 mov %movplay,1:goto *saya_config_loop

 ; Grotesque images switcher
 if %111=15 && %gro=1 mov %gro,0:goto *saya_config_loop
 if %111=15 && %gro=0 mov %gro,1:goto *saya_config_loop

 getmousepos %3,%4

 ; Text speed sliders
 if %111=30 mov %textspeed,%3-600:textspeed %textspeed  :goto *saya_config_loop
 if %111=31 mov %autospeed,%3-600:gosub *saya_aspeed_set:goto *saya_config_loop

 ; ...and it's buttons
 if %111=22 mov %textspeed,0  :textspeed %textspeed:goto *saya_config_loop
 if %111=23 mov %textspeed,100:textspeed %textspeed:goto *saya_config_loop
 
 if %111=24 mov %autospeed,0  :gosub *saya_aspeed_set:goto *saya_config_loop
 if %111=25 mov %autospeed,100:gosub *saya_aspeed_set:goto *saya_config_loop

 
 ; Reset to defaults button
 if %111=26 gosub *saya_config_def

 goto *saya_config_loop

 *saya_config_end

 barclear
 
 for %0=37 to 79
  csp %0
 next

 return

; ======================================================================
; * CG Mode Block *
; ======================================================================
; Drawing buttons ^3^
*saya_cg_gui
 lsp 61,":a/3,0,3;data\CG_menu.png",243,539
 lsp 62,":a/3,0,3;data\CG_back.png",363,539
 lsp 63,":a/3,0,3;data\CG_next.png",486,539
 return

*saya_cg

 csp -1:bg "cg\menu\cg_back.jpg":print 10,1000

 mov %cgpage,1
 mov %cg_sel,0

 *cg_loop

 btndef ""

 csp -1:bg "cg\menu\cg_back.jpg"

 *cg_loop2
 
 if %cgpage=1 gosub *cg_page_1
 if %cgpage=2 gosub *cg_page_2
 if %cgpage=3 gosub *cg_page_3
 if %cgpage=4 gosub *cg_page_4

 gosub *saya_cg_gui

 vsp 62,0
 vsp 63,0

 spbtn 61,1
 if %cgpage>1 vsp 62,1:spbtn 62,2
 if %cgpage<4 vsp 63,1:spbtn 63,3
 
 print 10,250
 
 btnwait %111

 if %111=-1 goto *cg_loop2
 if %111=0  goto *cg_loop2

 if %111=1  goto *cg_end
 if %111=2  dec %cgpage:goto *cg_loop2
 if %111=3  inc %cgpage

 if %111=101 goto *cg_101
 if %111=102 goto *cg_102
 if %111=103 goto *cg_103
 if %111=104 goto *cg_104
 if %111=105 goto *cg_105

 if %111=106 goto *cg_106
 if %111=107 goto *cg_107
 if %111=108 goto *cg_108
 if %111=109 goto *cg_109
 if %111=110 goto *cg_110

 if %111=111 goto *cg_111
 if %111=112 goto *cg_112
 if %111=113 goto *cg_113
 if %111=114 goto *cg_114
 if %111=115 goto *cg_115

 if %111=116 goto *cg_116
 if %111=117 goto *cg_117
 if %111=118 goto *cg_118
 if %111=119 goto *cg_119
 if %111=120 goto *cg_120

 if %111=121 goto *cg_121
 if %111=122 goto *cg_122
 if %111=123 goto *cg_123
 if %111=124 goto *cg_124
 if %111=125 goto *cg_125

 goto *cg_loop2

 *cg_101
 
  csp -1
 
  if %cgpage=1 goto *bg_101
  if %cgpage=2 goto *bg_201
  if %cgpage=3 goto *bg_301
  if %cgpage=4 goto *bg_401
  
 *cg_102

  csp -1
 
  if %cgpage=1 goto *bg_102
  if %cgpage=2 goto *bg_202
  if %cgpage=3 goto *bg_302
  if %cgpage=4 goto *bg_402
 
 *cg_103
 
  csp -1
 
  if %cgpage=1 goto *bg_103
  if %cgpage=2 goto *bg_203
  if %cgpage=3 goto *bg_303
  if %cgpage=4 goto *bg_403

 *cg_104
 
  csp -1
 
  if %cgpage=1 goto *bg_104
  if %cgpage=2 goto *bg_204
  if %cgpage=3 goto *bg_304
  if %cgpage=4 goto *bg_404

 *cg_105

  csp -1

  if %cgpage=1 goto *bg_105
  if %cgpage=2 goto *bg_205
  if %cgpage=3 goto *bg_305
  if %cgpage=4 goto *bg_405

 *cg_106
 
  csp -1
 
  if %cgpage=1 goto *bg_106
  if %cgpage=2 goto *bg_206
  if %cgpage=3 goto *bg_306
  if %cgpage=4 goto *bg_406

 *cg_107
 
  csp -1
 
  if %cgpage=1 goto *bg_107
  if %cgpage=2 goto *bg_207
  if %cgpage=3 goto *bg_307
  if %cgpage=4 goto *bg_407

 *cg_108
 
  csp -1
 
  if %cgpage=1 goto *bg_108
  if %cgpage=2 goto *bg_208
  if %cgpage=3 goto *bg_308
  if %cgpage=4 goto *bg_408

 *cg_109
 
  csp -1
 
  if %cgpage=1 goto *bg_109
  if %cgpage=2 goto *bg_209
  if %cgpage=3 goto *bg_309
  if %cgpage=4 goto *bg_409

 *cg_110

  csp -1

  if %cgpage=1 goto *bg_110
  if %cgpage=2 goto *bg_210
  if %cgpage=3 goto *bg_310
  if %cgpage=4 goto *bg_410

 *cg_111
 
  csp -1
 
  if %cgpage=1 goto *bg_111
  if %cgpage=2 goto *bg_211
  if %cgpage=3 goto *bg_311
  if %cgpage=4 goto *bg_411

 *cg_112
 
  csp -1
 
  if %cgpage=1 goto *bg_112
  if %cgpage=2 goto *bg_212
  if %cgpage=3 goto *bg_312
  if %cgpage=4 goto *bg_412

 *cg_113
 
  csp -1
 
  if %cgpage=1 goto *bg_113
  if %cgpage=2 goto *bg_213
  if %cgpage=3 goto *bg_313
  if %cgpage=4 goto *bg_413

 *cg_114
 
  csp -1
 
  if %cgpage=1 goto *bg_114
  if %cgpage=2 goto *bg_214
  if %cgpage=3 goto *bg_314
  if %cgpage=4 goto *bg_414

 *cg_115
 
  csp -1
 
  if %cgpage=1 goto *bg_115
  if %cgpage=2 goto *bg_215
  if %cgpage=3 goto *bg_315
  if %cgpage=4 goto *bg_415

 *cg_116
 
  csp -1 
 
  if %cgpage=1 goto *bg_116
  if %cgpage=2 goto *bg_216
  if %cgpage=3 goto *bg_316
  if %cgpage=4 goto *bg_416

 *cg_117

  csp -1
 
  if %cgpage=1 goto *bg_117
  if %cgpage=2 goto *bg_217
  if %cgpage=3 goto *bg_317
  if %cgpage=4 goto *bg_417

 *cg_118
 
  csp -1 
 
  if %cgpage=1 goto *bg_118
  if %cgpage=2 goto *bg_218
  if %cgpage=3 goto *bg_318
  if %cgpage=4 goto *bg_418

 *cg_119
 
  csp -1 
 
  if %cgpage=1 goto *bg_119
  if %cgpage=2 goto *bg_219
  if %cgpage=3 goto *bg_319
  if %cgpage=4 goto *bg_419

 *cg_120
 
  csp -1 
 
  if %cgpage=1 goto *bg_120
  if %cgpage=2 goto *bg_220
  if %cgpage=3 goto *bg_320
  if %cgpage=4 goto *bg_420

 *cg_121
 
  csp -1 
 
  if %cgpage=1 goto *bg_121
  if %cgpage=2 goto *bg_221
  if %cgpage=3 goto *bg_321
  if %cgpage=4 goto *bg_421

 *cg_122
 
  csp -1 
 
  if %cgpage=1 goto *bg_122
  if %cgpage=2 goto *bg_222
  if %cgpage=3 goto *bg_322
  if %cgpage=4 goto *bg_422

 *cg_123
 
  csp -1 
 
  if %cgpage=1 goto *bg_123
  if %cgpage=2 goto *bg_223
  if %cgpage=3 goto *bg_323

 *cg_124
 
  csp -1 
 
  if %cgpage=1 goto *bg_124
  if %cgpage=2 goto *bg_224
  if %cgpage=3 goto *bg_324

 *cg_125
 
  csp -1 
 
  if %cgpage=1 goto *bg_125
  if %cgpage=2 goto *bg_225
  if %cgpage=3 goto *bg_325

 *cg_player
 
 csp -1

 *bg_101
 if %cgset_0=1 bg "cg\02.jpg"  ,10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_102
 if %cgset_0=1 bg "cg\03_1.jpg",10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_103
 if %cgset_2=1 bg "cg\03_2.jpg",10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_104
 if %ending=3 bg "cg\03_3.jpg",10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_105
 if %cgset_2=1 bg "cg\05.jpg"  ,10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_106
 if %cgset_0=1 bg "cg\06.jpg"  ,10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_107
 if %cgset_0=1 bg "cg\07.jpg"  ,10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_108
 if %cgset_0=1 bg "cg\07_a.jpg",10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_109
 if %cgset_0=1 bg "cg\08.jpg"  ,10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_110
 if %cgset_0=1 bg "cg\08_a.jpg",10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_111
 if %cgset_0=1 bg "cg\09.jpg"  ,10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_112
 if %cgset_0=1 bg "cg\10.jpg"  ,10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_113
 if %cgset_0=1 bg "cg\10_a.jpg",10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_114
 if %cgset_0=1 bg "cg\11_1.jpg",10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_115
 if %cgset_0=1 bg "cg\11_2.jpg",10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_116
 if %cgset_0=1 bg "cg\11_3.jpg",10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_117
 if %cgset_0=1 bg "cg\12.jpg"  ,10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_118 
 if %cgset_0=1 bg "cg\13.jpg"  ,10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_119 
 if %cgset_0=1 bg "cg\14.jpg"  ,10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_120 
 if %cgset_0=1 bg "cg\15_1.jpg",10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_121
 if %cgset_0=1 bg "cg\15_2.jpg",10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_122 
 if %cgset_0=1 bg "cg\16.jpg"  ,10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_123 
 if %cgset_0=1 bg "cg\16_2.jpg",10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_124
 if %cgset_0=1 bg "cg\17.jpg"  ,10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_125
 if %cgset_0=1 bg "cg\17_2.jpg",10,500:mov %cgpage,1:btnwait %111:if %111=-1 goto *cg_loop
 *bg_201
 if %cgset_0=1 bg "cg\18.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_202
 if %cgset_0=1 bg "cg\18_a.jpg",10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_203 
 if %ending=3 bg "cg\18_b.jpg",10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_204 
 if %cgset_0=1 bg "cg\19.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_205 
 if %cgset_0=1 bg "cg\20.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_206
 if %cgset_0=1 bg "cg\21.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_207 
 if %cgset_0=1 bg "cg\22.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_208 
 if %cgset_0=1 bg "cg\23.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_209 
 if %cgset_1=1 bg "cg\24.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_210 
 if %cgset_0=1 bg "cg\25.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_211
 if %cgset_2=1 bg "cg\26.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_212 
 if %cgset_2=1 bg "cg\27.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_213 
 if %cgset_2=1 bg "cg\27_2.jpg",10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_214 
 if %cgset_2=1 bg "cg\28.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_215 
 if %cgset_2=1 bg "cg\29.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_216
 if %cgset_2=1 bg "cg\30.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_217 
 if %cgset_0=1 bg "cg\31.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_218 
 if %cgset_0=1 bg "cg\31_a.jpg",10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_219 
 if %cgset_0=1 bg "cg\32.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_220 
 if %cgset_2=1 bg "cg\33_1.jpg",10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_221
 if %cgset_2=1 bg "cg\33_2.jpg",10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_222 
 if %cgset_2=1 bg "cg\34.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_223 
 if %cgset_2=1 bg "cg\35.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_224
 if %cgset_2=1 bg "cg\36.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_225
 if %cgset_2=1 bg "cg\38.jpg"  ,10,500:mov %cgpage,2:btnwait %111:if %111=-1 goto *cg_loop
 *bg_301
 if %cgset_2=1 bg "cg\39.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_302
 if %cgset_2=1 bg "cg\40.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_303
 if %cgset_3=1 bg "cg\41.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_304
 if %cgset_2=1 bg "cg\42.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_305
 if %cgset_2=1 bg "cg\43_1.jpg",10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_306
 if %cgset_2=1 bg "cg\43_2.jpg",10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_307
 if %cgset_2=1 bg "cg\43_3.jpg",10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_308
 if %cgset_2=1 bg "cg\44.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_309
; if %cgset_4=1 bg "cg\45.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 if %cgset_4=1 gosub *cg_45:mov %cgpage,3:btnwait %111:csp -1:if %111=-1 goto *cg_loop
 *bg_310
 if %cgset_4=1 bg "cg\45_2.jpg",10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_311
 if %cgset_4=1 bg "cg\46.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_312
 if %cgset_3=1 bg "cg\47.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_313
 if %cgset_3=1 bg "cg\48.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_314
 if %cgset_3=1 bg "cg\49.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_315
 if %cgset_2=1 bg "cg\50.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_316
 if %cgset_0=1 bg "cg\51.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_317
 if %cgset_3=1 bg "cg\52.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_318
 if %cgset_4=1 bg "cg\53.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_319
 if %cgset_4=1 bg "cg\55.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_320
 if %cgset_1=1 bg "cg\56.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_321
 if %cgset_3=1 bg "cg\57.jpg"  ,10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_322
 if %cgset_4=1 bg "cg\bi02da1.jpg",10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_323
 if %cgset_0=1 bg "cg\bp01me0.jpg",10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_324
 if %cgset_0=1 bg "cg\bp02me0.jpg",10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_325
 if %cgset_0=1 bg "cg\bp03me0.jpg",10,500:mov %cgpage,3:btnwait %111:if %111=-1 goto *cg_loop
 *bg_401
 if %cgset_0=1 bg "cg\h01.jpg"  ,10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_402 
 if %cgset_0=1 bg "cg\h02.jpg"  ,10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_403
 if %cgset_0=1 bg "cg\h04_1.jpg",10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_404
 if %cgset_0=1 bg "cg\h04_3.jpg",10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_405
 if %cgset_2=1 bg "cg\h05.jpg"  ,10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_406
 if %cgset_0=1 bg "cg\h06.jpg"  ,10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_407
 if %cgset_0=1 bg "cg\h07.jpg"  ,10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_408
 if %cgset_0=1 bg "cg\h08.jpg"  ,10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_409
 if %cgset_0=1 bg "cg\h09.jpg"  ,10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_410
 if %cgset_0=1 bg "cg\h09_2.jpg",10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_411
 if %cgset_2=1 bg "cg\h10.jpg"  ,10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_412
 if %cgset_2=1 bg "cg\h11.jpg"  ,10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_413
 if %cgset_2=1 bg "cg\h12.jpg"  ,10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_414
 if %cgset_2=1 bg "cg\h13.jpg"  ,10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_415
 if %cgset_2=1 bg "cg\h14.jpg"  ,10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_416
 if %cgset_2=1 bg "cg\h14_1.jpg",10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_417
 if %cgset_2=1 bg "cg\h14_2.jpg",10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_418
 if %cgset_2=1 bg "cg\h15.jpg"  ,10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_419
 if %cgset_2=1 bg "cg\h16.jpg"  ,10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_420
 if %cgset_2=1 bg "cg\h17_1.jpg",10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_421
 if %cgset_2=1 bg "cg\h17_2.jpg",10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop
 *bg_422
 if %cgset_2=1 bg "cg\h18.jpg"  ,10,500:mov %cgpage,4:btnwait %111:if %111=-1 goto *cg_loop

 goto *cg_loop

 *cg_end

 csp -1

return

; Special CG
*cg_45
 csp -1:bg black:lsp 85,":c;cg\45.jpg",0,0:print 10,500:click
 
 for %0=0 to 720 step 80
 msp 85,-80,0:print 1
 next
 
return

*cg_page_1

 csp -1
 
 btndef ":a;data\cg_filter.png"
 
 if %cgset_0=1 lsp 101,":c;cg\mode\02.jpg"  ,130,90:btn 101,130,90,100,75,0,0
 if %cgset_0=1 lsp 102,":c;cg\mode\03_1.jpg",240,90:btn 102,240,90,100,75,0,0
 if %cgset_2=1 lsp 103,":c;cg\mode\03_2.jpg",350,90:btn 103,350,90,100,75,0,0
 if %end1_clear=1 && %end2_clear=1 && %end3_clear=1 lsp 104,":c;cg\mode\03_3.jpg",460,90:btn 104,460,90,100,75,0,0
 if %cgset_2=1 lsp 105,":c;cg\mode\05.jpg"  ,570,90:btn 105,570,90,100,75,0,0

 if %cgset_0=1 lsp 106,":c;cg\mode\06.jpg"  ,130,175:btn 106,130,175,100,75,0,0
 if %cgset_0=1 lsp 107,":c;cg\mode\07.jpg"  ,240,175:btn 107,240,175,100,75,0,0
 if %cgset_0=1 lsp 108,":c;cg\mode\07_a.jpg",350,175:btn 108,350,175,100,75,0,0
 if %cgset_0=1 lsp 109,":c;cg\mode\08.jpg"  ,460,175:btn 109,460,175,100,75,0,0
 if %cgset_0=1 lsp 110,":c;cg\mode\08_a.jpg",570,175:btn 110,570,175,100,75,0,0
 
 if %cgset_0=1 lsp 111,":c;cg\mode\09.jpg"  ,130,260:btn 111,130,260,100,75,0,0
 if %cgset_0=1 lsp 112,":c;cg\mode\10.jpg"  ,240,260:btn 112,240,260,100,75,0,0
 if %cgset_0=1 lsp 113,":c;cg\mode\10_a.jpg",350,260:btn 113,350,260,100,75,0,0
 if %cgset_0=1 lsp 114,":c;cg\mode\11_1.jpg",460,260:btn 114,460,260,100,75,0,0
 if %cgset_0=1 lsp 115,":c;cg\mode\11_2.jpg",570,260:btn 115,570,260,100,75,0,0
 
 if %cgset_0=1 lsp 116,":c;cg\mode\11_3.jpg",130,345:btn 116,130,345,100,75,0,0
 if %cgset_0=1 lsp 117,":c;cg\mode\12.jpg"  ,240,345:btn 117,240,345,100,75,0,0
 if %cgset_0=1 lsp 118,":c;cg\mode\13.jpg"  ,350,345:btn 118,350,345,100,75,0,0
 if %cgset_0=1 lsp 119,":c;cg\mode\14.jpg"  ,460,345:btn 119,460,345,100,75,0,0
 if %cgset_0=1 lsp 120,":c;cg\mode\15_1.jpg",570,345:btn 120,570,345,100,75,0,0
 
 if %cgset_0=1 lsp 121,":c;cg\mode\15_2.jpg",130,430:btn 121,130,430,100,75,0,0
 if %cgset_0=1 lsp 122,":c;cg\mode\16.jpg"  ,240,430:btn 122,240,430,100,75,0,0
 if %cgset_0=1 lsp 123,":c;cg\mode\16_2.jpg",350,430:btn 123,350,430,100,75,0,0
 if %cgset_0=1 lsp 124,":c;cg\mode\17.jpg"  ,460,430:btn 124,460,430,100,75,0,0
 if %cgset_0=1 lsp 125,":c;cg\mode\17_2.jpg",570,430:btn 125,570,430,100,75,0,0

 return

*cg_page_2

 csp -1
 
 btndef ":a;data\cg_filter.png"

 if %cgset_0=1 lsp 101,":c;cg\mode\18.jpg"  ,130,90 :btn 101,130,90,100,75,0,0
 if %cgset_0=1 lsp 102,":c;cg\mode\18_a.jpg",240,90 :btn 102,240,90,100,75,0,0
 if %end1_clear=1 && %end2_clear=1 && %end3_clear=1 lsp 103,":c;cg\mode\18_b.jpg",350,90:btn 103,350,90,100,75,0,0
 if %cgset_0=1 lsp 104,":c;cg\mode\19.jpg"  ,460,90 :btn 104,460,90,100,75,0,0
 if %cgset_0=1 lsp 105,":c;cg\mode\20.jpg"  ,570,90 :btn 105,570,90,100,75,0,0

 if %cgset_0=1 lsp 106,":c;cg\mode\21.jpg"  ,130,175:btn 106,130,175,100,75,0,0
 if %cgset_0=1 lsp 107,":c;cg\mode\22.jpg"  ,240,175:btn 107,240,175,100,75,0,0
 if %cgset_0=1 lsp 108,":c;cg\mode\23.jpg"  ,350,175:btn 108,350,175,100,75,0,0
 if %cgset_1=1 lsp 109,":c;cg\mode\24.jpg"  ,460,175:btn 109,460,175,100,75,0,0
 if %cgset_0=1 lsp 110,":c;cg\mode\25.jpg"  ,570,175:btn 110,570,175,100,75,0,0
 
 if %cgset_2=1 lsp 111,":c;cg\mode\26.jpg"  ,130,260:btn 111,130,260,100,75,0,0
 if %cgset_2=1 lsp 112,":c;cg\mode\27.jpg"  ,240,260:btn 112,240,260,100,75,0,0
 if %cgset_2=1 lsp 113,":c;cg\mode\27_2.jpg",350,260:btn 113,350,260,100,75,0,0
 if %cgset_2=1 lsp 114,":c;cg\mode\28.jpg"  ,460,260:btn 114,460,260,100,75,0,0
 if %cgset_2=1 lsp 115,":c;cg\mode\29.jpg"  ,570,260:btn 115,570,260,100,75,0,0

 if %cgset_2=1 lsp 116,":c;cg\mode\30.jpg"  ,130,345:btn 116,130,345,100,75,0,0
 if %cgset_0=1 lsp 117,":c;cg\mode\31.jpg"  ,240,345:btn 117,240,345,100,75,0,0
 if %cgset_0=1 lsp 118,":c;cg\mode\31_a.jpg",350,345:btn 118,350,345,100,75,0,0
 if %cgset_0=1 lsp 119,":c;cg\mode\32.jpg"  ,460,345:btn 119,460,345,100,75,0,0
 if %cgset_2=1 lsp 120,":c;cg\mode\33_1.jpg",570,345:btn 120,570,345,100,75,0,0
 
 if %cgset_2=1 lsp 121,":c;cg\mode\33_2.jpg",130,430:btn 121,130,430,100,75,0,0
 if %cgset_2=1 lsp 122,":c;cg\mode\34.jpg"  ,240,430:btn 122,240,430,100,75,0,0
 if %cgset_2=1 lsp 123,":c;cg\mode\35.jpg"  ,350,430:btn 123,350,430,100,75,0,0
 if %cgset_2=1 lsp 124,":c;cg\mode\36.jpg"  ,460,430:btn 124,460,430,100,75,0,0
 if %cgset_2=1 lsp 125,":c;cg\mode\38.jpg"  ,570,430:btn 125,570,430,100,75,0,0

 return

*cg_page_3

 csp -1
 
 btndef ":a;data\cg_filter.png"
 
 if %cgset_2=1 lsp 101,":c;cg\mode\39.jpg"  ,130,90:btn 101,130,90,100,75,0,0
 if %cgset_2=1 lsp 102,":c;cg\mode\40.jpg"  ,240,90:btn 102,240,90,100,75,0,0
 if %cgset_3=1 lsp 103,":c;cg\mode\41.jpg"  ,350,90:btn 103,350,90,100,75,0,0
 if %cgset_2=1 lsp 104,":c;cg\mode\42.jpg"  ,460,90:btn 104,460,90,100,75,0,0
 if %cgset_2=1 lsp 105,":c;cg\mode\43_1.jpg",570,90:btn 105,570,90,100,75,0,0

 if %cgset_2=1 lsp 106,":c;cg\mode\43_2.jpg",130,175:btn 106,130,175,100,75,0,0
 if %cgset_2=1 lsp 107,":c;cg\mode\43_3.jpg",240,175:btn 107,240,175,100,75,0,0
 if %cgset_2=1 lsp 108,":c;cg\mode\44.jpg"  ,350,175:btn 108,350,175,100,75,0,0
 if %cgset_4=1 lsp 109,":c;cg\mode\45.jpg"  ,460,175:btn 109,460,175,100,75,0,0
 if %cgset_4=1 lsp 110,":c;cg\mode\45_2.jpg",570,175:btn 110,570,175,100,75,0,0
 
 if %cgset_4=1 lsp 111,":c;cg\mode\46.jpg"  ,130,260:btn 111,130,260,100,75,0,0
 if %cgset_3=1 lsp 112,":c;cg\mode\47.jpg"  ,240,260:btn 112,240,260,100,75,0,0
 if %cgset_3=1 lsp 113,":c;cg\mode\48.jpg"  ,350,260:btn 113,350,260,100,75,0,0
 if %cgset_3=1 lsp 114,":c;cg\mode\49.jpg"  ,460,260:btn 114,460,260,100,75,0,0
 if %cgset_2=1 lsp 115,":c;cg\mode\50.jpg"  ,570,260:btn 115,570,260,100,75,0,0
 
 if %cgset_0=1 lsp 116,":c;cg\mode\51.jpg"  ,130,345:btn 116,130,345,100,75,0,0
 if %cgset_3=1 lsp 117,":c;cg\mode\52.jpg"  ,240,345:btn 117,240,345,100,75,0,0
 if %cgset_4=1 lsp 118,":c;cg\mode\53.jpg"  ,350,345:btn 118,350,345,100,75,0,0
 if %cgset_4=1 lsp 119,":c;cg\mode\55.jpg"  ,460,345:btn 119,460,345,100,75,0,0
 if %cgset_1=1 lsp 120,":c;cg\mode\56.jpg"  ,570,345:btn 120,570,345,100,75,0,0
 
 if %cgset_3=1 lsp 121,":c;cg\mode\57.jpg"  ,130,430:btn 121,130,430,100,75,0,0
 if %cgset_4=1 lsp 122,":c;cg\mode\bi02da1.jpg",240,430:btn 122,240,430,100,75,0,0
 if %cgset_0=1 lsp 123,":c;cg\mode\bp01me0.jpg",350,430:btn 123,350,430,100,75,0,0
 if %cgset_0=1 lsp 124,":c;cg\mode\bp02me0.jpg",460,430:btn 124,460,430,100,75,0,0
 if %cgset_0=1 lsp 125,":c;cg\mode\bp03me0.jpg",570,430:btn 125,570,430,100,75,0,0

 return

*cg_page_4

 csp -1
 
 btndef ":a;data\cg_filter.png"

 if %cgset_0=1 lsp 101,":c;cg\mode\h01.jpg"  ,130,90:btn 101,130,90,100,75,0,0
 if %cgset_0=1 lsp 102,":c;cg\mode\h02.jpg"  ,240,90:btn 102,240,90,100,75,0,0
 if %cgset_0=1 lsp 103,":c;cg\mode\h04_1.jpg",350,90:btn 103,350,90,100,75,0,0
 if %cgset_0=1 lsp 104,":c;cg\mode\h04_3.jpg",460,90:btn 104,460,90,100,75,0,0
 if %cgset_2=1 lsp 105,":c;cg\mode\h05.jpg"  ,570,90:btn 105,570,90,100,75,0,0

 if %cgset_0=1 lsp 106,":c;cg\mode\h06.jpg"  ,130,175:btn 106,130,175,100,75,0,0
 if %cgset_0=1 lsp 107,":c;cg\mode\h07.jpg"  ,240,175:btn 107,240,175,100,75,0,0
 if %cgset_0=1 lsp 108,":c;cg\mode\h08.jpg"  ,350,175:btn 108,350,175,100,75,0,0
 if %cgset_0=1 lsp 109,":c;cg\mode\h09.jpg"  ,460,175:btn 109,460,175,100,75,0,0
 if %cgset_0=1 lsp 110,":c;cg\mode\h09_2.jpg",570,175:btn 110,570,175,100,75,0,0
 
 if %cgset_2=1 lsp 111,":c;cg\mode\h10.jpg"  ,130,260:btn 111,130,260,100,75,0,0
 if %cgset_2=1 lsp 112,":c;cg\mode\h11.jpg"  ,240,260:btn 112,240,260,100,75,0,0
 if %cgset_2=1 lsp 113,":c;cg\mode\h12.jpg"  ,350,260:btn 113,350,260,100,75,0,0
 if %cgset_2=1 lsp 114,":c;cg\mode\h13.jpg"  ,460,260:btn 114,460,260,100,75,0,0
 if %cgset_2=1 lsp 115,":c;cg\mode\h14.jpg"  ,570,260:btn 115,570,260,100,75,0,0
 
 if %cgset_2=1 lsp 116,":c;cg\mode\h14_1.jpg",130,345:btn 116,130,345,100,75,0,0
 if %cgset_2=1 lsp 117,":c;cg\mode\h14_2.jpg",240,345:btn 117,240,345,100,75,0,0
 if %cgset_2=1 lsp 118,":c;cg\mode\h15.jpg"  ,350,345:btn 118,350,345,100,75,0,0
 if %cgset_2=1 lsp 119,":c;cg\mode\h16.jpg"  ,460,345:btn 119,460,345,100,75,0,0
 if %cgset_2=1 lsp 120,":c;cg\mode\h17_1.jpg",570,345:btn 120,570,345,100,75,0,0
 
 if %cgset_2=1 lsp 121,":c;cg\mode\h17_2.jpg",130,430:btn 121,130,430,100,75,0,0
 if %cgset_2=1 lsp 122,":c;cg\mode\h18.jpg"  ,240,430:btn 122,240,430,100,75,0,0

 return

; ======================================================================
; * OST Block *
; ======================================================================
*saya_ost

 stop

 mov %repeat,0

 csp -1:bg "cg\menu\sound_back.jpg":print 10,1000

 lsp 38,":a/5,200,2;data\eye.png",-24,-24 
 lsp 39,":a/5,200,2;data\eye.png",-24,-24

 lsp 40,":a/3,500,2;data\music_repeat.png",417,539,128

 lsp 41,":a/2,0,3;data\sl01.png",309,86
 lsp 42,":a/2,0,3;data\sl02.png",309,114
 lsp 43,":a/2,0,3;data\sl03.png",309,142
 lsp 44,":a/2,0,3;data\sl04.png",309,170
 lsp 45,":a/2,0,3;data\sl05.png",309,198
 lsp 46,":a/2,0,3;data\sl06.png",309,226
 lsp 47,":a/2,0,3;data\sl07.png",309,254
 lsp 48,":a/2,0,3;data\sl08.png",309,282
 lsp 49,":a/2,0,3;data\sl09.png",309,310
 lsp 50,":a/2,0,3;data\sl10.png",309,338
 lsp 51,":a/2,0,3;data\sl11.png",309,366
 lsp 52,":a/2,0,3;data\sl12.png",309,394
 lsp 53,":a/2,0,3;data\sl13.png",309,422
; lsp 54,":a/2,0,3;data\sl14.png",309,450
; lsp 55,":a/2,0,3;data\sl15.png",309,478
 lsp 54,":a/2,0,3;data\sl14_alt.png",309,450
 lsp 55,":a/2,0,3;data\sl15_alt.png",309,478

 lsp 56,":a/3,0,3;data\music_menu.png",304,539
 lsp 57,":a/3,0,3;data\music_repeat.png",417,539

 vsp 38,0:vsp 39,0:vsp 40,0:print 10,100

 *ost_loop

 ; Initialising buttons
 for %0=21 to 37
  
  mov %1,20
  mov %2,%0
  add %2,%1

  spbtn %2,%0

 next
 
 btnwait %111

 if %111=-1 mp3stop:vsp 38,0:vsp 39,0:goto *ost_loop
 if %111=0  goto *ost_loop
 
 if %111=21 mov %track_num,1
 if %111=22 mov %track_num,2
 if %111=23 mov %track_num,3
 if %111=24 mov %track_num,4
 if %111=25 mov %track_num,5
 if %111=26 mov %track_num,6
 if %111=27 mov %track_num,7
 if %111=28 mov %track_num,8
 if %111=29 mov %track_num,9
 if %111=30 mov %track_num,10
 if %111=31 mov %track_num,11
 if %111=32 mov %track_num,12
 if %111=33 mov %track_num,13
 if %111=34 mov %track_num,14
 if %111=35 mov %track_num,15
 if %111=36 goto *ost_end
 if %111=37 && %repeat=0 mov %repeat,1:goto *ost_paintrep
 if %111=37 && %repeat=1 mov %repeat,0:goto *ost_paintrep

 *ost_paintrep

 if %repeat=1 vsp 38,1:vsp 39,1:vsp 40,1
 if %repeat=0 vsp 40,0
 
 print 1

 mp3stop

 if %track_num=1  vsp 39,1:amsp 39,285,86 :vsp 38,1:amsp 38,491,86 
 if %track_num=2  vsp 39,1:amsp 39,285,114:vsp 38,1:amsp 38,491,114
 if %track_num=3  vsp 39,1:amsp 39,285,142:vsp 38,1:amsp 38,491,142
 if %track_num=4  vsp 39,1:amsp 39,285,170:vsp 38,1:amsp 38,491,170
 if %track_num=5  vsp 39,1:amsp 39,285,198:vsp 38,1:amsp 38,491,198
 if %track_num=6  vsp 39,1:amsp 39,285,226:vsp 38,1:amsp 38,491,226
 if %track_num=7  vsp 39,1:amsp 39,285,254:vsp 38,1:amsp 38,491,254
 if %track_num=8  vsp 39,1:amsp 39,285,282:vsp 38,1:amsp 38,491,282
 if %track_num=9  vsp 39,1:amsp 39,285,310:vsp 38,1:amsp 38,491,310
 if %track_num=10 vsp 39,1:amsp 39,285,338:vsp 38,1:amsp 38,491,338
 if %track_num=11 vsp 39,1:amsp 39,285,366:vsp 38,1:amsp 38,491,366
 if %track_num=12 vsp 39,1:amsp 39,285,394:vsp 38,1:amsp 38,491,394
 if %track_num=13 vsp 39,1:amsp 39,285,422:vsp 38,1:amsp 38,491,422
 if %track_num=14 vsp 39,1:amsp 39,285,450:vsp 38,1:amsp 38,491,450
 if %track_num=15 vsp 39,1:amsp 39,285,478:vsp 38,1:amsp 38,491,478

 if %track_num=1  && %repeat=0 mp3 s01
 if %track_num=2  && %repeat=0 mp3 s02
 if %track_num=3  && %repeat=0 mp3 s03
 if %track_num=4  && %repeat=0 mp3 s04
 if %track_num=5  && %repeat=0 mp3 s05
 if %track_num=6  && %repeat=0 mp3 s05_psycho
 if %track_num=7  && %repeat=0 mp3 s06
 if %track_num=8  && %repeat=0 mp3 s07
 if %track_num=9  && %repeat=0 mp3 s08
 if %track_num=10 && %repeat=0 mp3 s09
 if %track_num=11 && %repeat=0 mp3 s09_2
 if %track_num=12 && %repeat=0 mp3 s10
 if %track_num=13 && %repeat=0 mp3 s11
 if %track_num=14 && %repeat=0 mp3 song_of_saya
 if %track_num=15 && %repeat=0 mp3 shoes_of_glass

 if %track_num=1  && %repeat=1 mp3loop s01
 if %track_num=2  && %repeat=1 mp3loop s02
 if %track_num=3  && %repeat=1 mp3loop s03
 if %track_num=4  && %repeat=1 mp3loop s04
 if %track_num=5  && %repeat=1 mp3loop s05
 if %track_num=6  && %repeat=1 mp3loop s05_psycho
 if %track_num=7  && %repeat=1 mp3loop s06
 if %track_num=8  && %repeat=1 mp3loop s07
 if %track_num=9  && %repeat=1 mp3loop s08
 if %track_num=10 && %repeat=1 mp3loop s09
 if %track_num=11 && %repeat=1 mp3loop s09_2
 if %track_num=12 && %repeat=1 mp3loop s10
 if %track_num=13 && %repeat=1 mp3loop s11
 if %track_num=14 && %repeat=1 mp3loop song_of_saya
 if %track_num=15 && %repeat=1 mp3loop shoes_of_glass

 goto *ost_loop

 *ost_end

 stop

 if %volmp3<>-1 mp3loop s02

 return

; ======================================================================
; * Saya Staff block *
; ======================================================================
*saya_staff

rmode 0

 gosub *box9

^Congratulations! You've completed Saya no Uta.@ We have prepared something for you!
br
^Please visit
br
^#00ff00www.nitroplus.co.jp/secret/saya/login.php3?id=clear&pass=saya1226
br
^#fffffffor details.\

rmode 1

 return

; ======================================================================
; * Grotesque images controller block *
; ======================================================================
*grotesque

 rmode 0

 gosub *box8

^Эта игра содержит множество вызывающих изображений. Если вы находите их неприятными - выберите соответствующий пункт меню.
br
select "^Не изменять вызывающие изображения. (По умолчанию)",*gro_normal,"^Затемнить вызывающие изображения.",*gro_lower

 *gro_lower
  mov %gro,1
  goto *gro_finish

 *gro_normal
  mov %gro,0
 
 *gro_finish

 rmode 1 
 
 return

; ======================================================================
; !! Game start !!
; ======================================================================
*start

; Just left it here in case the newer engine will support them properly
; mp3fadein 250
; mp3fadeout 250

 gosub *saya_config_chk

 gosub *warning

 gosub *logo

 gosub *main_menu

*saya_start

mp3stop

csp -1:bg #FFFFFF:print 1
bg "cg\MENU\title2.png",1

bg black:print 10,1000

bg "cg\fiction.jpg",10

delay 3000

bg black,11

gosub *grotesque

goto *001

*saya_exit

*finish

stop

csp -1:bg #FFFFFF:print 1
bg "cg\MENU\title2.png",1
delay 1000

end

goto *start
