aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2021-02-10 19:23:46 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2021-02-10 19:23:46 +0100
commit22ee11fbb77b4c81e41832996ce216d790c2b0aa (patch)
treeab373538026588249f1f2b79869cd93f940b47f3
parentTranslating, added rc script (diff)
downloadlowbat-bsd-22ee11fbb77b4c81e41832996ce216d790c2b0aa.tar.gz
lowbat-bsd-22ee11fbb77b4c81e41832996ce216d790c2b0aa.tar.bz2
lowbat-bsd-22ee11fbb77b4c81e41832996ce216d790c2b0aa.tar.xz
lowbat-bsd-22ee11fbb77b4c81e41832996ce216d790c2b0aa.tar.zst
lowbat-bsd-22ee11fbb77b4c81e41832996ce216d790c2b0aa.zip
Comments update
-rw-r--r--LICENSE2
-rw-r--r--Makefile60
-rw-r--r--asm/c_args.S92
-rw-r--r--asm/c_args.asm59
-rw-r--r--asm/f_percent.S83
-rw-r--r--asm/f_percent.asm50
-rw-r--r--asm/f_status.S92
-rw-r--r--asm/f_status.asm59
-rw-r--r--asm/r_cpyhead.S62
-rw-r--r--asm/r_cpyhead.asm29
-rw-r--r--asm/r_loop.S120
-rw-r--r--asm/r_loop.asm88
-rw-r--r--asm/r_lowbat.S59
-rw-r--r--asm/r_lowbat.asm26
-rw-r--r--src/n_notify.c55
-rw-r--r--src/n_notify.h61
-rw-r--r--src/n_speak.c55
-rw-r--r--src/n_speak.h61
18 files changed, 724 insertions, 389 deletions
diff --git a/LICENSE b/LICENSE
index 70f30ee..a26ada1 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
BSD 3-Clause License
-Copyright (c) 2020, Joe
+Copyright (c) 2020-2021, Joe
All rights reserved.
Redistribution and use in source and binary forms, with or without
diff --git a/Makefile b/Makefile
index cf76bb6..a074287 100644
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,20 @@
-##########################################################################################
-#* *#
-#* File : Makefile /_________/ *#
-#* Author : Joe | *#
-#* Date : 04/2020 | *#
-#* Info : BSD Makefile | *#
-#* / | *#
-#* \ / *#
-#* \_____/ *#
-#* *#
-##########################################################################################
+# ========================
+# ===== ===============
+# ====== ================
+# ====== ================
+# ====== ==== ==== ==
+# ====== === == = =
+# ====== === = == =
+# = === === = == ====
+# = === === = == = =
+# == ===== ==== ==
+# ========================
+#
+# lowbat: Makefile
+# Wed Feb 10 19:20:35 CET 2021
+# Joe
+#
+# BSD Makefile
default: all
@@ -21,16 +27,16 @@ MANPREFIX ?= ${PREFIX}/share/man
C_SRCS += ${C_SRCS_DIR}/n_speak.c
C_SRCS += ${C_SRCS_DIR}/n_notify.c
-C_OBJS = ${C_SRCS:.c=.o}
+C_OBJS = ${C_SRCS:.c=.c.o}
-A_SRCS = ${A_SRCS_DIR}/r_lowbat.asm
-A_SRCS += ${A_SRCS_DIR}/r_loop.asm
-A_SRCS += ${A_SRCS_DIR}/r_cpyhead.asm
-A_SRCS += ${A_SRCS_DIR}/c_args.asm
-A_SRCS += ${A_SRCS_DIR}/f_status.asm
-A_SRCS += ${A_SRCS_DIR}/f_percent.asm
+A_SRCS = ${A_SRCS_DIR}/r_lowbat.S
+A_SRCS += ${A_SRCS_DIR}/r_loop.S
+A_SRCS += ${A_SRCS_DIR}/r_cpyhead.S
+A_SRCS += ${A_SRCS_DIR}/c_args.S
+A_SRCS += ${A_SRCS_DIR}/f_status.S
+A_SRCS += ${A_SRCS_DIR}/f_percent.S
-A_OBJS = ${A_SRCS:.asm=.o}
+A_OBJS = ${A_SRCS:.S=.S.o}
CC = cc
CFLAGS += -std=c89
@@ -60,10 +66,10 @@ LDLIBS += -lc
TARGET = lowbat
-ASM = yasm
-ASMFLAGS = -f elf64
-ASMFLAGS += -p gas
-# ASMFLAGS += -g
+AS = as
+# ASFLAGS = -f elf64
+# ASFLAGS += -p gas
+# ASFLAGS += -g
LDFLAGS ?=
LDLIBS = ${LDFLAGS}
@@ -78,12 +84,12 @@ CP = cp -pf
MV = mv
SED = sed
-.SUFFIXES: .asm .c .o
+.SUFFIXES: .S .c .S.o .c.o
-.asm.o:
- ${ASM} ${ASMFLAGS} -o ${.TARGET} ${.IMPSRC}
+.S.S.o:
+ ${AS} ${ASFLAGS} -o ${.TARGET} ${.IMPSRC}
-.c.o:
+.c.c.o:
${CC} -c ${CFLAGS} ${CINCS} -o ${.TARGET} ${.IMPSRC}
${TARGET}: ${A_OBJS} ${C_OBJS}
diff --git a/asm/c_args.S b/asm/c_args.S
new file mode 100644
index 0000000..dabffd3
--- /dev/null
+++ b/asm/c_args.S
@@ -0,0 +1,92 @@
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020-2021 Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the organization nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * lowbat: asm/c_args.S
+ * Wed Feb 10 18:23:00 CET 2021
+ * Joe
+ */
+
+/*
+ * c_args(argc: rdi, *argv[]: rsi)
+ * -------------------------------
+ * returns 0 if args are invalid
+ * returns 1 if args are valid
+ */
+
+.text
+.extern strncmp
+.globl c_args
+
+c_args:
+ cmp $0x2, %rdi
+ jle no_args
+ xorq %rax, %rax
+ pushq %rcx
+ xorq %rcx, %rcx
+ movb $0x8, %cl
+ movq (%rsi, %rcx, 2), %rax
+ cmpb $0x0, (%rax)
+ je no_args
+ pushq %rdi
+ movq (%rsi, %rcx, 1), %rdi
+ pushq %rsi
+ movq $reference, %rsi
+ pushq %rdx
+ xorq %rdx, %rdx
+ movb $0x6, %dl
+ callq strncmp
+ popq %rdx
+ popq %rsi
+ popq %rdi
+ popq %rcx
+ cmp $0x0, %rax
+ jne no_args
+ xorq %rax, %rax
+ movb $0x1, %al
+ jmp return
+
+no_args:
+ xorq %rax, %rax
+
+return:
+ retq
+
+.data
+ reference: .asciz "--say"
diff --git a/asm/c_args.asm b/asm/c_args.asm
deleted file mode 100644
index 17f90c9..0000000
--- a/asm/c_args.asm
+++ /dev/null
@@ -1,59 +0,0 @@
-/****************************************************************************************/
-/* */
-/* File : c_args.asm /_________/ */
-/* Author : Joe | */
-/* Date : 04/2020 | */
-/* Info : Check args | */
-/* / | */
-/* \ / */
-/* \_____/ */
-/* */
-/****************************************************************************************/
-
-/***********************************/
-/* c_args(argc: rdi, *argv[]: rsi) */
-/* ------------------------------- */
-/* returns 0 if args are invalid */
-/* returns 1 if args are valid */
-/***********************************/
-
-.text
-.extern strncmp
-.globl c_args
-
-c_args:
- cmp $0x2, %rdi
- jle no_args
- xorq %rax, %rax
- pushq %rcx
- xorq %rcx, %rcx
- movb $0x8, %cl
- movq (%rsi, %rcx, 2), %rax
- cmpb $0x0, (%rax)
- je no_args
- pushq %rdi
- movq (%rsi, %rcx, 1), %rdi
- pushq %rsi
- movq $reference, %rsi
- pushq %rdx
- xorq %rdx, %rdx
- movb $0x6, %dl
- callq strncmp
- popq %rdx
- popq %rsi
- popq %rdi
- popq %rcx
- cmp $0x0, %rax
- jne no_args
- xorq %rax, %rax
- movb $0x1, %al
- jmp return
-
-no_args:
- xorq %rax, %rax
-
-return:
- retq
-
-.data
- reference: .asciz "--say"
diff --git a/asm/f_percent.S b/asm/f_percent.S
new file mode 100644
index 0000000..e50d1a2
--- /dev/null
+++ b/asm/f_percent.S
@@ -0,0 +1,83 @@
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020-2021 Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the organization nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * lowbat: asm/f_percent.S
+ * Wed Feb 10 18:23:30 CET 2021
+ * Joe
+ */
+
+.text
+.extern system
+.extern atoi
+.globl f_percent
+
+f_percent:
+ movq $f_cmd, %rdi
+ callq system
+ movq $pr_file, %rdi
+ xorq %rsi, %rsi
+ xorq %rax, %rax
+ movb $0x5, %al /* sys_open */
+ syscall
+ jc err
+ movq %rax, %rdi
+ movq $buff, %rsi
+ xorq %rdx, %rdx
+ xorq %rax, %rax
+ movb $0x3, %dl
+ movb $0x3, %al /* sys_read */
+ syscall
+ jc err
+ xorq %rax, %rax
+ movb $0x6, %al /* sys_close */
+ syscall
+ xorq %rax, %rax
+ movq %rsi, %rdi
+ callq atoi
+ retq
+
+err:
+ movq $0xfe, %rax
+ retq
+
+.data
+ f_cmd: .asciz "apm -l >/tmp/lowbat.percent"
+ pr_file: .asciz "/tmp/lowbat.percent"
+ buff: .byte 0x0, 0x0, 0x0, 0x0
diff --git a/asm/f_percent.asm b/asm/f_percent.asm
deleted file mode 100644
index d38daef..0000000
--- a/asm/f_percent.asm
+++ /dev/null
@@ -1,50 +0,0 @@
-/****************************************************************************************/
-/* */
-/* File : f_percent.asm /_________/ */
-/* Author : Joe | */
-/* Date : 04/2020 | */
-/* Info : Gets batt remaining capacity | */
-/* / | */
-/* \ / */
-/* \_____/ */
-/* */
-/****************************************************************************************/
-
-.text
-.extern system
-.extern atoi
-.globl f_percent
-
-f_percent:
- movq $f_cmd, %rdi
- callq system
- movq $pr_file, %rdi
- xorq %rsi, %rsi
- xorq %rax, %rax
- movb $0x5, %al /* sys_open */
- syscall
- jc err
- movq %rax, %rdi
- movq $buff, %rsi
- xorq %rdx, %rdx
- xorq %rax, %rax
- movb $0x3, %dl
- movb $0x3, %al /* sys_read */
- syscall
- jc err
- xorq %rax, %rax
- movb $0x6, %al /* sys_close */
- syscall
- xorq %rax, %rax
- movq %rsi, %rdi
- callq atoi
- retq
-
-err:
- movq $0xfe, %rax
- retq
-
-.data
- f_cmd: .asciz "apm -l >/tmp/lowbat.percent"
- pr_file: .asciz "/tmp/lowbat.percent"
- buff: .byte 0x0, 0x0, 0x0, 0x0
diff --git a/asm/f_status.S b/asm/f_status.S
new file mode 100644
index 0000000..54f25a6
--- /dev/null
+++ b/asm/f_status.S
@@ -0,0 +1,92 @@
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020-2021 Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the organization nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * lowbat: asm/f_status.S
+ * Wed Feb 10 18:23:30 CET 2021
+ * Joe
+ */
+
+/*
+ * apm status
+ * ----------
+ * 0: high
+ * 1: low
+ * 2: critical
+ * 3: charging
+ */
+
+.text
+.extern system
+.globl f_status
+
+f_status:
+ movq $f_cmd, %rdi
+ callq system
+ movq $st_file, %rdi
+ xorq %rsi, %rsi
+ xorq %rax, %rax
+ movb $0x5, %al /* sys_open */
+ syscall
+ jc err
+ movq %rax, %rdi
+ movq $buff, %rsi
+ xorq %rdx, %rdx
+ xorq %rax, %rax
+ movb $0x1, %dl
+ movb $0x3, %al /* sys_read */
+ syscall
+ jc err
+ xorq %rax, %rax
+ movb $0x6, %al /* sys_close */
+ syscall
+ xorq %rax, %rax
+ movb (%rsi), %al
+ subb $0x30, %al
+ retq
+
+err:
+ xorq %rax, %rax
+ movb $0xfe, %al
+ retq
+
+.data
+ f_cmd: .asciz "apm -b >/tmp/lowbat.status"
+ st_file: .asciz "/tmp/lowbat.status"
+ buff: .byte 0x0, 0x0
diff --git a/asm/f_status.asm b/asm/f_status.asm
deleted file mode 100644
index c07a2f3..0000000
--- a/asm/f_status.asm
+++ /dev/null
@@ -1,59 +0,0 @@
-/****************************************************************************************/
-/* */
-/* File : f_status.asm /_________/ */
-/* Author : Joe | */
-/* Date : 04/2020 | */
-/* Info : Gets batt status | */
-/* / | */
-/* \ / */
-/* \_____/ */
-/* */
-/****************************************************************************************/
-
-/***************/
-/* apm status */
-/* ---------- */
-/* 0: high */
-/* 1: low */
-/* 2: critical */
-/* 3: charging */
-/***************/
-
-.text
-.extern system
-.globl f_status
-
-f_status:
- movq $f_cmd, %rdi
- callq system
- movq $st_file, %rdi
- xorq %rsi, %rsi
- xorq %rax, %rax
- movb $0x5, %al /* sys_open */
- syscall
- jc err
- movq %rax, %rdi
- movq $buff, %rsi
- xorq %rdx, %rdx
- xorq %rax, %rax
- movb $0x1, %dl
- movb $0x3, %al /* sys_read */
- syscall
- jc err
- xorq %rax, %rax
- movb $0x6, %al /* sys_close */
- syscall
- xorq %rax, %rax
- movb (%rsi), %al
- subb $0x30, %al
- retq
-
-err:
- xorq %rax, %rax
- movb $0xfe, %al
- retq
-
-.data
- f_cmd: .asciz "apm -b >/tmp/lowbat.status"
- st_file: .asciz "/tmp/lowbat.status"
- buff: .byte 0x0, 0x0
diff --git a/asm/r_cpyhead.S b/asm/r_cpyhead.S
new file mode 100644
index 0000000..f290cbb
--- /dev/null
+++ b/asm/r_cpyhead.S
@@ -0,0 +1,62 @@
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020-2021 Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the organization nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * lowbat: asm/r_cpyhead.S
+ * Wed Feb 10 18:25:22 CET 2021
+ * Joe
+ */
+
+.text
+.extern sprintf
+.globl r_cpyhead
+
+r_cpyhead:
+ movq $buff, %rdi
+ movq $n_head, %rsi
+ xorq %rax, %rax
+ callq sprintf
+ movq $buff, %rax
+ retq
+
+.data
+ n_head: .asciz "Low battery: %d%%"
+
+.bss
+ buff: .zero 0x11
diff --git a/asm/r_cpyhead.asm b/asm/r_cpyhead.asm
deleted file mode 100644
index 2e40877..0000000
--- a/asm/r_cpyhead.asm
+++ /dev/null
@@ -1,29 +0,0 @@
-/****************************************************************************************/
-/* */
-/* File : r_cpyhead.asm /_________/ */
-/* Author : Joe | */
-/* Date : 04/2020 | */
-/* Info : Formats and returns notification head title | */
-/* / | */
-/* \ / */
-/* \_____/ */
-/* */
-/****************************************************************************************/
-
-.text
-.extern sprintf
-.globl r_cpyhead
-
-r_cpyhead:
- movq $buff, %rdi
- movq $n_head, %rsi
- xorq %rax, %rax
- callq sprintf
- movq $buff, %rax
- retq
-
-.data
- n_head: .asciz "Low battery: %d%%"
-
-.bss
- buff: .zero 0x11
diff --git a/asm/r_loop.S b/asm/r_loop.S
new file mode 100644
index 0000000..032b96b
--- /dev/null
+++ b/asm/r_loop.S
@@ -0,0 +1,120 @@
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020-2021 Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the organization nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * lowbat: asm/r_loop.S
+ * Wed Feb 10 18:27:08 CET 2021
+ * Joe
+ */
+
+/*
+ * jo_r_loop(speak (0-1), *argv[])
+ */
+
+.text
+.extern sleep
+.extern f_percent
+.extern f_status
+.extern n_speak
+.extern n_notify
+.extern r_cpyhead
+.globl r_loop
+
+r_loop:
+ pushq %rbp
+ pushq %rbx
+ movq %rsi, %rbx
+ movl %edi, %ebp
+ jmp bigloop
+
+bigloop:
+ callq f_status /* check the status */
+ cmp $0xfe, %rax /* if sys_open/sys_read failed */
+ je err
+ cmp $0x3, %rax
+ je sleepalot
+ callq f_percent /* check the capacity */
+ cmp $0xfe, %rax /* if sys_open/sys_read failed */
+ je err
+ cmp $0xf, %rax
+ jge sleepalot
+ movq %rax, %rdi
+ callq r_cpyhead /* notification head */
+ movq %rax, %rdi
+ movq $n_body, %rsi /* notification body */
+ movq $0x3, %rdx /* critical notification */
+ movq $0x3a98, %rcx /* 15000ms notification timeout */
+ callq n_notify /* n_notify(head: rdi, body: rsi, */
+ /* urgency: rdx, timeout: rcx */
+
+speak:
+ cmp $0x1, %ebp
+ jne sleepabit
+ pushq %rcx
+ movq $0x8, %rcx
+ movq (%rbx,%rcx,0x2), %rdi
+ popq %rcx
+ callq n_speak
+
+sleepabit:
+ movq $0x14, %rdi
+ callq sleep /* sleep 20 seconds before next check/notification */
+ jmp bigloop
+
+sleepalot:
+ movq $0xf0, %rdi
+ callq sleep /* sleep 240s (4m) if it's fine */
+ jmp bigloop
+
+return:
+ xorq %rax, %rax
+ retq
+
+err:
+ movq $0x2, %rdi /* stderr */
+ movq $errmsg, %rsi
+ movq $0x25, %rdx
+ movq $0x4, %rax
+ syscall /* write error message on stderr */
+ xorq %rax, %rax
+ retq
+
+.data
+ n_body: .asciz "Please plug in computer"
+ errmsg: .asciz "Failed to read battery informations\n"
diff --git a/asm/r_loop.asm b/asm/r_loop.asm
deleted file mode 100644
index a3a9126..0000000
--- a/asm/r_loop.asm
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************************/
-/* */
-/* File : r_loop.asm /_________/ */
-/* Author : Joe | */
-/* Date : 04/2020 | */
-/* Info : The main loop | */
-/* / | */
-/* \ / */
-/* \_____/ */
-/* */
-/****************************************************************************************/
-
-/***********************************/
-/* jo_r_loop(speak (0-1), *argv[]) */
-/* ------------------------------- */
-/***********************************/
-
-.text
-.extern sleep
-.extern f_percent
-.extern f_status
-.extern n_speak
-.extern n_notify
-.extern r_cpyhead
-.globl r_loop
-
-r_loop:
- pushq %rbp
- pushq %rbx
- movq %rsi, %rbx
- movl %edi, %ebp
- jmp bigloop
-
-bigloop:
- callq f_status /* check the status */
- cmp $0xfe, %rax /* if sys_open/sys_read failed */
- je err
- cmp $0x3, %rax
- je sleepalot
- callq f_percent /* check the capacity */
- cmp $0xfe, %rax /* if sys_open/sys_read failed */
- je err
- cmp $0xf, %rax
- jge sleepalot
- movq %rax, %rdi
- callq r_cpyhead /* notification head */
- movq %rax, %rdi
- movq $n_body, %rsi /* notification body */
- movq $0x3, %rdx /* critical notification */
- movq $0x3a98, %rcx /* 15000ms notification timeout */
- callq n_notify /* n_notify(head: rdi, body: rsi, */
- /* urgency: rdx, timeout: rcx */
-
-speak:
- cmp $0x1, %ebp
- jne sleepabit
- pushq %rcx
- movq $0x8, %rcx
- movq (%rbx,%rcx,0x2), %rdi
- popq %rcx
- callq n_speak
-
-sleepabit:
- movq $0x14, %rdi
- callq sleep /* sleep 20 seconds before next check/notification */
- jmp bigloop
-
-sleepalot:
- movq $0xf0, %rdi
- callq sleep /* sleep 240s (4m) if it's fine */
- jmp bigloop
-
-return:
- xorq %rax, %rax
- retq
-
-err:
- movq $0x2, %rdi /* stderr */
- movq $errmsg, %rsi
- movq $0x25, %rdx
- movq $0x4, %rax
- syscall /* write error message on stderr */
- xorq %rax, %rax
- retq
-
-.data
- n_body: .asciz "Please plug in computer"
- errmsg: .asciz "Failed to read battery informations\n"
diff --git a/asm/r_lowbat.S b/asm/r_lowbat.S
new file mode 100644
index 0000000..17939a2
--- /dev/null
+++ b/asm/r_lowbat.S
@@ -0,0 +1,59 @@
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020-2021 Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the organization nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * lowbat: asm/r_lowbat.S
+ * Wed Feb 10 19:13:28 CET 2021
+ * Joe
+ */
+
+.text
+.extern c_args
+.extern r_loop
+.globl main
+
+main:
+ callq c_args
+ movq %rax, %rdi
+ callq r_loop /* jo_r_loop(speak: 0-1, *argv[]) */
+
+ xorq %rax, %rax
+ xorq %rdi, %rdi
+ mov $0x1, %rax
+ syscall
diff --git a/asm/r_lowbat.asm b/asm/r_lowbat.asm
deleted file mode 100644
index a1da30b..0000000
--- a/asm/r_lowbat.asm
+++ /dev/null
@@ -1,26 +0,0 @@
-/****************************************************************************************/
-/* */
-/* File : r_lowbat.asm /_________/ */
-/* Author : Joe | */
-/* Date : 04/2020 | */
-/* Info : The main program | */
-/* / | */
-/* \ / */
-/* \_____/ */
-/* */
-/****************************************************************************************/
-
-.text
-.extern c_args
-.extern r_loop
-.globl main
-
-main:
- callq c_args
- movq %rax, %rdi
- callq r_loop /* jo_r_loop(speak: 0-1, *argv[]) */
-
- xorq %rax, %rax
- xorq %rdi, %rdi
- mov $0x1, %rax
- syscall
diff --git a/src/n_notify.c b/src/n_notify.c
index f88f6b5..24b4d7e 100644
--- a/src/n_notify.c
+++ b/src/n_notify.c
@@ -1,14 +1,47 @@
-/****************************************************************************************/
-/* */
-/* File : n_notify.c /_________/ */
-/* Author : Joe | */
-/* Date : 04/2020 | */
-/* Info : Uses libnotify lib to notify | */
-/* / | */
-/* \ / */
-/* \_____/ */
-/* */
-/****************************************************************************************/
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020-2021 Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the organization nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * lowbat: src/n_notify.c
+ * Wed Feb 10 19:21:25 CET 2021
+ * Joe
+ */
#include "n_notify.h"
diff --git a/src/n_notify.h b/src/n_notify.h
index 9bd1c44..a3cec6a 100644
--- a/src/n_notify.h
+++ b/src/n_notify.h
@@ -1,17 +1,50 @@
-/****************************************************************************************/
-/* */
-/* File : n_notify.h /_________/ */
-/* Author : Joe | */
-/* Date : 04/2020 | */
-/* Info : Uses libnotify lib to notify | */
-/* / | */
-/* \ / */
-/* \_____/ */
-/* */
-/****************************************************************************************/
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020-2021 Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the organization nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * lowbat: src/n_notify.h
+ * Wed Feb 10 19:21:51 CET 2021
+ * Joe
+ */
-#ifndef JO_N_NOTIFY_H
-#define JO_N_NOTIFY_H
+#ifndef __N_NOTIFY_H__
+#define __N_NOTIFY_H__
#include <libnotify/notify.h>
#include <stddef.h>
@@ -26,4 +59,4 @@ void n_notify(
int32_t
);
-#endif
+#endif /*__N_NOTIFY_H__ */
diff --git a/src/n_speak.c b/src/n_speak.c
index 53bcdd0..78a1c6a 100644
--- a/src/n_speak.c
+++ b/src/n_speak.c
@@ -1,14 +1,47 @@
-/****************************************************************************************/
-/* */
-/* File : n_speak.c /_________/ */
-/* Author : Joe | */
-/* Date : 04/2020 | */
-/* Info : Uses espeak lib to speak | */
-/* / | */
-/* \ / */
-/* \_____/ */
-/* */
-/****************************************************************************************/
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020-2021 Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the organization nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * lowbat: src/n_speak.c
+ * Wed Feb 10 19:22:45 CET 2021
+ * Joe
+ */
#include "n_speak.h"
diff --git a/src/n_speak.h b/src/n_speak.h
index 3270292..6545971 100644
--- a/src/n_speak.h
+++ b/src/n_speak.h
@@ -1,17 +1,50 @@
-/****************************************************************************************/
-/* */
-/* File : n_speak.h /_________/ */
-/* Author : Joe | */
-/* Date : 04/2020 | */
-/* Info : Use espeak lib to speak | */
-/* / | */
-/* \ / */
-/* \_____/ */
-/* */
-/****************************************************************************************/
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020-2021 Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the organization nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * lowbat: src/n_speak.h
+ * Wed Feb 10 19:23:33 CET 2021
+ * Joe
+ */
-#ifndef JO_N_SPEAK_H
-#define JO_N_SPEAK_H
+#ifndef __N_SPEAK_H__
+#define __N_SPEAK_H__
#include <espeak/speak_lib.h>
#include <string.h>
@@ -31,4 +64,4 @@ enum
void n_speak(const char *);
-#endif
+#endif /* __N_SPEAK_H__ */