added key redefinition to winsys
[urasm.git] / samples / winsys / main.zas
blobb0de61f7c37e13cee38502d22940a69fffff562f
1   deffmt runtap
3 USE_IM2 equ 1
5   org  #6000
7   ld   (origSP),sp
8  IFX USE_IM2
9   di
10   ld   a,#39
11   ld   i,a
12   ld   a,#18
13   ld   (#FFFF),a  ; jr
14   ld   a,#C3      ; jp
15   ld   (#FFF4),a
16   ld   hl,IntrHandler
17   ld   (#FFF5),hl
18   im   2
19   ei
20  ENDIF
21   jp   MainEntry
23 origSP: dw 0
25   include <winsys>
28  IFX USE_IM2
29 inMenu: db 0
30 intrFirePressed: db 0
31 IntrHandler:
32   push bc,de,hl,af
33   exx
34   ex   af,af'
35   push bc,de,hl,af
37   ;ld   a,2
38   ;out  (#fe),a
40   ld   a,(inMenu)
41   or   a
42   jp   z,.notInMenu
43   ;
44   call WinMouse.Scan
45   jp   c,.mactionok
46   call WinInput.StickMoves
47   ld   a,c
48   or   a
49   jp   z,.notInMenu  ; no stick events
50 .mactionok:
51   call WinMenu.RedrawArrowFromIntr
52   ; check "fire"
53   ld   a,(WinInput.joystate)
54   rra
55   jp   nc,.notInMenu ; return if fire isn't pressed
56   ld   a,1
57   ld   (intrFirePressed),a
58   ;
59   call WinMenu.IsArrowInWindow
60   jp   nc,.inside
61   ld   a,#ff
62   ld   (WinMenu.lastSelectedItem),a
63 .inside:
65 .notInMenu:
66   ;xor  a
67   ;out  (#fe),a
69   pop  af,hl,de,bc
70   exx
71   ex   af,af'
72   pop  af,hl,de,bc
73   ei
74   ret
75  ENDIF
78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
79 ;; ÂÅÇÁÅÍ ÐÏ ÍÅÎÀÈÅ, Öģ͠"fire"
80 ;; out:
81 ;;   a: selected item (or #ff ÅÖÅÌÉ ×ÎÅ ÏËÏÛËÁ)
82 ;;   f,af',bc,de,hl,bc',de',hl': destroyed
83 RunMenuLoop:
84  IFX USE_IM2
85   xor  a
86   ld   (intrFirePressed),a
87   inc  a
88   ld   (inMenu),a
89 .loop:
90   halt
91   ld   a,(intrFirePressed)
92   or   a
93   jr   z,.loop
94   xor  a
95   ld   (inMenu),a
96   ld   a,(WinMenu.lastSelectedItem)
97   ret
98  ELSE
99   jp   WinMenu.RunMenuLoop
100  ENDIF
103 txtBack:
104   db WinPrint.ch_cls
105   db WinPrint.ch_attr,0307,WinPrint.ch_rep,32,WinPrint.ch_bigspc,WinPrint.ch_attr,017
106   db 10,WinPrint.ch_center,"Window Testing",10
107   db WinPrint.ch_center,WinPrint.ch_attr,0117,"Vampire Avalon",WinPrint.ch_bigspc
108   db WinPrint.ch_attr,017,"window system testing...",10
109   db 0
112 winMain:
113   db 12,5
114   db 10,9
115   db 050
116   db WinOpen.FLAG_FRAME|WinOpen.FLAG_SAVE|WinOpen.FLAG_SHADOW
117   db 0
119 txtMain:
120   ;db WinPrint.ch_cls
121   db WinPrint.ch_center,"redefine",10
122   db WinPrint.ch_center,"charz",10
123   db WinPrint.ch_center,"notez",10
124   db WinPrint.ch_center,"dox",10
125   db WinPrint.ch_center,"quit",10
126   db 10
127   db WinPrint.ch_center,"about"
128   db 0
130 menuMain:
131   db 0,6,8  ; about
132   db 0,4,8  ; quit
133   db 0,0,8  ; redefine
134   db 0,1,8  ; charz
135   db 0,2,8  ; notez
136   db 0,3,8  ; dox
137   db #ff
139 subrMain:
140   dw doAbout
141   dw doQuit
142   dw doRedefine
143   dw doCharSet
144   dw doNotez
145   dw doDox
148 process_text:
149 .x1:
150   ld   a,(hl)
151   or   a
152   jr   nz,.x4
153   ld   (hl),0
154   inc  hl
155   jr   .x2
156 .x4:
157   cp   10
158   jr   nz,.x3
159   inc  hl
160   ld   a,(hl)
161   dec  hl
162   or   a
163   ld   a,0
164   jr   nz,.x3
165   ; eof
166   ld   (hl),0
167   inc  hl
168   jr   .x2
169 .x3:
170   ld   (hl),a
171   inc  hl
172   jr   .x1
173 .x2:
174   ld   (hl),1
175   ret
178 notez_txt:
179   incbin "texts/notes.txt"
180   dw 0
181 dox_txt:
182   incbin "texts/dox.txt"
183   dw 0
186 MainEntry:
187   ld   hl,arrbuf
188   ld   (WinArrow.saveBufAddr),hl
189   ;
190   call WinArrow.Init
191   call WinInput.TestKeyShifts
192   jr   c,.donttestkm
193   call WinInput.TestJoyMouse  ; ÜÔÏ ÏÂÑÚÁÔÅÌØÎÏ × ÓÁÍÏÍ ÎÁÞÁÌÅ
194 .donttestkm:
196   ld   hl,notez_txt
197   call process_text
198   ld   hl,dox_txt
199   call process_text
201   xor  a
202   out  (#fe),a
204   ; ÎÁÞÁÌØÎÏÅ ÏËÏÛËÏ ÎÁËÒÙ×ÁÅÔ ×ÅÓØ ÜËÒÁÎ
205   call WinSys.MakeFullScreen
206   ;call WinPrint.ClearWin
208   ld   hl,txtBack
209   call WinPrint.PrintStrZ
211   ;call doAbout
213 showMainWin:
214   ld   ix,winMain
215   call WinOpen.Open
216   ld   hl,txtMain
217   call WinPrint.PrintStrZ
219 again:
220   ld   hl,menuMain
221 mainMenuDefItem: equ $+1
222   ld   a,2
223   call WinMenu.InitMenu
224 menuLoop:
225   call RunMenuLoop
226   call WinMenu.HideWaitRelease
227   ld   (mainMenuDefItem),a
228   ld   hl,subrMain
229   call WinMenu.GetTableWord
230   jr   z,.notselected
231   call WinMenu.CallHL
232   jr   again
233 .notselected:
234   call WinMenu.ShowArrow
235   jr   menuLoop
238 doQuit:
239   ; ÐÒÉÂأ͠ÏËÏÛËÏ É ×Ù×ÁÌÉÍÓÑ
240   call WinOpen.Close
241   ; restore interrupts and basic regs
242   ld   iy,23610
243   im   1
244   ld   hl,10072
245   exx
246   ei
247   ld   sp,(origSP)
248   ret
249   ;jp    0
250   ;ld   hl,#2758  ; for rom
251   ;exx
252   ;rst  8
253   ;db   255
254   ;ret
257 winAbout:
258   db 5,5
259   db 20,12
260   db 070
261   db WinOpen.FLAG_FRAME|WinOpen.FLAG_SAVE|WinOpen.FLAG_SHADOW
262   db "VAWS",WinPrint.ch_right,"Vampire Avalon",WinPrint.ch_smallspc,WinPrint.ch_smallspc
263   db 0
265 txtAbout:
266   db WinPrint.ch_cls
267   db 10
268   db WinPrint.ch_attr,071
269   db WinPrint.ch_center,"Vampire Avalon",10
270   db WinPrint.ch_center,"window system",10
271   db WinPrint.ch_attr,070
272   db WinPrint.ch_center,"-------------",10,10
273   db "code:",WinPrint.ch_attr,071,WinPrint.ch_right,"Ketmar",10
274   db WinPrint.ch_attr,070
275   db "guest star:",WinPrint.ch_attr,072,WinPrint.ch_right,"Pete Cooke",10
276   db WinPrint.ch_attr,070,10,10
277   db WinPrint.ch_center,"ok",WinPrint.ch_right,"i"
278   db WinPrint.ch_smallspc,WinPrint.ch_smallspc,WinPrint.ch_smallspc
279   db 0
281 menuAbout:
282   db 7, 9, 4
283   db 17,9, 1
284   db #ff
286 txtInfo:
287   db WinPrint.ch_at,0,1," "
288 txt_info_kj:
289   db WinPrint.ch_smallcheck," Kempston Joystick",10," "
290 txt_info_km:
291   db WinPrint.ch_smallcheck," Kempston Mouse",10
292   db 10,10,10,10,10,10,WinPrint.ch_center,"ok"
293   db 0
295 menuInfo:
296   db 7, 9, 4
297   db 0, 1, 18
298   db 0, 2, 18
299   db #ff
302 doAbout:
303   ld   ix,winAbout
304   call WinOpen.Open
305 about_xx:
306   ld   hl,txtAbout
307   call WinPrint.PrintStrZ
308   ld   hl,menuAbout
309   xor  a
310   call WinMenu.InitMenu
311   call RunMenuLoop
312   call WinMenu.HideWaitRelease
313   dec  a
314   jr   z,about_i
315 about_c:
316   call WinOpen.Close
317   ret
318 about_i:
319   ; info
320   call WinPrint.ClearWin
321 about_i0:
322   ld   hl,menuInfo
323   xor  a
324   call WinMenu.InitMenu
325   call WinMenu.HideArrow
326 about_il:
327   ld   a,(WinStick.kempston_here)
328   rra
329   ld   c,a
330   ld   a,WinPrint.ch_smallcheck
331   adc  a,0
332   ld   (txt_info_kj),a
333   ld   a,c
334   rra
335   ld   a,WinPrint.ch_smallcheck
336   adc  a,0
337   ld   (txt_info_km),a
338   ;
339   ld   hl,txtInfo
340   call WinPrint.PrintStrZ
341   call WinMenu.ShowArrow
342   call RunMenuLoop
343   call WinMenu.HideWaitRelease
344   cp   1
345   jr   c,about_xx
346   cp   #ff
347   jr   z,about_c
348   ;
349   ld   hl,WinStick.kempston_here
350   xor  (hl)
351   ld   (hl),a
352   jr   about_il
355 doNotez:
356   pop  hl  ; don't return
357   call WinOpen.Close
358   ld   hl,notez_txt
359   call runPager
360   jp   showMainWin
363 doDox:
364   pop  hl  ; don't return
365   call WinOpen.Close
366   ld   hl,dox_txt
367   call runPager
368   jp   showMainWin
371 winPager:
372   db 2,2
373   db 28,20
374   db 070
375   db WinOpen.FLAG_FRAME|WinOpen.FLAG_SAVE ;|WinOpen.FLAG_SHADOW
376   db WinPrint.ch_center,"Pager"
377   db 0
379 LINES_PER_PAGE: equ 16
380 runPager:
381   push hl
382   ld   ix,winPager
383   call WinOpen.Open
384   pop  hl
385 .x1:
386   ld   a,(winPager+3)
387   dec  a
388   dec  a
389   ld   b,a
390 .x2:
391   ld   a,(hl)
392   dec  a
393   jr   z,.x3
394   call WinPrint.PrintNL
395   push bc
396   call WinPrint.PrintStrZ
397   pop  bc
398   djnz .x2
399   push hl
400   call WinMenu.WaitFirePress
401   call WinMenu.WaitFireRelease
402   pop  hl
403   ld   a,(hl)
404   dec  a
405   jr   nz,.x1
406   call WinOpen.Close
407   ret
408 .x3:
409   call WinMenu.WaitFirePress
410   call WinMenu.WaitFireRelease
411   call WinOpen.Close
412   ret
415 winCharSet:
416   db 1,8
417   db 29,6
418   db 007
419   db WinOpen.FLAG_FRAME|WinOpen.FLAG_SAVE|WinOpen.FLAG_SHADOW
420   db WinPrint.ch_center,"Choose",WinPrint.ch_bigspc,"first",WinPrint.ch_bigspc,"char:"
421   db 0
423 txtCharSet0:
424   db 10
425   db "#20",WinPrint.ch_bigspc,WinPrint.ch_nextp
426   db "#40",WinPrint.ch_bigspc,WinPrint.ch_nextp
427   db "#60",WinPrint.ch_bigspc,WinPrint.ch_nextp
428   db "#80",WinPrint.ch_bigspc,WinPrint.ch_nextp
429   db "#A0",WinPrint.ch_bigspc,WinPrint.ch_nextp
430   db "#C0",WinPrint.ch_bigspc,WinPrint.ch_nextp
431   db "#E0",10,10
432   db WinPrint.ch_center,"close"
433   db 0
435 txtCharSet1:
436   db WinPrint.ch_at,0,3
437   db 0
439 menuCharSet:
440   db  0,1,3
441   db  4,1,3
442   db  8,1,3
443   db 12,1,3
444   db 16,1,3
445   db 20,1,3
446   db 24,1,3
447   db 11,3,5
448   db #ff
451 doCharSet:
452   ld   ix,winCharSet
453   call WinOpen.Open
454   ld   hl,txtCharSet0
455   call WinPrint.PrintStrZ
456   ld   hl,menuCharSet
457   ld   a,7
458   call WinMenu.InitMenu
459 .loop1:
460   call RunMenuLoop
461   call WinMenu.HideArrow
462   inc  a
463   jr   z,.quit
464   cp   8
465   jr   c,.goon
466 .loop1_q:
467   call WinMenu.WaitFireRelease
468 .quit:
469   call WinOpen.Close
470   ret
472 .goon:
473   rlca:rlca:rlca:rlca:rlca  ; *32
474   push af
475   ld   hl,txtCharSet1
476   call WinPrint.PrintStrZ
477   pop  af
478   ld   b,32
479 .loop2:
480   push af
481   call WinPrint.PrintChar
482   pop  af
483   inc  a
484   djnz .loop2
485   jr   .loop1_q
488 winKeyDef:
489   db 6,8
490   db 10,9
491   db 040
492   db WinOpen.FLAG_FRAME|WinOpen.FLAG_SAVE|WinOpen.FLAG_SHADOW
493   db WinPrint.ch_center,"New Keys"
494   db 0
496 txtKeyDef:
497   db 13,"left",WinPrint.ch_nextp," ",WinPrint.ch_nextp,": ",0
498   db "right",WinPrint.ch_nextp,": ",0
499   db "up",WinPrint.ch_nextp," ",WinPrint.ch_nextp," ",WinPrint.ch_nextp,": ",0
500   db "down",WinPrint.ch_nextp,": ",0
501   db "fire",WinPrint.ch_nextp," ",WinPrint.ch_nextp,": ",0
503 txtSS: db "SS",13,0
504 txtCS: db "CS",13,0
505 txtSP: db "SP",13,0
506 txtRT: db "RET",13,0
507 txtKK: db 0,13,0
509 doRedefine:
510   ; clear keys
511   ld   hl,WinStick.keystick_table
512   ld   de,WinStick.keystick_table+1
513   ld   bc,5
514   ld   (hl),255
515   ldir
516   ;
517   ld   ix,winKeyDef
518   call WinOpen.Open
519   ld   b,5
520   ld   hl,txtKeyDef
521   ld   de,WinStick.keystick_table
522 .nextkey:
523   call WinInput.WaitKeysRelease
524   push de
525   call WinPrint.PrintStrZ
526 .wloop:
527   halt
528   call WinStick.ReadAnyKey
529   jr   nc,.wloop
530   ; check if this key already used
531   push hl
532   ld   hl,WinStick.keystick_table
533   ld   c,a
534 .checkloop:
535   ld   a,(hl)
536   inc  hl
537   cp   #ff
538   jr   z,.checkok
539   cp   c
540   jr   nz,.checkloop
541   ; duplicate key
542   pop  hl
543   jr   .wloop
544 .checkok:
545   pop  hl
546   ld   a,c
547   pop  de
548   ld   (de),a
549   inc  de
550   ;
551   push hl,bc,de
552   ld   hl,WinStick.keynames
553   ld   b,0
554   add  hl,bc
555   ld   a,(hl)
556   ld   hl,txtKK
557   ld   (hl),a
558   cp   33
559   jr   nc,.nameok
560   ld   hl,txtRT
561   cp   13
562   jr   z,.nameok
563   ld   hl,txtCS
564   cp   30
565   jr   z,.nameok
566   ld   hl,txtSS
567   cp   31
568   jr   z,.nameok
569   ld   hl,txtSP
570   cp   32
571   jr   z,.nameok
572 .nameok:
573   call WinPrint.PrintStrZ
574   pop  de,bc,hl
575   djnz .nextkey
576 .done:
577   call WinInput.WaitKeysRelease
578   call WinOpen.Close
579   ret
582 arrbuf: ds 3*8
584 WinSys.SaveBufAddr equ $