1
2	MODULE	generic_console_ioctl
3	PUBLIC	generic_console_ioctl
4
5	SECTION	code_clib
6	INCLUDE	"ioctl.def"
7
8	EXTERN	generic_console_cls
9	EXTERN	generic_console_font32
10	EXTERN	generic_console_udg32
11	EXTERN	__laser500_mode
12	EXTERN	__console_w
13
14	INCLUDE	"target/laser500/def/laser500.def"
15
16        EXTERN          generic_console_caps
17        PUBLIC          CLIB_GENCON_CAPS
18        defc            CLIB_GENCON_CAPS = CAPS_MODE0
19
20        ; 40 column
21        defc    CAPS_MODE0 = CAP_GENCON_INVERSE | CAP_GENCON_FG_COLOUR | CAP_GENCON_BG_COLOUR
22        ; 80 column
23        defc    CAPS_MODE1 = 0
24        ; Hires
25        defc    CAPS_MODE2 = CAP_GENCON_INVERSE | CAP_GENCON_CUSTOM_FONT | CAP_GENCON_UDGS | CAP_GENCON_FG_COLOUR | CAP_GENCON_BG_COLOUR | CAP_GENCON_BOLD | CAP_GENCON_UNDERLINE
26
27; a = ioctl
28; de = arg
29generic_console_ioctl:
30	ex	de,hl
31	ld	c,(hl)	;bc = where we point to
32	inc	hl
33	ld	b,(hl)
34	cp	IOCTL_GENCON_SET_FONT32
35	jr	nz,check_set_udg
36	ld	(generic_console_font32),bc
37success:
38	and	a
39	ret
40check_set_udg:
41	cp	IOCTL_GENCON_SET_UDGS
42	jr	nz,check_mode
43	ld	(generic_console_udg32),bc
44	jr	success
45check_mode:
46	cp	IOCTL_GENCON_SET_MODE
47	jr	nz,failure
48	ld	a,c
49	ld	d,0
50	ld	e,80
51	ld	b,CAPS_MODE1
52	cp	1		;80 column mode
53	jr	z,set_mode
54	ld	e,40
55	ld	b,CAPS_MODE0
56	and	a		;40 column mode
57	jr	z,set_mode
58	cp	2
59	jr	nz,failure
60	ld	d,8
61	ld	b,CAPS_MODE2
62	; Value of 2 is GR4 - 320x192
63set_mode:
64	ld	(__laser500_mode),a
65	ld	c,a
66	ld	a,b
67	ld	(generic_console_caps),a
68	ld	a,(SYSVAR_port44)
69	and	@11111000
70	or	c
71	ld	(SYSVAR_port44),a
72	out	($44),a
73	ld	a,e		;columns
74	ld	(__console_w),a
75	; Toggle graphics mode
76	; We need to enable grpahi
77not_graphics_mode:
78	ld	a,(SYSVAR_bank1)
79	push	af
80	ld	a,2
81	ld	(SYSVAR_bank1),a
82	out	($41),a
83	ld	hl,SYSVAR_mem6800
84	ld	a,(hl)
85	and	@11110111
86	or	d
87	ld	(hl),a
88	ld	($4000 + $2800),a	;Enable/disable graphics
89	pop	af
90	ld	(SYSVAR_bank1),a
91	out	($41),a
92	call	generic_console_cls
93	and	a
94	ret
95failure:
96	scf
97	ret
98