Skip to content

Commit e2be74f

Browse files
Added os_GetStringInput
1 parent 0db6850 commit e2be74f

File tree

6 files changed

+194
-0
lines changed

6 files changed

+194
-0
lines changed

examples/os_input/autotester.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"rom": "84pce_515.rom",
3+
"transfer_files": [
4+
"bin/DEMO.8xp"
5+
],
6+
"target": {
7+
"name": "DEMO",
8+
"isASM": true
9+
},
10+
"sequence": [
11+
"action|launch",
12+
"delay|700",
13+
"key|1",
14+
"delay|200",
15+
"key|2",
16+
"delay|200",
17+
"key|enter",
18+
"delay|200",
19+
"hash|1",
20+
"key|enter",
21+
"delay|200",
22+
"hashWait|2"
23+
],
24+
"hashes": {
25+
"1": {
26+
"description": "Output should be N is 12",
27+
"start": "0xD44B00",
28+
"size": "0x25800",
29+
"expected_CRCs": [ "7DBE5A77" ]
30+
},
31+
"2": {
32+
"description": "Back to the home screen (exit check)",
33+
"start": "vram_start",
34+
"size": "vram_16_size",
35+
"expected_CRCs": [ "FFAF89BA", "101734A5", "9DA19F44" ]
36+
}
37+
}
38+
}
39+

examples/os_input/makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# ----------------------------
2+
# Set NAME to the program name
3+
# Set DEBUGMODE to "DEBUG" to use debug functions
4+
# Set ICON to the png icon file name
5+
# Set DESCRIPTION to display within a compatible shell
6+
# Set COMPRESSED to "YES" to create a compressed program
7+
# ** Add all shared library names to L **
8+
# ----------------------------
9+
10+
NAME ?= DEMO
11+
DEBUGMODE ?= NDEBUG
12+
COMPRESSED ?= NO
13+
ICON ?= iconc.png
14+
DESCRIPTION ?= "C SDK Demo"
15+
16+
L ?=
17+
18+
# ----------------------------
19+
# Specify source and output locations
20+
# ----------------------------
21+
22+
SRCDIR ?= src
23+
OBJDIR ?= obj
24+
BINDIR ?= bin
25+
GFXDIR ?= src/gfx
26+
27+
# ----------------------------
28+
# Use OS helper functions (Advanced)
29+
# ----------------------------
30+
31+
USE_FLASH_FUNCTIONS ?= YES
32+
33+
include $(CEDEV)/include/.makefile

examples/os_input/readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### OS Input Demo
2+
3+
This demo shows how to get an input string from the OS.
4+
5+
---
6+
7+
This demo is a part of the C SDK Toolchain for use on the CE.

examples/os_input/src/main.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <stdbool.h>
2+
#include <stddef.h>
3+
#include <stdint.h>
4+
#include <tice.h>
5+
6+
#include <math.h>
7+
#include <stdio.h>
8+
#include <stdlib.h>
9+
#include <string.h>
10+
11+
#define INPUT_SIZE 10
12+
#define BUFFER_SIZE 20
13+
14+
/* Function prototypes */
15+
void print(char *text, uint8_t xpos, uint8_t ypos);
16+
17+
/* Main Function */
18+
void main(void) {
19+
const char prompt[] = "What is N? ";
20+
char input[INPUT_SIZE];
21+
char response[BUFFER_SIZE];
22+
23+
/* Clear the homescreen */
24+
os_ClrHome();
25+
26+
/* Get an input string from the user */
27+
os_GetStringInput(prompt, input, sizeof input);
28+
29+
/* Build the user response */
30+
strcpy(response, "N is ");
31+
strcat(response, input);
32+
33+
/* Clear the homescreen */
34+
os_ClrHome();
35+
36+
/* Print the message back to the user */
37+
print(response, 0, 0);
38+
39+
/* Wait for a key press */
40+
while (!os_GetCSC());
41+
}
42+
43+
/* Draw text on the homescreen at the given X/Y location */
44+
void print(char *text, uint8_t xpos, uint8_t ypos) {
45+
os_SetCursorPos(ypos, xpos);
46+
os_PutStrFull(text);
47+
}
48+

src/ce/getstringinput.src

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
;-------------------------------------------------------------------------
2+
; void os_GetStringInput(char *string, char *buf, size_t bufsize)
3+
;-------------------------------------------------------------------------
4+
.def _os_GetStringInput
5+
.assume adl=1
6+
7+
_os_GetStringInput:
8+
push ix
9+
ld ix,0
10+
add ix,sp
11+
ld hl,(ix+6) ; hl -> input string prompt
12+
add hl,de
13+
xor a,a
14+
sbc hl,de
15+
ld de,0D00879h ; ioPrompt
16+
jr z,donecopy
17+
copyloop:
18+
ld a,(hl)
19+
or a,a
20+
jr z,donecopy
21+
ld (de),a
22+
inc hl
23+
inc de
24+
jr copyloop ; copy the input prompt here
25+
donecopy:
26+
ld (de),a
27+
ld (0D00599h),a ; curUnder
28+
ld iy,0D00080h
29+
ld b,(iy+9)
30+
ld c,(iy+28) ; back up old flag values
31+
res 6,(iy+28)
32+
set 7,(iy+9)
33+
push ix
34+
push bc
35+
call 021320h ; _GetStringInput, get the input from the user
36+
pop bc
37+
res 4,b ; restore old flag values
38+
ld (iy+9),b
39+
ld (iy+28),c
40+
ld hl,(0D0244Eh) ; editSym
41+
call 020AE8h ; _VarNameToOP1HL, lookup the temporary input symbol
42+
call 02050Ch ; _ChkFindSym
43+
pop ix
44+
jr c,SomeError
45+
ex de,hl
46+
inc hl
47+
inc hl
48+
ld de,(ix+9) ; hl -> input string prompt
49+
ld bc,(ix+12) ; bc = input string length
50+
dec bc
51+
ldir
52+
xor a,a
53+
ld (de),a ; null terminate the string
54+
SomeError:
55+
call 021578h ; DeleteTempEditEqu, delete the temporary input
56+
pop ix
57+
ret

src/ce/tice.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,16 @@ int os_TestFlagBits(uint16_t offset_pattern);
667667
void os_SetFlagBits(int16_t offset_pattern);
668668
void os_ResetFlagBits(int16_t offset_pattern);
669669

670+
/**
671+
* Custom implementation input routine for use in conjunction with the TIOS
672+
*
673+
* @param string Input prompt string to be displayed to the user
674+
* @param buf Storage location to store input string
675+
* @param bufsize Available storage size for input string. -1 for null termination.
676+
* @returns None
677+
*/
678+
void os_GetStringInput(char *string, char *buf, size_t bufsize);
679+
670680
/**
671681
* Gets a key from the OS
672682
*

0 commit comments

Comments
 (0)