diff --git a/platform/pc-6001/ctk/ctk-conio_arch-asm.cS b/platform/pc-6001/ctk/ctk-conio_arch-asm.cS new file mode 100644 index 000000000..e28224ee5 --- /dev/null +++ b/platform/pc-6001/ctk/ctk-conio_arch-asm.cS @@ -0,0 +1,1118 @@ +;;; +;;; +;;; ctk-conio_arch-asm.hS +;;; +;;; Architecture depend ctk-conio implementation. +;;; This assembler source contributes saving speed and memory. +;;; +;;; @author Takahide Matsutsuka +;;; +;;; $Id: ctk-conio_arch-asm.cS,v 1.1 2007/09/19 12:46:15 matsutsuka Exp $ +;;; + + ;; uses preprocessor to enable definitions +#include "ctk_arch-def.h" + + ;; export symbols + .globl _ctk_draw_init + .globl _ctk_draw_clear + .globl _ctk_draw_clear_window + .globl _ctk_draw_window + .globl _ctk_draw_dialog + .globl _ctk_draw_widget + .globl _ctk_draw_windowtitle_height + .globl _ctk_draw_menus + .globl _ctk_draw_width + .globl _ctk_draw_height + + ;; import symbols + .globl _cputc_arch + .globl _cputs_arch + .globl _cputsn_arch + .globl _gotoxy_arch + .globl _clip_arch + .globl _clearto_arch + .globl _wherex_arch + .globl _clearbox_arch + .globl _drawbox_arch +.if CTK_CONF_ICONS + .globl _drawicon_arch +.endif ; CTK_CONF_ICONS + .globl _revers_arch + .globl _chline_arch + + ;; offsets + .globl _off_window_x + .globl _off_window_y + .globl _off_window_h + .globl _off_window_w + .globl _off_window_inactive + .globl _off_window_active + .globl _off_window_next + .globl _off_window_focused + + .globl _off_widget_x + .globl _off_widget_y + .globl _off_widget_w + .globl _off_widget_h + .globl _off_widget_type + .globl _off_widget_window + .globl _off_widget_label_text + .globl _off_widget_button_text + .globl _off_widget_textentry_text + .globl _off_widget_textentry_xpos + .globl _off_widget_textentry_ypos + .globl _off_widget_textentry_state +.if CTK_CONF_ICONS + .globl _off_widget_icon_title + .globl _off_widget_icon_textmap +.endif ; CTK_CONF_ICONS +.if CTK_CONF_MENUS + .globl _off_menu_title + .globl _off_menu_active + .globl _off_menu_nitems + .globl _off_menu_items + .globl _off_menu_next + .globl _off_menuitem_title + .globl _size_menuitem + .globl _off_menus_open + .globl _off_menus_menus + .globl _off_menus_desktopmenu +.endif ; CTK_CONF_MENUS + + .area _DATA + + .area _CODE +_ctk_draw_windowtitle_height: + .db 1 + +_ctk_conio_arch_asm_start:: + ;; --------------------------------- + ;; void ctk_draw_init(void) + ;; Stack; retl reth + ;; _F____HL____ AFBCDEHL____ + ;; return void + ;; --------------------------------- +_ctk_draw_init: + ld d, #SCREEN_HEIGHT + ld e, #0 + jr _ctk_draw_clear_asm + + ;; --------------------------------- + ;; ctk_draw_clear(unsigned char clipy1, unsigned char clipy2); + ;; Stack; retl reth clipy1 clipy2 + ;; AFBCDEHL____ + ;; return void + ;; --------------------------------- +_ctk_draw_clear: + ld hl, #2 + add hl, sp + ld e, (hl) ; clipy1 + inc hl + ld d, (hl) ; clipy2 + ;; E = clip1, D = clip2 +_ctk_draw_clear_asm: + push de + call _clip_arch + pop de + ld a, d + sub e + ld h, a ; height + ld l, #SCREEN_WIDTH ; width + push hl + ld l, #0 ; x + ld h, e ; y + push hl + call _clearbox_arch + pop hl + pop hl + ret + +_get_offset: + ;; BC = offset address + ;; HL = base address + ;; return DE = data + ;; ___DE______ + push af + push hl + ld a, (bc) + add a, l + ld l, a + ld a, h + adc #0 + ld h, a + ld e, (hl) + inc hl + ld d, (hl) + pop hl + pop af + ret + + ;; --------------------------------- + ;; ctk_draw_clear_window(struct ctk_window *window, + ;; unsigned char focus, + ;; unsigned char clipy1, + ;; unsigned char clipy2) + ;; Stack; retl reth winl winh focus clipy1 clipy2 + ;; AFBCDEHL____ + ;; return void + ;; --------------------------------- +_ctk_draw_clear_window: + ;; clip_arch(clipy1, clipy2); + ld hl, #5 + add hl, sp + ld e, (hl) + inc hl + ld d, (hl) + push de + call _clip_arch + pop de + ;; clearbox_arch(window->x + 1, window->y + 2, window->w, window->h); + ld hl, #2 + add hl, sp + ld e, (hl) + inc hl + ld d, (hl) + ld h, d + ld l, e ; HL = window + + ld bc, #_off_window_h + call _get_offset ; E = window->h + ld a, e + ld bc, #_off_window_w + call _get_offset ; E = window->w + ld d, a + push de + ld bc, #_off_window_y + call _get_offset ; E = window->y + ld a, e + inc a + inc a + ld bc, #_off_window_x + call _get_offset ; E = window->x + inc e + ld d, a ; D = window->y + 2, E = window->x + 1 + push de + call _clearbox_arch + pop de + pop de + ret + + ;; --------------------------------- + ;; void ctk_draw_dialog(struct ctk_window *dialog) + ;; Stack; retl reth dialogl dialogh + ;; AFBCDEHL____ + ;; return void + ;; --------------------------------- +_ctk_draw_dialog: + ;; ctk_draw_clear_window(dialog, 0, 0, SCREEN_HEIGHT) + ld hl, #2 + add hl, sp + ld e, (hl) + inc hl + ld d, (hl) + ld h, #SCREEN_HEIGHT + ld l, #0 + push hl + xor a + push af + inc sp + push de + call _ctk_draw_clear_window + pop de + inc sp + pop hl + + ;; draw_window_asm(dialog, CTK_FOCUS_DIALOG) + ld a, #_CTK_FOCUS_DIALOG + call _draw_window_asm + ret + + ;; --------------------------------- + ;; void ctk_draw_window(struct ctk_window *window, unsigned char focus, + ;; unsigned char clipy1, unsigned char clipy2, + ;; unsigned char draw_borders) + ;; Stack; retl reth winl winh focus cy1 cy2 borders + ;; AFBCDEHL____ + ;; return void + ;; --------------------------------- +_ctk_draw_window: + ;; clip_arch(clipy1, clipy2); + ld hl, #5 + add hl, sp + ld e, (hl) + inc hl + ld d, (hl) + push de + call _clip_arch + pop de + + ;; DE = window + ;; A = focus = focus & CTK_FOCUS_WINDOW + ;; draw_window_asm(window, focus); + ld hl, #2 + add hl, sp + ld e, (hl) + inc hl + ld d, (hl) + inc hl + ld a, (hl) + and a, #_CTK_FOCUS_WINDOW + call _draw_window_asm + ret + + ;; --------------------------------- + ;; void draw_window_asm + ;; (struct ctk_window *window, unsigned char focus) + ;; DE = window, A = focus + ;; Stack; retl reth + ;; AFBCDEHL____ + ;; return void + ;; --------------------------------- +_draw_window_asm: + ;; drawbox_arch(window->x, window->y + 1, window->w, window->h); + push af ; focus + ld h, d + ld l, e ; HL = window + push hl ; window + ld bc, #_off_window_h + call _get_offset + ld a, e + ld bc, #_off_window_w + call _get_offset + ld d, a + push de ; D = window->h, E = window->w + ld bc, #_off_window_y + call _get_offset + ld a, e + inc a + ld bc, #_off_window_x + call _get_offset + ld d, a + push de ; D = window->y + 1, E = window->x + call _drawbox_arch + pop de ; pop yx + pop bc ; pop hw, Stack; window focus + pop hl ; HL = window; Stack; focus + inc d ; D = x = window->y + 2 + inc e ; E = y = window->x + 1 + push de ; Stack; yx focus + + ;; for(w = window->inactive; w != NULL; w = w->next) { + ld bc, #_off_window_inactive + call _get_offset ; DE = w = window->inactive + pop bc ; yx + pop af ; focus + push hl + ;; de = widget, bc = yx, a = focus, hl = window; Stack; window +_ctk_draw_window_asm_loop1: ; draw inactive widgets + ;; HL = e4cd + push af ; Stack; focus window + ld a, d + or e + jr z, _draw_window_asm_next1 ; if (DE == NULL) + pop af ; A = focus, Stack; window + ;; bc = yx, de = w, a = focus + ;; draw_widget(w, x, y, focus); + call _draw_widget_asm + push bc ; Stack; BC=xy HL=window + ld h, d + ld l, e ; HL = w + ld bc, #_off_window_next + call _get_offset ; DE = window->next + pop bc ; bc = yx, Stack; window + jr _ctk_draw_window_asm_loop1 + ;; for(w = window->active; w != NULL; w = w->next) + ;; HL = window, BC = xy, A = focus; Stack; focus +_draw_window_asm_next1: ; Stack; focus window + pop af ; A = focus + pop hl ; HL = window; Stack null + push bc ; Stack yx + ;; calc window->focused + ld bc, #_off_window_focused + call _get_offset ; DE = window->focused + push de ; Stack focused yx + ld bc, #_off_window_active + call _get_offset ; DE = window->active + pop hl ; HL = window->focused, Stack; yx + pop bc ; BC = yx, Stack; null + push af ; Stack; focus + push hl ; Stack; focused focus + + ;; BC = yx, DE = widget, Stack; focused focus +_ctk_draw_window_asm_loop2: ; draw active widgets + ld a, d ; DE = w + or e + jr z, _draw_window_asm_next2 + ;; if (w == window->focused) focus |= CTK_FOCUS_WIDGET; + pop hl ; HL = window->focused; Stack focus + ld a, h + cp d + jr nz, _draw_window_asm_nofocus + ld a, l + cp e + jr nz, _draw_window_asm_nofocus + pop af + push af + or a, #_CTK_FOCUS_WIDGET + jr _draw_window_asm_draw +_draw_window_asm_nofocus: + pop af + push af + ;; A = wfocus, BC = yx de = widget hl = focused +_draw_window_asm_draw: ; Stack; focus + ;; draw_widget(w, posx, posy, wfocus); + call _draw_widget_asm + + push hl ; Stack; focused focus + push bc ; Stack; yx focused focus + ld h, d + ld l, e + ld bc, #_off_window_next + call _get_offset ; DE = w->next + pop bc ; BC = yx, Stack; focused focus + jr _ctk_draw_window_asm_loop2 +_draw_window_asm_next2: ; Stack; focused focus + pop hl + pop af + ret + + ;; --------------------------------- + ;; ctk_draw_widget(struct ctk_widget *w, + ;; unsigned char focus, + ;; unsigned char clipy1, + ;; unsigned char clipy2); + ;; Stack; retl reth wl wh focus clipy1 clipy2 + ;; AFBCDEHL____ + ;; return void + ;; --------------------------------- +_ctk_draw_widget: + ld hl, #2 + add hl, sp + ld e, (hl) + inc hl + ld d, (hl) ; DE = widget + inc hl + ld a, (hl) ; A = focus + inc hl + ld c, (hl) ; clipy1 + inc hl + ld b, (hl) ; clipy2 + push af ; focus + push bc + call _clip_arch + pop bc + push de ; Stack; widget focus + ld h, d + ld l, e + ld bc, #_off_widget_window + call _get_offset + ld h, d + ld l, e ; HL = window + ld bc, #_off_window_focused + call _get_offset ; DE = focused + pop bc ; pop widget, Stack focus + ld a, b ; compare DE(fucosed) and BC(widget) + sub d + jr nz, _ctk_draw_widget_nofocus + ld a, c + sub e + jr nz, _ctk_draw_widget_nofocus + pop af + or a, #_CTK_FOCUS_WIDGET + push af +_ctk_draw_widget_nofocus: + push bc ; widget, Stack widget focus + ld bc, #_off_window_x + call _get_offset + inc e + ld c, e + push bc + ld bc, #_off_window_y + call _get_offset + inc e + inc e + pop bc + ld b, e ; yx + pop de ; widget + pop af ; focus + ;; FALL THROUGH + + ;; --------------------------------- + ;; void draw_widget_asm(struct ctk_widget *w, + ;; unsigned char x, unsigned char y, + ;; unsigned char focus) + ;; Stack; retl reth + ;; in; a = focus, bc = yx, de = widget + ;; ____________ + ;; return void + ;; --------------------------------- +_draw_widget_asm: + push hl + push de + push bc + push af + + push de + ld h, d + ld l, e + push af + push bc ; Stack; xy, focus, w + ld bc, #_off_widget_x + call _get_offset + ld a, e + pop bc ; Stack; focus w + add c + ld c, a + push bc + ld bc, #_off_widget_y + call _get_offset + ld a, e + pop bc ; Stack; focus, w + add b + ld b, a ; B = ypos, C = xpos + pop af + and #_CTK_FOCUS_WIDGET + push af + inc sp + call _revers_arch + inc sp ; Stack; w + push bc ; Stack; yx, w + call _gotoxy_arch + pop bc + pop hl ; Stack; null + push hl + push bc + ld bc, #_off_widget_type + call _get_offset + ld a, e ; A = type + ld bc, #_off_widget_w + call _get_offset ; E = w->w; + pop bc ; B = ypos, C = xpos + pop hl ; HL = w + cp a, #_CTK_WIDGET_SEPARATOR + jp z, _draw_widget_separator + cp a, #_CTK_WIDGET_LABEL + jp z, _draw_widget_label + cp a, #_CTK_WIDGET_BUTTON + jp z, _draw_widget_button + cp a, #_CTK_WIDGET_HYPERLINK + jp z, _draw_widget_hyperlink + cp a, #_CTK_WIDGET_TEXTENTRY + jp z, _draw_widget_textentry +.if CTK_CONF_ICONS + cp a, #_CTK_WIDGET_ICON + jp z, _draw_widget_icon +.endif ; CTK_CONF_ICONS +_draw_widget_ret: + xor a + push af + inc sp + call _revers_arch + inc sp + + pop af + pop bc + pop de + pop hl + ret + ;; BC = ypos, xpos, HL = w, E = w->w, Stack; null +_draw_widget_separator: + push de + inc sp + call _chline_arch + inc sp + jr _draw_widget_ret + ;; BC = ypos, xpos, HL = w, E = w->w, Stack; null +_draw_widget_label: + ld a, e + push bc + push hl + ld bc, #_off_widget_h + call _get_offset ; E = h + ld h, e + ld l, a ; H = h, L = w->w + ex (sp), hl ; Stack; H = h, L = w->w; HL = w + ld bc, #_off_widget_label_text + call _get_offset ; DE = text + pop hl ; Stack; yx; H = h, L = w->w + pop bc ; BC = yx +_draw_widget_label_loop: + ld a, h + or a + jr z, _draw_widget_ret + + push de + push hl + push bc + call _gotoxy_arch + pop bc + pop hl + pop de + ;; BC = ypos, xpos, H = h, L = w->w, DE = text + ;; cputsn_arch(text, w->w); + ld a, l + push hl + push bc + push af + inc sp + push de + call _cputsn_arch + pop de + inc sp + pop bc + pop hl + ;; clearto_arch(xpos + w->w); + ld a, c + add a, l + push hl + push de + push bc + push af + inc sp + call _clearto_arch + inc sp + pop bc + pop de + pop hl + ;; ++ypos; + inc b + ;; text += w->w; + ld a, e + add a, l + ld e, a + ld a, d + adc a, #0 + ld d, a + + dec h + jr _draw_widget_label_loop + + ;; BC = ypos, xpos, HL = w, E = w->w, Stack; null +_draw_widget_button: + push hl ; w + push de ; w->w + ld a, #0x5b ; '[' + push af + inc sp + call _cputc_arch + inc sp + pop de + pop hl + push de + ld bc, #_off_widget_button_text + call _get_offset + push de + call _cputsn_arch + pop de + pop de + ld a, #0x5d ; ']' + push af + inc sp + call _cputc_arch + inc sp + jp _draw_widget_ret + ;; BC = ypos, xpos, HL = w, E = w->w, Stack; null +_draw_widget_hyperlink: + push de + ld bc, #_off_widget_button_text + call _get_offset + push de + call _cputsn_arch + pop de + pop de + jp _draw_widget_ret + + ;; BC = ypos, xpos, HL = w, E = w->w, Stack; null +_draw_widget_textentry: ; 0xc5dc sp=0xf97e + ;; stable variables; + ;; w->w, w->h, w->widget.textentry.{state,ypos,xpos), xscroll + push ix + ld ix, #-6 + add ix, sp + ld sp, ix + push bc + + ld 0(ix), e ; w->w + ld bc, #_off_widget_h + call _get_offset + ld 1(ix), e ; w->h + ld bc, #_off_widget_textentry_state + call _get_offset + ld a, e + sub a, #_CTK_TEXTENTRY_EDIT + ld 2(ix), a ; w->widget.textentry.state + ld bc, #_off_widget_textentry_ypos + call _get_offset + ld 3(ix), e ; w->widget.textentry.ypos + ld bc, #_off_widget_textentry_xpos + call _get_offset + ld 4(ix), e ; w->widget.textentry.xpos + + ld bc, #_off_widget_textentry_xpos + call _get_offset + ld a, e + inc a + sub 0(ix) ; w->w + jr nc, _draw_widget_textentry_next + xor a +_draw_widget_textentry_next: ; A = xscroll, Stack; yx - IX + ld 5(ix), a ; w->widget.textentry.xscroll + + ld bc, #_off_widget_textentry_text + call _get_offset ; DE = text + + ld l, #0 ; loop counter + pop bc + ;; L = counter, IX = sp, DE = text, BC = yx, Stack; null +_draw_widget_textentry_loop1: ; 0xc629 + ;; gotoxy_arch(xpos, ypos); + push de + push hl ; Stack; yx count text + push bc + call _gotoxy_arch + + ;; if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT && + ;; w->widget.textentry.ypos == j) + pop bc + pop hl ; Stack; text + pop de ; Stack; null + push bc ; Stack; yx + ld a, l + cp a, 1(ix) ; j - w->h + jp nc, _draw_widget_textentry_ret + ld a, 2(ix) ; state + or a + jr nz, _draw_widget_textentry_else + ld a, 3(ix) ; ypos + cp a, l + jr nz, _draw_widget_textentry_else + ;; revers_arch(0); + push hl ; Stack count yx + push de ; Stack text count yx + xor a + push af + inc sp + call _revers_arch + inc sp + ;; cputc_arch('>'); + ld a, #0x3e ; '>' + push af + inc sp + call _cputc_arch + inc sp + + pop de ; Stack count yx + push de ; Stack text count yx + ld a, 5(ix) ; xscroll + add a, e + ld e, a + ld a, d + adc a, #0 + ld d, a ; DE = text[xscroll] + + ld h, #0 ; loop counter + ;; for(i = 0; i < w->w; ++i) +_draw_widget_textentry_loop2: ; 0xc666 Stack text count yx + ld a, h + cp a, 0(ix) ; i - w->w + jr nc, _draw_widget_textentry_loop2exit + ;; revers_arch(i == w->widget.textentry.xpos - xscroll); + push hl ; Stack count2 text count1 yx + ld a, 4(ix) ; w->w.widget.textentry.xpos + sub 5(ix) ; xscroll + sub h ; textentry.xpos - xscroll- i + jr z, _draw_widget_textentry_revers1 + xor a + jr _draw_widget_textentry_revers0 +_draw_widget_textentry_revers1: + ld a, #01 +_draw_widget_textentry_revers0: + push af + inc sp + call _revers_arch + inc sp + + ld a, (de) ; ch + or a + jr nz, _draw_widget_textentry_nospace + ld a, #CH_SPACE +_draw_widget_textentry_nospace: + push de + push af + inc sp + call _cputc_arch + inc sp + pop de + pop hl ; Stack text count1 yx + inc h + inc de + jr _draw_widget_textentry_loop2 + +_draw_widget_textentry_loop2exit: ; Stack text count yx + xor a + push af + inc sp + call _revers_arch + inc sp + ld a, #0x3c ; '<' + push af + inc sp + call _cputc_arch + inc sp + jr _draw_widget_textentry_endif + +_draw_widget_textentry_else: ; 0xc68a DE = text, L = count1, Stack yx + ;; cputc_arch(CH_VERTLINE); + ld a, #CH_VERTLINE + push hl + push de + push af + inc sp + call _cputc_arch + inc sp + pop de + ;; cputsn_arch(text, w->w); + ld a, 0(ix) ; w->w + push af + inc sp + push de + call _cputsn_arch + pop de + inc sp ; Stack j yx + ;; clearto_arch(xpos + w->w + 1); + pop hl + pop bc + push bc + push hl + push de ; Stack text count yx + ld a, 0(ix) ; w->w + add a, c + inc a ; xpos + w->w + 1 + push af + inc sp + call _clearto_arch + inc sp + ;; cputc_arch(CH_VERTLINE); + ld a, #CH_VERTLINE + push af + inc sp + call _cputc_arch + inc sp +_draw_widget_textentry_endif: ; Stack text count yx + ;; text += w->w + pop de + ld a, e + add a, 0(ix) + ld e, a + ld a, d + adc a, #0 + ld d, a + + pop hl + ;; i++ + inc l + pop bc + ;; ++ypos; + inc b + jp _draw_widget_textentry_loop1 +_draw_widget_textentry_ret: + pop bc + ld hl, #6 + add hl, sp + ld sp, hl + pop ix + jp _draw_widget_ret + +.if CTK_CONF_ICONS +_draw_widget_icon: + ld bc, #_off_widget_icon_title + call _get_offset + push de + ld bc, #_off_widget_icon_textmap + call _get_offset + push de + call _drawicon_arch + pop de + pop de + jp _draw_widget_ret +.endif ; CTK_CONF_ICONS + +.if CTK_CONF_MENUS + ;; --------------------------------- + ;; static void draw_menu(struct ctk_menu *m, struct ctk_menu *open) + ;; in; HL = menu, BC = open + ;; AFBCDEHL____ + ;; return void + ;; --------------------------------- +_draw_menu_asm: + ;; x = wherex_arch(); + push hl + call _wherex_arch ; A = x + pop hl + push af + ;; cputs_arch(m->title); + push bc + ld bc, #_off_menu_title + call _get_offset ; DE = m->title + push hl + push de + call _cputs_arch + pop de ; Stack; menu open x + ;; cputc_arch(CH_SPACE); + ld a, #CH_SPACE + push af + inc sp + call _cputc_arch + inc sp + + pop hl ; menu + pop bc ; open, Stack; x + ld a, h + sub b + jp nz, _draw_menu_ret2 + ld a, l + sub c + jp nz, _draw_menu_ret2 + ;; x2 = wherex_arch(); + ;; 0xc473 + push hl + call _wherex_arch ; A = x2 + ld c, l ; C = x2 + pop hl ; Stack; x + ;; HL = menu + push bc + ld bc, #_off_menu_active + call _get_offset + pop bc ; E = m->active + ld d, #0 ; D = y + pop af ; A = x, Stack; null + ld b, a + add a, #CTK_CONF_MENUWIDTH + sub #SCREEN_WIDTH + jr c, _draw_menu_loop1 + jr z, _draw_menu_loop1 + ld a, #SCREEN_WIDTH + sub #CTK_CONF_MENUWIDTH + ld b, a + ;; B = x, C = x2, D = y, E = m->active, HL = menu +_draw_menu_loop1: + ;; if (y == m->nitems) _draw_menu_ret + ld a, d + push de + push hl + push bc + ld bc, #_off_menu_nitems + call _get_offset + cp e + pop bc + pop hl + jr z, _draw_menu_ret ; leave 2byte to pop while return + pop de + ;; if (y == m->active) revers_arch(0); + cp e + jr nz, _draw_menu_next1 + xor a + push hl + push af + inc sp + call _revers_arch + inc sp + pop hl + ;; B = x, C = x2, D = y, HL = menu +_draw_menu_next1: ; c4ae + ;; gotoxy_arch(x, y + 1); + push hl + push de + inc d + ld e, b + push de + call _gotoxy_arch + pop de + pop de ; D = y + pop hl ; HL = menu, Stack; null + ;; if(m->items[y].title[0] == '-') + push de + push hl ; e7ca + push bc ; Stack; x2x menu y + + ld bc, #_off_menu_items + ld a, (bc) + add a, l + ld l, a + ld a, h + adc #0 + ld h, a ; HL = m->items[0] + + ld bc, #_size_menuitem + ld a, (bc) + ld c, a + ld b, #0 ; BC = sizeof(struct menuitem) + + ld a, d ; A = y +_draw_menu_loop2: + or a + jr z, _draw_menu_next2 + add hl, bc + dec a + jr _draw_menu_loop2 +_draw_menu_next2: + ld bc, #_off_menuitem_title + call _get_offset + ld a, (de) + cp a, #0x2d ; '-' + jr nz, _draw_menu_else + ;; chline_arch(CTK_CONF_MENUWIDTH); + ld a, #CTK_CONF_MENUWIDTH + push af + inc sp + call _chline_arch + inc sp + jr _draw_menu_next3 +_draw_menu_else: + ;; cputs_arch(m->items[y].title); + push de + call _cputs_arch + pop de +_draw_menu_next3: + ;; clearto_arch(x + CTK_CONF_MENUWIDTH); + pop bc ; B = x, C = x2, Stack; menu y + push bc + ld a, b + add a, #CTK_CONF_MENUWIDTH + push af + inc sp + call _clearto_arch + inc sp + ;; revers_arch(1); + ld a, #1 + push af + inc sp + call _revers_arch + inc sp + pop bc + pop hl + pop de + inc d + jr _draw_menu_loop1 +_draw_menu_ret: ; C = x2 + ld b, #0 + push bc + call _gotoxy_arch + pop bc +_draw_menu_ret2: + pop af + ret + +_ctk_draw_menus: + ;; --------------------------------- + ;; void ctk_draw_menus(struct ctk_menus *menus); + ;; Stack; retl reth menusl menush + ;; AFBCDEHL____ + ;; return void + ;; --------------------------------- + ;; clip_arch(0, SCREEN_HEIGHT); + ld h, #SCREEN_HEIGHT + ld l, #0 + push hl + call _clip_arch + ;; gotoxy_arch(0, 0); + ld hl, #0 + ex (sp), hl + call _gotoxy_arch + ;; revers_arch(1); + ld h, #1 + ex (sp), hl + inc sp + call _revers_arch + inc sp ; Stack; null + + ld hl, #2 + add hl, sp + ld e, (hl) + inc hl + ld d, (hl) + ld h, d + ld l, e ; HL = menus + ld bc, #_off_menus_desktopmenu + call _get_offset + push de ; Stack; menus->desktopmenu + ld bc, #_off_menus_open + call _get_offset + push de ; Stack; menus->open menus->desktopmenu + ld bc, #_off_menus_menus + call _get_offset + ld h, d + ld l, e ; HL = menu +_ctk_draw_menus_loop1: + ld bc, #_off_menu_next + call _get_offset + ;; if (menu == NULL) _ctk_draw_menus_next1 + ld a, d + or e + jr z, _ctk_draw_menus_next1 + ;; draw_menu_asm(m, menus->open); + ld h, d + ld l, e ; HL = menu->next + pop bc + push bc ; Stack; menus->open menus->desktopmenu + push hl ; Stack; menu menus->open menus->desktopmenu + call _draw_menu_asm + pop hl ; Stack; menus->open menus->desktopmenu + jr _ctk_draw_menus_loop1 +_ctk_draw_menus_next1: + pop de ; menus->open + pop hl ; menus->desktopmenu + push de ; Stack; menus->open + ;; clearto_arch(SCREEN_WIDTH - strlen(menus->desktopmenu->title) - 1); + ld bc, #_off_menu_title + call _get_offset + ld b ,#0 +_ctk_draw_menus_loop2: + ld a, (de) + or a + jr z, _ctk_draw_menus_next2 + inc b + inc de + jr _ctk_draw_menus_loop2 +_ctk_draw_menus_next2: + ld a, #SCREEN_WIDTH + sub b ; strlen(menus->desktopmenu->title) + dec a ; SCREEN_WIDTH - strlen(menus->desktopmenu->title) - 1 + push hl + push af + inc sp + call _clearto_arch + inc sp + pop hl ; desktopmenu + pop bc ; open, Stack; null + call _draw_menu_asm + xor a + push af + inc sp + call _revers_arch + inc sp + ret +.endif ; CTK_CONF_MENUS + + ;; --------------------------------- + ;; unsigned char ctk_draw_width(void); + ;; Stack; retl reth + ;; _______L____ + ;; return width + ;; --------------------------------- +_ctk_draw_width: + ld l, #SCREEN_WIDTH + ret + + ;; --------------------------------- + ;; unsigned char ctk_draw_height(void); + ;; Stack; retl reth + ;; _______L____ + ;; return width + ;; --------------------------------- +_ctk_draw_height: + ld l, #SCREEN_HEIGHT + ret + +_ctk_conio_arch_asm_end:: diff --git a/platform/pc-6001/ctk/ctk-conio_arch-asm.hS b/platform/pc-6001/ctk/ctk-conio_arch-asm.hS deleted file mode 100644 index 792372f84..000000000 --- a/platform/pc-6001/ctk/ctk-conio_arch-asm.hS +++ /dev/null @@ -1,432 +0,0 @@ -;;; -;;; -;;; ctk-conio_arch-asm.hS -;;; -;;; Architecture depend ctk-conio implementation. -;;; This assembler source contributes basically saving for speed and memory. -;;; -;;; @author Takahide Matsutsuka -;;; -;;; $Id: ctk-conio_arch-asm.hS,v 1.1 2007/09/11 12:12:59 matsutsuka Exp $ -;;; - - ;; uses preprocessor to enable definitions -#include "ctk_arch-def.h" - - ;; export symbols - .globl _cputc_arch - .globl _cputs_arch - .globl _cputsn_arch - .globl _chline_arch - .globl _cvline_arch - .globl _gotoxy_arch - .globl _cclear_arch - .globl _revers_arch - .globl _clip_arch - .globl _ctk_draw_init - .globl _ctk_draw_clear - .globl _ctk_draw_clear_window - ;; import symbols - .globl _info -.if 0 - .globl _ctk_arch_window_x - .globl _ctk_arch_window_y - .globl _ctk_arch_window_h - .globl _ctk_arch_window_w -.endif - - .area _DATA -_ctk_arch_reversed: - .ds 1 - - .area _CODE - - ;; --------------------------------- - ;; void cputc(char ch); - ;; Stack; ixl ixh retl reth ch - ;; AF__DEHL____ - ;; return void - ;; --------------------------------- -_cputc_arch: - push ix - ld ix, #_info - ld a, CURSY(ix) - cp a, CY1(ix) ; cursy - cy1 - jr c, _cputc_arch_ret ; cusy < cy1 - cp a, CY2(ix) ; cursy - cy2 - jr z, _cputc_arch_next1 - jr nc, _cputc_arch_ret ; cursy > cy2 -_cputc_arch_next1: - cp a, #SCREEN_HEIGHT ; cursy - SCREEN_HEIGHT - jr z, _cputc_arch_next2 - jr nc, _cputc_arch_ret ; cursy > SCREEN_HEIGHT -_cputc_arch_next2: - ld a, CURSX(ix) - cp a, #SCREEN_WIDTH ; cursx - SCREEN_WIDTH - jr nc, _cputc_arch_ret - ;; calculate offset - ld a, CURSY(ix) - ld hl, #0 - ld de, #SCREEN_WIDTH -_cputc_arch_loop: - or a - jr z, _cputc_arch_calcx - add hl, de - dec a - jr _cputc_arch_loop -_cputc_arch_calcx: - ld d, #0 - ld e, CURSX(ix) - add hl, de - ;; putchar - push hl - ld hl, #6 - add hl, sp - ld a, (hl) - pop hl - ld de, #VRAM_CHAR - push hl - add hl, de - ld (hl), a - pop hl - ;; putattr - ld de, #VRAM_ATTR - add hl, de - ld de, #_ctk_arch_reversed - ld a, (de) - or a - jr z, _cputc_arch_normal - ld (hl), #COLOR_REVERSED - jr _cputc_arch_ret -_cputc_arch_normal: - ld (hl), #COLOR_NORMAL -_cputc_arch_ret: - inc CURSX(ix) - pop ix - ret - - ;; --------------------------------- - ;; void cputs_arch(char *str); - ;; Stack; ixl ixh retl reth strl strh - ;; AFB_DEHL____ - ;; return void - ;; --------------------------------- -_cputs_arch: - push ix - ld hl, #4 - add hl, sp - ld e, (hl) - inc hl - ld d, (hl) - ld b, #0 ; max length -_cputs_arch_loop: - ld a, (de) - or a - jr z, _cputs_arch_ret - push bc - push de - push af - inc sp - call _cputc_arch - inc sp - pop de - pop bc - inc de - djnz _cputs_arch_loop -_cputs_arch_ret: - pop ix - ret - - ;; --------------------------------- - ;; void cputsn(char *str, unsigned char length); - ;; Stack; ixl ixh retl reth length - ;; AFB_DEHL____ - ;; return void - ;; --------------------------------- -_cputsn_arch: - push ix - ld ix, #4 - add ix, sp - ld e, 0(ix) - ld d, 1(ix) - ld b, 2(ix) - jr _cputs_arch_loop ; take over B and DE - - ;; --------------------------------- - ;; void chline(unsigned char length); - ;; Stack; ixl ixh retl reth length - ;; AFB_DEHL____ - ;; return void - ;; --------------------------------- -_chline_arch: - push ix - ld hl, #4 - add hl, sp - ld b, (hl) - ld a, #CH_HOLILINE -_chline_arch_loop: - push bc - push af - inc sp - call _cputc_arch - dec sp - pop af - pop bc - djnz _chline_arch_loop - pop ix - ret - - ;; --------------------------------- - ;; void cvline(unsigned char length); - ;; Stack; ixl ixh retl reth length - ;; AFB_DEHL____ - ;; return void - ;; --------------------------------- -_cvline_arch: - push ix - ld hl, #4 ; subject to change - add hl, sp - ld b, (hl) ; length - ld a, #CH_VERTLINE - ld ix, #_info -_cvline_arch_loop: - push bc - push af - inc sp - call _cputc_arch - dec sp - pop af - pop bc - inc CURSY(ix) - dec CURSX(ix) - djnz _cvline_arch_loop - pop ix - ret - - ;; --------------------------------- - ;; void gotoxy(unsigned char x, unsigned char y) - ;; Stack; ixl ixh retl reth x y - ;; AF____HL____ - ;; return void - ;; --------------------------------- -_gotoxy_arch: - push ix - ld hl, #4 - add hl, sp - ld ix, #_info - ld a, (hl) - ld CURSX(ix), a - inc hl - ld a, (hl) - ld CURSY(ix), a - pop ix - ret - - ;; --------------------------------- - ;; void clearTo(char x) - ;; Stack; ixl ixh retl reth x - ;; AF__DEHL____ - ;; return void - ;; --------------------------------- -_cclear_arch: - push ix - ld ix, #_info - ld hl, #4 - add hl, sp -_cclear_arch_loop: - ld a, (hl) ; x - cp a, CURSX(ix) - jr z, _cclear_arch_ret - jr c, _cclear_arch_ret - ld a, #CH_SPACE - push hl - push af - inc sp - call _cputc_arch - inc sp - pop hl - jr _cclear_arch_loop -_cclear_arch_ret: - ld a, (hl) - ld CURSX(ix), a - pop ix - ret - - ;; --------------------------------- - ;; void revers_arch(unsigned char reverse) - ;; Stack; retl reth reverse - ;; A_____HL____ - ;; return void - ;; --------------------------------- -_revers_arch: - ld hl, #2 - add hl, sp - ld a, (hl) - ld hl, #_ctk_arch_reversed - ld (hl), a - ret - - ;; --------------------------------- - ;; void clip_arch(unsigned char clip1, unsigned char clip2) - ;; Stack; retl reth clip1 clip2 - ;; A_____HL____ - ;; return void - ;; --------------------------------- -_clip_arch: - push ix - ld ix, #_info - ld hl, #4 - add hl, sp - ld a, (hl) - ld CY1(ix), a - inc hl - ld a, (hl) - ld CY2(ix), a - pop ix - ret - - ;; --------------------------------- - ;; void ctk_draw_init(void) - ;; Stack; retl reth - ;; _F____HL____ AFBCDEHL____ - ;; return void - ;; --------------------------------- -_ctk_draw_init: - push ix - ld ix, #_info - ld h, #SCREEN_HEIGHT - ld l, #0 - ld CY1(ix), l - ld CY2(ix), h - push hl - call _ctk_draw_clear - pop hl - pop ix - ret - - ;; --------------------------------- - ;; ctk_draw_clear(unsigned char clipy1, unsigned char clipy2); - ;; Stack; retl reth clipy1 clipy2 - ;; AFBCDEHL____ - ;; return void - ;; --------------------------------- -_ctk_draw_clear: - ld hl, #2 - add hl, sp - ld d, (hl) ; clipy1 - inc hl - ld e, (hl) ; clipy2 - ld c, #0 -_ctk_draw_clear_loop: - ld a, d - cp a, e ; d - e (clipy1 - clipy2) - ret nc ; ret if clipy1 >= clipy2 - push de - ld b, d - push bc - call _gotoxy_arch - pop bc - ld a, #SCREEN_WIDTH - push af - inc sp - call _cclear_arch - inc sp - pop de - inc d - jr _ctk_draw_clear_loop - -.if 0 - ;; --------------------------------- - ;; void ctk_draw_clear_window(struct ctk_window *window, - ;; unsigned char focus, - ;; unsigned clipy1, - ;; unsigned clipy2); - ;; Stack; retl reth windowl windowh focus clipy1 clipy2 - ;; AFBCDEHL____ - ;; return void - ;; --------------------------------- -_ctk_draw_clear_get_value: - ;; param; de=window, hl=offset - ;; return a=value - ;; A___________ - push de - ld a, (hl) - add a, e - ld e, a - ld a, d - adc #0 - ld d, a - ld a, (de) - pop de - ret -_ctk_draw_clear_window: - push ix - ld ix, #4 - add ix, sp - ld l, 3(ix) - ld h, 4(ix) - push hl - call _clip_arch - pop hl - ld e, 0(ix) - ld d, 1(ix) ; #_window - ld hl, #_ctk_arch_window_y - call _ctk_draw_clear_get_value - ld b, a - inc b - inc b ; window->y + 2 - - ld hl, #_ctk_arch_window_h - call _ctk_draw_clear_get_value - ld c, a ; window->h - - ld hl, #_ctk_arch_window_x - call _ctk_draw_clear_get_value - ld h, a - inc h ; window->x + 1 - - push hl - ld hl, #_ctk_arch_window_w - call _ctk_draw_clear_get_value - pop hl - ld l, a ; window->w - ld a, b ; i -_ctk_draw_clear_window_loop: - cp a, c ; i - h - jr nc, _ctk_draw_clear_window_ret - ld d, a - ld e, h ; d=i, e=window->x+1 - push af - push hl - push de - call _gotoxy_arch - pop de - pop hl - ld a, h - add a, l ; window->x + 1+ window->w - push hl - push af - inc sp - call _cclear_arch - inc sp - pop af - pop hl - inc a - jr _ctk_draw_clear_window_loop -_ctk_draw_clear_window_ret: - pop ix - ret - -void -ctk_draw_clear_window(struct ctk_window *window, - unsigned char focus, - unsigned char ctk_arch_clipy1, - unsigned char ctk_arch_clipy2) { - clip_arch(clipy1, clipy2); - h = window->y + 2 + window->h; - - for(i = window->y + 2; i < h; ++i) { - gotoxy(window->x + 1, i) - cclear(window->x + 1 + window->w); - } -.endif diff --git a/platform/pc-6001/ctk/ctk-conio_arch.c b/platform/pc-6001/ctk/ctk-conio_arch.c index 4735cc585..7c18a9195 100644 --- a/platform/pc-6001/ctk/ctk-conio_arch.c +++ b/platform/pc-6001/ctk/ctk-conio_arch.c @@ -27,7 +27,7 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: ctk-conio_arch.c,v 1.1 2007/09/11 12:12:59 matsutsuka Exp $ + * $Id: ctk-conio_arch.c,v 1.2 2007/09/19 12:46:15 matsutsuka Exp $ * */ @@ -43,278 +43,59 @@ #include "ctk/ctk-draw.h" #include "contiki-conf.h" #include "ctk/ctk_arch.h" -#include "ctk/ctk-conio_arch.h" #include -struct screen_info { - char cursx; // +0 - char cursy; // +1 - char cy1; // +2 - char cy2; // +3 -}; -struct screen_info info; -#if 0 -const unsigned char ctk_arch_window_x = offsetof(struct ctk_window, x); -const unsigned char ctk_arch_window_y = offsetof(struct ctk_window, y); -const unsigned char ctk_arch_window_h = offsetof(struct ctk_window, h); -const unsigned char ctk_arch_window_w = offsetof(struct ctk_window, w); -#endif - -unsigned char ctk_draw_windowtitle_height = 1; - /*---------------------------------------------------------------------------*/ /* - * w: widget - * x, y: screen position of client drawing area (left, top) - * focus: boolean + * Offset constants for assembler */ -static void draw_widget(struct ctk_widget *w, - unsigned char x, unsigned char y, - unsigned char focus) { - unsigned char xpos, ypos, xscroll; - unsigned char i, j; - char c, *text; +const u8_t off_widget_x = offsetof(struct ctk_widget, x); +const u8_t off_widget_y = offsetof(struct ctk_widget, y); +const u8_t off_widget_w = offsetof(struct ctk_widget, w); +const u8_t off_widget_h = offsetof(struct ctk_widget, h); +const u8_t off_widget_type = offsetof(struct ctk_widget, type); +const u8_t off_widget_window = offsetof(struct ctk_widget, window); + +const u8_t off_widget_label_text = offsetof(struct ctk_widget, widget) + + offsetof(struct ctk_widget_label, text); +const u8_t off_widget_button_text = offsetof(struct ctk_widget, widget) + + offsetof(struct ctk_widget_button, text); +const u8_t off_widget_textentry_text = offsetof(struct ctk_widget, widget) + + offsetof(struct ctk_widget_textentry, text); +const u8_t off_widget_textentry_xpos = offsetof(struct ctk_widget, widget) + + offsetof(struct ctk_widget_textentry, xpos); +const u8_t off_widget_textentry_ypos = offsetof(struct ctk_widget, widget) + + offsetof(struct ctk_widget_textentry, ypos); +const u8_t off_widget_textentry_state = offsetof(struct ctk_widget, widget) + + offsetof(struct ctk_widget_textentry, state); + #if CTK_CONF_ICONS - unsigned char len; +const u8_t off_widget_icon_title = offsetof(struct ctk_widget, widget) + + offsetof(struct ctk_widget_icon, title); +const u8_t off_widget_icon_textmap = offsetof(struct ctk_widget, widget) + + offsetof(struct ctk_widget_icon, textmap); #endif /* CTK_CONF_ICONS */ - xpos = x + w->x; - ypos = y + w->y; - - revers_arch(focus & CTK_FOCUS_WIDGET); - gotoxy_arch(xpos, ypos); +const u8_t off_window_x = offsetof(struct ctk_window, x); +const u8_t off_window_y = offsetof(struct ctk_window, y); +const u8_t off_window_h = offsetof(struct ctk_window, h); +const u8_t off_window_w = offsetof(struct ctk_window, w); +const u8_t off_window_inactive = offsetof(struct ctk_window, inactive); +const u8_t off_window_active = offsetof(struct ctk_window, active); +const u8_t off_window_next = offsetof(struct ctk_window, next); +const u8_t off_window_focused = offsetof(struct ctk_window, focused); - if (w->type == CTK_WIDGET_SEPARATOR) { - chline_arch(w->w); - } else if (w->type == CTK_WIDGET_LABEL) { - text = w->widget.label.text; - for(i = 0; i < w->h; ++i) { - gotoxy_arch(xpos, ypos); - cputsn_arch(text, w->w); - cclear_arch(xpos + w->w); - ++ypos; - text += w->w; - } - } else if (w->type == CTK_WIDGET_BUTTON) { - cputc_arch('['); - cputsn_arch(w->widget.button.text, w->w); - cputc_arch(']'); - } else if (w->type == CTK_WIDGET_HYPERLINK) { - cputsn_arch(w->widget.button.text, w->w); - } else if (w->type == CTK_WIDGET_TEXTENTRY) { - text = w->widget.textentry.text; - xscroll = 0; - if(w->widget.textentry.xpos >= w->w - 1) { - xscroll = w->widget.textentry.xpos - w->w + 1; - } - for(j = 0; j < w->h; ++j) { - gotoxy_arch(xpos, ypos); - if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT && - w->widget.textentry.ypos == j) { - revers_arch(0); - cputc_arch('>'); - for(i = 0; i < w->w; ++i) { - c = text[i + xscroll]; - revers_arch(i == w->widget.textentry.xpos - xscroll); - cputc_arch((c == 0) ? CH_SPACE : c); - } - revers_arch(0); - cputc_arch('<'); - } else { - cputc_arch(CH_VERTLINE); - cputsn_arch(text, w->w); - cclear_arch(xpos + w->w + 1); - cputc_arch(CH_VERTLINE); - } - ++ypos; - text += w->w; - } -#if CTK_CONF_ICONS - } else if (w->type == CTK_WIDGET_ICON) { - if(w->widget.icon.textmap != NULL) { - for(i = 0; i < 3; ++i) { - gotoxy_arch(xpos, ypos); - cputc_arch(w->widget.icon.textmap[0 + 3 * i]); - cputc_arch(w->widget.icon.textmap[1 + 3 * i]); - cputc_arch(w->widget.icon.textmap[2 + 3 * i]); - ++ypos; - } - x = xpos; - - len = strlen(w->widget.icon.title); - if(x + len >= SCREEN_WIDTH) { - x = SCREEN_WIDTH - len; - } - gotoxy_arch(x, ypos); - cputs_arch(w->widget.icon.title); - } -#endif /* CTK_CONF_ICONS */ - } - revers_arch(0); - -} -/*---------------------------------------------------------------------------*/ -void -ctk_draw_widget(struct ctk_widget *w, - unsigned char focus, - unsigned char clipy1, - unsigned char clipy2) { - - struct ctk_window *win = w->window; - unsigned char posx, posy; - clip_arch(clipy1, clipy2); - - posx = win->x + 1; - posy = win->y + 2; - - if(w == win->focused) { - focus |= CTK_FOCUS_WIDGET; - } - - draw_widget(w, posx, posy, focus); -} -/*---------------------------------------------------------------------------*/ -void -ctk_draw_clear_window(struct ctk_window *window, - unsigned char focus, - unsigned char clipy1, - unsigned char clipy2) { - - unsigned char i; - unsigned char x1, x2, y1, y2; - x1 = window->x + 1; - x2 = x1 + window->w; - y1 = window->y + 2; - y2 = y1 + window->h; - clip_arch(clipy1, clipy2); - - for(i = y1; i < y2; ++i) { - gotoxy_arch(x1, i); - cclear_arch(x2); - } -} -/*---------------------------------------------------------------------------*/ -static void draw_window_sub(struct ctk_window *window, unsigned char focus) { - - unsigned char x, y; - unsigned char x1, y1, x2; - struct ctk_widget *w; - unsigned char wfocus; - - x = window->x; - y = window->y + 1; - - x1 = x + 1; - y1 = y + 1; - x2 = x1 + window->w; - - // |_ - gotoxy_arch(x, y1); - cvline_arch(window->h); - cputc_arch(CH_LLCORNER); - chline_arch(window->w); - cputc_arch(CH_LRCORNER); - - // - - gotoxy_arch(x, y); - cputc_arch(CH_ULCORNER); - chline_arch(window->w); - cputc_arch(CH_URCORNER); - // | - gotoxy_arch(x2, y1); - cvline_arch(window->h); - - /* Draw inactive widgets. */ - for(w = window->inactive; w != NULL; w = w->next) { - draw_widget(w, x1, y1, focus); - } - - /* Draw active widgets. */ - for(w = window->active; w != NULL; w = w->next) { - wfocus = focus; - if(w == window->focused) { - wfocus |= CTK_FOCUS_WIDGET; - } - draw_widget(w, x1, y1, wfocus); - } -} -/*---------------------------------------------------------------------------*/ -void ctk_draw_window(struct ctk_window *window, unsigned char focus, - unsigned char clipy1, unsigned char clipy2, - unsigned char draw_borders) { - clip_arch(clipy1, clipy2); - - focus = focus & CTK_FOCUS_WINDOW; - draw_window_sub(window, focus); -} -/*---------------------------------------------------------------------------*/ -void ctk_draw_dialog(struct ctk_window *dialog) { - clip_arch(0, SCREEN_HEIGHT); - - ctk_draw_clear_window(dialog, 0, 0, SCREEN_HEIGHT); - draw_window_sub(dialog, CTK_FOCUS_DIALOG); -} -/*---------------------------------------------------------------------------*/ #if CTK_CONF_MENUS -static void draw_menu(struct ctk_menu *m, struct ctk_menu *open) { -#if CC_CONF_UNSIGNED_CHAR_BUGS - unsigned char x2; - unsigned int x, y; -#else - unsigned char x2; - unsigned char x, y; +const u8_t off_menu_title = offsetof(struct ctk_menu, title); +const u8_t off_menu_active = offsetof(struct ctk_menu, active); +const u8_t off_menu_nitems = offsetof(struct ctk_menu, nitems); +const u8_t off_menu_items = offsetof(struct ctk_menu, items); +const u8_t off_menu_next = offsetof(struct ctk_menu, next); +const u8_t off_menuitem_title = offsetof(struct ctk_menuitem, title); +const u8_t size_menuitem = sizeof(struct ctk_menuitem); +const u8_t off_menus_open = offsetof(struct ctk_menus, open); +const u8_t off_menus_menus = offsetof(struct ctk_menus, menus); +const u8_t off_menus_desktopmenu = offsetof(struct ctk_menus, desktopmenu); #endif - x = info.cursx; - cputs_arch(m->title); - cputc_arch(CH_SPACE); - if (m == open) { - x2 = info.cursx; - if(x + CTK_CONF_MENUWIDTH > SCREEN_WIDTH) { - x = SCREEN_WIDTH - CTK_CONF_MENUWIDTH; - } - - for(y = 0; y < m->nitems; y++) { - if(y == m->active) { - revers_arch(0); - } - gotoxy_arch(x, y + 1); - if(m->items[y].title[0] == '-') { - chline_arch(CTK_CONF_MENUWIDTH); - } else { - cputs_arch(m->items[y].title); - } - cclear_arch(x + CTK_CONF_MENUWIDTH); - revers_arch(1); - } - gotoxy_arch(x2, 0); - } -} /*---------------------------------------------------------------------------*/ -void ctk_draw_menus(struct ctk_menus *menus) { - struct ctk_menu *m; - - clip_arch(0, SCREEN_HEIGHT); - /* Draw menus */ - gotoxy_arch(0, 0); - revers_arch(1); - for(m = menus->menus->next; m != NULL; m = m->next) { - draw_menu(m, menus->open); - } - - cclear_arch(SCREEN_WIDTH - strlen(menus->desktopmenu->title) - 1); - - /* Draw desktopmenu */ - draw_menu(menus->desktopmenu, menus->open); - - revers_arch(0); -} -#endif /* CTK_CONF_MENUS */ -/*---------------------------------------------------------------------------*/ -/* Returns width and height of screen. */ -unsigned char ctk_draw_width(void) { - return SCREEN_WIDTH; -} -unsigned char ctk_draw_height(void) { - return SCREEN_HEIGHT; -} diff --git a/platform/pc-6001/ctk/ctk_arch-def.h b/platform/pc-6001/ctk/ctk_arch-def.h index 3445ce492..8a803785a 100644 --- a/platform/pc-6001/ctk/ctk_arch-def.h +++ b/platform/pc-6001/ctk/ctk_arch-def.h @@ -27,10 +27,10 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: ctk_arch-def.h,v 1.1 2007/09/11 12:12:59 matsutsuka Exp $ + * $Id: ctk_arch-def.h,v 1.2 2007/09/19 12:46:15 matsutsuka Exp $ * */ - + /* * \file * ctk_arch-def.h @@ -106,7 +106,7 @@ #define CH_CURS_RIGHT 0x1c #define CH_ENTER 0x0d #define CH_ESC 0x1b -#define CH_STOP 0x03 +#define CH_STOP 0x03 #define CH_DEL 0x08 /* Contiki toolkit options */ @@ -136,16 +136,28 @@ /* Key used to switch the frontmost window. */ #define CTK_CONF_WINDOWSWITCH_KEY CH_F3 /* Key used to move down a widget. */ -#define CTK_CONF_WIDGETDOWN_KEY CH_TAB +#define CTK_CONF_WIDGETDOWN_KEY CH_TAB /* Key used to move up a widget. */ #define CTK_CONF_WIDGETUP_KEY CH_F5 /* Defines which key that is to be used for activating the menus */ #define CTK_CONF_MENU_KEY CH_F1 -/* offsets of struct screen_info for assembler */ -#define CURSX 0 -#define CURSY 1 -#define CY1 2 -#define CY2 3 +/* Imported symbols from ctk.h */ + +#define _CTK_FOCUS_NONE 0 +#define _CTK_FOCUS_WIDGET 1 +#define _CTK_FOCUS_WINDOW 2 +#define _CTK_FOCUS_DIALOG 4 + +#define _CTK_WIDGET_SEPARATOR 1 +#define _CTK_WIDGET_LABEL 2 +#define _CTK_WIDGET_BUTTON 3 +#define _CTK_WIDGET_HYPERLINK 4 +#define _CTK_WIDGET_TEXTENTRY 5 +#define _CTK_WIDGET_BITMAP 6 +#define _CTK_WIDGET_ICON 7 + +#define _CTK_TEXTENTRY_NORMAL 0 +#define _CTK_TEXTENTRY_EDIT 1 #endif /* __CTK_ARCH_DEF_H__ */ diff --git a/platform/pc-6001/ctk/libconio_arch-asm.cS b/platform/pc-6001/ctk/libconio_arch-asm.cS new file mode 100644 index 000000000..19d3cda5e --- /dev/null +++ b/platform/pc-6001/ctk/libconio_arch-asm.cS @@ -0,0 +1,525 @@ +;;; +;;; +;;; libconio_arch-asm.hS +;;; +;;; Architecture depend libconio implementation. +;;; This assembler source contributes basically saving for speed and memory. +;;; +;;; @author Takahide Matsutsuka +;;; +;;; $Id: libconio_arch-asm.cS,v 1.1 2007/09/19 12:46:15 matsutsuka Exp $ +;;; + + ;; uses preprocessor to enable definitions +#include "ctk_arch-def.h" + + ;; export symbols + .globl _cputc_arch + .globl _cputs_arch + .globl _cputsn_arch + .globl _chline_arch + .globl _cvline_arch + .globl _gotoxy_arch + .globl _clearto_arch + .globl _revers_arch + .globl _clip_arch + .globl _wherex_arch + .globl _drawbox_arch + .globl _drawicon_arch + .globl _clearbox_arch + .globl _newline_arch + + .area _DATA +_screen_cursor: + .ds 1 ; x + .ds 1 ; y +_screen_clips: + .ds 1 ; clip y1 + .ds 1 ; clip y2 +_screen_reversed: + .ds 1 + + .area _CODE + +_libconio_arch_asm_start:: +.if 0 + ;; input: B = y, C = x + ;; output: HL = offset + ;; ______HL____ +_calc_offset: + push af + push de + ld a, b + ld hl, #0 + ld de, #SCREEN_WIDTH +_calc_offset_loop: + or a + jr z, _calc_offset_calcx + add hl, de + dec a + jr _calc_offset_loop +_calc_offset_calcx: + ld d, #0 + ld e, c + add hl, de + pop de + pop af + ret +.endif + ;; --------------------------------- + ;; void cputc(char ch); + ;; Stack; retl reth ch + ;; AFBCDEHL____ + ;; return A=1 if output is succeeded, A=0 if not + ;; --------------------------------- +_cputc_arch: + ld hl, #2 + add hl, sp + ld a, (hl) + ;; ------------ + ;; A = char + ;; AFBCDEHL____ + ;; ------------ +_cputc_arch_asm: + push af + ld bc, (#_screen_cursor) ;B=y, C=x + ld de, (#_screen_clips) ;D=cy2, E=cy1 + ld a, b + cp a, e + jr c, _cputc_arch_ret_false ; if (cursy < cy1) + cp a, d + jr z, _cputc_arch_next1 + jr nc, _cputc_arch_ret_false ; if (cursy > cy2) +_cputc_arch_next1: + cp a, #SCREEN_HEIGHT ; cursy - SCREEN_HEIGHT + jr z, _cputc_arch_next2 + jr nc, _cputc_arch_ret_false ; if (cursy > SCREEN_HEIGHT) +_cputc_arch_next2: + ld a, c + cp a, #SCREEN_WIDTH ; cursx - SCREEN_WIDTH + jr nc, _cputc_arch_ret_false ; if (cursx >= SCREEN_WIDTH) + ;; calculate offset +.if 0 + call _calc_offset +.else + ld a, b ; A=y + ld hl, #0 + ld de, #SCREEN_WIDTH +_cputc_arch_loop: + or a + jr z, _cputc_arch_calcx + add hl, de + dec a + jr _cputc_arch_loop +_cputc_arch_calcx: + ld d, #0 + ld e, c + add hl, de +.endif + ;; putchar + pop af + ld de, #VRAM_CHAR + push hl + add hl, de + ld (hl), a + pop hl + ;; putattr + ld de, #VRAM_ATTR + add hl, de + ld a, (#_screen_reversed) + or a + jr z, _cputc_arch_normal + ld (hl), #COLOR_REVERSED + jr _cputc_arch_ret +_cputc_arch_normal: + ld (hl), #COLOR_NORMAL + ld a, #0x01 +_cputc_arch_ret: + ld hl, #_screen_cursor + inc (hl) + ret +_cputc_arch_ret_false: + pop af + xor a + jr _cputc_arch_ret + + ;; --------------------------------- + ;; void cputs_arch(char *str); + ;; Stack; retl reth strl strh + ;; AFB_DEHL____ + ;; return void + ;; --------------------------------- +_cputs_arch: + ld hl, #2 + add hl, sp + ld e, (hl) + inc hl + ld d, (hl) + ld b, #SCREEN_WIDTH ; max length + ;; ------------ + ;; B = nchars + ;; DE = str + ;; AFB_DEHL____ + ;; ------------ +_cputs_arch_loop: + ld a, (de) + or a + ret z + push bc + push de + call _cputc_arch_asm + pop de + pop bc + inc de + djnz _cputs_arch_loop + ret + + ;; --------------------------------- + ;; void cputsn(char *str, unsigned char length); + ;; Stack; retl reth strl strh length + ;; AFB_DEHL____ + ;; return void + ;; --------------------------------- +_cputsn_arch: + ld hl, #2 + add hl, sp + ld e, (hl) + inc hl + ld d, (hl) + inc hl + ld b, (hl) + jr _cputs_arch_loop ; take over B and DE + + ;; --------------------------------- + ;; void chline(unsigned char length); + ;; Stack; retl reth length + ;; AFB_DEHL____ + ;; return void + ;; --------------------------------- +_chline_arch: + ld hl, #2 + add hl, sp + ld b, (hl) + ;; ------------ + ;; B = length + ;; AFB_DEHL____ + ;; ------------ +_chline_arch_asm: + ld a, #CH_HOLILINE +_chline_arch_loop: + push bc + push af + call _cputc_arch_asm + pop af + pop bc + djnz _chline_arch_loop + ret + + ;; --------------------------------- + ;; void cvline(unsigned char length); + ;; Stack; retl reth length + ;; AFB_DEHL____ + ;; return void + ;; --------------------------------- +_cvline_arch: + ld hl, #2 + add hl, sp + ld b, (hl) ; length + ;; ------------ + ;; B = length + ;; AFB_DEHL____ + ;; ------------ +_cvline_arch_asm: + ld a, #CH_VERTLINE + ld hl, (#_screen_cursor) ; H=y, L=x +_cvline_arch_loop: + push hl + push bc + push af + call _cputc_arch_asm + pop af + pop bc + pop hl + inc h + ld (#_screen_cursor), hl + djnz _cvline_arch_loop + ret + + ;; --------------------------------- + ;; void gotoxy(unsigned char x, unsigned char y) + ;; Stack; retl reth x y + ;; _F__DEHL____ + ;; return void + ;; --------------------------------- +_gotoxy_arch: + ld hl, #2 + add hl, sp + ld d, (hl) ; x + inc hl + ld e, (hl) ; y + ;; ------------ + ;; D = x, E = y + ;; ______HL____ + ;; ------------ +_gotoxy_arch_asm: + ld l, d ; L=x + ld h, e ; H=y + ld (#_screen_cursor), hl + ret + + ;; --------------------------------- + ;; void clearto_arch(unsigned char to) + ;; Stack; retl reth to + ;; AFBCDEHL____ + ;; return void + ;; --------------------------------- +_clearto_arch: + ld hl, #2 + add hl, sp + ld a, (hl) +_clearto_arch_loop: + ld hl, #_screen_cursor + cp (hl) ; to - cursx + ret z + ret c + push af + ld a, #CH_SPACE + call _cputc_arch_asm + or a + pop af + ret z + jr _clearto_arch_loop + + ;; --------------------------------- + ;; void revers_arch(unsigned char reverse) + ;; Stack; retl reth reverse + ;; A_____HL____ + ;; return void + ;; --------------------------------- +_revers_arch: + ld hl, #2 + add hl, sp + ld a, (hl) + ld (#_screen_reversed), a + ret + + ;; --------------------------------- + ;; void clip_arch(unsigned char clip1, unsigned char clip2) + ;; Stack; retl reth clip1 clip2 + ;; ____________ + ;; return void + ;; --------------------------------- +_clip_arch: + push af + push hl + push de + ld hl, #0x08 + add hl, sp + ld de, #_screen_clips + ld a, (hl) + ld (de), a + inc hl + inc de + ld a, (hl) + ld (de), a + pop de + pop hl + pop af + ret + + ;; --------------------------------- + ;; unsigned char wherex_arch() + ;; Stack; retl reth + ;; A_____HL____ + ;; return void + ;; --------------------------------- +_wherex_arch: + ld a, (#_screen_cursor) + ld l, a + ret + + ;; --------------------------------- + ;; void drawbox_arch(unsigned char x, y, w, h) + ;; Stack; retl reth x y w h + ;; AFBCDEHL____ + ;; return void + ;; --------------------------------- +_drawbox_arch: + ld hl, #2 + add hl, sp + ld d, (hl) ; x + inc hl + ld e, (hl) ; y + inc hl + ld c, (hl) ; w + inc hl + ld b, (hl) ; h + inc e + call _gotoxy_arch_asm ; (x, y + 1) + dec e + push de + push bc + call _cvline_arch_asm + ld a, #CH_LLCORNER + call _cputc_arch_asm + pop bc + push bc ; Stack; BC DE + ld b, c ; w + call _chline_arch_asm + ld a, #CH_LRCORNER + call _cputc_arch_asm + pop bc + pop de + call _gotoxy_arch_asm ; (x, y) + push de + push bc ; Stack; BC DE + ld a, #CH_ULCORNER + call _cputc_arch_asm + pop bc + push bc ; Stack; BC DE + ld b, c + call _chline_arch_asm + ld a, #CH_URCORNER + call _cputc_arch_asm + pop bc ; B = h + pop de + ld a, d + inc a + add a, c + ld d, a ; D = x + 1 + w + inc e ; E = y + 1 + call _gotoxy_arch_asm + call _cvline_arch_asm + ret + +.if CTK_CONF_ICONS + ;; --------------------------------- + ;; void drawicon_arch(char* textmap, char *title); + ;; Stack; retl reth textmapl textmaph titlel titleh + ;; AFBCDEHL____ + ;; return void + ;; --------------------------------- +_drawicon_arch: + ld hl, #_screen_cursor + ld b, (hl) ; x + inc hl + ld c, (hl) ; y + ld hl, #2 + add hl, sp + ld e, (hl) + inc hl + ld d, (hl) ; DE = textmap + ld a, e + or d + ret z ; if (textmap == NULL) return; + ld a, #3 ; loop counter +_drawicon_arch_loop: + push af + push de + ld d, b + ld e, c + call _gotoxy_arch_asm + pop de + push bc + ld b, #3 + call _cputs_arch_loop ; DE = DE + 3 + pop bc + pop af + inc c ; y++ + dec a + jr z, _drawicon_arch_title + jr _drawicon_arch_loop + ;; B = x, C = y +_drawicon_arch_title: + ld hl, #4 + add hl, sp + ld e, (hl) + inc hl + ld d, (hl) ; DE = title + ld h, d + ld l, e + xor a + push de + ld d, #0 +_drawicon_arch_title_strlen: + ld a, (hl) + or a + jr z, _drawicon_arch_title_setpos + inc hl + inc d + jr _drawicon_arch_title_strlen +_drawicon_arch_title_setpos: + ld h, d ; H = len + ld a, d + pop de + add a, b + cp a, #SCREEN_WIDTH ; x + len - SCREEN_WIDTH + jr c, _drawicon_arch_title_show + ld a, #SCREEN_WIDTH + sub h + ld b, a + ;; B = x, C = y, DE = title, H = len +_drawicon_arch_title_show: + push de + ld d, b + ld e, c + call _gotoxy_arch_asm + pop de + ld b, #SCREEN_WIDTH + call _cputs_arch_loop + ret +.endif + + ;; --------------------------------- + ;; void clearbox_arch(unsigned char x, y, w, h) + ;; Stack; retl reth x y w h + ;; AFBCDEHL____ + ;; return void + ;; --------------------------------- +_clearbox_arch: + ld hl, #2 + add hl, sp + ld d, (hl) ; x + inc hl + ld e, (hl) ; y + inc hl + ld c, (hl) ; w + inc hl + ld b, (hl) ; h + ld a, d + add a, c + ld c, a ; to_x +_clearbox_arch_loop: + call _gotoxy_arch_asm ; (x, y + 1) + push de + push bc + ld a, c + call _clearto_arch_loop + pop bc + pop de + inc e + djnz _clearbox_arch_loop + ret + +_newline_arch: + ld hl, #_screen_cursor + xor a + ld (hl), a + inc hl + ld a, (hl) + inc a + cp a, #SCREEN_HEIGHT + jr nc, _newline_arch_scroll + ld (hl), a + ret +_newline_arch_scroll: + ;; TODO: attr and specific impl + dec a + ld (hl), a + ld hl, #VRAM_CHAR + #SCREEN_WIDTH + ld de, #VRAM_CHAR + ld bc, #SCREEN_HEIGHT * #SCREEN_WIDTH - #SCREEN_WIDTH + ldir + ret + +_libconio_arch_asm_end:: diff --git a/platform/pc-6001/ctk/ctk-conio_arch.h b/platform/pc-6001/ctk/libconio_arch.h similarity index 79% rename from platform/pc-6001/ctk/ctk-conio_arch.h rename to platform/pc-6001/ctk/libconio_arch.h index 5924560b1..10c9ce4de 100644 --- a/platform/pc-6001/ctk/ctk-conio_arch.h +++ b/platform/pc-6001/ctk/libconio_arch.h @@ -27,7 +27,7 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: ctk-conio_arch.h,v 1.1 2007/09/11 12:12:59 matsutsuka Exp $ + * $Id: libconio_arch.h,v 1.1 2007/09/19 12:46:15 matsutsuka Exp $ * */ @@ -38,8 +38,8 @@ * Takahide Matsutsuka */ -#ifndef __CTK_CONIO_ARCH_H__ -#define __CTK_CONIO_ARCH_H__ +#ifndef __LIBCONIO_ARCH_H__ +#define __LIBCONIO_ARCH_H__ void cputc_arch(char c); void cputs_arch(char *str); @@ -47,8 +47,16 @@ void cputsn_arch(char *str, unsigned char len); void chline_arch(unsigned char length); void cvline_arch(unsigned char length); void clip_arch(unsigned char clip1, unsigned char clip2); +unsigned char wherex_arch(); void gotoxy_arch(unsigned char x, unsigned char y); -void cclear_arch(char x); +void clearto_arch(unsigned char to); void revers_arch(unsigned char reversed); +void drawbox_arch(unsigned char x, unsigned char y, + unsigned char w, unsigned char h); +void drawicon_arch(unsigned char x, unsigned char y, + char* textmap, char* title); +void clearbox_arch(unsigned char x, unsigned char y, + unsigned char w, unsigned char h); +void newline_arch(); -#endif /* __CTK_CONIO_ARCH_H__ */ +#endif /* __LIBCONIO_ARCH_H__ */