forked from ry755/menuet32-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libmenuet: Initial commit with example
- Loading branch information
Showing
11 changed files
with
284 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "libmenuet.h" | ||
|
||
#include <stdint.h> | ||
|
||
void RedrawWindow(); | ||
|
||
void main() { | ||
RedrawWindow(); | ||
|
||
while (true) { | ||
uint32_t event = WaitForEvent(); | ||
switch (event) { | ||
case 1: { | ||
// redraw event | ||
RedrawWindow(); | ||
break; | ||
} | ||
|
||
case 3: { | ||
// button event | ||
uint32_t button = GetButtonID() >> 8; | ||
if (button == 1) | ||
EndApplication(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void RedrawWindow() { | ||
BeginRedraw(); | ||
DrawWindow(64, 64, 128, 128, 0xFFFFFF, "C TEST", NULL); | ||
DisplayText(32, 32, 0x10000000, "hi"); | ||
EndRedraw(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
libmenuet.a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
all: libmenuet.a | ||
|
||
libmenuet.a: src/libmenuet.asm $(wildcard src/*.asm) | ||
cd src && nasm -f elf -o ../$@ libmenuet.asm | ||
|
||
clean: | ||
rm -f libmenuet.a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef LIBMENUET_H | ||
#define LIBMENUET_H | ||
|
||
#include <stdint.h> | ||
|
||
#ifndef NULL | ||
#define NULL ((void*) 0x0) | ||
#endif | ||
|
||
#ifndef bool | ||
typedef int bool; | ||
#endif | ||
|
||
#ifndef true | ||
#define true 0x1 | ||
#endif | ||
|
||
#ifndef false | ||
#define false 0x0 | ||
#endif | ||
|
||
// application | ||
void EndApplication(); | ||
|
||
// button | ||
uint32_t GetButtonID(); | ||
|
||
// event | ||
uint32_t WaitForEvent(); | ||
uint32_t CheckForEvent(); | ||
|
||
// window | ||
void DrawWindow(uint16_t x_start, uint16_t y_start, uint16_t x_size, uint16_t y_size, uint32_t color, char *label, char *menu_struct); | ||
void PutPixel(uint32_t x, uint32_t y, uint32_t color); | ||
void DisplayText(uint16_t x, uint16_t y, uint32_t color, char *text); | ||
void BeginRedraw(); | ||
void EndRedraw(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
; void EndApplication(); | ||
global _EndApplication | ||
_EndApplication: | ||
push ebp | ||
mov ebp, esp | ||
pushad | ||
|
||
mov eax, -1 ; syscall -1 | ||
int 0x40 | ||
|
||
popad | ||
leave | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; uint32_t GetButtonID(); | ||
global _GetButtonID | ||
_GetButtonID: | ||
push ebp | ||
mov ebp, esp | ||
pushad | ||
|
||
mov eax, 17 ; syscall 17 | ||
int 0x40 | ||
mov dword [return], eax | ||
|
||
popad | ||
leave | ||
mov eax, dword [return] | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
bits 32 | ||
|
||
; __start must be here in order for the linker to not insert a jump before the Menuet header | ||
global __start | ||
__start: | ||
db 'MENUET01' ; 8 byte id | ||
dd 0x01 ; header version | ||
dd actual_start ; program start | ||
dd 0x00100000 ; program image size (FIXME: this should be the actual image size) | ||
dd 0x00100000 ; required amount of memory | ||
dd 0x0007F000 ; stack | ||
dd 0x00, 0x00 ; param,icon | ||
|
||
extern _main | ||
actual_start: | ||
call _main | ||
call _EndApplication | ||
jmp $ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
; uint32_t WaitForEvent(); | ||
global _WaitForEvent | ||
_WaitForEvent: | ||
push ebp | ||
mov ebp, esp | ||
pushad | ||
|
||
mov eax, 10 ; syscall 10 | ||
int 0x40 | ||
mov dword [return], eax | ||
|
||
popad | ||
leave | ||
mov eax, dword [return] | ||
ret | ||
|
||
; uint32_t CheckForEvent(); | ||
global _CheckForEvent | ||
_CheckForEvent: | ||
push ebp | ||
mov ebp, esp | ||
pushad | ||
|
||
mov eax, 11 ; syscall 11 | ||
int 0x40 | ||
mov dword [return], eax | ||
|
||
popad | ||
leave | ||
mov eax, dword [return] | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
bits 32 | ||
|
||
%include "crt0.asm" | ||
|
||
%include "application.asm" | ||
%include "button.asm" | ||
%include "event.asm" | ||
%include "window.asm" | ||
|
||
return: dd 0x00000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
; void DrawWindow( | ||
; uint16_t x_start, | ||
; uint16_t y_start, | ||
; uint16_t x_size, | ||
; uint16_t y_size, | ||
; uint32_t color, | ||
; char *label, | ||
; char *menu_struct | ||
; ); | ||
global _DrawWindow | ||
_DrawWindow: | ||
push ebp | ||
mov ebp, esp | ||
pushad | ||
|
||
mov eax, 0 ; syscall 0 | ||
movzx ebx, word [ebp + 8] ; x_start | ||
shl ebx, 16 | ||
mov bx, word [ebp + 16] ; x_size | ||
movzx ecx, word [ebp + 12] ; y_start | ||
shl ecx, 16 | ||
mov cx, word [ebp + 20] ; y_size | ||
mov edx, dword [ebp + 24] ; color | ||
and edx, 0x00FFFFFF | ||
or edx, 0x04000000 ; "skinned window with menu" | ||
mov esi, dword [ebp + 28] ; label | ||
mov edi, dword [ebp + 32] ; menu_struct | ||
int 0x40 | ||
|
||
popad | ||
leave | ||
ret | ||
|
||
; void PutPixel( | ||
; uint32_t x, | ||
; uint32_t y, | ||
; uint32_t color | ||
; ); | ||
global _PutPixel | ||
_PutPixel: | ||
push ebp | ||
mov ebp, esp | ||
pushad | ||
|
||
mov eax, 1 ; syscall 1 | ||
mov ebx, dword [ebp + 8] ; x | ||
mov ecx, dword [ebp + 12] ; y | ||
mov edx, dword [ebp + 16] ; color | ||
int 0x40 | ||
|
||
popad | ||
leave | ||
ret | ||
|
||
; void DisplayText( | ||
; uint16_t x, | ||
; uint16_t y, | ||
; uint32_t color, | ||
; char *text | ||
; ); | ||
global _DisplayText | ||
_DisplayText: | ||
push ebp | ||
mov ebp, esp | ||
pushad | ||
|
||
mov eax, 4 ; syscall 4 | ||
movzx ebx, word [ebp + 8] ; x | ||
shl ebx, 16 | ||
mov bx, word [ebp + 12] ; y | ||
mov ecx, dword [ebp + 16] ; color | ||
mov edx, dword [ebp + 20] ; text | ||
mov esi, -1 ; null-terminated string | ||
int 0x40 | ||
|
||
popad | ||
leave | ||
ret | ||
|
||
; void BeginRedraw(); | ||
global _BeginRedraw | ||
_BeginRedraw: | ||
push ebp | ||
mov ebp, esp | ||
pushad | ||
|
||
mov eax, 12 ; syscall 12 | ||
mov ebx, 1 ; begin redraw | ||
int 0x40 | ||
|
||
popad | ||
leave | ||
ret | ||
|
||
; void EndRedraw(); | ||
global _EndRedraw | ||
_EndRedraw: | ||
push ebp | ||
mov ebp, esp | ||
pushad | ||
|
||
mov eax, 12 ; syscall 12 | ||
mov ebx, 2 ; end redraw | ||
int 0x40 | ||
|
||
popad | ||
leave | ||
ret |