about summary refs log tree commit diff stats
path: root/apps
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-12-22 17:01:54 -0800
committerKartik Agaram <vc@akkartik.com>2020-12-23 00:04:20 -0800
commit2b61e5e0a02e6c4bd919c842ecf74ff3e089ec73 (patch)
treec7a89c5cb20460dce87b8c9dba8e81b6374deb36 /apps
parent6216a79974d2742bc454f722a28a3ed934f269c6 (diff)
downloadmu-2b61e5e0a02e6c4bd919c842ecf74ff3e089ec73.tar.gz
7376
Diffstat (limited to 'apps')
-rw-r--r--apps/boot.hex10
1 files changed, 7 insertions, 3 deletions
diff --git a/apps/boot.hex b/apps/boot.hex
index ec32103c..3157ce58 100644
--- a/apps/boot.hex
+++ b/apps/boot.hex
@@ -32,7 +32,8 @@
 #   to the address range [0x7c00, 0x7e00)
 
 # 00:
-  fa  # cli  # TODO: don't forget to reenable interrupts in a real program
+  # disable interrupts for this initialization
+  fa  # cli
 
   # initialize segment registers
   # this isn't always needed, but is considered safe not to assume
@@ -147,11 +148,14 @@ e9 fb ff  # loop forever
   8e c0  # es <- ax
   8e e0  # fs <- ax
   8e e8  # gs <- ax
+
+  # initialization is done; enable interrupts
+  fb
   e9 1d 00 00 00  # jump to 0x7cf0
 
 # padding
-# d3:
-         00 00 00 00 00 00 00 00 00 00 00 00 00
+# d4:
+            00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 
 ## 'application' SubX code: print one character to top-left of screen
d=c16871d143a00eeb04d40e7b4ab20590b8ae93c6'>c16871d1 ^
f2728096 ^













c16871d1 ^
f2728096 ^
c16871d1 ^
c16871d1 ^


f2728096 ^
c16871d1 ^
c16871d1 ^























































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


               
                                                            







































                                                                                
                             
























                                                                                                 

                                                          
                       
                                                                          








                                                                                
                                                                                                               









                                                               













                                                                             
                                                     
                                               
                 


                                              
                   
         























































                                                                                    
/*
 * chat_state.c
 *
 * Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
 *
 * This file is part of Profanity.
 *
 * Profanity is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Profanity is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Profanity.  If not, see <http://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give permission to
 * link the code of portions of this program with the OpenSSL library under
 * certain conditions as described in each individual source file, and
 * distribute linked combinations including the two.
 *
 * You must obey the GNU General Public License in all respects for all of the
 * code used other than OpenSSL. If you modify file(s) with this exception, you
 * may extend this exception to your version of the file(s), but you are not
 * obligated to do so. If you do not wish to do so, delete this exception
 * statement from your version. If you delete this exception statement from all
 * source files in the program, then also delete it here.
 *
 */

#include <stdlib.h>

#include <glib.h>

#include "chat_state.h"
#include "chat_session.h"
#include "xmpp/xmpp.h"
#include "config/preferences.h"

#define PAUSED_TIMEOUT 10.0
#define INACTIVE_TIMEOUT 30.0

static void _send_if_supported(const char * const barejid, void(*send_func)(const char * const));

ChatState*
chat_state_new(void)
{
    ChatState *new_state = malloc(sizeof(struct prof_chat_state_t));
    new_state->type = CHAT_STATE_GONE;
    new_state->timer = g_timer_new();

    return new_state;
}

void
chat_state_free(ChatState *state)
{
    if (state && state->timer!= NULL) {
        g_timer_destroy(state->timer);
    }
    free(state);
}

void
chat_state_handle_idle(const char * const barejid, ChatState *state)
{
    gdouble elapsed = g_timer_elapsed(state->timer, NULL);

    // TYPING -> PAUSED
    if (state->type == CHAT_STATE_COMPOSING && elapsed > PAUSED_TIMEOUT) {
        state->type = CHAT_STATE_PAUSED;
        g_timer_start(state->timer);
        if (prefs_get_boolean(PREF_STATES) && prefs_get_boolean(PREF_OUTTYPE)) {
            _send_if_supported(barejid, message_send_paused);
        }
        return;
    }

    // PAUSED|ACTIVE -> INACTIVE
    if ((state->type == CHAT_STATE_PAUSED || state->type == CHAT_STATE_ACTIVE) && elapsed > INACTIVE_TIMEOUT) {
        state->type = CHAT_STATE_INACTIVE;
        g_timer_start(state->timer);
        if (prefs_get_boolean(PREF_STATES)) {
            _send_if_supported(barejid, message_send_inactive);
        }
        return;

    }

    // INACTIVE -> GONE
    if (state->type == CHAT_STATE_INACTIVE) {
        if (prefs_get_gone() != 0 && (elapsed > (prefs_get_gone() * 60.0))) {
            ChatSession *session = chat_session_get(barejid);
            if (session) {
                // never move to GONE when resource override
                if (!session->resource_override) {
                    if (prefs_get_boolean(PREF_STATES)) {
                        _send_if_supported(barejid, message_send_gone);
                    }
                    chat_session_remove(barejid);
                    state->type = CHAT_STATE_GONE;
                    g_timer_start(state->timer);
                }
            } else {
                if (prefs_get_boolean(PREF_STATES)) {
                    message_send_gone(barejid);
                }
                state->type = CHAT_STATE_GONE;
                g_timer_start(state->timer);
            }
            return;
        }
    }
}

void
chat_state_handle_typing(const char * const barejid, ChatState *state)
{
    // ACTIVE|INACTIVE|PAUSED|GONE -> COMPOSING
    if (state->type != CHAT_STATE_COMPOSING) {
        state->type = CHAT_STATE_COMPOSING;
        g_timer_start(state->timer);
        if (prefs_get_boolean(PREF_STATES) && prefs_get_boolean(PREF_OUTTYPE)) {
            _send_if_supported(barejid, message_send_composing);
        }
    }
}

void
chat_state_active(ChatState *state)
{
    state->type = CHAT_STATE_ACTIVE;
    g_timer_start(state->timer);
}

void
chat_state_gone(const char * const barejid, ChatState *state)
{
    if (state->type != CHAT_STATE_GONE) {
        if (prefs_get_boolean(PREF_STATES)) {
            _send_if_supported(barejid, message_send_gone);
        }
        state->type = CHAT_STATE_GONE;
        g_timer_start(state->timer);
    }
}

static void
_send_if_supported(const char * const barejid, void(*send_func)(const char * const))
{
    gboolean send = TRUE;
    GString *jid = g_string_new(barejid);
    ChatSession *session = chat_session_get(barejid);
    if (session) {
        if (session->send_states) {
            g_string_append(jid, "/");
            g_string_append(jid, session->resource);
        } else {
            send = FALSE;
        }
    }

    if (send) {
        send_func(jid->str);
    }

    g_string_free(jid, TRUE);
}