winsys sample: cosmetix
[urasm.git] / samples / winsys / main.zas
blob21ab0d61b995a67725f1184ab94b6bb3e05d0a2d
1   deffmt runtap
3 USE_IM2 equ 0
5 FIXUP_NATURAL_ORG EQU #6000
6   IF defined(USE_FIXUPS) && USE_FIXUPS
7     include <fixup/fixupheader.zas>
8     include <fixup/dofixup.zas>
9   ELSE
10     org  #6000
11     clr  #6000-1
12     ent  #6000
13   ENDIF
15   ld   (origSP),sp
16  IF defined(USE_IM2) && USE_IM2
17   di
18   ld   a,#39
19   ld   i,a
20   ld   a,#18
21   ld   (#FFFF),a  ; jr
22   ld   a,#C3      ; jp
23   ld   (#FFF4),a
24   ld   hl,IntrHandler
25   ld   (#FFF5),hl
26   im   2
27   ei
28  ENDIF
29   jp   MainEntry
31 origSP: dw 0
33 _wsstart: equ $
34   include <winsys>
35 _wslen: equ ($-_wsstart)|0
36   display "winsys size: ", _wslen, " bytes\n"
38  IF defined(USE_IM2) && USE_IM2
39   $printf "IM2!"
40 inMenu: db 0
41 intrFirePressed: db 0
42 IntrHandler:
43   push bc,de,hl,af
44   exx
45   ex   af,af'
46   push bc,de,hl,af
48   ;ld   a,2
49   ;out  (#fe),a
51   ld   a,(inMenu)
52   or   a
53   jp   z,.notInMenu
54   ;
55   call WinMouse.Scan
56   jp   c,.mactionok
57   call WinInput.StickMoves
58   ld   a,c
59   or   a
60   jp   z,.notInMenu  ; no stick events
61 .mactionok:
62   call WinMenu.RedrawArrowFromIntr
63   ; check "fire"
64   ld   a,(WinInput.joystate)
65   rra
66   jp   nc,.notInMenu ; return if fire isn't pressed
67   ld   a,1
68   ld   (intrFirePressed),a
69   ;
70   call WinMenu.IsArrowInWindow
71   jp   nc,.inside
72   ld   a,#ff
73   ld   (WinMenu.lastSelectedItem),a
74 .inside:
76 .notInMenu:
77   ;xor  a
78   ;out  (#fe),a
80   pop  af,hl,de,bc
81   exx
82   ex   af,af'
83   pop  af,hl,de,bc
84   ei
85   ret
86  ENDIF
89 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
90 ;; ÂÅÇÁÅÍ ÐÏ ÍÅÎÀÈÅ, Öģ͠"fire"
91 ;; out:
92 ;;   a: selected item (or #ff ÅÖÅÌÉ ×ÎÅ ÏËÏÛËÁ)
93 ;;   f,af',bc,de,hl,bc',de',hl': destroyed
94 RunMenuLoop:
95  IF defined(USE_IM2) && USE_IM2
96   xor  a
97   ld   (intrFirePressed),a
98   inc  a
99   ld   (inMenu),a
100 .loop:
101   halt
102   ld   a,(intrFirePressed)
103   or   a
104   jr   z,.loop
105   xor  a
106   ld   (inMenu),a
107   ld   a,(WinMenu.lastSelectedItem)
108   ret
109  ELSE
110   jp   WinMenu.RunMenuLoop
111  ENDIF
114 txtBack:
115   db WinPrint.ch_cls
116   db WinPrint.ch_attr,0307
117   db WinPrint.ch_rep,32,WinPrint.ch_bigspc
118   db WinPrint.ch_at,0,0
119   db " File ",WinPrint.ch_nextp
120   db " Edit ",WinPrint.ch_nextp
121   db " View ",WinPrint.ch_nextp
122   db " Tools",WinPrint.ch_nextp
123   db WinPrint.ch_right," Help "
124   db WinPrint.ch_attr,017
125   db 10,WinPrint.ch_center,"Window Testing",10
126   db WinPrint.ch_center,WinPrint.ch_attr,0117,"Invisible Vector",WinPrint.ch_bigspc
127   db WinPrint.ch_attr,017,"window system testing...",10
128   db 0
131 winMain:
132   db 12,5
133   db 10,9
134   db 050
135   db WinOpen.FLAG_FRAME|WinOpen.FLAG_SAVE|WinOpen.FLAG_SHADOW
136   db 0
138 txtMain:
139   ;db WinPrint.ch_cls
140   db WinPrint.ch_center,"redefine",10
141   db WinPrint.ch_center,"charz",10
142   db WinPrint.ch_center,"notez",10
143   db WinPrint.ch_center,"readstr",10
144   db WinPrint.ch_center,"close",10
145   db 10
146   db WinPrint.ch_center,"about"
147   db 0
149 menuMain:
150   db 0,6,8  ; about
151   db 0,4,8  ; quit
152   db 0,0,8  ; redefine
153   db 0,1,8  ; charz
154   db 0,2,8  ; notez
155   db 0,3,8  ; readstr
156   db #ff
158 subrMain:
159   dw doAbout
160   dw doQuit
161   dw doRedefine
162   dw doCharSet
163   dw doNotez
164   dw doReadStr
167 process_text:
168 .x1:
169   ld   a,(hl)
170   or   a
171   jr   nz,.x4
172   ld   (hl),0
173   inc  hl
174   jr   .x2
175 .x4:
176   cp   10
177   jr   nz,.x3
178   inc  hl
179   ld   a,(hl)
180   dec  hl
181   or   a
182   ld   a,0
183   jr   nz,.x3
184   ; eof
185   ld   (hl),0
186   inc  hl
187   jr   .x2
188 .x3:
189   ld   (hl),a
190   inc  hl
191   jr   .x1
192 .x2:
193   ld   (hl),1
194   ret
197 notez_txt:
198   incbin "texts/notes.txt"
199   dw 0
202 MainEntry:
203   ld   hl,arrbuf
204   ld   (WinArrow.saveBufAddr),hl
205   ;
206   call WinArrow.Init
207   call WinInput.TestKeyShifts
208   jr   c,.donttestkm
209   halt                        ; ÞÔÏÂÙ ÐÌÁ×ÁÀÝÁÑ ÛÉÎÁ ÎÅ ÎÁÓÒÁÌÁ
210   call WinInput.TestJoyMouse  ; ÜÔÏ ÏÂÑÚÁÔÅÌØÎÏ × ÓÁÍÏÍ ÎÁÞÁÌÅ
211 .donttestkm:
213   ld   hl,notez_txt
214   call process_text
216   xor  a
217   out  (#fe),a
219   ; ÎÁÞÁÌØÎÏÅ ÏËÏÛËÏ ÎÁËÒÙ×ÁÅÔ ×ÅÓØ ÜËÒÁÎ
220   call WinSys.MakeFullScreen
221   ;call WinPrint.ClearWin
223   ld   hl,txtBack
224   call WinPrint.PrintStrZ
226   ;call doAbout
228 showMainWin:
229   ld   ix,winMain
230   call WinOpen.Open
231   ld   hl,txtMain
232   call WinPrint.PrintStrZ
234 again:
235   ld   hl,menuMain
236 mainMenuDefItem: equ $+1
237   ld   a,0
238   call WinMenu.InitMenu
239 menuLoop:
240   call RunMenuLoop
241   call WinMenu.HideWaitRelease
242   ld   (mainMenuDefItem),a
243   ld   hl,subrMain
244   call WinMenu.GetTableWord
245   jr   z,.notselected
246   call WinMenu.CallHL
247   jr   again
248 .notselected:
249   call WinMenu.ShowArrow
250   jr   menuLoop
253 doQuit:
254   call WinOpen.Close
255   ;
256   call xtopmenu
257   ;
258   ; restore interrupts and basic regs
259   ld   iy,23610
260   im   1
261   ld   hl,10072
262   exx
263   ei
264   ld   sp,(origSP)
265   ret
267 xtopmenu:
268   ld   hl,ztopmenu
269   ld   a,#ff
270   call WinMenu.InitMenu
271 .loop:
272   call RunMenuLoop
273   inc  a
274   jr   nz,.loop
275   ret
277 ztopmenu:
278   db 0,0,4
279   db 4,0,4
280   db 8,0,4
281   db 12,0,5
282   db 32-4,0,4
283   db #ff
286 winReadStr:
287   db 13,8
288   db 13,4
289   db 070
290   db WinOpen.FLAG_FRAME|WinOpen.FLAG_SAVE|WinOpen.FLAG_SHADOW
291   db WinPrint.ch_center,"input string"
292   db 0
294   db 13
295   db WinPrint.ch_center
296 sbuf:
297   db "string"
298   ds 33,0
301 doReadStr:
302   ld   ix,winReadStr
303   call WinOpen.Open
304   call WinPrint.PrintNL
305   ld   a,'`'
306   call WinPrint.PrintChar
307   ld   hl,sbuf
308   ld   c,10
309   call WinInput.ReadStrZ
310   jr   c,.quit
311   call WinPrint.ClearWin
312   ld   hl,sbuf-2
313   call WinPrint.PrintStrZ
314   call WinMenu.WaitFirePress
315   call WinMenu.WaitFireRelease
316 .quit:
317   call WinOpen.Close
318   ret
321 winAbout:
322   db 5,5
323   db 20,12
324   db 070
325   db WinOpen.FLAG_FRAME|WinOpen.FLAG_SAVE|WinOpen.FLAG_SHADOW
326   db "VAWS",WinPrint.ch_right,"Invisible Vector",WinPrint.ch_smallspc,WinPrint.ch_smallspc
327   db 0
330 txtAbout:
331   db WinPrint.ch_cls
332   db 10
333   db WinPrint.ch_attr,071
334   db WinPrint.ch_center,"Invisible Vector",10
335   db WinPrint.ch_center,"window system",10
336   db WinPrint.ch_attr,070
337   db WinPrint.ch_center,"-------------",10,10
338   db "code:",WinPrint.ch_attr,071,WinPrint.ch_right,"Ketmar",10
339   db WinPrint.ch_attr,070
340   db "guest star:",WinPrint.ch_attr,072,WinPrint.ch_right,"Pete Cooke",10
341   db WinPrint.ch_attr,070,10,10
342   db WinPrint.ch_center,"ok",WinPrint.ch_right,"i"
343   db WinPrint.ch_smallspc,WinPrint.ch_smallspc,WinPrint.ch_smallspc
344   db 0
346 menuAbout:
347   db 7, 9, 4
348   db 17,9, 1
349   db #ff
351 txtInfo:
352   db WinPrint.ch_at,0,1," "
353 txt_info_kj:
354   db WinPrint.ch_smallcheck," Kempston Joystick",10," "
355 txt_info_km:
356   db WinPrint.ch_smallcheck," Kempston Mouse",10
357   db 10,10,10,10,10,10,WinPrint.ch_center,"ok"
358   db 0
360 menuInfo:
361   db 7, 9, 4
362   db 0, 1, 18
363   db 0, 2, 18
364   db #ff
367 doAbout:
368   ld   ix,winAbout
369   call WinOpen.Open
370 about_xx:
371   ld   hl,txtAbout
372   call WinPrint.PrintStrZ
373   ld   hl,menuAbout
374   xor  a
375   call WinMenu.InitMenu
376   call RunMenuLoop
377   call WinMenu.HideWaitRelease
378   dec  a
379   jr   z,about_i
380 about_c:
381   call WinOpen.Close
382   ret
383 about_i:
384   ; info
385   call WinPrint.ClearWin
386 about_i0:
387   ld   hl,menuInfo
388   xor  a
389   call WinMenu.InitMenu
390   call WinMenu.HideArrow
391 about_il:
392   ld   a,(WinStick.kempston_here)
393   rra
394   ld   c,a
395   ld   a,WinPrint.ch_smallcheck
396   adc  a,0
397   ld   (txt_info_kj),a
398   ld   a,c
399   rra
400   ld   a,WinPrint.ch_smallcheck
401   adc  a,0
402   ld   (txt_info_km),a
403   ;
404   ld   hl,txtInfo
405   call WinPrint.PrintStrZ
406   call WinMenu.ShowArrow
407   call RunMenuLoop
408   call WinMenu.HideWaitRelease
409   cp   1
410   jr   c,about_xx
411   cp   #ff
412   jr   z,about_c
413   ;
414   ld   hl,WinStick.kempston_here
415   xor  (hl)
416   ld   (hl),a
417   jr   about_il
420 doNotez:
421   pop  hl  ; don't return
422   call WinOpen.Close
423   ld   hl,notez_txt
424   call runPager
425   jp   showMainWin
428 winPager:
429   db 2,2
430   db 28,20
431   db 070
432   db WinOpen.FLAG_FRAME|WinOpen.FLAG_SAVE ;|WinOpen.FLAG_SHADOW
433   db WinPrint.ch_center,"Pager"
434   db 0
436 LINES_PER_PAGE: equ 16
437 runPager:
438   push hl
439   ld   ix,winPager
440   call WinOpen.Open
441   ld   hl,WinSys.printy
442   dec  (hl)
443   pop  hl
444 .x1:
445   ld   a,(winPager+3)
446   dec  a
447   dec  a
448   ld   b,a
449 .x2:
450   ld   a,(hl)
451   dec  a
452   jr   z,.x3
453   call WinPrint.PrintNL
454   push bc
455   call WinPrint.PrintStrZ
456   pop  bc
457   djnz .x2
458 .x3:
459   push hl
460   call WinMenu.WaitFirePress
461   call WinMenu.WaitFireRelease
462   pop  hl
463   ld   a,(hl)
464   dec  a
465   jr   nz,.x1
466   call WinOpen.Close
467   ret
470 winCharSet:
471   db 1,8
472   db 29,6
473   db 007
474   db WinOpen.FLAG_FRAME|WinOpen.FLAG_SAVE|WinOpen.FLAG_SHADOW
475   db WinPrint.ch_center,"Choose",WinPrint.ch_bigspc,"first",WinPrint.ch_bigspc,"char:"
476   db 0
478 txtCharSet0:
479   db 10
480   db "#20",WinPrint.ch_bigspc,WinPrint.ch_nextp
481   db "#40",WinPrint.ch_bigspc,WinPrint.ch_nextp
482   db "#60",WinPrint.ch_bigspc,WinPrint.ch_nextp
483   db "#80",WinPrint.ch_bigspc,WinPrint.ch_nextp
484   db "#A0",WinPrint.ch_bigspc,WinPrint.ch_nextp
485   db "#C0",WinPrint.ch_bigspc,WinPrint.ch_nextp
486   db "#E0",10,10
487   db WinPrint.ch_center,"close"
488   db 0
490 txtCharSet1:
491   db WinPrint.ch_at,0,3
492   db 0
494 menuCharSet:
495   db  0,1,3
496   db  4,1,3
497   db  8,1,3
498   db 12,1,3
499   db 16,1,3
500   db 20,1,3
501   db 24,1,3
502   db 11,3,5
503   db #ff
506 doCharSet:
507   ld   ix,winCharSet
508   call WinOpen.Open
509   ld   hl,txtCharSet0
510   call WinPrint.PrintStrZ
511   ld   hl,menuCharSet
512   ld   a,7
513   call WinMenu.InitMenu
514 .loop1:
515   call RunMenuLoop
516   call WinMenu.HideArrow
517   inc  a
518   jr   z,.quit
519   cp   8
520   jr   c,.goon
521 .loop1_q:
522   call WinMenu.WaitFireRelease
523 .quit:
524   call WinOpen.Close
525   ret
527 .goon:
528   rlca:rlca:rlca:rlca:rlca  ; *32
529   push af
530   ld   hl,txtCharSet1
531   call WinPrint.PrintStrZ
532   pop  af
533   ld   b,32
534 .loop2:
535   push af
536   call WinPrint.PrintChar
537   pop  af
538   inc  a
539   djnz .loop2
540   jr   .loop1_q
543 winKeyDef:
544   db 6,8
545   db 10,9
546   db 040
547   db WinOpen.FLAG_FRAME|WinOpen.FLAG_SAVE|WinOpen.FLAG_SHADOW
548   db WinPrint.ch_center,"New Keys"
549   db 0
551 txtKeyDef:
552   db WinPrint.ch_cls
553   db WinPrint.ch_at,0,1
554   db "left",WinPrint.ch_nextp," ",WinPrint.ch_nextp,": ",0
555   db "right",WinPrint.ch_nextp,": ",0
556   db "up",WinPrint.ch_nextp," ",WinPrint.ch_nextp," ",WinPrint.ch_nextp,": ",0
557   db "down",WinPrint.ch_nextp,": ",0
558   db "fire",WinPrint.ch_nextp," ",WinPrint.ch_nextp,": ",0
559   db WinPrint.ch_center,"ok (Y/N)?",0
561 txtSS: db "SS",13,0
562 txtCS: db "CS",13,0
563 txtSP: db "SP",13,0
564 txtRT: db "RET",13,0
565 txtKK: db 0,13,0
567 doRedefine:
568   ld   ix,winKeyDef
569   call WinOpen.Open
570 .again:
571   ; clear keys
572   ld   hl,WinStick.keystick_table
573   ld   de,WinStick.keystick_table+1
574   ld   bc,5
575   ld   (hl),255
576   ldir
577   ;
578   ld   b,5
579   ld   hl,txtKeyDef
580   ; first print all selections
581   push hl,bc
582 .printall:
583   call WinPrint.PrintStrZ
584   call WinPrint.PrintNL
585   djnz .printall
586   pop  bc,hl
587   inc  hl
588   ;
589   ld   de,WinStick.keystick_table
590 .nextkey:
591   call WinInput.WaitKeysRelease
592   push de
593   call WinPrint.PrintStrZ
594 .wloop:
595   halt
596   call WinStick.ReadAnyKey
597   jr   nc,.wloop
598   ; check if this key already used
599   push hl
600   ld   hl,WinStick.keystick_table
601   ld   c,a
602 .checkloop:
603   ld   a,(hl)
604   inc  hl
605   cp   #ff
606   jr   z,.checkok
607   cp   c
608   jr   nz,.checkloop
609   ; duplicate key
610   pop  hl
611   jr   .wloop
612 .checkok:
613   pop  hl
614   ld   a,c
615   pop  de
616   ld   (de),a
617   inc  de
618   ;
619   push hl,bc,de
620   ld   hl,WinStick.keynames
621   ld   b,0
622   add  hl,bc
623   ld   a,(hl)
624   ld   hl,txtKK
625   ld   (hl),a
626   cp   33
627   jr   nc,.nameok
628   ld   hl,txtRT
629   cp   13
630   jr   z,.nameok
631   ld   hl,txtCS
632   cp   30
633   jr   z,.nameok
634   ld   hl,txtSS
635   cp   31
636   jr   z,.nameok
637   ld   hl,txtSP
638   cp   32
639   jr   z,.nameok
640 .nameok:
641   call WinPrint.PrintStrZ
642   pop  de,bc,hl
643   djnz .nextkey
644 .done:
645   call WinInput.WaitKeysRelease
646   call WinPrint.PrintStrZ
647   call WinInput.AskYN
648   jp   nc,.again
649   call WinInput.WaitKeysRelease
650   call WinOpen.Close
651   ret
654 arrbuf: ds 3*8,0
655 WinSys.SaveBufAddr equ $
657   IF defined(USE_FIXUPS) && USE_FIXUPS
658     include <fixup/fixupfooter.zas>
659   ENDIF