UrForth: more superinstruction optimising patterns ("TO" optimisation)
[urasm.git] / samples / miniboot / kxboot.zas
blobea8f9c29ff78e7fc433559fc7d563b4107f64043
1 OPT_USE_KEMPSTON_JOYSTICK EQU 1
2 OPT_BOLD_FONT EQU 1
4 OPT_DEFAULT_ATTR EQU 016
5 OPT_CURSOR_ATTR  EQU 026
7   IFX !OPT_USE_KEMPSTON_JOYSTICK && OPT_BOLD_FONT
8 _OPT_HAVE_PLUS_ EQU 0
9   DISPLAY "NO PLUS!\n"
10   ELSE
11 _OPT_HAVE_PLUS_ EQU 1
12   ENDIF
14   org  #5D3B-17
15   ; HoBeta header
16   db #62,#6F,#6F,#74,#20,#20,#20,#20,#42,#FC,#00,#FC,#00,#00,#01,#D8,#73
18 boot_code_start:
19   ;org  #5D3B
20 ;5D3B:
21   db #00,#01,#F8,#00
22 ;5D3F:
23   db #E7,#BC,#A7,":"   ; border sgn pi
24 ;5D43:
25   db #F9,#C0,#B0,#22   ; randomize usr val "23907"
26 ;5D47:
27   db "2390"
28   IFX _OPT_HAVE_PLUS_
29    db "8"
30   ELSE
31    db "7"
32   ENDIF
33   db #22,":"
34 ;5D4E:
35   db #EA,":",#F7,#22   ; rem : run "
36 author_msg:
37   db 23,9,32,"POLTERGEYST"
38   IFX _OPT_HAVE_PLUS_
39    db "+"
40   ENDIF
41   db "k8"
42   db 34
44 reread_disk:
45   ld   (iy+#53),OPT_DEFAULT_ATTR
46   call #0D6B        ; clear screen
47   ; now: bc=#1721;de=0;hl=#50E0
48   add  hl,bc        ; hl=#6801
49   ld   bc,#0905
50   push hl
51   call #3D13        ; load dir; addr=#6801
52   ; print (c)
53   ld   de,author_msg
54   IFX _OPT_HAVE_PLUS_
55    ld   c,17
56   ELSE
57    ld   c,16
58   ENDIF
59   call #203C
60   ; open screen channel
61   ld   a,2
62   call #1601
63   pop  hl           ; directory address
64   ld   d,h
65   ld   e,l
66 dir_process_loop:
67   ld   bc,8
68   dec  (hl)
69   jr   z,.next_file ; #1: erased file
70   inc  (hl)
71   jr   z,.dir_done  ; end of dir
72   push hl
73   add  hl,bc
74   ld   a,(hl)       ; file type
75   pop  hl
76   cp   "B"          ; basic?
77   jr   nz,.next_file; not a basic...
78   ; print file name & copy it (thus compacting dir)
79   push hl
80   ld   a,32
81   rst  #10
82 .name_print:
83   ld   a,(hl)
84   rst  #10
85   ldi
86   jp   pe,.name_print
87   ;
88   ld   hl,#70D1     ; file counter
89   inc  (hl)
90   ld   a,(hl)
91 .col_check_loop:
92   sub  3            ; 3 names in a line
93   jr   z,.col_done
94   jr   nc,.col_check_loop
95   ld   a,32
96   rst  #10
97 .col_done:
98   ld   a,32
99   rst  #10
100   pop  hl
101 .next_file:
102   ld   c,#10
103   add  hl,bc
104   jr   dir_process_loop
105 .dir_done:
107  IFX OPT_BOLD_FONT
108   ; bold screen image
109   ld   h,#57
110 bold_loop:
111   ld   a,(hl)
112   rrca
113   or   (hl)
114   ld   (hl),a
115   dec  hl
116   bit  6,h
117   jr   nz,bold_loop
118  ENDIF
120 init_cursor:
121   ld   c,b       ; c=b=0
122 move_cursor:
123   ld   hl,#57F5  ; 22528-11
124   xor  a         ; temporary counter
125   ld   de,11
126 lines_loop:
127   ld   b,3
128 .line_attr_loop:
129   add  hl,de           ; next file name attrs
130   cp   c               ; was the counter hit?
131   jr   z,show_cursor   ; tan, draw the cursor
132   inc  a               ; increase temp.counter
133   djnz .line_attr_loop ; next name in the line
134   dec  hl              ; next line
135   jr   lines_loop
137   ; erase old cursor; draw new one
138 show_cursor:
139   ld   b,10            ; cursor width
140   ld   de,(#70D3)      ; old cursor address
141   ld   (#70D3),hl      ; store new address
142   ld   a,OPT_DEFAULT_ATTR
143 .cur_draw_loop:
144   ld   (de),a          ; erase old
145   inc  de              ; draw new
146   ld   (hl),OPT_CURSOR_ATTR
147   inc  hl
148   djnz .cur_draw_loop
150   ; ask for keys
151   ld   hl,#5C08
152   ld   (hl),b
153 key_test:
154   ; pause
155   ld   b,5
156   halt
157   djnz $-1
159   ld   a,(hl)
160   cp   32
161   jp   z,reread_disk
163  IFX OPT_USE_KEMPSTON_JOYSTICK
164   ; test kempston joystick
165   xor  a
166   in   a,(#1F)
167   rra
168   jr   c,do_right
169   rra
170   jr   c,do_left
171   rra
172   jr   c,do_down
173   rra
174   jr   c,do_up
175   rra
176   jr   nc,key_test
177   jr   run_prg
178  ELSE
179   cp   13
180   jr   z,run_prg
181   res  5,a  ; upcase
182   cp   "P"
183   jr   z,do_right
184   cp   "O"
185   jr   z,do_left
186   cp   "A"
187   jr   z,do_down
188   cp   "Q"
189   jr   nz,key_test
190  ENDIF
192 do_up:
193   dec  c
194   dec  c
195 do_left:
196   dec  c
197   jp   p,move_cursor
198   ld   bc,(#70D1)
199   dec  c
200   jr   move_cursor
201 do_down:
202   inc  c
203   inc  c
204 do_right:
205   inc  c
206   ld   a,(#70D1)
207   dec  a
208   sub  c
209   jr   nc,move_cursor
210   jr   init_cursor
212 run_prg:
213   ld   hl,bc
214   add  hl,hl
215   add  hl,hl
216   add  hl,hl
217   ld   de,#6801
218   add  hl,de
219   ld   de,author_msg
220   ld   c,8
221   ldir
222   jp   #3D03
224   ;defb 0,0,0
225   ;DISPLAY $-boot_code_start,"\n"
226 boot_padding equ 252-($-boot_code_start)
227   DISPLAY boot_padding, " free bytes left\n"
228   IFX boot_padding
229    defs boot_padding,0
230   ENDIF
232   ; tr-dos autostart info
233   defw #AA80,1