blob: 21c87dfdffc8646fa9d9308ea1a11977b5e3be0c [file] [log] [blame]
;*****************************************************************************/
; CONIO.S - Amstrad CPC version of the Contiki conio.h (derived from
;borland C) ; To use with the Small Devices C Compiler ; ; 2003 H. Hansen
;*****************************************************************************/
;; contiki uses coordinates between 0..width-1, 0..height-1
;; cpc uses coordinates between 1..width, 1..height
; void clrscr (void);
; Clear the whole screen and put the cursor into the top left corner
; TESTED
.globl _clrscr
.area _CODE
_clrscr::
ld a,#1
call 0xBC0E ; SCR SET MODE
; BACKGROUND
XOR A
LD BC,#0x0D0D ; GREY
CALL 0xBC32 ; SCR SET INK
; BORDERS
LD A,#1
LD BC,#0x0e0e ; BLUE
CALL 0xBC32 ; SCR SET INK
; WIDGETS
LD A,#2
LD BC,#0x1a1a ; WHITE
CALL 0xBC32 ; SCR SET INK
; FOCUS
LD A,#3
LD BC,#0x0000 ; BLACK
CALL 0xBC32 ; SCR SET INK
LD DE,#255
LD HL,#0xbe80
jp 0xbbab ; TXT SET M TABLE
; void gotox (unsigned char x);
; Set the cursor to the specified X position, leave the Y position untouched
.globl _gotox
_gotox::
inc a
jp 0xBB6F ; TXT SET COLUMN
; void gotoy (unsigned char y);
; Set the cursor to the specified Y position, leave the X position untouched
.globl _gotoy
_gotoy::
inc a
jp 0xBB72 ; TXT SET ROW
; void gotoxy (unsigned char x, unsigned char y)
; Set the cursor to the specified position
.globl _gotoxy
_gotoxy::
ld h,a
inc h
inc l
jp 0xBB75 ; TXT SET CURSOR
; unsigned char wherex (void);
; Return the X position of the cursor
.globl _wherex
_wherex::
call 0xBB78 ; TXT GET CURSOR
ld a,h
dec a
ret
; unsigned char wherey (void);
; Return the Y position of the cursor
.globl _wherey
_wherey::
call 0xBB78 ; TXT GET CURSOR
ld a,l
dec a
ret
; void cputcxy (unsigned char x, unsigned char y, char c)
; Same as "gotoxy (x, y); cputc (c);"
; INPUT: A = x, L = y, char on stack
.globl _cputcxy
_cputcxy::
LD H,A ; HL = cursor position
inc h
inc l
call 0xBB75 ; TXT SET CURSOR
pop de ; Return value
dec sp
pop af ; character to print
push de ; Put return value back on stack
jp 0xbb5d
; void cputsn(const char *str, unsigned char len);
; INPUT: str is in HL, len is on the stack
.globl _cputsn
_cputsn::
pop de ; RV
dec sp
pop bc ; len
push de
cputsn$:
LD A,(HL)
INC HL
OR A
RET Z
PUSH HL
PUSH BC
CALL 0xBB5D
POP BC
POP HL
DJNZ cputsn$
RET
; void cputs (const char* s);
; Output a NUL terminated string at the current cursor position
; TESTED
.globl _cputs
_cputs::
cputs$:
ld a,(hl)
inc hl
or a
ret z
push hl
call 0xbb5d
pop hl
jr cputs$
.globl _bordercolor
_bordercolor::
ld b,a
ld c,a
jp 0xBC38 ; SCR SET BORDER
; void cclear (unsigned char length);
; Clear part of a line (write length spaces).
.globl _cclear
_cclear::
ld b,a
ld c,#0x020 ; White space
jr chlineloop$
; void chline (unsigned char length);
; Output a horizontal line with the given length starting at the current
; cursor position.
.globl _chline
_chline::
ld b,a
dochline$:
ld c,#0x09a
chlineloop$:
push bc
ld a,c
call 0xbb5d
pop bc
djnz chlineloop$
ret
; void chlinexy (unsigned char x, unsigned char y, unsigned char length);
; Same as "gotoxy (x, y); chline (length);"
; TESTED
.globl _chlinexy
_chlinexy::
POP DE ; RV
dec sp
POP BC ; Length in B, C is unimportant
PUSH DE ; Put return value back on stack
LD H, A ; HL = XY
inc h
inc l
call 0xBB75
jr dochline$
; void cvline (unsigned char length);
; Output a vertical line with the given length at the current cursor
; position.
.globl _cvline
_cvline::
ld b,a
call 0xBB78 ; TXT GET CURSOR
docvline$:
cvloop$:
push hl
push bc
call 0xBB75 ; TXT SET CURSOR
ld a,#0x095
call 0xbb5d
pop bc
pop hl
inc l
djnz cvloop$
ret
; void cvlinexy (unsigned char x, unsigned char y, unsigned char length);
; Same as "gotoxy (x, y); cvline (length);"
; INPUT: A = Y, L = X, length on stack
.globl _cvlinexy
_cvlinexy::
POP DE ; RV
dec sp
LD H, A ; HL = XY
POP BC ; Length
PUSH DE ; Put return value back on stack
inc h
inc l
jr docvline$
; void screensize (unsigned char* x, unsigned char* y);
; Return the current screen size.
; INPUT: HL = X ptr, DE = Y ptr
.globl _screensize
_screensize::
ld a,#40 ; X Size
ld (hl),a
ld a,#25 ; Y Size
ld (de),a
ret