Skip to content

Commit

Permalink
system: initial manual sleep implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Dec 27, 2024
1 parent 9e0d57d commit ed231fc
Show file tree
Hide file tree
Showing 9 changed files with 361 additions and 26 deletions.
21 changes: 1 addition & 20 deletions bios/hw_irq_vblank.s
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,7 @@ hw_irq_vblank_handler:
// === KEY PRESS HANDLER ===

// Scan key presses
mov al, 0x10
out IO_KEY_SCAN, al
daa
in al, IO_KEY_SCAN
and al, 0x0F
mov ch, al

mov al, 0x20
out IO_KEY_SCAN, al
daa
in al, IO_KEY_SCAN
shl al, 4
mov cl, al

mov al, 0x40
out IO_KEY_SCAN, al
daa
in al, IO_KEY_SCAN
and al, 0x0F
or cl, al
call __key_scan

// Update key variables
mov ax, word ptr [keys_held]
Expand Down
38 changes: 38 additions & 0 deletions bios/system/sys_get_awake_key.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2023, 2024 Adrian "asie" Siekierka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

.arch i186
.code16
.intel_syntax noprefix

#include "common.inc"

/**
* INT 17h AH=08h - sys_get_awake_key
* Input:
* Output:
* - AX = Waking key pattern
*/
.global sys_get_awake_key
sys_get_awake_key:
ss mov ax, [sys_awake_key]
ret
39 changes: 39 additions & 0 deletions bios/system/sys_get_sleep_time.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2023, 2024 Adrian "asie" Siekierka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

.arch i186
.code16
.intel_syntax noprefix

#include "common.inc"

/**
* INT 17h AH=06h - sys_get_sleep_time
* Input:
* Output:
* - AX = Time to sleep (in minutes)
*/
.global sys_get_sleep_time
sys_get_sleep_time:
xor ax, ax
ss mov al, [sys_sleep_time]
ret
38 changes: 38 additions & 0 deletions bios/system/sys_set_awake_key.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2023, 2024 Adrian "asie" Siekierka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

.arch i186
.code16
.intel_syntax noprefix

#include "common.inc"

/**
* INT 17h AH=07h - sys_set_awake_key
* Input:
* - BX = Waking key pattern
* Output:
*/
.global sys_set_awake_key
sys_set_awake_key:
ss mov [sys_awake_key], bx
ret
38 changes: 38 additions & 0 deletions bios/system/sys_set_keepalive_int.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2023, 2024 Adrian "asie" Siekierka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

.arch i186
.code16
.intel_syntax noprefix

#include "common.inc"

/**
* INT 17h AH=09h - sys_set_keepalive_int
* Input:
* - BL = Interrupt mask
* Output:
*/
.global sys_set_keepalive_int
sys_set_keepalive_int:
ss mov [sys_keepalive_int], bl
ret
38 changes: 38 additions & 0 deletions bios/system/sys_set_sleep_time.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2023, 2024 Adrian "asie" Siekierka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

.arch i186
.code16
.intel_syntax noprefix

#include "common.inc"

/**
* INT 17h AH=05h - sys_set_sleep_time
* Input:
* - BL = Time until sleep when idle (minutes)
* Output:
*/
.global sys_set_sleep_time
sys_set_sleep_time:
ss mov [sys_sleep_time], bl
ret
99 changes: 99 additions & 0 deletions bios/system/sys_sleep.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* Copyright (c) 2023, 2024 Adrian "asie" Siekierka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

.arch i186
.code16
.intel_syntax noprefix

#include "common.inc"

/**
* INT 17h AH=04h - sys_sleep
* Input:
* Output:
*/
.global sys_sleep
sys_sleep:
pusha

push ds
push ss
pop ds

// BL = old interrupt mask
in al, IO_HWINT_ENABLE
mov bl, al

// Sleep until VBlank
// TODO: Is this necessary?
mov al, HWINT_VBLANK
// out IO_HWINT_ACK, al
out IO_HWINT_ENABLE, al
hlt
nop
// out IO_HWINT_ACK, al

// Turn off LCD panel
in al, IO_LCD_CTRL
// BH = old LCD control
mov bh, al
or al, LCD_SLEEP_MASK
out IO_LCD_CTRL, al

// Sleep given provided mask
mov al, [sys_keepalive_int]

// out IO_HWINT_ACK, al
out IO_HWINT_ENABLE, al
1:
hlt
nop
// out IO_HWINT_ACK, al

call __key_scan
mov ax, cx
test ax, ax
jz 1b
and ax, [sys_awake_key]
cmp ax, [sys_awake_key]
jne 1b

// Sleep until VBlank
// TODO: Is this necessary?
mov al, HWINT_VBLANK
// out IO_HWINT_ACK, al
out IO_HWINT_ENABLE, al
hlt
nop
// out IO_HWINT_ACK, al

// Restore LCD panel control
mov al, bh
out IO_LCD_CTRL, al
// Restore interrupt mask
mov al, bl
out IO_HWINT_ENABLE, al

pop ds

popa
ret
22 changes: 16 additions & 6 deletions bios/system/system.s
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ irq_system_handlers:
.word sys_interrupt_reset_hook
.word sys_wait
.word sys_get_tick_count
.word error_handle_irq23 // TODO: sys_sleep
.word error_handle_irq23 // TODO: sys_set_sleep_time
.word error_handle_irq23 // TODO: sys_get_sleep_time
.word error_handle_irq23 // TODO: sys_set_awake_key
.word error_handle_irq23 // TODO: sys_get_awake_key
.word error_handle_irq23 // TODO: sys_set_keepalive_int
.word sys_sleep
.word sys_set_sleep_time
.word sys_get_sleep_time
.word sys_set_awake_key
.word sys_get_awake_key
.word sys_set_keepalive_int
.word sys_get_ownerinfo
.word sys_suspend
.word sys_resume
Expand All @@ -55,3 +55,13 @@ irq_system_handlers:
irq_system_handler:
m_irq_table_handler irq_system_handlers, 22, 0, error_handle_irq23
iret

.section ".data"
.global sys_keepalive_int
sys_keepalive_int: .byte HWINT_KEY

.section ".bss"
.global sys_awake_key
sys_awake_key: .word 0
.global sys_sleep_time
sys_sleep_time: .byte 0
Loading

0 comments on commit ed231fc

Please sign in to comment.