This file is indexed.

/usr/share/z88dk/lib/oz_crt0.asm is in z88dk-data 1.8.ds1-10.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
;       CRT0 for the Sharp OZ family
;
;       Stefano Bodrato 13 Aug. 2002
;
;	Mix of the Dominic's work and the Hi-Tech C modifications
;	by the OZDEV team (Alexander R. Pruss, Green, etc..)
;
;	all the "$" prefixes have been changed to "s_";
;	the "$sp$" label is been changed to "s_sp".
; 
;	the "-DOZDK" enables the OZ7xx DK compatibility mode
;	with extra functions and interrupt handling
;	(this causes the DEFINED_ozgetch2 flag to be activated)
;
; - - - - - - -
;
;       $Id: oz_crt0.asm,v 1.6 2007/06/27 20:49:27 dom Exp $
;
; - - - - - - -


	MODULE  oz_crt0

;-------
; Include zcc_opt.def to find out information about us
;-------

        INCLUDE "zcc_opt.def"

;-------
; Some general scope declarations
;-------

        XREF    _main           ;main() is always external to crt0 code

        XDEF    cleanup         ;jp'd to by exit()
        XDEF    l_dcal          ;jp(hl)

        XDEF    _std_seed        ;Integer rand() seed

        XDEF    _vfprintf       ;jp to the printf() core

        XDEF    exitsp          ;atexit() variables
        XDEF    exitcount

        XDEF    __sgoioblk      ;stdio info block

       	XDEF	heaplast	;Near malloc heap variables
	XDEF	heapblocks

        XDEF    base_graphics   ;Graphical variables

        XDEF    coords          ;Current xy position
        XDEF	s_filetypetable

	XDEF	saved_hl	;Temporary store used by compiler
	XDEF	saved_de	;for hl and de

; --- OZ related stuff---

        XDEF    ozactivepage    ;current mem page
	XDEF    ozmodel         ;detected model (call "detect" first)
	XDEF    ozbacklight     ;display light status
	XDEF    ozcontrast      ;display contrast
	XDEF	ozbacklight_save
        XDEF	s_ozlcdstatus
	XDEF	s_init_unblank	;service entry point to go back from "ozfast" or "ozblankscreen"

	XDEF	ScrCharSet

IF DEFINED_ozgetch2
	XDEF	KeyBufGetPos	;
	XDEF	KeyBufPutPos	; don't
        XDEF    EnableKeyboard
	XDEF	KeyboardBuffer
ENDIF

; --- settings ---
	XDEF	ozkeyrepeatspeed
	XDEF	ozkeyrepeatdelay
	XDEF	ozclick_setting
	XDEF	ozautoofftime
	XDEF	ozautoblanktime
	XDEF	ozautolightofftime
	XDEF	ozprogoptions
; --- -------- ---
	defc	contrast  = 0c026h
	defc	lcdstatus = 0c024h

	org	$8000


        DEFB 00h, 64h, 09h, 0FEh, 31h, 26h, 48h, 41h
        DEFB 30h, 31h, 32h,  0Dh, 75h, 31h, 03h, 0FEh, 5Ah, 0Fh

start:
        jr     skipname
ozfilename:
        defm    "BFILNAMEBAS"
        defb    00
ozfileowner:
        defw    65535
; __ozspare1start:
skipname:
        in     a,(1)
        push   af
        in     a,(2)
        push   af        ; save starting 8000 page
        ld     a,2
        out    (1),a
        ld     a,4
        out    (2),a     ; page first code page into 8000h
        jp     continue
continue:

        ld      a,(0c068h)  ; backlight state
        ld      (ozbacklight),a
        ld      (ozbacklight_save),a

        ld      hl,(lcdstatus)
        ld      (s_ozlcdstatus),hl

        ld      a,(contrast)
        ld      (ozcontrast),a

        di

        in     a,(7)
        ;ld     (intset),a
        ld     (intset+1),a
        ld     a,0ffh-(16+128+1) ;; ARP: was 4+32 !!
        out    (7),a

        call   s_swapupperpages

;; now our code is paged in as follows:
;;  8000h: first code page, originally in page 406h
;;  a000h: second code page, originally in page 407h
;;  c000h: third code page, originally in page 408h
;;  e000h: fourth code page, originally in page 409h
;;  pages 408h and 409h store the initial contents of c000h-ffffh
;; sp points to 0fe00h

; clear BSS segment (lifted from Hi-Tech C init code, but modified)
        ;ld      de,__Lbss       ;Start of BSS segment
	;or	a		;clear carry
	;ld	hl,__Hbss
	;sbc	hl,de		;size of uninitialized data area
        ;jr      z,EmptyBSS
	;ld	c,l
	;ld	b,h
	;dec	bc	
	;ld	l,e
	;ld	h,d
	;inc	de
	;ld	(hl),0
        ;ldir                    ;clear memory
;EmptyBSS:

IF DEFINED_ozgetch2
        ld      hl,KeyBufGetPos
        ld      (hl),0
        ld      de,KeyBufGetPos+1
        ld      bc,26-1
        ldir

;        ld      a,1
;        out     (19h),a
;        ld      a,10
;        out     (17h),a
;        xor     a
;        out     (18h),a
;        ld      a,2
;        out     (16h),a         ;; enable key click

	LIB	ozcustomisr
	LIB	ozsetisr
	
        ld      hl,ozcustomisr
        push    hl
        call    ozsetisr       ;; install our ISR
        pop     bc
        ld      a,l
        or      h
        jr      nz,__exit
ENDIF

        ;ld      hl,1
        ;push    hl
        ;call    _ozclick
        ;pop     hl

        ;ld      hl,argv
        ;push    hl
        ;ld      hl,1
        ;push    hl

;------- Z88DK specific code (begin) -------
        ld      (start1+1),sp	;Save entry stack
        ld      hl,-64
        add     hl,sp
        ld      sp,hl
        ld      (exitsp),sp

IF !DEFINED_nostreams
IF DEFINED_ANSIstdio
; Set up the std* stuff so we can be called again
	ld	hl,__sgoioblk+2
	ld	(hl),19	;stdin
	ld	hl,__sgoioblk+6
	ld	(hl),21	;stdout
	ld	hl,__sgoioblk+10
	ld	(hl),21	;stderr
ENDIF
ENDIF
;-------- Z88DK specific code (end) -------

        call    _main    ;call main program
; __ozspare1end:

;------- Z88DK specific code (begin) -------
.cleanup
;
;       Deallocate memory which has been allocated here!
;

IF !DEFINED_nostreams
IF DEFINED_ANSIstdio
	LIB	closeall
	call	closeall
ENDIF
ENDIF

.start1	ld	sp,0		;Restore stack to entry value
        ;ret
;-------- Z88DK specific code (end) -------

        ;pop     hl
        ;pop     hl	; argv (??)
_ozexitrestoreint:
_exit:
        ld      a,7
        out     (3),a
        ld      a,4
        out     (4),a   ;; page in proper second page
        ;call    __ozcallexitfunctions
__exit:
s_init_unblank:			; ozblankscreen or ozfast might have hidden everything;
        call    ret_only	; if so, ret_only is changed into "ozunblankscreen" to make it back visible.

        di
;intset  equ    $+1
.intset        ld     a,0ffh
        out    (7),a
        im     1

        call    s_swapupperpages

        call    s_clearbacklighttimer

;; restore a bunch of stuff
        ld      a,(ozbacklight_save)
        ld      (0c068h),a

        ld      hl,(s_ozlcdstatus)
        ld      (lcdstatus),hl	;; restore right LCD Status

        ld      a,(ozcontrast)
        ld      (contrast),a

IF DEFINED_ozgetch2
        ld      hl,KeyBufGetPos ;; put keyboard buffer in standard buffer
        ld      de,0c031h
        ld      bc,24
        ldir
ENDIF

s_wipe_hook:
        nop
        nop
        nop

;        ld     hl,0406h
;        ld     c,4
;        out    (c),h
;        dec    c
;        out    (c),l
;        dec    c
        ld      a,6
        out     (3),a
        ld      a,4
        out     (4),a

        jp     continue2+2000h
continue2:
;        pop    hl
;        out    (c),h
;        dec    c
;        out    (c),l     ; restore starting page

        pop    af
        out    (2),a
        pop    af
        out    (1),a

        xor    a
        out    (22h),a   ; restore default display page
        ei

_bdos:                ;; dummy routines
        ret
s_sp:
        defw 0fe00h

swapret: defw 0

s_swapupperpages:       ;; must be called with interrupts disabled
        pop     bc
        ld      (s_swapupperpages_ret+1),bc


        ld     a,8
        out    (3),a
        ld     a,4      ; page in page 408 at 0a000h
        out    (4),a

        ld      d,0c0h
        call    s_swappage     ; swap 0a000h page with 0c000h page

        ld      a,9
        out     (3),a
;        ld      a,4
;        out     (4),a   ; page in page 409 at 0a000h

        ld      d,0e0h
        call    s_swappage      ; swap 0a000h page with 0e000h page

        ld      hl,0
        add     hl,sp
        ld      de,(s_sp)
        ld      (s_sp),hl
        ex      de,hl
        ld      sp,hl

.s_swapupperpages_ret        jp      0
;s_swapupperpages_ret equ $-2

s_swappage:   ;; must be called with interrupts disabled!
        ;; swaps pages at a000 and at d*256

        pop     bc
        ld      (s_swappage_ret+1),bc

        ld      hl,0
        add     hl,sp
        ld      (s_saved_sp+1),hl

        ld      hl,0a000h
        ld      sp,hl
        ld      e,l
        ex      de,hl
        ld      a,h
        add     a,20h      ; end marker
top:
        pop bc   ;10
        ld e,(hl)  ;7
        ld (hl),c  ;7
        inc l       ;4
        ld d,(hl)  ;7
        ld (hl),b  ;7
        inc l        ;4
        push de  ;11
        pop de    ;10    ;SP=SP+2
        pop bc    ;10
        ld e,(hl)
        ld (hl),c
        inc l
        ld d,(hl)
        ld (hl),b
        inc l
        push de
        pop de
        jp nz,top  ;10
        inc h
        cp h
        jp nz,top

.s_saved_sp       ld      hl,0000   ;;
;s_saved_sp equ $-2         ;; self-mod
        ld      sp,hl
        ld      a,7
        out     (3),a
;;        ld      a,4
;;        out     (4),a     ; page in second code page
.s_swappage_ret        jp      0
;$swappage_ret equ $-2

s_32kintoff:
        di
        im      1

ret_only:
        ret

s_32kinton:
        ld      a,0feh
        ld      i,a
        im      2
        ei
        ret

s_clearbacklighttimer:
        ld      hl,0
        ld      (0c00dh),hl
        ld      hl,(s_ozlcdstatus)
        ld      (lcdstatus),hl
        ret

ozbacklight:
        defb    0

ozbacklight_save:
        defb    0

ozcontrast:
        defb   0

s_ozlcdstatus:
        defw  0

IF DEFINED_ozgetch2
KeyBufGetPos:   defb 0
KeyBufPutPos:   defb 0
KeyboardBuffer: ;     123456789012345678901234
                defm "(c)Pruss,Green,&c vZ88DK"
ENDIF

ScrCharSet:     defb 1

;argv:   defw __ozfilename

EnableKeyboard: defs 1

;HeapTop EQU 0f980h
;Model32k EQU 1



; --- settings - leave untouched ---

ozkeyrepeatspeed:
        defb 5
ozkeyrepeatdelay:
        defb 32
ozclick_setting:
        defb 1
ozautoofftime:
        defw 60*180 ;; 3 hours
ozautoblanktime:
        defw 240    ;; 4 minutes
ozautolightofftime:
        defw 120    ;; 2 minutes
ozprogoptions:
        defb 0
;; padding (for future expansion)
defb 0,0,0,0


;------------------------------------------
;------------------------------------------
; End of startup part, routines following
;------------------------------------------
;------------------------------------------

.l_dcal
	jp	(hl)


; Now, define some values for stdin, stdout, stderr
IF (!DEFINED_nostreams) ~ (DEFINED_ANSIstdio) ; ~ = AND
.__sgoioblk
	INCLUDE	"#stdio_fp.asm"
ENDIF


;---------------------------------
; Select which printf core we want
;---------------------------------
._vfprintf
IF DEFINED_floatstdio
	LIB	vfprintf_fp
	jp	vfprintf_fp
ELSE
	IF DEFINED_complexstdio
		LIB	vfprintf_comp
		jp	vfprintf_comp
	ELSE
		IF DEFINED_ministdio
			LIB	vfprintf_mini
			jp	vfprintf_mini
		ENDIF
	ENDIF
ENDIF


;-----------
; Now some variables
;-----------
.coords         defw    0       ; Current graphics xy coordinates

base_graphics:	defw A000h	; Address of the Graphics map
ozactivepage:	defw 0400h	; Page number for the graph map (0400h for A000h)
ozmodel:	defb    -1	; Set with "ozdetectmodel" (see libraries)
s_filetypetable: defw    0c089h

._std_seed       defw    0       ; Seed for integer rand() routines

.exitsp         defw    0       ; Address of where the atexit() stack is
.exitcount      defb    0       ; How many routines on the atexit() stack


.heaplast       defw    0       ; Address of last block on heap
.heapblocks     defw    0       ; Number of blocks
.saved_hl	defw	0	; Temp store for hl
.saved_de	defw	0	; Temp store for de

         	defm  "Small C+ OZ"	;Unnecessary file signature
		defb	0

;-----------------------
; Floating point support
;-----------------------
IF NEED_floatpack
        INCLUDE         "#float.asm"
.fp_seed        defb    $80,$80,0,0,0,0 ;FP seed (unused ATM)
.extra          defs    6               ;FP register
.fa             defs    6               ;FP Accumulator
.fasign         defb    0               ;FP register
ENDIF